use the edited timezone title when appropriate
This commit is contained in:
parent
19e20f51c7
commit
1c48c5b44f
|
@ -92,7 +92,7 @@ class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTime
|
||||||
val formattedDate = activity.getFormattedDate(calendar)
|
val formattedDate = activity.getFormattedDate(calendar)
|
||||||
|
|
||||||
view.apply {
|
view.apply {
|
||||||
time_zone_title.text = timeZone.title.substring(timeZone.title.indexOf(' '))
|
time_zone_title.text = timeZone.title
|
||||||
time_zone_title.setTextColor(textColor)
|
time_zone_title.setTextColor(textColor)
|
||||||
|
|
||||||
time_zone_time.text = formattedTime
|
time_zone_time.text = formattedTime
|
||||||
|
|
|
@ -4,6 +4,8 @@ import android.support.v7.app.AlertDialog
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||||
import com.simplemobiletools.clock.extensions.config
|
import com.simplemobiletools.clock.extensions.config
|
||||||
|
import com.simplemobiletools.clock.extensions.getEditedTimeZonesMap
|
||||||
|
import com.simplemobiletools.clock.extensions.getModifiedTimeZoneTitle
|
||||||
import com.simplemobiletools.clock.helpers.EDITED_TIME_ZONE_SEPARATOR
|
import com.simplemobiletools.clock.helpers.EDITED_TIME_ZONE_SEPARATOR
|
||||||
import com.simplemobiletools.clock.helpers.getDefaultTimeZoneTitle
|
import com.simplemobiletools.clock.helpers.getDefaultTimeZoneTitle
|
||||||
import com.simplemobiletools.clock.models.MyTimeZone
|
import com.simplemobiletools.clock.models.MyTimeZone
|
||||||
|
@ -16,7 +18,7 @@ class EditTimeZoneDialog(val activity: SimpleActivity, val myTimeZone: MyTimeZon
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_edit_time_zone, null).apply {
|
val view = activity.layoutInflater.inflate(R.layout.dialog_edit_time_zone, null).apply {
|
||||||
edit_time_zone_title.setText(myTimeZone.title)
|
edit_time_zone_title.setText(activity.getModifiedTimeZoneTitle(myTimeZone.id))
|
||||||
edit_time_zone_value.text = getDefaultTimeZoneTitle(myTimeZone.id)
|
edit_time_zone_value.text = getDefaultTimeZoneTitle(myTimeZone.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,12 +33,7 @@ class EditTimeZoneDialog(val activity: SimpleActivity, val myTimeZone: MyTimeZon
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun dialogConfirmed(newTitle: String) {
|
private fun dialogConfirmed(newTitle: String) {
|
||||||
val editedTimeZoneTitles = activity.config.editedTimeZoneTitles
|
val editedTitlesMap = activity.getEditedTimeZonesMap()
|
||||||
val editedTitlesMap = HashMap<Int, String>()
|
|
||||||
editedTimeZoneTitles.forEach {
|
|
||||||
val parts = it.split(EDITED_TIME_ZONE_SEPARATOR.toRegex(), 2)
|
|
||||||
editedTitlesMap[parts[0].toInt()] = parts[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newTitle.isEmpty()) {
|
if (newTitle.isEmpty()) {
|
||||||
editedTitlesMap.remove(myTimeZone.id)
|
editedTitlesMap.remove(myTimeZone.id)
|
||||||
|
|
|
@ -3,6 +3,10 @@ package com.simplemobiletools.clock.extensions
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
import com.simplemobiletools.clock.helpers.Config
|
import com.simplemobiletools.clock.helpers.Config
|
||||||
|
import com.simplemobiletools.clock.helpers.EDITED_TIME_ZONE_SEPARATOR
|
||||||
|
import com.simplemobiletools.clock.helpers.getAllTimeZones
|
||||||
|
import com.simplemobiletools.clock.helpers.getDefaultTimeZoneTitle
|
||||||
|
import com.simplemobiletools.clock.models.MyTimeZone
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
|
@ -17,3 +21,28 @@ fun Context.getFormattedDate(calendar: Calendar): String {
|
||||||
val monthString = resources.getStringArray(R.array.months)[month]
|
val monthString = resources.getStringArray(R.array.months)[month]
|
||||||
return "$shortDayString, $dayOfMonth $monthString"
|
return "$shortDayString, $dayOfMonth $monthString"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getEditedTimeZonesMap(): HashMap<Int, String> {
|
||||||
|
val editedTimeZoneTitles = config.editedTimeZoneTitles
|
||||||
|
val editedTitlesMap = HashMap<Int, String>()
|
||||||
|
editedTimeZoneTitles.forEach {
|
||||||
|
val parts = it.split(EDITED_TIME_ZONE_SEPARATOR.toRegex(), 2)
|
||||||
|
editedTitlesMap[parts[0].toInt()] = parts[1]
|
||||||
|
}
|
||||||
|
return editedTitlesMap
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.getAllTimeZonesModified(): ArrayList<MyTimeZone> {
|
||||||
|
val timeZones = getAllTimeZones()
|
||||||
|
val editedTitlesMap = getEditedTimeZonesMap()
|
||||||
|
timeZones.forEach {
|
||||||
|
if (editedTitlesMap.keys.contains(it.id)) {
|
||||||
|
it.title = editedTitlesMap[it.id]!!
|
||||||
|
} else {
|
||||||
|
it.title = it.title.substring(it.title.indexOf(' ')).trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return timeZones
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.getModifiedTimeZoneTitle(id: Int) = getAllTimeZonesModified().firstOrNull { it.id == id }?.title ?: getDefaultTimeZoneTitle(id)
|
||||||
|
|
|
@ -12,8 +12,8 @@ import com.simplemobiletools.clock.adapters.TimeZonesAdapter
|
||||||
import com.simplemobiletools.clock.dialogs.AddTimeZonesDialog
|
import com.simplemobiletools.clock.dialogs.AddTimeZonesDialog
|
||||||
import com.simplemobiletools.clock.dialogs.EditTimeZoneDialog
|
import com.simplemobiletools.clock.dialogs.EditTimeZoneDialog
|
||||||
import com.simplemobiletools.clock.extensions.config
|
import com.simplemobiletools.clock.extensions.config
|
||||||
|
import com.simplemobiletools.clock.extensions.getAllTimeZonesModified
|
||||||
import com.simplemobiletools.clock.extensions.getFormattedDate
|
import com.simplemobiletools.clock.extensions.getFormattedDate
|
||||||
import com.simplemobiletools.clock.helpers.getAllTimeZones
|
|
||||||
import com.simplemobiletools.clock.models.MyTimeZone
|
import com.simplemobiletools.clock.models.MyTimeZone
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
|
@ -125,7 +125,7 @@ class ClockFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectedTimeZoneIDs = context!!.config.selectedTimeZones.map { it.toInt() }
|
val selectedTimeZoneIDs = context!!.config.selectedTimeZones.map { it.toInt() }
|
||||||
val timeZones = getAllTimeZones().filter { selectedTimeZoneIDs.contains(it.id) } as ArrayList<MyTimeZone>
|
val timeZones = context!!.getAllTimeZonesModified().filter { selectedTimeZoneIDs.contains(it.id) } as ArrayList<MyTimeZone>
|
||||||
val currAdapter = view.time_zones_list.adapter
|
val currAdapter = view.time_zones_list.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
TimeZonesAdapter(activity as SimpleActivity, timeZones, view.time_zones_list) {
|
TimeZonesAdapter(activity as SimpleActivity, timeZones, view.time_zones_list) {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package com.simplemobiletools.clock.models
|
package com.simplemobiletools.clock.models
|
||||||
|
|
||||||
data class MyTimeZone(val id: Int, val title: String, val zoneName: String)
|
data class MyTimeZone(val id: Int, var title: String, val zoneName: String)
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
android:layout_below="@+id/clock_date"
|
android:layout_below="@+id/clock_date"
|
||||||
android:layout_marginTop="@dimen/activity_margin"
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
|
android:overScrollMode="ifContentScrolls"
|
||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
||||||
|
|
Loading…
Reference in New Issue