diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt index 033ad2d..1bc691b 100755 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt @@ -31,6 +31,7 @@ object Preferences : KotprefModel() { var customLocationAdd by stringPref(key = "PREF_CUSTOM_LOCATION_ADD", default = "") var dateFormat by stringPref(default = "") var isDateCapitalize by booleanPref(default = true) + var isDateUppercase by booleanPref(default = false) var weatherRefreshPeriod by intPref(key = "PREF_WEATHER_REFRESH_PERIOD", default = 1) var showUntil by intPref(key = "PREF_SHOW_UNTIL", default = 1) var calendarAppName by stringPref(key = "PREF_CALENDAR_APP_NAME", default = "") diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/DateHelper.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/DateHelper.kt index 1539736..7c3a480 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/DateHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/DateHelper.kt @@ -2,7 +2,6 @@ package com.tommasoberlose.anotherwidget.helpers import android.content.Context import android.text.format.DateUtils -import android.util.Log import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.utils.getCapWordString import java.lang.Exception @@ -17,7 +16,11 @@ object DateHelper { } catch (e: Exception) { getDefaultDateText(context, date) } - if (Preferences.isDateCapitalize) text.getCapWordString() else text + when { + Preferences.isDateUppercase -> text.toUpperCase(Locale.getDefault()) + Preferences.isDateCapitalize -> text.getCapWordString() + else -> text + } } else { val flags: Int = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH @@ -25,17 +28,20 @@ object DateHelper { SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time), DateUtils.formatDateTime(context, date.timeInMillis, flags) ) - if (Preferences.isDateCapitalize) text.getCapWordString() else text + when { + Preferences.isDateUppercase -> text.toUpperCase(Locale.getDefault()) + Preferences.isDateCapitalize -> text.getCapWordString() + else -> text + } } } fun getDefaultDateText(context: Context, date: Calendar): String { val flags: Int = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH - val text = "%s, %s".format( + return "%s, %s".format( SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time), DateUtils.formatDateTime(context, date.timeInMillis, flags) ) - return if (Preferences.isDateCapitalize) text.getCapWordString() else text } } \ No newline at end of file diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/CustomDateActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/CustomDateActivity.kt index a643052..6038f26 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/CustomDateActivity.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/CustomDateActivity.kt @@ -6,12 +6,14 @@ import android.os.Bundle import android.util.Log import android.view.View import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.databinding.DataBindingUtil import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager +import com.chibatching.kotpref.blockingBulk import com.chibatching.kotpref.bulk import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.databinding.ActivityCustomDateBinding @@ -90,10 +92,14 @@ class CustomDateActivity : AppCompatActivity() { "__" } - if (Preferences.isDateCapitalize) { + if (viewModel.isDateCapitalize.value == true) { text = text.getCapWordString() } + if (viewModel.isDateUppercase.value == true) { + text = text.toUpperCase(Locale.getDefault()) + } + withContext(Dispatchers.Main) { action_save.isVisible = text != ERROR_STRING loader.visibility = View.INVISIBLE @@ -105,8 +111,30 @@ class CustomDateActivity : AppCompatActivity() { viewModel.isDateCapitalize.observe(this, Observer { viewModel.dateInput.value = viewModel.dateInput.value - binding.isdCapitalizeEnabled = it + updateCapitalizeUi() }) + + viewModel.isDateUppercase.observe(this, Observer { + viewModel.dateInput.value = viewModel.dateInput.value + updateCapitalizeUi() + }) + } + + private fun updateCapitalizeUi() { + when { + viewModel.isDateUppercase.value == true -> { + action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish)) + action_capitalize.alpha = 1f + } + viewModel.isDateCapitalize.value == true -> { + action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.ic_capitalize)) + action_capitalize.alpha = 1f + } + else -> { + action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish)) + action_capitalize.alpha = 0.3f + } + } } private fun setupListener() { @@ -115,12 +143,29 @@ class CustomDateActivity : AppCompatActivity() { } action_save.setOnClickListener { - Preferences.dateFormat = viewModel.dateInput.value ?: "" + Preferences.blockingBulk { + dateFormat = viewModel.dateInput.value ?: "" + isDateCapitalize = viewModel.isDateCapitalize.value ?: true + isDateUppercase = viewModel.isDateUppercase.value ?: false + } finish() } action_capitalize.setOnClickListener { - Preferences.isDateCapitalize = !Preferences.isDateCapitalize + when { + viewModel.isDateUppercase.value == true -> { + viewModel.isDateCapitalize.value = false + viewModel.isDateUppercase.value = false + } + viewModel.isDateCapitalize.value == true -> { + viewModel.isDateCapitalize.value = false + viewModel.isDateUppercase.value = true + } + else -> { + viewModel.isDateCapitalize.value = true + viewModel.isDateUppercase.value = false + } + } } action_capitalize.setOnLongClickListener { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt index 0312559..4b03e8e 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt @@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope +import com.chibatching.kotpref.blockingBulk import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetMenu @@ -256,6 +257,12 @@ class GeneralTabFragment : Fragment() { dialog.addOnSelectItemListener { value -> if (value == "-") { startActivity(Intent(requireContext(), CustomDateActivity::class.java)) + } else if (value == "") { + Preferences.blockingBulk { + isDateCapitalize = false + isDateUppercase = false + } + Preferences.dateFormat = value } else { Preferences.dateFormat = value } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/CustomDateViewModel.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/CustomDateViewModel.kt index f116b46..2caf3e8 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/CustomDateViewModel.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/CustomDateViewModel.kt @@ -8,5 +8,6 @@ import com.tommasoberlose.anotherwidget.global.Preferences class CustomDateViewModel(application: Application) : AndroidViewModel(application) { val dateInput: MutableLiveData = MutableLiveData(if (Preferences.dateFormat == "") "EEEE, MMM dd" else Preferences.dateFormat) - val isDateCapitalize = Preferences.asLiveData(Preferences::isDateCapitalize) + val isDateCapitalize = MutableLiveData(Preferences.isDateCapitalize) + val isDateUppercase = MutableLiveData(Preferences.isDateUppercase) } \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/ic_capitalize.png b/app/src/main/res/drawable-hdpi/ic_capitalize.png new file mode 100644 index 0000000..fcf1157 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_capitalize.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_capitalize.png b/app/src/main/res/drawable-mdpi/ic_capitalize.png new file mode 100644 index 0000000..c808e7f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_capitalize.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_capitalize.png b/app/src/main/res/drawable-xhdpi/ic_capitalize.png new file mode 100644 index 0000000..00a8aa3 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_capitalize.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_capitalize.png b/app/src/main/res/drawable-xxhdpi/ic_capitalize.png new file mode 100644 index 0000000..d615bc2 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_capitalize.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_capitalize.png b/app/src/main/res/drawable-xxxhdpi/ic_capitalize.png new file mode 100644 index 0000000..861783e Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_capitalize.png differ diff --git a/app/src/main/res/layout/activity_custom_date.xml b/app/src/main/res/layout/activity_custom_date.xml index f420b93..bb4fcf1 100644 --- a/app/src/main/res/layout/activity_custom_date.xml +++ b/app/src/main/res/layout/activity_custom_date.xml @@ -5,9 +5,6 @@ -