show an extra timezone date too if it is different than the local one
This commit is contained in:
parent
d4edaf646b
commit
8107901a1c
|
@ -42,6 +42,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.14.1'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
}
|
||||
|
||||
Properties props = new Properties()
|
||||
|
|
|
@ -5,8 +5,11 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||
import com.simplemobiletools.clock.extensions.getFormattedDate
|
||||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.beVisible
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.item_time_zone.view.*
|
||||
import java.util.*
|
||||
|
@ -14,6 +17,8 @@ import java.util.*
|
|||
class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTimeZone>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
var todayDateString = activity.getFormattedDate(Calendar.getInstance())
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_timezones
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
@ -58,6 +63,7 @@ class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTime
|
|||
val minutes = (passedSeconds / 60) % 60
|
||||
val format = "%02d:%02d"
|
||||
val formattedTime = String.format(format, hours, minutes)
|
||||
val formattedDate = activity.getFormattedDate(calendar)
|
||||
|
||||
view.apply {
|
||||
time_zone_title.text = timeZone.title.substring(timeZone.title.indexOf(' '))
|
||||
|
@ -65,6 +71,14 @@ class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTime
|
|||
|
||||
time_zone_time.text = formattedTime
|
||||
time_zone_time.setTextColor(textColor)
|
||||
|
||||
if (formattedDate != todayDateString) {
|
||||
time_zone_date.beVisible()
|
||||
time_zone_date.text = formattedDate
|
||||
time_zone_date.setTextColor(textColor)
|
||||
} else {
|
||||
time_zone_date.beGone()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
package com.simplemobiletools.clock.extensions
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.helpers.Config
|
||||
import java.util.*
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||
|
||||
fun Context.getFormattedDate(calendar: Calendar): String {
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 // make sure index 0 means monday
|
||||
val dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
|
||||
val month = calendar.get(Calendar.MONTH)
|
||||
|
||||
val dayString = resources.getStringArray(R.array.week_days)[dayOfWeek]
|
||||
val shortDayString = dayString.substring(0, Math.min(3, dayString.length))
|
||||
val monthString = resources.getStringArray(R.array.months)[month]
|
||||
return "$shortDayString, $dayOfMonth $monthString"
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.simplemobiletools.clock.activities.SimpleActivity
|
|||
import com.simplemobiletools.clock.adapters.TimeZonesAdapter
|
||||
import com.simplemobiletools.clock.dialogs.AddTimeZonesDialog
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.getFormattedDate
|
||||
import com.simplemobiletools.clock.helpers.getAllTimeZones
|
||||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
|
@ -87,13 +88,13 @@ class ClockFragment : Fragment() {
|
|||
view.clock_time.text = formattedText
|
||||
|
||||
if (seconds == 0) {
|
||||
if (displayOtherTimeZones) {
|
||||
(view.time_zones_list.adapter as? TimeZonesAdapter)?.updateTimes()
|
||||
}
|
||||
|
||||
if (hours == 0 && minutes == 0) {
|
||||
updateDate()
|
||||
}
|
||||
|
||||
if (displayOtherTimeZones) {
|
||||
(view.time_zones_list.adapter as? TimeZonesAdapter)?.updateTimes()
|
||||
}
|
||||
}
|
||||
|
||||
updateHandler.postDelayed({
|
||||
|
@ -104,16 +105,12 @@ class ClockFragment : Fragment() {
|
|||
|
||||
private fun updateDate() {
|
||||
calendar = Calendar.getInstance()
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 // make sure index 0 means monday
|
||||
val dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
|
||||
val month = calendar.get(Calendar.MONTH)
|
||||
val formattedDate = context!!.getFormattedDate(calendar)
|
||||
view.clock_date.text = formattedDate
|
||||
|
||||
val dayString = context!!.resources.getStringArray(R.array.week_days)[dayOfWeek]
|
||||
val shortDayString = dayString.substring(0, Math.min(3, dayString.length))
|
||||
val monthString = context!!.resources.getStringArray(R.array.months)[month]
|
||||
|
||||
val dateString = "$shortDayString, $dayOfMonth $monthString"
|
||||
view.clock_date.text = dateString
|
||||
if (displayOtherTimeZones) {
|
||||
(view.time_zones_list.adapter as? TimeZonesAdapter)?.todayDateString = formattedDate
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTimeZones() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
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/time_zone_frame"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -10,34 +11,52 @@
|
|||
android:focusable="true"
|
||||
android:foreground="@drawable/selector">
|
||||
|
||||
<RelativeLayout
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:id="@+id/time_zone_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/time_zone_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_toLeftOf="@+id/time_zone_time"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:textSize="@dimen/big_text_size"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:text="GMT-11:00 Midway"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/time_zone_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@+id/time_zone_title"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:textSize="@dimen/actionbar_text_size"
|
||||
app:layout_constraintBottom_toTopOf="@+id/time_zone_date"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
tools:text="11:00"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/time_zone_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/time_zone_time"
|
||||
android:ellipsize="end"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/time_zone_time"
|
||||
tools:text="Mon, 1 January"/>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in New Issue