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 @@ -7,9 +7,11 @@ import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.widget.SeekBar
import androidx.core.view.isVisible
import org.fossify.clock.databinding.WidgetConfigDigitalBinding
import org.fossify.clock.extensions.config
import org.fossify.clock.helpers.FORMAT_12H
import org.fossify.clock.helpers.FORMAT_12H_NO_AM_PM
import org.fossify.clock.helpers.FORMAT_24H
import org.fossify.clock.helpers.MyDigitalTimeWidgetProvider
import org.fossify.clock.helpers.SIMPLE_PHONE
Expand All @@ -30,6 +32,7 @@ class WidgetDigitalConfigureActivity : SimpleActivity() {
private var mWidgetId = 0
private var mBgColor = 0
private var mTextColor = 0
private var mShowAmPm = true
private var mBgColorWithoutTransparency = 0
private var mFeatureLockedDialog: FeatureLockedDialog? = null
private val binding: WidgetConfigDigitalBinding by viewBinding(WidgetConfigDigitalBinding::inflate)
Expand Down Expand Up @@ -60,6 +63,13 @@ class WidgetDigitalConfigureActivity : SimpleActivity() {
binding.configDigitalBgColor.setOnClickListener { pickBackgroundColor() }
binding.configDigitalTextColor.setOnClickListener { pickTextColor() }

binding.configDigitalShowAmPm.isVisible = !config.use24HourFormat
binding.configDigitalShowAmPm.isChecked = mShowAmPm
binding.configDigitalShowAmPm.setOnCheckedChangeListener { _, isChecked ->
mShowAmPm = isChecked
updateClockPreviewFormat()
}

val primaryColor = getProperPrimaryColor()
binding.configDigitalBgSeekbar.setColors(mTextColor, primaryColor, primaryColor)

Expand Down Expand Up @@ -98,15 +108,30 @@ class WidgetDigitalConfigureActivity : SimpleActivity() {
mTextColor = resources.getColor(org.fossify.commons.R.color.you_primary_color, theme)
}

mShowAmPm = config.widgetShowAmPm
updateTextColor()
updateClockPreviewFormat()
}

private fun updateClockPreviewFormat() {
val clockFormat = if (config.use24HourFormat) {
FORMAT_24H
} else if (mShowAmPm) {
FORMAT_12H
} else {
FORMAT_12H_NO_AM_PM
}

val clockFormat = if (config.use24HourFormat) FORMAT_24H else FORMAT_12H
binding.configDigitalTime.format24Hour = clockFormat
binding.configDigitalTime.format12Hour = clockFormat
}

private fun saveConfig() {
storeWidgetColors()
config.apply {
widgetBgColor = mBgColor
widgetTextColor = mTextColor
widgetShowAmPm = mShowAmPm
}
requestWidgetUpdate()

Intent().apply {
Expand All @@ -116,13 +141,6 @@ class WidgetDigitalConfigureActivity : SimpleActivity() {
finish()
}

private fun storeWidgetColors() {
config.apply {
widgetBgColor = mBgColor
widgetTextColor = mTextColor
}
}

private fun pickBackgroundColor() {
ColorPickerDialog(this, mBgColorWithoutTransparency) { wasPositivePressed, color ->
if (wasPositivePressed) {
Expand Down
4 changes: 4 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 @@ -138,6 +138,10 @@ class Config(context: Context) : BaseConfig(context) {
putBoolean(WAS_INITIAL_WIDGET_SET_UP, wasInitialWidgetSetUp)
}

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

var lastDataExportPath: String
get() = prefs.getString(LAST_DATA_EXPORT_PATH, "")!!
set(lastDataExportPath) = prefs.edit {
Expand Down
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 @@ -38,6 +38,7 @@ const val TIMERS_SORT_BY = "timers_sort_by"
const val TIMERS_CUSTOM_SORTING = "timers_custom_sorting"
const val STOPWATCH_LAPS_SORT_BY = "stopwatch_laps_sort_by"
const val WAS_INITIAL_WIDGET_SET_UP = "was_initial_widget_set_up"
const val WIDGET_SHOW_AM_PM = "widget_show_am_pm"
const val DATA_EXPORT_EXTENSION = ".json"
const val LAST_DATA_EXPORT_PATH = "last_alarms_export_path"
const val MIGRATE_FIRST_DAY_OF_WEEK = "migrate_first_day_of_week"
Expand Down Expand Up @@ -100,6 +101,7 @@ const val STOPWATCH_TOGGLE_ACTION = "org.fossify.clock.TOGGLE_STOPWATCH"

// time formatting
const val FORMAT_12H = "h:mm a"
const val FORMAT_12H_NO_AM_PM = "h:mm"
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,9 @@ class MyDigitalTimeWidgetProvider : AppWidgetProvider() {

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

val format12Hour = if (context.config.widgetShowAmPm) FORMAT_12H else FORMAT_12H_NO_AM_PM
setCharSequence(R.id.widget_text_clock_12, "setFormat12Hour", format12Hour)
}
}

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/widget_config_digital.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@

</RelativeLayout>

<org.fossify.commons.views.MyMaterialSwitch
android:id="@+id/config_digital_show_am_pm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/config_digital_bg_color"
android:layout_marginStart="@dimen/tiny_margin"
android:layout_marginEnd="@dimen/tiny_margin"
android:text="@string/show_am_pm" />

<ImageView
android:id="@+id/config_digital_bg_color"
android:layout_width="@dimen/widget_colorpicker_size"
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 @@ -15,6 +15,7 @@
<string name="time_expired">Time expired</string>
<string name="clock_and_date">Clock and date</string>
<string name="use_text_shadow">Use text shadow</string>
<string name="show_am_pm">Show AM/PM</string>
<string name="swipe_right_to_dismiss">Swipe right to Dismiss, or left to Snooze.</string>
<string name="sort_by_creation_order">Creation order</string>
<string name="sort_by_alarm_time">Alarm time</string>
Expand Down
Loading