store the titles of edited timezones in shared prefs

This commit is contained in:
tibbi 2018-03-02 15:04:24 +01:00
parent 60bac7087d
commit b800435bb2
3 changed files with 18 additions and 2 deletions

View File

@ -41,7 +41,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.14.2'
implementation 'com.simplemobiletools:commons:3.14.4'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

View File

@ -4,6 +4,7 @@ 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.EDITED_TIME_ZONE_SEPARATOR
import com.simplemobiletools.clock.helpers.getDefaultTimeZoneTitle
import com.simplemobiletools.clock.models.MyTimeZone
import com.simplemobiletools.commons.extensions.setupDialogStuff
@ -33,8 +34,22 @@ class EditTimeZoneDialog(val activity: SimpleActivity, val myTimeZone: MyTimeZon
val editedTimeZoneTitles = activity.config.editedTimeZoneTitles
val editedTitlesMap = HashMap<Int, String>()
editedTimeZoneTitles.forEach {
val parts = it.split(":".toRegex(), 2)
val parts = it.split(EDITED_TIME_ZONE_SEPARATOR.toRegex(), 2)
editedTitlesMap[parts[0].toInt()] = parts[1]
}
if (newTitle.isEmpty()) {
editedTitlesMap.remove(myTimeZone.id)
} else {
editedTitlesMap[myTimeZone.id] = newTitle
}
val newTitlesSet = HashSet<String>()
for ((key, value) in editedTitlesMap) {
newTitlesSet.add("$key$EDITED_TIME_ZONE_SEPARATOR$value")
}
activity.config.editedTimeZoneTitles = newTitlesSet
callback()
}
}

View File

@ -9,6 +9,7 @@ const val SELECTED_TIME_ZONES = "selected_time_zones"
const val EDITED_TIME_ZONE_TITLES = "edited_time_zone_titles"
const val TABS_COUNT = 3
const val EDITED_TIME_ZONE_SEPARATOR = ":"
fun getDefaultTimeZoneTitle(id: Int) = getAllTimeZones().firstOrNull { it.id == id }?.title ?: ""