Skip to content

Commit

Permalink
feat: Update time formatting based on system settings
Browse files Browse the repository at this point in the history
- Adjusted time formatting in HomeFragment to respect system's 12/24-hour preference.
- Dynamically determine time pattern based on system settings.
- Enhanced logging for debugging time-related operations.

Also Closes #469
  • Loading branch information
HeCodes2Much committed Apr 23, 2024
1 parent a8de30f commit e6b3939
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ class Prefs(val context: Context) {
Constants.Language.valueOf(
prefs.getString(
APP_LANGUAGE,
Constants.Language.EnglishUS.name
Constants.Language.System.name
).toString()
)
} catch (_: Exception) {
Constants.Language.EnglishUS
Constants.Language.System
}
}
set(value) = prefs.edit().putString(APP_LANGUAGE, value.name).apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
requireContext().registerReceiver(batteryReceiver, filter)

val timezone = prefs.language.timezone()
val is24HourFormat = DateFormat.is24HourFormat(requireContext())
val best12 = DateFormat.getBestDateTimePattern(timezone, "hhmma")
val best24 = DateFormat.getBestDateTimePattern(timezone, "HHmm")
binding.clock.format12Hour = best12
binding.clock.format24Hour = best24
val timePattern = if (is24HourFormat) best24 else best12
binding.clock.format12Hour = timePattern
binding.clock.format24Hour = timePattern

val best12Date = DateFormat.getBestDateTimePattern(timezone, "eeeddMMM")
val best24Date = DateFormat.getBestDateTimePattern(timezone, "eeeddMMM")

Log.d("timezone","timezone: $timezone, best12: $best12, best24: $best24, best12Date: $best12Date, best24Date: $best24Date")
binding.date.format12Hour = best12Date
binding.date.format24Hour = best24Date

Expand Down

0 comments on commit e6b3939

Please sign in to comment.