Close #148
This commit is contained in:
parent
94825808f4
commit
e58fef66aa
@ -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 = "")
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
|
||||
class CustomDateViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val dateInput: MutableLiveData<String> = MutableLiveData(if (Preferences.dateFormat == "") "EEEE, MMM dd" else Preferences.dateFormat)
|
||||
val isDateCapitalize = Preferences.asLiveData(Preferences::isDateCapitalize)
|
||||
val isDateCapitalize = MutableLiveData<Boolean>(Preferences.isDateCapitalize)
|
||||
val isDateUppercase = MutableLiveData<Boolean>(Preferences.isDateUppercase)
|
||||
}
|
BIN
app/src/main/res/drawable-hdpi/ic_capitalize.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_capitalize.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 471 B |
BIN
app/src/main/res/drawable-mdpi/ic_capitalize.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_capitalize.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 355 B |
BIN
app/src/main/res/drawable-xhdpi/ic_capitalize.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_capitalize.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 592 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_capitalize.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_capitalize.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 773 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_capitalize.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_capitalize.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -5,9 +5,6 @@
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.tommasoberlose.anotherwidget.ui.viewmodels.CustomDateViewModel" />
|
||||
<variable
|
||||
name="isdCapitalizeEnabled"
|
||||
type="Boolean" />
|
||||
</data>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
@ -145,14 +142,13 @@
|
||||
android:layout_height="40dp"
|
||||
android:padding="5dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/round_publish"
|
||||
android:src="@drawable/ic_capitalize"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
app:tint="@color/colorPrimaryText"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:alpha="@{isdCapitalizeEnabled ? 1f : 0.3f, default=0.3}"
|
||||
android:id="@+id/action_capitalize" />
|
||||
</RelativeLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
Loading…
x
Reference in New Issue
Block a user