Skip to content

Commit

Permalink
Improved time zone support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MadeiraAlexandre committed Aug 29, 2023
1 parent 1fd39a4 commit 568edcd
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 296 deletions.
2 changes: 0 additions & 2 deletions Shared/Configuration/Story (iOS).entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Shared/Extensions/Episode-Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Episode {
guard let date else { return false }
return Date() >= date
}
// MARK: URL
var itemImageMedium: URL? {
#if os(tvOS)
Expand Down
11 changes: 3 additions & 8 deletions Shared/Extensions/ItemContent-Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,9 @@ extension ItemContent {
return ""
}
var itemRating: String? {
if let voteAverage {
if voteAverage <= 0.9 {
return nil
} else {
return NSLocalizedString("\(voteAverage.rounded(.down))/10", comment: "")
}
}
return nil
guard let voteAverage else { return nil }
let formattedString = String(format: "%.1f", voteAverage)
return "\(formattedString)/10"
}

// MARK: Double
Expand Down
21 changes: 20 additions & 1 deletion Shared/Helpers/EpisodeHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,26 @@ class EpisodeHelper {
} catch {
if Task.isCancelled { return nil }
let message = "Episode:\(episode.seasonNumber as Any)\nSeason:\(episode.seasonNumber as Any)\nShow: \(show).\nError: \(error.localizedDescription)"
CronicaTelemetry.shared.handleMessage(message, for: "EpisodeHelper.fetchNextEpisode")
guard let showContent = try? await network.fetchItem(id: show, type: .tvShow) else {
CronicaTelemetry.shared.handleMessage(message, for: "EpisodeHelper.fetchNextEpisode")
return nil
}
let lastEpisodeToAir = showContent.lastEpisodeToAir
guard let lastEpisodeToAir else {
CronicaTelemetry.shared.handleMessage(message, for: "EpisodeHelper.fetchNextEpisode")
return nil
}
if lastEpisodeToAir.itemEpisodeNumber == episode.itemEpisodeNumber {
let hasLastEpisodeReleased = lastEpisodeToAir.isItemReleased
if showContent.itemStatus == .ended && hasLastEpisodeReleased {
let contentId = "\(show)@\(MediaType.tvShow.toInt)"
guard let watchlistItem = PersistenceController.shared.fetch(for: contentId) else {
CronicaTelemetry.shared.handleMessage(message, for: "EpisodeHelper.fetchNextEpisode")
return nil
}
PersistenceController.shared.updateWatched(for: watchlistItem)
}
}
return nil
}
}
Expand Down
5 changes: 4 additions & 1 deletion Shared/Manager/DatesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ class DatesManager {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
return decoder
return decoder
}()
static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.timeZone = .current
formatter.dateFormat = "y,MM,dd"
return formatter
}()
static let dateString: DateFormatter = {
let formatter = DateFormatter()
formatter.timeZone = .current
formatter.dateStyle = .medium
formatter.timeStyle = .none
return formatter
}()
private static var releaseDateFormatter: ISO8601DateFormatter {
let formatter = ISO8601DateFormatter()
formatter.timeZone = .current
formatter.formatOptions = .withFullDate
return formatter
}
Expand Down
11 changes: 10 additions & 1 deletion Shared/Store/SettingsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ class SettingsStore: ObservableObject {
@AppStorage("displayDeveloperSettings") var displayDeveloperSettings = false
@AppStorage("gesture") var gesture: UpdateItemProperties = .favorite
@AppStorage("appThemeColor") var appTheme: AppThemeColors = .blue
#if os(iOS)
@AppStorage("watchlistStyle") var watchlistStyle: SectionDetailsPreferredStyle = UIDevice.isIPhone ? .list : .poster
#else
@AppStorage("watchlistStyle") var watchlistStyle: SectionDetailsPreferredStyle = .card
#endif
@AppStorage("disableTranslucentBackground") var disableTranslucent = false
@AppStorage("user_theme") var currentTheme: AppTheme = .system
@AppStorage("openInYouTube") var openInYouTube = false
Expand All @@ -36,7 +40,11 @@ class SettingsStore: ObservableObject {
#else
@AppStorage("itemContentListDisplayType") var listsDisplayType: ItemContentListPreferredDisplayType = .standard
#endif
#if os(iOS)
@AppStorage("exploreDisplayType") var sectionStyleType: SectionDetailsPreferredStyle = UIDevice.isIPhone ? .card : .poster
#else
@AppStorage("exploreDisplayType") var sectionStyleType: SectionDetailsPreferredStyle = .card
#endif
@AppStorage("preferCompactUI") var isCompactUI = false
@AppStorage("selectedWatchProviderEnabled") var isSelectedWatchProviderEnabled = false
@AppStorage("selectedWatchProviders") var selectedWatchProviders = ""
Expand All @@ -60,7 +68,8 @@ class SettingsStore: ObservableObject {
#endif
@AppStorage("shareLinkPreference") var shareLinkPreference: ShareLinkPreference = .tmdb
@AppStorage("upNextStyle") var upNextStyle: UpNextDetailsPreferredStyle = .card
@AppStorage("showDateOnWatchlistRow") var showDateOnWatchlist = false
@AppStorage("showDateOnWatchlistRow") var showDateOnWatchlist = true
@AppStorage("disableSearchFilter") var disableSearchFilter = false
#if os(macOS)
@AppStorage("quitAppWhenClosingWindow") var quitApp = false
#endif
Expand Down
2 changes: 1 addition & 1 deletion Shared/View/Components/OverviewBoxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct OverviewBoxView: View {
#endif
}
} label: {
Text("About")
Text(type == .person ? "Biography" : "About")
.unredacted()
}
.onTapGesture {
Expand Down
36 changes: 28 additions & 8 deletions Shared/View/CustomList/DefaultWatchlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ struct DefaultWatchlist: View {
}
.padding(.horizontal, 64)
}
if smartFiltersItems.isEmpty {
empty
} else {
WatchlistCardSection(items: smartFiltersItems,
title: "Search results", showPopup: $showPopup, popupType: $popupType)
}
if smartFiltersItems.isEmpty {
empty
} else {
WatchlistCardSection(items: smartFiltersItems,
title: "Search results", showPopup: $showPopup, popupType: $popupType)
}
}
#else
if items.isEmpty {
Expand Down Expand Up @@ -173,7 +173,7 @@ struct DefaultWatchlist: View {
}
}
}
#endif
#endif
}
.sheet(isPresented: $showFilter) {
NavigationStack {
Expand Down Expand Up @@ -203,8 +203,8 @@ struct DefaultWatchlist: View {
}
#elseif os(macOS)
HStack {
sortButton
filterButton
sortButton
styleButton
}
#endif
Expand Down Expand Up @@ -259,6 +259,15 @@ struct DefaultWatchlist: View {
private var sortButton: some View {
#if os(tvOS)
EmptyView()
#elseif os(macOS)
Picker(selection: $sortOrder) {
ForEach(WatchlistSortOrder.allCases) { item in
Text(item.localizableName).tag(item)
}
} label: {
Label("Sort Order", systemImage: "arrow.up.arrow.down.circle")
.labelStyle(.iconOnly)
}
#else
Menu {
Picker(selection: $sortOrder) {
Expand All @@ -277,6 +286,16 @@ struct DefaultWatchlist: View {

#if os(iOS) || os(macOS)
private var styleButton: some View {
#if os(macOS)
Picker(selection: $settings.watchlistStyle) {
ForEach(SectionDetailsPreferredStyle.allCases) { item in
Text(item.title).tag(item)
}
} label: {
Label("watchlistDisplayTypePicker", systemImage: "circle.grid.2x2")
.labelStyle(.iconOnly)
}
#else
Menu {
Picker(selection: $settings.watchlistStyle) {
ForEach(SectionDetailsPreferredStyle.allCases) { item in
Expand All @@ -289,6 +308,7 @@ struct DefaultWatchlist: View {
Label("watchlistDisplayTypePicker", systemImage: "circle.grid.2x2")
.labelStyle(.iconOnly)
}
#endif
}
#endif

Expand Down
1 change: 0 additions & 1 deletion Shared/View/ItemContent/Platform/ItemContentPadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ struct ItemContentPadView: View {

}

AttributionView().padding([.top, .bottom])
}
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ struct ItemContentPhoneView: View {
dismiss: $showReleaseDateInfo)
}

AttributionView().padding([.top, .bottom])
}
.navigationTitle(navigationTitle)
.navigationBarTitleDisplayMode(.inline)
Expand Down
72 changes: 37 additions & 35 deletions Shared/View/Keywords/TrendingKeywordsListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,43 @@ struct TrendingKeywordsListView: View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(viewModel.trendingKeywords) { keyword in
NavigationLink(value: keyword) {
WebImage(url: keyword.image, options: [.continueInBackground, .highPriority])
.resizable()
.placeholder {
ZStack {
Rectangle().fill(.gray.gradient)
}
}
.aspectRatio(contentMode: .fill)
.overlay {
ZStack {
Rectangle().fill(.black.opacity(0.5))
VStack {
Spacer()
HStack {
Text(keyword.name)
.foregroundColor(.white)
.font(.subheadline)
.fontWeight(.semibold)
.multilineTextAlignment(.leading)
.lineLimit(2)
Spacer()
}
.padding(.horizontal)
.padding(.bottom, 8)
}
}
}
.frame(width: 160, height: 100, alignment: .center)
.clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
.shadow(radius: 2)
.buttonStyle(.plain)
}
.disabled(viewModel.isLoadingTrendingKeywords)
.frame(width: 160, height: 100, alignment: .center)
if keyword.image != nil {
NavigationLink(value: keyword) {
WebImage(url: keyword.image, options: [.continueInBackground, .highPriority])
.resizable()
.placeholder {
ZStack {
Rectangle().fill(.gray.gradient)
}
}
.aspectRatio(contentMode: .fill)
.overlay {
ZStack {
Rectangle().fill(.black.opacity(0.5))
VStack {
Spacer()
HStack {
Text(keyword.name)
.foregroundColor(.white)
.font(.subheadline)
.fontWeight(.semibold)
.multilineTextAlignment(.leading)
.lineLimit(2)
Spacer()
}
.padding(.horizontal)
.padding(.bottom, 8)
}
}
}
.frame(width: 160, height: 100, alignment: .center)
.clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
.shadow(radius: 2)
.buttonStyle(.plain)
}
.disabled(viewModel.isLoadingTrendingKeywords)
.frame(width: 160, height: 100, alignment: .center)
}
}
}
.padding([.horizontal, .bottom])
Expand Down
Loading

0 comments on commit 568edcd

Please sign in to comment.