Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,19 @@ class WidgetDigitalConfigureActivity : SimpleActivity() {

updateTextColor()

val clockFormat = if (config.use24HourFormat) FORMAT_24H else FORMAT_12H
binding.configDigitalShowAmPm.isChecked = config.widgetShowAmPm
binding.configDigitalShowAmPm.setOnCheckedChangeListener { _, checked ->
config.widgetShowAmPm = checked
val clockFormat = if (config.use24HourFormat) FORMAT_24H else if (checked) FORMAT_12H else FORMAT_12H_NO_AMPM
binding.configDigitalTime.format24Hour = clockFormat
binding.configDigitalTime.format12Hour = clockFormat
}

val clockFormat = when {
config.use24HourFormat -> FORMAT_24H
config.widgetShowAmPm -> FORMAT_12H
else -> FORMAT_12H_NO_AMPM
}
binding.configDigitalTime.format24Hour = clockFormat
binding.configDigitalTime.format12Hour = clockFormat
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/kotlin/org/fossify/clock/helpers/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ class Config(context: Context) : BaseConfig(context) {
set(migrateFirstDayOfWeek) = prefs.edit {
putBoolean(MIGRATE_FIRST_DAY_OF_WEEK, migrateFirstDayOfWeek)
}

var widgetShowAmPm: Boolean
get() = prefs.getBoolean(WIDGET_SHOW_AM_PM, true)
set(showAmPm) = prefs.edit().putBoolean(WIDGET_SHOW_AM_PM, showAmPm).apply()

}
2 changes: 2 additions & 0 deletions app/src/main/kotlin/org/fossify/clock/helpers/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const val STOPWATCH_TOGGLE_ACTION = "org.fossify.clock.TOGGLE_STOPWATCH"

// time formatting
const val FORMAT_12H = "h:mm a"
const val FORMAT_12H_NO_AMPM = "h:mm"
const val WIDGET_SHOW_AM_PM = "widget_show_am_pm"
const val FORMAT_24H = "HH:mm"
const val FORMAT_12H_WITH_SECONDS = "h:mm:ss a"
const val FORMAT_24H_WITH_SECONDS = "HH:mm:ss"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class MyDigitalTimeWidgetProvider : AppWidgetProvider() {

setViewVisibility(clockToHide, View.GONE)
setViewVisibility(clockToShow, View.VISIBLE)

// Optional AM/PM for 12-hour digital widget (#138)
val format12 = if (config.widgetShowAmPm) FORMAT_12H else FORMAT_12H_NO_AMPM
setCharSequence(R.id.widget_text_clock_12, "setFormat12Hour", format12)
setCharSequence(R.id.widget_text_clock_12, "setFormat24Hour", FORMAT_24H)
}
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/widget_config_digital.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/tiny_margin" />

<androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/config_digital_show_am_pm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/config_digital_save"
android:layout_margin="@dimen/activity_margin"
android:text="@string/show_am_pm" />

<Button
android:id="@+id/config_digital_save"
style="@style/MyWidgetConfigSaveStyle"
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 @@ -65,4 +65,5 @@
https://github.com/FossifyOrg/Commons/tree/master/commons/src/main/res
-->

<string name="show_am_pm">Show AM/PM</string>
</resources>
Loading