diff --git a/app/build.gradle b/app/build.gradle index 00594820..4d180548 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:3.14.1' + implementation 'com.simplemobiletools:commons:3.14.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2' } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditTimeZoneDialog.kt b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditTimeZoneDialog.kt new file mode 100644 index 00000000..5febc726 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/EditTimeZoneDialog.kt @@ -0,0 +1,40 @@ +package com.simplemobiletools.clock.dialogs + +import android.support.v7.app.AlertDialog +import com.simplemobiletools.clock.R +import com.simplemobiletools.clock.activities.SimpleActivity +import com.simplemobiletools.clock.extensions.config +import com.simplemobiletools.clock.helpers.getDefaultTimeZoneTitle +import com.simplemobiletools.clock.models.MyTimeZone +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showKeyboard +import com.simplemobiletools.commons.extensions.value +import kotlinx.android.synthetic.main.dialog_edit_time_zone.view.* + +class EditTimeZoneDialog(val activity: SimpleActivity, val myTimeZone: MyTimeZone, val callback: () -> Unit) { + + init { + val view = activity.layoutInflater.inflate(R.layout.dialog_edit_time_zone, null).apply { + edit_time_zone_title.setText(myTimeZone.title) + edit_time_zone_value.text = getDefaultTimeZoneTitle(myTimeZone.id) + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed(view.edit_time_zone_title.value) }) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) { + showKeyboard(view.edit_time_zone_title) + } + } + } + + private fun dialogConfirmed(newTitle: String) { + val editedTimeZoneTitles = activity.config.editedTimeZoneTitles + val editedTitlesMap = HashMap() + editedTimeZoneTitles.forEach { + val parts = it.split(":".toRegex(), 2) + } + callback() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt index bce970bd..eb9efaaa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.clock.R import com.simplemobiletools.clock.activities.SimpleActivity import com.simplemobiletools.clock.adapters.TimeZonesAdapter import com.simplemobiletools.clock.dialogs.AddTimeZonesDialog +import com.simplemobiletools.clock.dialogs.EditTimeZoneDialog import com.simplemobiletools.clock.extensions.config import com.simplemobiletools.clock.extensions.getFormattedDate import com.simplemobiletools.clock.helpers.getAllTimeZones @@ -127,8 +128,13 @@ class ClockFragment : Fragment() { val timeZones = getAllTimeZones().filter { selectedTimeZoneIDs.contains(it.id) } as ArrayList val currAdapter = view.time_zones_list.adapter if (currAdapter == null) { - val timeZonesAdapter = TimeZonesAdapter(activity as SimpleActivity, timeZones, view.time_zones_list) {} - view.time_zones_list.adapter = timeZonesAdapter + TimeZonesAdapter(activity as SimpleActivity, timeZones, view.time_zones_list) { + EditTimeZoneDialog(activity as SimpleActivity, it as MyTimeZone) { + updateTimeZones() + } + }.apply { + view.time_zones_list.adapter = this + } } else { (currAdapter as TimeZonesAdapter).updateItems(timeZones) } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt index f92bcc9c..13e6b7c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Config.kt @@ -19,4 +19,8 @@ class Config(context: Context) : BaseConfig(context) { var selectedTimeZones: Set get() = prefs.getStringSet(SELECTED_TIME_ZONES, HashSet()) set(selectedTimeZones) = prefs.edit().putStringSet(SELECTED_TIME_ZONES, selectedTimeZones).apply() + + var editedTimeZoneTitles: Set + get() = prefs.getStringSet(EDITED_TIME_ZONE_TITLES, HashSet()) + set(editedTimeZoneTitles) = prefs.edit().putStringSet(EDITED_TIME_ZONE_TITLES, editedTimeZoneTitles).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt index 374f0fc5..2b78305e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/Constants.kt @@ -6,9 +6,12 @@ import com.simplemobiletools.clock.models.MyTimeZone const val SHOW_SECONDS = "show_seconds" const val DISPLAY_OTHER_TIME_ZONES = "display_other_time_zones" const val SELECTED_TIME_ZONES = "selected_time_zones" +const val EDITED_TIME_ZONE_TITLES = "edited_time_zone_titles" const val TABS_COUNT = 3 +fun getDefaultTimeZoneTitle(id: Int) = getAllTimeZones().firstOrNull { it.id == id }?.title ?: "" + fun getAllTimeZones() = arrayListOf( MyTimeZone(1, "GMT-11:00 Midway", "Pacific/Midway"), MyTimeZone(2, "GMT-10:00 Honolulu", "Pacific/Honolulu"), diff --git a/app/src/main/res/layout/dialog_edit_time_zone.xml b/app/src/main/res/layout/dialog_edit_time_zone.xml new file mode 100644 index 00000000..54cf8a35 --- /dev/null +++ b/app/src/main/res/layout/dialog_edit_time_zone.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index c8c8ba39..d4c275e0 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -1,6 +1,7 @@ Jednoduché hodinky Hodinky + Časové pásmo Okno s časom diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e88875d9..039c812f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ Simple Clock Clock + Time zone Clock tab