mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-03 16:41:26 +01:00
feat(android,ios): open the library the way it was last sorted
Sort order and franchise folding reset on every launch on both phones. They are kept with the front end's own settings now, and Android reads them before the first grid is drawn, off the main thread.
This commit is contained in:
1 parent
d154002109
commit
9d72acce88
4 files changed
+60
-4
No files matched your search
@@ -44,8 +44,9 @@ final class AppModel {
|
||||
/// `grouped`, and the shelves above it. Nil until the bridge has answered,
|
||||
/// when the grid falls back to `titles` as they are.
|
||||
var arrangement: ArrangementRecord?
|
||||
var sort: LibrarySort = .name
|
||||
var grouped = true
|
||||
/// As the viewer last left them.
|
||||
var sort: LibrarySort = SettingsStore().librarySort
|
||||
var grouped = SettingsStore().libraryGrouped
|
||||
var shares: [ShareRecord] = []
|
||||
var offline: [OfflineRecord] = []
|
||||
var metadataSettings = MetadataSettingsRecord(enabled: false, provider: .aniList, language: "en", ready: true)
|
||||
@@ -105,6 +106,9 @@ final class AppModel {
|
||||
func arrange(_ sort: LibrarySort, _ grouped: Bool) {
|
||||
self.sort = sort
|
||||
self.grouped = grouped
|
||||
let settings = SettingsStore()
|
||||
settings.librarySort = sort
|
||||
settings.libraryGrouped = grouped
|
||||
Task { await reloadLibrary(query) }
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,23 @@ struct SettingsStore {
|
||||
|
||||
static func gibToBytes(_ gib: Int) -> UInt64 { UInt64(gib) * 1024 * 1024 * 1024 }
|
||||
|
||||
/// How the library was last sorted; `.name` until the viewer chooses.
|
||||
var librarySort: LibrarySort {
|
||||
get {
|
||||
let stored = defaults.string(forKey: Key.librarySort)
|
||||
return Self.sorts.first { String(describing: $0) == stored } ?? .name
|
||||
}
|
||||
nonmutating set { defaults.set(String(describing: newValue), forKey: Key.librarySort) }
|
||||
}
|
||||
|
||||
/// Whether the library folds each franchise into one tile.
|
||||
var libraryGrouped: Bool {
|
||||
get { bool(Key.libraryGrouped, default: true) }
|
||||
nonmutating set { defaults.set(newValue, forKey: Key.libraryGrouped) }
|
||||
}
|
||||
|
||||
private static let sorts: [LibrarySort] = [.name, .recent, .added, .release, .rating, .popularity]
|
||||
|
||||
private func bool(_ key: String, default value: Bool) -> Bool {
|
||||
defaults.object(forKey: key) as? Bool ?? value
|
||||
}
|
||||
@@ -51,5 +68,7 @@ struct SettingsStore {
|
||||
static let backgroundAudio = "background_audio"
|
||||
static let hardwareDecoding = "hardware_decoding"
|
||||
static let cacheBudgetGib = "cache_budget_gib"
|
||||
static let librarySort = "library_sort"
|
||||
static let libraryGrouped = "library_grouped"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user