add a dialog for changing time zone title

This commit is contained in:
tibbi 2018-03-02 11:53:17 +01:00
parent 48b798d692
commit 60bac7087d
8 changed files with 99 additions and 3 deletions

View File

@ -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'
}

View File

@ -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<Int, String>()
editedTimeZoneTitles.forEach {
val parts = it.split(":".toRegex(), 2)
}
callback()
}
}

View File

@ -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<MyTimeZone>
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)
}

View File

@ -19,4 +19,8 @@ class Config(context: Context) : BaseConfig(context) {
var selectedTimeZones: Set<String>
get() = prefs.getStringSet(SELECTED_TIME_ZONES, HashSet())
set(selectedTimeZones) = prefs.edit().putStringSet(SELECTED_TIME_ZONES, selectedTimeZones).apply()
var editedTimeZoneTitles: Set<String>
get() = prefs.getStringSet(EDITED_TIME_ZONE_TITLES, HashSet())
set(editedTimeZoneTitles) = prefs.edit().putStringSet(EDITED_TIME_ZONE_TITLES, editedTimeZoneTitles).apply()
}

View File

@ -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"),

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/edit_time_zone_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/edit_time_zone_title_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/edit_time_zone_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/small_margin"
android:singleLine="true"
android:textCursorDrawable="@null"
android:textSize="@dimen/normal_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/edit_time_zone_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/time_zone"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/edit_time_zone_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:textSize="@dimen/normal_text_size"
tools:text="GMT-11:00 Midway"/>
</LinearLayout>

View File

@ -1,6 +1,7 @@
<resources>
<string name="app_name">Jednoduché hodinky</string>
<string name="app_launcher_name">Hodinky</string>
<string name="time_zone">Časové pásmo</string>
<!-- Settings -->
<string name="clock_tab">Okno s časom</string>

View File

@ -1,6 +1,7 @@
<resources>
<string name="app_name">Simple Clock</string>
<string name="app_launcher_name">Clock</string>
<string name="time_zone">Time zone</string>
<!-- Settings -->
<string name="clock_tab">Clock tab</string>