create a dialog for changing date/time format
This commit is contained in:
parent
f6d5528e8b
commit
f95027b588
4 changed files with 142 additions and 11 deletions
|
@ -0,0 +1,55 @@
|
|||
package com.simplemobiletools.commons.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.R.id.*
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.helpers.DATE_FORMAT_FOUR
|
||||
import com.simplemobiletools.commons.helpers.DATE_FORMAT_ONE
|
||||
import com.simplemobiletools.commons.helpers.DATE_FORMAT_THREE
|
||||
import com.simplemobiletools.commons.helpers.DATE_FORMAT_TWO
|
||||
import kotlinx.android.synthetic.main.dialog_change_date_time_format.view.*
|
||||
|
||||
class ChangeDateTimeFormatDialog(val activity: Activity, val callback: () -> Unit) {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_change_date_time_format, null)!!
|
||||
|
||||
init {
|
||||
view.apply {
|
||||
change_date_time_dialog_radio_one.text = DATE_FORMAT_ONE
|
||||
change_date_time_dialog_radio_two.text = DATE_FORMAT_TWO
|
||||
change_date_time_dialog_radio_three.text = DATE_FORMAT_THREE
|
||||
change_date_time_dialog_radio_four.text = DATE_FORMAT_FOUR
|
||||
|
||||
change_date_time_dialog_24_hour.isChecked = activity.baseConfig.use24HourFormat
|
||||
|
||||
val formatButton = when (activity.baseConfig.dateFormat) {
|
||||
DATE_FORMAT_ONE -> change_date_time_dialog_radio_one
|
||||
DATE_FORMAT_TWO -> change_date_time_dialog_radio_two
|
||||
DATE_FORMAT_THREE -> change_date_time_dialog_radio_three
|
||||
else -> change_date_time_dialog_radio_four
|
||||
}
|
||||
formatButton.isChecked = true
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialogConfirmed() {
|
||||
activity.baseConfig.dateFormat = when (view.change_date_time_dialog_radio_group.checkedRadioButtonId) {
|
||||
change_date_time_dialog_radio_one -> DATE_FORMAT_ONE
|
||||
change_date_time_dialog_radio_two -> DATE_FORMAT_TWO
|
||||
change_date_time_dialog_radio_three -> DATE_FORMAT_THREE
|
||||
else -> DATE_FORMAT_FOUR
|
||||
}
|
||||
|
||||
activity.baseConfig.use24HourFormat = view.change_date_time_dialog_24_hour.isChecked
|
||||
callback()
|
||||
}
|
||||
}
|
|
@ -24,29 +24,29 @@ open class BaseConfig(val context: Context) {
|
|||
set(lastVersion) = prefs.edit().putInt(LAST_VERSION, lastVersion).apply()
|
||||
|
||||
var treeUri: String
|
||||
get() = prefs.getString(TREE_URI, "")
|
||||
get() = prefs.getString(TREE_URI, "")!!
|
||||
set(uri) = prefs.edit().putString(TREE_URI, uri).apply()
|
||||
|
||||
var OTGTreeUri: String
|
||||
get() = prefs.getString(OTG_TREE_URI, "")
|
||||
get() = prefs.getString(OTG_TREE_URI, "")!!
|
||||
set(OTGTreeUri) = prefs.edit().putString(OTG_TREE_URI, OTGTreeUri).apply()
|
||||
|
||||
var OTGPartition: String
|
||||
get() = prefs.getString(OTG_PARTITION, "")
|
||||
get() = prefs.getString(OTG_PARTITION, "")!!
|
||||
set(OTGPartition) = prefs.edit().putString(OTG_PARTITION, OTGPartition).apply()
|
||||
|
||||
var OTGPath: String
|
||||
get() = prefs.getString(OTG_REAL_PATH, "")
|
||||
get() = prefs.getString(OTG_REAL_PATH, "")!!
|
||||
set(OTGPath) = prefs.edit().putString(OTG_REAL_PATH, OTGPath).apply()
|
||||
|
||||
var sdCardPath: String
|
||||
get() = prefs.getString(SD_CARD_PATH, getDefaultSDCardPath())
|
||||
get() = prefs.getString(SD_CARD_PATH, getDefaultSDCardPath())!!
|
||||
set(sdCardPath) = prefs.edit().putString(SD_CARD_PATH, sdCardPath).apply()
|
||||
|
||||
private fun getDefaultSDCardPath() = if (prefs.contains(SD_CARD_PATH)) "" else context.getSDCardPath()
|
||||
|
||||
var internalStoragePath: String
|
||||
get() = prefs.getString(INTERNAL_STORAGE_PATH, getDefaultInternalPath())
|
||||
get() = prefs.getString(INTERNAL_STORAGE_PATH, getDefaultInternalPath())!!
|
||||
set(internalStoragePath) = prefs.edit().putString(INTERNAL_STORAGE_PATH, internalStoragePath).apply()
|
||||
|
||||
private fun getDefaultInternalPath() = if (prefs.contains(INTERNAL_STORAGE_PATH)) "" else context.getInternalStoragePath()
|
||||
|
@ -104,7 +104,7 @@ open class BaseConfig(val context: Context) {
|
|||
set(isHiddenPasswordProtectionOn) = prefs.edit().putBoolean(PASSWORD_PROTECTION, isHiddenPasswordProtectionOn).apply()
|
||||
|
||||
var hiddenPasswordHash: String
|
||||
get() = prefs.getString(PASSWORD_HASH, "")
|
||||
get() = prefs.getString(PASSWORD_HASH, "")!!
|
||||
set(hiddenPasswordHash) = prefs.edit().putString(PASSWORD_HASH, hiddenPasswordHash).apply()
|
||||
|
||||
var hiddenProtectionType: Int
|
||||
|
@ -117,7 +117,7 @@ open class BaseConfig(val context: Context) {
|
|||
set(isAppPasswordProtectionOn) = prefs.edit().putBoolean(APP_PASSWORD_PROTECTION, isAppPasswordProtectionOn).apply()
|
||||
|
||||
var appPasswordHash: String
|
||||
get() = prefs.getString(APP_PASSWORD_HASH, "")
|
||||
get() = prefs.getString(APP_PASSWORD_HASH, "")!!
|
||||
set(appPasswordHash) = prefs.edit().putString(APP_PASSWORD_HASH, appPasswordHash).apply()
|
||||
|
||||
var appProtectionType: Int
|
||||
|
@ -130,7 +130,7 @@ open class BaseConfig(val context: Context) {
|
|||
set(isDeletePasswordProtectionOn) = prefs.edit().putBoolean(DELETE_PASSWORD_PROTECTION, isDeletePasswordProtectionOn).apply()
|
||||
|
||||
var deletePasswordHash: String
|
||||
get() = prefs.getString(DELETE_PASSWORD_HASH, "")
|
||||
get() = prefs.getString(DELETE_PASSWORD_HASH, "")!!
|
||||
set(deletePasswordHash) = prefs.edit().putString(DELETE_PASSWORD_HASH, deletePasswordHash).apply()
|
||||
|
||||
var deleteProtectionType: Int
|
||||
|
@ -240,7 +240,7 @@ open class BaseConfig(val context: Context) {
|
|||
set(vibrateOnButton) = prefs.edit().putBoolean(VIBRATE_ON_BUTTON_PRESS, vibrateOnButton).apply()
|
||||
|
||||
var yourAlarmSounds: String
|
||||
get() = prefs.getString(YOUR_ALARM_SOUNDS, "")
|
||||
get() = prefs.getString(YOUR_ALARM_SOUNDS, "")!!
|
||||
set(yourAlarmSounds) = prefs.edit().putString(YOUR_ALARM_SOUNDS, yourAlarmSounds).apply()
|
||||
|
||||
var isUsingModifiedAppIcon: Boolean
|
||||
|
@ -248,7 +248,7 @@ open class BaseConfig(val context: Context) {
|
|||
set(isUsingModifiedAppIcon) = prefs.edit().putBoolean(IS_USING_MODIFIED_APP_ICON, isUsingModifiedAppIcon).apply()
|
||||
|
||||
var appId: String
|
||||
get() = prefs.getString(APP_ID, "")
|
||||
get() = prefs.getString(APP_ID, "")!!
|
||||
set(appId) = prefs.edit().putString(APP_ID, appId).apply()
|
||||
|
||||
var initialWidgetHeight: Int
|
||||
|
@ -282,4 +282,8 @@ open class BaseConfig(val context: Context) {
|
|||
var appSideloadingStatus: Int
|
||||
get() = prefs.getInt(APP_SIDELOADING_STATUS, SIDELOADING_UNCHECKED)
|
||||
set(appSideloadingStatus) = prefs.edit().putInt(APP_SIDELOADING_STATUS, appSideloadingStatus).apply()
|
||||
|
||||
var dateFormat: String
|
||||
get() = prefs.getString(DATE_FORMAT, DATE_FORMAT_ONE)!!
|
||||
set(dateFormat) = prefs.edit().putString(DATE_FORMAT, dateFormat).apply()
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ const val WAS_BEFORE_ASKING_SHOWN = "was_before_asking_shown"
|
|||
const val WAS_INITIAL_UPGRADE_TO_PRO_SHOWN = "was_initial_upgrade_to_pro_shown"
|
||||
const val WAS_APP_ICON_CUSTOMIZATION_WARNING_SHOWN = "was_app_icon_customization_warning_shown"
|
||||
const val APP_SIDELOADING_STATUS = "app_sideloading_status"
|
||||
const val DATE_FORMAT = "date_format"
|
||||
|
||||
// licenses
|
||||
internal const val LICENSE_KOTLIN = 1
|
||||
|
@ -202,6 +203,11 @@ val videoExtensions: Array<String> get() = arrayOf(".mp4", ".mkv", ".webm", ".av
|
|||
val audioExtensions: Array<String> get() = arrayOf(".mp3", ".wav", ".wma", ".ogg", ".m4a", ".opus", ".flac", ".aac")
|
||||
val rawExtensions: Array<String> get() = arrayOf(".dng", ".orf", ".nef", ".arw")
|
||||
|
||||
const val DATE_FORMAT_ONE = "dd.MM.yyyy"
|
||||
const val DATE_FORMAT_TWO = "dd/MM/yyyy"
|
||||
const val DATE_FORMAT_THREE = "MM/dd/yyyy"
|
||||
const val DATE_FORMAT_FOUR = "yyyy-MM-dd"
|
||||
|
||||
val appIconColorStrings = arrayListOf(
|
||||
".Red",
|
||||
".Pink",
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?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/change_date_time_dialog_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin">
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/change_date_time_dialog_radio_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/medium_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/change_date_time_dialog_radio_one"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:textAllCaps="true"
|
||||
tools:text="dd.MM.yyyy"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/change_date_time_dialog_radio_two"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:textAllCaps="true"
|
||||
tools:text="dd/MM/yyyy"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/change_date_time_dialog_radio_three"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:textAllCaps="true"
|
||||
tools:text="MM/dd/yyyy"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/change_date_time_dialog_radio_four"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:textAllCaps="true"
|
||||
tools:text="yyyy-MM-dd"/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/change_date_time_dialog_24_hour"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:text="@string/use_24_hour_time_format"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue