add a toggle for displaying other timezones in the first tab
This commit is contained in:
parent
b7bb078b98
commit
2b0ace315d
13 changed files with 145 additions and 10 deletions
|
@ -58,6 +58,8 @@ class MainActivity : SimpleActivity() {
|
|||
if (config.preventPhoneFromSleeping) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
(viewpager.adapter as? ViewPagerAdapter)?.activityResumed()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
|
|
@ -24,6 +24,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
setupAvoidWhatsNew()
|
||||
setupPreventPhoneFromSleeping()
|
||||
setupShowSeconds()
|
||||
setupDisplayOtherTimeZones()
|
||||
updateTextColors(settings_holder)
|
||||
setupSectionColors()
|
||||
}
|
||||
|
@ -74,4 +75,12 @@ class SettingsActivity : SimpleActivity() {
|
|||
config.showSeconds = settings_show_seconds.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDisplayOtherTimeZones() {
|
||||
settings_display_other_timezones.isChecked = config.displayOtherTimeZones
|
||||
settings_display_other_timezones_holder.setOnClickListener {
|
||||
settings_display_other_timezones.toggle()
|
||||
config.displayOtherTimeZones = settings_display_other_timezones.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,18 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.fragments.MyViewPagerFragment
|
||||
import com.simplemobiletools.clock.helpers.TABS_COUNT
|
||||
|
||||
class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||
private val fragments = HashMap<Int, MyViewPagerFragment>()
|
||||
|
||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||
val layout = getFragment(position)
|
||||
val view = activity.layoutInflater.inflate(layout, container, false)
|
||||
container.addView(view)
|
||||
return view
|
||||
val fragment = activity.layoutInflater.inflate(layout, container, false) as MyViewPagerFragment
|
||||
fragments[position] = fragment
|
||||
container.addView(fragment)
|
||||
return fragment
|
||||
}
|
||||
|
||||
override fun destroyItem(container: ViewGroup, position: Int, item: Any) {
|
||||
|
@ -28,4 +31,10 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
|||
1 -> R.layout.fragment_alarm
|
||||
else -> R.layout.fragment_stopwatch
|
||||
}
|
||||
|
||||
fun activityResumed() {
|
||||
fragments.values.forEach {
|
||||
it.onActivityResume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,15 @@ package com.simplemobiletools.clock.fragments
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_alarm.view.*
|
||||
|
||||
class AlarmFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
class AlarmFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
context.updateTextColors(alarm_fragment)
|
||||
}
|
||||
|
||||
override fun onActivityResume() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,16 @@ package com.simplemobiletools.clock.fragments
|
|||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
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.underlineText
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_clock.view.*
|
||||
import java.util.*
|
||||
|
||||
class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
class ClockFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
private val ONE_SECOND = 1000L
|
||||
private var passedSeconds = 0
|
||||
private var calendar = Calendar.getInstance()
|
||||
|
@ -19,11 +21,25 @@ class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayo
|
|||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
context.updateTextColors(clock_fragment)
|
||||
val offset = calendar.timeZone.rawOffset
|
||||
passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
|
||||
updateCurrentTime()
|
||||
updateDate()
|
||||
|
||||
time_zones_placeholder_2.apply {
|
||||
underlineText()
|
||||
setOnClickListener {
|
||||
placeholderClicked()
|
||||
}
|
||||
}
|
||||
|
||||
setupViews()
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
time_zones_holder.beVisibleIf(context.config.displayOtherTimeZones)
|
||||
context.updateTextColors(clock_fragment)
|
||||
time_zones_placeholder_2.setTextColor(context.getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
private fun updateCurrentTime() {
|
||||
|
@ -69,4 +85,12 @@ class ClockFragment(context: Context, attributeSet: AttributeSet) : RelativeLayo
|
|||
super.onDetachedFromWindow()
|
||||
updateHandler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
|
||||
private fun placeholderClicked() {
|
||||
|
||||
}
|
||||
|
||||
override fun onActivityResume() {
|
||||
setupViews()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.simplemobiletools.clock.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
abstract fun onActivityResume()
|
||||
}
|
|
@ -2,13 +2,15 @@ package com.simplemobiletools.clock.fragments
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_stopwatch.view.*
|
||||
|
||||
class StopwatchFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
class StopwatchFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
context.updateTextColors(stopwatch_fragment)
|
||||
}
|
||||
|
||||
override fun onActivityResume() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var showSeconds: Boolean
|
||||
get() = prefs.getBoolean(SHOW_SECONDS, true)
|
||||
set(showSeconds) = prefs.edit().putBoolean(SHOW_SECONDS, showSeconds).apply()
|
||||
|
||||
var displayOtherTimeZones: Boolean
|
||||
get() = prefs.getBoolean(DISPLAY_OTHER_TIME_ZONES, false)
|
||||
set(displayOtherTimeZones) = prefs.edit().putBoolean(DISPLAY_OTHER_TIME_ZONES, displayOtherTimeZones).apply()
|
||||
}
|
||||
|
|
|
@ -2,5 +2,6 @@ package com.simplemobiletools.clock.helpers
|
|||
|
||||
// shared preferences
|
||||
const val SHOW_SECONDS = "show_seconds"
|
||||
const val DISPLAY_OTHER_TIME_ZONES = "display_other_time_zones"
|
||||
|
||||
const val TABS_COUNT = 3
|
||||
|
|
|
@ -142,5 +142,28 @@
|
|||
android:text="@string/show_seconds"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_display_other_timezones_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_display_other_timezones"
|
||||
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/display_other_time_zones"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.clock.fragments.ClockFragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/clock_fragment"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -24,4 +25,43 @@
|
|||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="Mon, 1 January"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/time_zones_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/clock_date"
|
||||
android:layout_marginTop="@dimen/medium_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/time_zones_placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:text="@string/time_zones_placeholder_1"
|
||||
android:textSize="@dimen/bigger_text_size"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/time_zones_placeholder_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/time_zones_placeholder"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/time_zones_placeholder_2"
|
||||
android:textSize="@dimen/bigger_text_size"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/time_zones_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
||||
</RelativeLayout>
|
||||
</com.simplemobiletools.clock.fragments.ClockFragment>
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
<string name="app_name">Jednoduché hodinky</string>
|
||||
<string name="app_launcher_name">Hodinky</string>
|
||||
|
||||
<!-- Time zones -->
|
||||
<string name="time_zones_placeholder_1">Zdá sa, že ste nezvolil žiadne dodatočné časové pásma.</string>
|
||||
<string name="time_zones_placeholder_2">Pridať nové časové pásma</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>
|
||||
<string name="display_other_time_zones">Povoliť zobrazenie dodatočných časových pásiem</string>
|
||||
|
||||
<!--
|
||||
Haven't found some strings? There's more at
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
<string name="app_name">Simple Clock</string>
|
||||
<string name="app_launcher_name">Clock</string>
|
||||
|
||||
<!-- Time zones -->
|
||||
<string name="time_zones_placeholder_1">Seems like you haven\'t selected any extra time zones.</string>
|
||||
<string name="time_zones_placeholder_2">Add new time zones</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>
|
||||
<string name="display_other_time_zones">Allow displaying other time zones</string>
|
||||
|
||||
<!--
|
||||
Haven't found some strings? There's more at
|
||||
|
|
Loading…
Reference in a new issue