mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-04-03 13:21:01 +02:00
add a toggle for showing seconds
This commit is contained in:
parent
febb166894
commit
60f4244acf
@ -4,6 +4,7 @@ import android.os.Bundle
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.extensions.useEnglishToggled
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
@ -22,7 +23,16 @@ class SettingsActivity : SimpleActivity() {
|
||||
setupUseEnglish()
|
||||
setupAvoidWhatsNew()
|
||||
setupPreventPhoneFromSleeping()
|
||||
setupShowSeconds()
|
||||
updateTextColors(settings_holder)
|
||||
setupSectionColors()
|
||||
}
|
||||
|
||||
private fun setupSectionColors() {
|
||||
val adjustedPrimaryColor = getAdjustedPrimaryColor()
|
||||
arrayListOf(clock_tab_label).forEach {
|
||||
it.setTextColor(adjustedPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupCustomizeColors() {
|
||||
@ -56,4 +66,12 @@ class SettingsActivity : SimpleActivity() {
|
||||
config.preventPhoneFromSleeping = settings_prevent_phone_from_sleeping.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupShowSeconds() {
|
||||
settings_show_seconds.isChecked = config.showSeconds
|
||||
settings_show_seconds_holder.setOnClickListener {
|
||||
settings_show_seconds.toggle()
|
||||
config.showSeconds = settings_show_seconds.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_clock.view.*
|
||||
import java.util.*
|
||||
@ -25,9 +26,17 @@ class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayo
|
||||
private fun updateCurrentTime() {
|
||||
val hours = (passedSeconds / 3600) % 24
|
||||
val minutes = (passedSeconds / 60) % 60
|
||||
val seconds = passedSeconds % 60
|
||||
val format = "%02d:%02d:%02d"
|
||||
clock_time.text = String.format(format, hours, minutes, seconds)
|
||||
var format = "%02d:%02d"
|
||||
|
||||
val formattedText = if (context.config.showSeconds) {
|
||||
val seconds = passedSeconds % 60
|
||||
format += ":%02d"
|
||||
String.format(format, hours, minutes, seconds)
|
||||
} else {
|
||||
String.format(format, hours, minutes)
|
||||
}
|
||||
|
||||
clock_time.text = formattedText
|
||||
|
||||
updateHandler.postDelayed({
|
||||
passedSeconds++
|
||||
|
@ -7,4 +7,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
fun newInstance(context: Context) = Config(context)
|
||||
}
|
||||
|
||||
var showSeconds: Boolean
|
||||
get() = prefs.getBoolean(SHOW_SECONDS, true)
|
||||
set(showSeconds) = prefs.edit().putBoolean(SHOW_SECONDS, showSeconds).apply()
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
package com.simplemobiletools.clock.helpers
|
||||
|
||||
// shared preferences
|
||||
const val SHOW_SECONDS = "show_seconds"
|
@ -101,5 +101,46 @@
|
||||
android:text="@string/prevent_phone_from_sleeping"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/clock_tab_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:background="@color/divider_grey"
|
||||
android:importantForAccessibility="no"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/clock_tab_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/bigger_margin"
|
||||
android:layout_marginStart="@dimen/bigger_margin"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:text="@string/clock_tab"
|
||||
android:textAllCaps="true"
|
||||
android:textSize="@dimen/smaller_text_size"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_show_seconds_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingRight="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_show_seconds"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_seconds"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
@ -7,6 +7,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/clock_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/big_margin"
|
||||
|
15
app/src/main/res/values-sk/strings.xml
Normal file
15
app/src/main/res/values-sk/strings.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<resources>
|
||||
<string name="app_name">Jednoduché hodinky</string>
|
||||
<string name="app_launcher_name">Hodinky</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="clock_tab">Okno s časom</string>
|
||||
<string name="alarm_tab">Okno s budíkom</string>
|
||||
<string name="stopwatch_tab">Okno so stopkami</string>
|
||||
<string name="show_seconds">Zobraziť sekundy</string>
|
||||
|
||||
<!--
|
||||
Haven't found some strings? There's more at
|
||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||
-->
|
||||
</resources>
|
@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<dimen name="clock_text_size">54sp</dimen>
|
||||
<dimen name="clock_text_size">70sp</dimen>
|
||||
</resources>
|
||||
|
@ -2,6 +2,12 @@
|
||||
<string name="app_name">Simple Clock</string>
|
||||
<string name="app_launcher_name">Clock</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="clock_tab">Clock tab</string>
|
||||
<string name="alarm_tab">Alarm tab</string>
|
||||
<string name="stopwatch_tab">Stopwatch tab</string>
|
||||
<string name="show_seconds">Show seconds</string>
|
||||
|
||||
<!--
|
||||
Haven't found some strings? There's more at
|
||||
https://github.com/SimpleMobileTools/Simple-Commons/tree/master/commons/src/main/res
|
||||
|
Loading…
x
Reference in New Issue
Block a user