Show seconds in messages option

This commit is contained in:
kukuruzka 2025-03-09 02:40:38 +02:00
parent af7abe56b1
commit 1ae0544c1b
4 changed files with 51 additions and 2 deletions

View File

@ -93,6 +93,7 @@ private enum SGBoolSetting: String {
case wideChannelPosts case wideChannelPosts
case forceEmojiTab case forceEmojiTab
case forceBuiltInMic case forceBuiltInMic
case secondsInMessages
case hideChannelBottomButton case hideChannelBottomButton
case confirmCalls case confirmCalls
case swipeForVideoPIP case swipeForVideoPIP
@ -260,6 +261,7 @@ private func SGControllerEntries(presentationData: PresentationData, callListSet
entries.append(.toggle(id: id.count, section: .other, settingName: .wideChannelPosts, value: SGSimpleSettings.shared.wideChannelPosts, text: i18n("Settings.wideChannelPosts", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .other, settingName: .wideChannelPosts, value: SGSimpleSettings.shared.wideChannelPosts, text: i18n("Settings.wideChannelPosts", lang), enabled: true))
entries.append(.toggle(id: id.count, section: .other, settingName: .forceBuiltInMic, value: SGSimpleSettings.shared.forceBuiltInMic, text: i18n("Settings.forceBuiltInMic", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .other, settingName: .forceBuiltInMic, value: SGSimpleSettings.shared.forceBuiltInMic, text: i18n("Settings.forceBuiltInMic", lang), enabled: true))
entries.append(.notice(id: id.count, section: .other, text: i18n("Settings.forceBuiltInMic.Notice", lang))) entries.append(.notice(id: id.count, section: .other, text: i18n("Settings.forceBuiltInMic.Notice", lang)))
entries.append(.toggle(id: id.count, section: .other, settingName: .secondsInMessages, value: SGSimpleSettings.shared.secondsInMessages, text: i18n("Settings.secondsInMessages", lang), enabled: true))
entries.append(.toggle(id: id.count, section: .other, settingName: .messageDoubleTapActionOutgoingEdit, value: SGSimpleSettings.shared.messageDoubleTapActionOutgoing == SGSimpleSettings.MessageDoubleTapAction.edit.rawValue, text: i18n("Settings.messageDoubleTapActionOutgoingEdit", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .other, settingName: .messageDoubleTapActionOutgoingEdit, value: SGSimpleSettings.shared.messageDoubleTapActionOutgoing == SGSimpleSettings.MessageDoubleTapAction.edit.rawValue, text: i18n("Settings.messageDoubleTapActionOutgoingEdit", lang), enabled: true))
entries.append(.toggle(id: id.count, section: .other, settingName: .hideRecordingButton, value: !SGSimpleSettings.shared.hideRecordingButton, text: i18n("Settings.RecordingButton", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .other, settingName: .hideRecordingButton, value: !SGSimpleSettings.shared.hideRecordingButton, text: i18n("Settings.RecordingButton", lang), enabled: true))
entries.append(.toggle(id: id.count, section: .other, settingName: .disableSnapDeletionEffect, value: !SGSimpleSettings.shared.disableSnapDeletionEffect, text: i18n("Settings.SnapDeletionEffect", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .other, settingName: .disableSnapDeletionEffect, value: !SGSimpleSettings.shared.disableSnapDeletionEffect, text: i18n("Settings.SnapDeletionEffect", lang), enabled: true))
@ -465,6 +467,8 @@ public func sgSettingsController(context: AccountContext/*, focusOnItemTag: Int?
SGSimpleSettings.shared.forceBuiltInMic = value SGSimpleSettings.shared.forceBuiltInMic = value
case .hideChannelBottomButton: case .hideChannelBottomButton:
SGSimpleSettings.shared.hideChannelBottomButton = !value SGSimpleSettings.shared.hideChannelBottomButton = !value
case .secondsInMessages:
SGSimpleSettings.shared.secondsInMessages = value
case .confirmCalls: case .confirmCalls:
SGSimpleSettings.shared.confirmCalls = value SGSimpleSettings.shared.confirmCalls = value
case .swipeForVideoPIP: case .swipeForVideoPIP:

View File

@ -118,6 +118,7 @@ public class SGSimpleSettings {
case wideChannelPosts case wideChannelPosts
case forceEmojiTab case forceEmojiTab
case forceBuiltInMic case forceBuiltInMic
case secondsInMessages
case hideChannelBottomButton case hideChannelBottomButton
case forceSystemSharing case forceSystemSharing
case confirmCalls case confirmCalls
@ -418,6 +419,9 @@ public class SGSimpleSettings {
@UserDefault(key: Keys.forceBuiltInMic.rawValue) @UserDefault(key: Keys.forceBuiltInMic.rawValue)
public var forceBuiltInMic: Bool public var forceBuiltInMic: Bool
@UserDefault(key: Keys.secondsInMessages.rawValue)
public var secondsInMessages: Bool
@UserDefault(key: Keys.hideChannelBottomButton.rawValue) @UserDefault(key: Keys.hideChannelBottomButton.rawValue)
public var hideChannelBottomButton: Bool public var hideChannelBottomButton: Bool

View File

@ -139,6 +139,8 @@
"Settings.showChannelBottomButton" = "Channel Bottom Panel"; "Settings.showChannelBottomButton" = "Channel Bottom Panel";
"Settings.secondsInMessages" = "Show seconds in messages";
"Settings.CallConfirmation" = "Call Confirmation"; "Settings.CallConfirmation" = "Call Confirmation";
"Settings.CallConfirmation.Notice" = "Swiftgram will ask for your confirmation before making a call."; "Settings.CallConfirmation.Notice" = "Swiftgram will ask for your confirmation before making a call.";

View File

@ -1,3 +1,4 @@
import SGSimpleSettings
import Foundation import Foundation
import TelegramPresentationData import TelegramPresentationData
import TelegramUIPreferences import TelegramUIPreferences
@ -46,8 +47,11 @@ public func stringForMessageTimestamp(timestamp: Int32, dateTimeFormat: Presenta
} else { } else {
gmtime_r(&t, &timeinfo) gmtime_r(&t, &timeinfo)
} }
if SGSimpleSettings.shared.secondsInMessages {
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat) return stringForShortTimestampWithSeconds(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, seconds: timeinfo.tm_sec, dateTimeFormat: dateTimeFormat)
} else {
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat)
}
} }
public func getDateTimeComponents(timestamp: Int32) -> (day: Int32, month: Int32, year: Int32, hour: Int32, minutes: Int32) { public func getDateTimeComponents(timestamp: Int32) -> (day: Int32, month: Int32, year: Int32, hour: Int32, minutes: Int32) {
@ -222,3 +226,38 @@ public func stringForDateWithoutDayAndMonth(date: Date, timeZone: TimeZone? = Ti
formatter.setLocalizedDateFormatFromTemplate("yyyy") formatter.setLocalizedDateFormatFromTemplate("yyyy")
return formatter.string(from: date) return formatter.string(from: date)
} }
public func stringForShortTimestampWithSeconds(hours: Int32, minutes: Int32, seconds: Int32, dateTimeFormat: PresentationDateTimeFormat) -> String {
switch dateTimeFormat.timeFormat {
case .regular:
let hourString: String
if hours == 0 {
hourString = "12"
} else if hours > 12 {
hourString = "\(hours - 12)"
} else {
hourString = "\(hours)"
}
let periodString: String
if hours >= 12 {
periodString = "PM"
} else {
periodString = "AM"
}
let minuteString: String
if minutes >= 10 {
minuteString = "\(minutes)"
} else {
minuteString = "0\(minutes)"
}
if seconds >= 10 {
return "\(hourString):\(minuteString):\(seconds)\u{00a0}\(periodString)"
} else {
return "\(hourString):\(minuteString):0\(seconds)\u{00a0}\(periodString)"
}
case .military:
return String(format: "%02d:%02d:%02d", arguments: [Int(hours), Int(minutes), Int(seconds)])
}
}