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:
parent
bfc20655c4
commit
0e207cf65d
|
@ -224,9 +224,9 @@ extension NotificationViewController {
|
||||||
|
|
||||||
switch category {
|
switch category {
|
||||||
case .mentions:
|
case .mentions:
|
||||||
scrollToPage(.first, animated: true, completion: nil)
|
|
||||||
case .everything:
|
|
||||||
scrollToPage(.last, animated: true, completion: nil)
|
scrollToPage(.last, animated: true, completion: nil)
|
||||||
|
case .everything:
|
||||||
|
scrollToPage(.first, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,18 @@ final class NotificationViewModel {
|
||||||
|
|
||||||
private var lastPageIndex: Int {
|
private var lastPageIndex: Int {
|
||||||
get {
|
get {
|
||||||
UserDefaults.shared.getLastSelectedNotificationsTab(
|
guard let selectedTabName = UserDefaults.shared.getLastSelectedNotificationsTabName(
|
||||||
accessToken: authContext.mastodonAuthenticationBox.userAuthorization.accessToken
|
accessToken: authContext.mastodonAuthenticationBox.userAuthorization.accessToken
|
||||||
)
|
), let scope = APIService.MastodonNotificationScope(rawValue: selectedTabName) else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return APIService.MastodonNotificationScope.allCases.firstIndex(of: scope) ?? 0
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.shared.setLastSelectedNotificationsTab(
|
UserDefaults.shared.setLastSelectedNotificationsTabName(
|
||||||
accessToken: authContext.mastodonAuthenticationBox.userAuthorization.accessToken,
|
accessToken: authContext.mastodonAuthenticationBox.userAuthorization.accessToken,
|
||||||
value: newValue
|
value: APIService.MastodonNotificationScope.allCases[newValue].rawValue
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,14 +38,14 @@ extension UserDefaults {
|
||||||
let count = getNotificationCountWithAccessToken(accessToken: accessToken)
|
let count = getNotificationCountWithAccessToken(accessToken: accessToken)
|
||||||
setNotificationCountWithAccessToken(accessToken: accessToken, value: count + 1)
|
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 prefix = UserDefaults.notificationsLastTabIndexKeyPrefix
|
||||||
let key = UserDefaults.deriveKey(from: accessToken, prefix: prefix)
|
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 prefix = UserDefaults.notificationsLastTabIndexKeyPrefix
|
||||||
let key = UserDefaults.deriveKey(from: accessToken, prefix: prefix)
|
let key = UserDefaults.deriveKey(from: accessToken, prefix: prefix)
|
||||||
setValue(value, forKey: key)
|
setValue(value, forKey: key)
|
||||||
|
|
|
@ -14,9 +14,9 @@ import OSLog
|
||||||
|
|
||||||
extension APIService {
|
extension APIService {
|
||||||
|
|
||||||
public enum MastodonNotificationScope: Hashable, CaseIterable {
|
public enum MastodonNotificationScope: String, Hashable, CaseIterable {
|
||||||
case mentions
|
|
||||||
case everything
|
case everything
|
||||||
|
case mentions
|
||||||
|
|
||||||
public var includeTypes: [MastodonNotificationType]? {
|
public var includeTypes: [MastodonNotificationType]? {
|
||||||
switch self {
|
switch self {
|
||||||
|
|
Loading…
Reference in New Issue