From 779901c2fc06ea2441afc26fc1e65b6c8cbbc3d7 Mon Sep 17 00:00:00 2001 From: Maxime Marinel Date: Wed, 7 Aug 2024 13:53:14 +0200 Subject: [PATCH] Add new sorting option on reading time --- App/Features/Entry/EntriesListView.swift | 18 +++++++++++-- App/Features/Entry/EntriesView.swift | 34 +++++++++++++++--------- App/fr.lproj/Localizable.strings | 4 +++ wallabag.xcodeproj/project.pbxproj | 4 +-- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/App/Features/Entry/EntriesListView.swift b/App/Features/Entry/EntriesListView.swift index f9f5fa1d..b494967e 100644 --- a/App/Features/Entry/EntriesListView.swift +++ b/App/Features/Entry/EntriesListView.swift @@ -7,10 +7,24 @@ struct EntriesListView: View { @Environment(AppSync.self) var appSync: AppSync @FetchRequest var entries: FetchedResults - init(predicate: NSPredicate, entriesSortAscending: Bool) { + init( + predicate: NSPredicate, + entriesSortedById: Bool, + entriesSortedByReadingTime: Bool, + entriesSortedByAscending: Bool + ) { + var sortDescriptors: [NSSortDescriptor] = [] + if entriesSortedById { + sortDescriptors.append(NSSortDescriptor(key: "id", ascending: entriesSortedByAscending)) + } + + if entriesSortedByReadingTime { + sortDescriptors.append(NSSortDescriptor(key: "readingTime", ascending: entriesSortedByAscending)) + } + _entries = FetchRequest( entity: Entry.entity(), - sortDescriptors: [NSSortDescriptor(key: "id", ascending: entriesSortAscending)], + sortDescriptors: sortDescriptors, predicate: predicate, animation: nil ) } diff --git a/App/Features/Entry/EntriesView.swift b/App/Features/Entry/EntriesView.swift index f8f1e903..d5fdf785 100644 --- a/App/Features/Entry/EntriesView.swift +++ b/App/Features/Entry/EntriesView.swift @@ -6,7 +6,9 @@ struct EntriesView: View { @Environment(Router.self) var router: Router @EnvironmentObject var appState: AppState @StateObject var searchViewModel = SearchViewModel() - @State var entriesSortAscending = false + @State var entriesSortedById = true + @State var entriesSortedByReadingTime = false + @State var entriesSortedByAscending = false var body: some View { VStack { @@ -14,19 +16,27 @@ struct EntriesView: View { PasteBoardView() #endif SearchView(searchViewModel: searchViewModel) - EntriesListView(predicate: searchViewModel.predicate, entriesSortAscending: entriesSortAscending) + EntriesListView( + predicate: searchViewModel.predicate, + entriesSortedById: entriesSortedById, + entriesSortedByReadingTime: entriesSortedByReadingTime, + entriesSortedByAscending: entriesSortedByAscending + ) + } + .onChange(of: entriesSortedByReadingTime) { _, _ in + entriesSortedById = false } .toolbar { - ToolbarItem(placement: .navigationBarTrailing) { - HStack { - Button(action: { - entriesSortAscending.toggle() - }, label: { - Image(systemName: "line.3.horizontal.decrease.circle") - .rotationEffect(.degrees(entriesSortAscending ? 180 : 0)) - }) - RefreshButton() - } + ToolbarItemGroup(placement: .navigationBarTrailing) { + Menu(content: { + Toggle("Order by id", systemImage: "line.3.horizontal.decrease.circle", isOn: $entriesSortedById) + Toggle("Order by reading time", systemImage: "clock.arrow.circlepath", isOn: $entriesSortedByReadingTime) + Divider() + Toggle("Sorting", systemImage: entriesSortedByAscending ? "arrow.up.circle" : "arrow.down.circle", isOn: $entriesSortedByAscending) + }, label: { + Label("Sort options", systemImage: "line.3.horizontal.decrease.circle") + }) + RefreshButton() } ToolbarItem(placement: .navigationBarLeading) { Menu(content: { diff --git a/App/fr.lproj/Localizable.strings b/App/fr.lproj/Localizable.strings index e09d6edc..ace35faf 100644 --- a/App/fr.lproj/Localizable.strings +++ b/App/fr.lproj/Localizable.strings @@ -50,3 +50,7 @@ //Player "Select one entry" = "Sélectionnez une entrée"; "Confirm delete?" = "Confirmer la suppression ?"; + +"Order by id" = "Trier par id"; +"Order by reading time" = "Trier par temps de lecture"; +"Sorting" = "Tri"; diff --git a/wallabag.xcodeproj/project.pbxproj b/wallabag.xcodeproj/project.pbxproj index 6628ecab..f2806943 100644 --- a/wallabag.xcodeproj/project.pbxproj +++ b/wallabag.xcodeproj/project.pbxproj @@ -1271,7 +1271,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 17.0; - MARKETING_VERSION = 7.2.4; + MARKETING_VERSION = 7.3.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -1330,7 +1330,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 17.0; - MARKETING_VERSION = 7.2.4; + MARKETING_VERSION = 7.3.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SWIFT_COMPILATION_MODE = wholemodule;