disableDeleteChatSwipeOption + refactor restart alert

This commit is contained in:
Kylmakalle 2024-08-13 00:17:04 +03:00
parent 58f020eeef
commit 44fe90b317
5 changed files with 30 additions and 14 deletions

View File

@ -35,6 +35,7 @@ swift_library(
"//submodules/AccountContext:AccountContext", "//submodules/AccountContext:AccountContext",
"//submodules/AppBundle:AppBundle", "//submodules/AppBundle:AppBundle",
"//submodules/TelegramUI/Components/Settings/PeerNameColorScreen", "//submodules/TelegramUI/Components/Settings/PeerNameColorScreen",
"//submodules/UndoUI:UndoUI",
], ],
visibility = [ visibility = [
"//visibility:public", "//visibility:public",

View File

@ -22,6 +22,7 @@ import AccountContext
import AppBundle import AppBundle
import WebKit import WebKit
import PeerNameColorScreen import PeerNameColorScreen
import UndoUI
private enum SGControllerSection: Int32, SGItemListSection { private enum SGControllerSection: Int32, SGItemListSection {
@ -56,6 +57,7 @@ private enum SGBoolSetting: String {
case sendLargePhotos case sendLargePhotos
case storyStealthMode case storyStealthMode
case disableSwipeToRecordStory case disableSwipeToRecordStory
case disableDeleteChatSwipeOption
case quickTranslateButton case quickTranslateButton
case hideReactions case hideReactions
case showRepostToStory case showRepostToStory
@ -151,6 +153,7 @@ private func SGControllerEntries(presentationData: PresentationData, callListSet
entries.append(.header(id: id.count, section: .chatList, text: i18n("Settings.ChatList.Header", lang), badge: nil)) entries.append(.header(id: id.count, section: .chatList, text: i18n("Settings.ChatList.Header", lang), badge: nil))
entries.append(.toggle(id: id.count, section: .chatList, settingName: .compactChatList, value: SGSimpleSettings.shared.compactChatList, text: i18n("Settings.CompactChatList", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .chatList, settingName: .compactChatList, value: SGSimpleSettings.shared.compactChatList, text: i18n("Settings.CompactChatList", lang), enabled: true))
entries.append(.toggle(id: id.count, section: .chatList, settingName: .disableChatSwipeOptions, value: !SGSimpleSettings.shared.disableChatSwipeOptions, text: i18n("Settings.ChatSwipeOptions", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .chatList, settingName: .disableChatSwipeOptions, value: !SGSimpleSettings.shared.disableChatSwipeOptions, text: i18n("Settings.ChatSwipeOptions", lang), enabled: true))
entries.append(.toggle(id: id.count, section: .chatList, settingName: .disableDeleteChatSwipeOption, value: !SGSimpleSettings.shared.disableDeleteChatSwipeOption, text: i18n("Settings.DeleteChatSwipeOption", lang), enabled: !SGSimpleSettings.shared.disableChatSwipeOptions))
entries.append(.header(id: id.count, section: .profiles, text: i18n("Settings.Profiles.Header", lang), badge: nil)) entries.append(.header(id: id.count, section: .profiles, text: i18n("Settings.Profiles.Header", lang), badge: nil))
entries.append(.toggle(id: id.count, section: .profiles, settingName: .showProfileId, value: SGSettings.showProfileId, text: i18n("Settings.ShowProfileID", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .profiles, settingName: .showProfileId, value: SGSettings.showProfileId, text: i18n("Settings.ShowProfileID", lang), enabled: true))
@ -386,6 +389,10 @@ public func sgSettingsController(context: AccountContext/*, focusOnItemTag: Int?
SGSimpleSettings.shared.disableScrollToNextTopic = !value SGSimpleSettings.shared.disableScrollToNextTopic = !value
case .disableChatSwipeOptions: case .disableChatSwipeOptions:
SGSimpleSettings.shared.disableChatSwipeOptions = !value SGSimpleSettings.shared.disableChatSwipeOptions = !value
simplePromise.set(true) // Trigger update for 'enabled' field of other toggles
askForRestart?()
case .disableDeleteChatSwipeOption:
SGSimpleSettings.shared.disableDeleteChatSwipeOption = !value
askForRestart?() askForRestart?()
case .disableGalleryCamera: case .disableGalleryCamera:
SGSimpleSettings.shared.disableGalleryCamera = !value SGSimpleSettings.shared.disableGalleryCamera = !value
@ -622,18 +629,19 @@ public func sgSettingsController(context: AccountContext/*, focusOnItemTag: Int?
return return
} }
let presentationData = context.sharedContext.currentPresentationData.with { $0 } let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let actionSheet = ActionSheetController(presentationData: presentationData) presentControllerImpl?(
actionSheet.setItemGroups([ActionSheetItemGroup(items: [ UndoOverlayController(
ActionSheetTextItem(title: i18n("Common.RestartRequired", presentationData.strings.baseLanguageCode)), presentationData: presentationData,
ActionSheetButtonItem(title: i18n("Common.RestartNow", presentationData.strings.baseLanguageCode), color: .destructive, font: .default, action: { content: .info(title: nil, // i18n("Common.RestartRequired", presentationData.strings.baseLanguageCode),
exit(0) text: i18n("Common.RestartRequired", presentationData.strings.baseLanguageCode),
}) timeout: nil,
]), ActionSheetItemGroup(items: [ customUndoText: i18n("Common.RestartNow", presentationData.strings.baseLanguageCode) //presentationData.strings.Common_Yes
ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in ),
actionSheet?.dismissAnimated() elevatedLayout: false,
}) action: { action in if action == .undo { exit(0) }; return true }
])]) ),
presentControllerImpl?(actionSheet, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) nil
)
} }
return controller return controller

View File

@ -80,6 +80,7 @@ public class SGSimpleSettings {
case disableScrollToNextChannel case disableScrollToNextChannel
case disableScrollToNextTopic case disableScrollToNextTopic
case disableChatSwipeOptions case disableChatSwipeOptions
case disableDeleteChatSwipeOption
case disableGalleryCamera case disableGalleryCamera
case disableSendAsButton case disableSendAsButton
case disableSnapDeletionEffect case disableSnapDeletionEffect
@ -168,6 +169,7 @@ public class SGSimpleSettings {
Keys.disableScrollToNextChannel.rawValue: false, Keys.disableScrollToNextChannel.rawValue: false,
Keys.disableScrollToNextTopic.rawValue: false, Keys.disableScrollToNextTopic.rawValue: false,
Keys.disableChatSwipeOptions.rawValue: false, Keys.disableChatSwipeOptions.rawValue: false,
Keys.disableDeleteChatSwipeOption.rawValue: false,
Keys.disableGalleryCamera.rawValue: false, Keys.disableGalleryCamera.rawValue: false,
Keys.disableSendAsButton.rawValue: false, Keys.disableSendAsButton.rawValue: false,
Keys.disableSnapDeletionEffect.rawValue: false, Keys.disableSnapDeletionEffect.rawValue: false,
@ -289,6 +291,9 @@ public class SGSimpleSettings {
@UserDefault(key: Keys.disableChatSwipeOptions.rawValue) @UserDefault(key: Keys.disableChatSwipeOptions.rawValue)
public var disableChatSwipeOptions: Bool public var disableChatSwipeOptions: Bool
@UserDefault(key: Keys.disableDeleteChatSwipeOption.rawValue)
public var disableDeleteChatSwipeOption: Bool
@UserDefault(key: Keys.disableGalleryCamera.rawValue) @UserDefault(key: Keys.disableGalleryCamera.rawValue)
public var disableGalleryCamera: Bool public var disableGalleryCamera: Bool

View File

@ -100,6 +100,7 @@
"Settings.ChatSwipeOptions" = "Chat List Swipe Options"; "Settings.ChatSwipeOptions" = "Chat List Swipe Options";
"Settings.DeleteChatSwipeOption" = "Swipe to Delete Chat";
/* Re-word like this string on offical app https://translations.telegram.org/en/ios/groups_and_channels/Chat.NextChannelSameLocationSwipeProgress */ /* Re-word like this string on offical app https://translations.telegram.org/en/ios/groups_and_channels/Chat.NextChannelSameLocationSwipeProgress */
"Settings.PullToNextChannel" = "Pull to Next Unread Channel"; "Settings.PullToNextChannel" = "Pull to Next Unread Channel";
/* Re-word like this string on offical app https://translations.telegram.org/en/ios/groups_and_channels/Chat.NextUnreadTopicSwipeProgress */ /* Re-word like this string on offical app https://translations.telegram.org/en/ios/groups_and_channels/Chat.NextUnreadTopicSwipeProgress */

View File

@ -619,7 +619,7 @@ private func revealOptions(strings: PresentationStrings, theme: PresentationThem
} }
} }
} }
if canDelete { if canDelete && !SGSimpleSettings.shared.disableDeleteChatSwipeOption {
options.append(ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: strings.Common_Delete, icon: deleteIcon, color: theme.list.itemDisclosureActions.destructive.fillColor, textColor: theme.list.itemDisclosureActions.destructive.foregroundColor)) options.append(ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: strings.Common_Delete, icon: deleteIcon, color: theme.list.itemDisclosureActions.destructive.fillColor, textColor: theme.list.itemDisclosureActions.destructive.foregroundColor))
} }
if case .savedMessagesChats = location { if case .savedMessagesChats = location {
@ -707,7 +707,7 @@ private func forumThreadRevealOptions(strings: PresentationStrings, theme: Prese
} }
} }
} }
if canDelete { if canDelete && !SGSimpleSettings.shared.disableDeleteChatSwipeOption {
options.append(ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: strings.Common_Delete, icon: deleteIcon, color: theme.list.itemDisclosureActions.destructive.fillColor, textColor: theme.list.itemDisclosureActions.destructive.foregroundColor)) options.append(ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: strings.Common_Delete, icon: deleteIcon, color: theme.list.itemDisclosureActions.destructive.fillColor, textColor: theme.list.itemDisclosureActions.destructive.foregroundColor))
} }
if canOpenClose { if canOpenClose {
@ -3282,6 +3282,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
ItemListRevealOption(key: RevealOptionKey.edit.rawValue, title: item.presentationData.strings.ChatList_ItemMenuEdit, icon: .none, color: item.presentationData.theme.list.itemDisclosureActions.neutral2.fillColor, textColor: item.presentationData.theme.list.itemDisclosureActions.neutral2.foregroundColor), ItemListRevealOption(key: RevealOptionKey.edit.rawValue, title: item.presentationData.strings.ChatList_ItemMenuEdit, icon: .none, color: item.presentationData.theme.list.itemDisclosureActions.neutral2.fillColor, textColor: item.presentationData.theme.list.itemDisclosureActions.neutral2.foregroundColor),
ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: item.presentationData.strings.ChatList_ItemMenuDelete, icon: .none, color: item.presentationData.theme.list.itemDisclosureActions.destructive.fillColor, textColor: item.presentationData.theme.list.itemDisclosureActions.destructive.foregroundColor) ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: item.presentationData.strings.ChatList_ItemMenuDelete, icon: .none, color: item.presentationData.theme.list.itemDisclosureActions.destructive.fillColor, textColor: item.presentationData.theme.list.itemDisclosureActions.destructive.foregroundColor)
] ]
if SGSimpleSettings.shared.disableDeleteChatSwipeOption { peerRevealOptions.removeLast() }
} else { } else {
peerRevealOptions = [] peerRevealOptions = []
} }