Switch Everything and Mentions Tabs order (IOS-240) (#1258)

* Switch Everything and Mentions Tabs order (IOS-240)

* Swap switch category (IOS-240)
This commit is contained in:
Marcus Kida 2024-03-14 07:19:46 +01:00 committed by GitHub
parent bfc20655c4
commit 0e207cf65d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 12 deletions

View File

@ -224,9 +224,9 @@ extension NotificationViewController {
switch category {
case .mentions:
scrollToPage(.first, animated: true, completion: nil)
case .everything:
scrollToPage(.last, animated: true, completion: nil)
case .everything:
scrollToPage(.first, animated: true, completion: nil)
}
}

View File

@ -31,14 +31,18 @@ final class NotificationViewModel {
private var lastPageIndex: Int {
get {
UserDefaults.shared.getLastSelectedNotificationsTab(
guard let selectedTabName = UserDefaults.shared.getLastSelectedNotificationsTabName(
accessToken: authContext.mastodonAuthenticationBox.userAuthorization.accessToken
)
), let scope = APIService.MastodonNotificationScope(rawValue: selectedTabName) else {
return 0
}
return APIService.MastodonNotificationScope.allCases.firstIndex(of: scope) ?? 0
}
set {
UserDefaults.shared.setLastSelectedNotificationsTab(
UserDefaults.shared.setLastSelectedNotificationsTabName(
accessToken: authContext.mastodonAuthenticationBox.userAuthorization.accessToken,
value: newValue
value: APIService.MastodonNotificationScope.allCases[newValue].rawValue
)
}
}

View File

@ -38,14 +38,14 @@ extension UserDefaults {
let count = getNotificationCountWithAccessToken(accessToken: accessToken)
setNotificationCountWithAccessToken(accessToken: accessToken, value: count + 1)
}
@objc public func getLastSelectedNotificationsTab(accessToken: String) -> Int {
@objc public func getLastSelectedNotificationsTabName(accessToken: String) -> String? {
let prefix = UserDefaults.notificationsLastTabIndexKeyPrefix
let key = UserDefaults.deriveKey(from: accessToken, prefix: prefix)
return integer(forKey: key)
return object(forKey: key) as? String
}
@objc public func setLastSelectedNotificationsTab(accessToken: String, value: Int) {
@objc public func setLastSelectedNotificationsTabName(accessToken: String, value: String?) {
let prefix = UserDefaults.notificationsLastTabIndexKeyPrefix
let key = UserDefaults.deriveKey(from: accessToken, prefix: prefix)
setValue(value, forKey: key)

View File

@ -14,9 +14,9 @@ import OSLog
extension APIService {
public enum MastodonNotificationScope: Hashable, CaseIterable {
case mentions
public enum MastodonNotificationScope: String, Hashable, CaseIterable {
case everything
case mentions
public var includeTypes: [MastodonNotificationType]? {
switch self {