Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Feat: Added the ability to hide times AM/PM.
Browse files Browse the repository at this point in the history
Closes: #496
  • Loading branch information
CreativeCodeCat committed May 5, 2024
1 parent 93b79ca commit 48ed53e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private const val SHOW_DATE = "SHOW_DATE"
private const val HOME_LOCKED = "HOME_LOCKED"
private const val SETTINGS_LOCKED = "SETTINGS_LOCKED"
private const val SHOW_TIME = "SHOW_TIME"
private const val SHOW_TIME_FORMAT = "SHOW_TIME_FORMAT"
private const val SEARCH_START = "SEARCH_START"
private const val SWIPE_UP_ACTION = "SWIPE_UP_ACTION"
private const val SWIPE_DOWN_ACTION = "SWIPE_DOWN_ACTION"
Expand Down Expand Up @@ -219,6 +220,10 @@ class Prefs(val context: Context) {
get() = prefs.getBoolean(SHOW_TIME, true)
set(value) = prefs.edit().putBoolean(SHOW_TIME, value).apply()

var showTimeFormat: Boolean
get() = prefs.getBoolean(SHOW_TIME_FORMAT, true)
set(value) = prefs.edit().putBoolean(SHOW_TIME_FORMAT, value).apply()

var showDate: Boolean
get() = prefs.getBoolean(SHOW_DATE, true)
set(value) = prefs.edit().putBoolean(SHOW_DATE, value).apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener

val timezone = prefs.language.timezone()
val is24HourFormat = DateFormat.is24HourFormat(requireContext())
val best12 = DateFormat.getBestDateTimePattern(timezone, "hhmma")
val best12 = DateFormat.getBestDateTimePattern(timezone, if (prefs.showTimeFormat) "hhmma" else "hhmm").let {
if (!prefs.showTimeFormat) it.removeSuffix(" a") else it
}
Log.d("currentDateTime", best12)
val best24 = DateFormat.getBestDateTimePattern(timezone, "HHmm")
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")

binding.date.format12Hour = best12Date
binding.date.format24Hour = best24Date
val datePattern = DateFormat.getBestDateTimePattern(timezone, "eeeddMMM")
binding.date.format12Hour = datePattern
binding.date.format24Hour = datePattern

binding.clock.textSize = prefs.clockSize.toFloat()
binding.date.textSize = prefs.textSizeLauncher.toFloat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ class SettingsFragment : Fragment() {
state = remember { mutableStateOf(prefs.showTime) }
) { toggleShowTime() }
},
{ _, onChange ->
if (prefs.showTime) {
SettingsToggle(
title = stringResource(R.string.show_time_format),
fontSize = iconFs,
onChange = onChange,
state = remember { mutableStateOf(prefs.showTimeFormat) }
) { toggleShowTimeFormat() }
}
},
{ _, onChange ->
SettingsToggle(
title = stringResource(R.string.show_date),
Expand Down Expand Up @@ -849,6 +859,10 @@ class SettingsFragment : Fragment() {
viewModel.setShowTime(prefs.showTime)
}

private fun toggleShowTimeFormat() {
prefs.showTimeFormat = !prefs.showTimeFormat
}

private fun showHiddenApps() {
viewModel.getHiddenApps()
findNavController().navigate(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<string name="pages_on_home_screen">Number of Pages</string>
<string name="enable_home_pager">Enable Home Pager</string>
<string name="show_time">Show Time</string>
<string name="show_time_format">Time Format (AM/PM)</string>
<string name="show_date">Show Date</string>
<string name="show_battery">Show Battery</string>
<string name="show_battery_icon">Show Battery Icon</string>
Expand Down

0 comments on commit 48ed53e

Please sign in to comment.