mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
CheckmarkDialog: Format date using current locale
This commit is contained in:
@@ -8,6 +8,8 @@ import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import org.isoron.platform.gui.toInt
|
||||
import org.isoron.platform.time.JavaLocalDateFormatter
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||
@@ -22,6 +24,7 @@ import org.isoron.uhabits.databinding.CheckmarkDialogBinding
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.InterfaceUtils
|
||||
import org.isoron.uhabits.utils.StyledResources
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
class CheckmarkDialog
|
||||
@@ -36,9 +39,9 @@ class CheckmarkDialog
|
||||
private var selectedButton: Button? = null
|
||||
|
||||
fun create(
|
||||
value: Int,
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
date: LocalDate,
|
||||
paletteColor: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback,
|
||||
theme: Theme,
|
||||
@@ -46,11 +49,11 @@ class CheckmarkDialog
|
||||
binding = CheckmarkDialogBinding.inflate(LayoutInflater.from(context))
|
||||
fontAwesome = InterfaceUtils.getFontAwesome(context)!!
|
||||
binding.etNotes.append(notes)
|
||||
setUpButtons(value, theme.color(paletteColor).toInt())
|
||||
setUpButtons(selectedValue, theme.color(paletteColor).toInt())
|
||||
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setView(binding.root)
|
||||
.setTitle(dateString)
|
||||
.setTitle(JavaLocalDateFormatter(Locale.getDefault()).longFormat(date))
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
val newValue = when (selectedButton?.id) {
|
||||
R.id.yesBtn -> YES_MANUAL
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import dagger.Lazy
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.dialogs.CheckmarkDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory
|
||||
@@ -235,16 +236,17 @@ class ListHabitsScreen
|
||||
}
|
||||
|
||||
override fun showCheckmarkDialog(
|
||||
value: Int,
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
date: LocalDate,
|
||||
dateString: String,
|
||||
color: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
) {
|
||||
checkMarkDialog.create(
|
||||
value,
|
||||
selectedValue,
|
||||
notes,
|
||||
dateString,
|
||||
date,
|
||||
color,
|
||||
callback,
|
||||
themeSwitcher.currentTheme!!,
|
||||
|
||||
@@ -27,6 +27,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.AndroidDirFinder
|
||||
import org.isoron.uhabits.HabitsApplication
|
||||
import org.isoron.uhabits.R
|
||||
@@ -174,17 +175,17 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
}
|
||||
|
||||
override fun showCheckmarkDialog(
|
||||
value: Int,
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
date: LocalDate,
|
||||
preferences: Preferences,
|
||||
color: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
) {
|
||||
CheckmarkDialog(this@ShowHabitActivity, preferences).create(
|
||||
value,
|
||||
selectedValue,
|
||||
notes,
|
||||
dateString,
|
||||
date,
|
||||
color,
|
||||
callback,
|
||||
themeSwitcher.currentTheme!!,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.isoron.platform.time
|
||||
|
||||
import java.text.DateFormat
|
||||
import java.util.Calendar.DAY_OF_MONTH
|
||||
import java.util.Calendar.DAY_OF_WEEK
|
||||
import java.util.Calendar.HOUR_OF_DAY
|
||||
@@ -66,4 +67,10 @@ class JavaLocalDateFormatter(private val locale: Locale) : LocalDateFormatter {
|
||||
val cal = date.toGregorianCalendar()
|
||||
return cal.getDisplayName(DAY_OF_WEEK, SHORT, locale)
|
||||
}
|
||||
|
||||
fun longFormat(date: LocalDate): String {
|
||||
val df = DateFormat.getDateInstance(DateFormat.LONG, locale)
|
||||
df.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return df.format(date.toGregorianCalendar().time)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.isoron.uhabits.core.ui.screens.habits.list
|
||||
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
@@ -65,6 +66,7 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
screen.showCheckmarkDialog(
|
||||
entry.value,
|
||||
entry.notes,
|
||||
timestamp.toLocalDate(),
|
||||
timestamp.toDialogDateString(),
|
||||
habit.color,
|
||||
) { newValue, newNotes ->
|
||||
@@ -168,8 +170,9 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
callback: NumberPickerCallback
|
||||
)
|
||||
fun showCheckmarkDialog(
|
||||
value: Int,
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
date: LocalDate,
|
||||
dateString: String,
|
||||
color: PaletteColor,
|
||||
callback: CheckMarkDialogCallback
|
||||
|
||||
@@ -93,7 +93,7 @@ class HistoryCardPresenter(
|
||||
screen.showCheckmarkDialog(
|
||||
entry.value,
|
||||
entry.notes,
|
||||
timestamp.toDialogDateString(),
|
||||
timestamp.toLocalDate(),
|
||||
preferences,
|
||||
habit.color,
|
||||
) { newValue, newNotes ->
|
||||
@@ -206,9 +206,9 @@ class HistoryCardPresenter(
|
||||
callback: ListHabitsBehavior.NumberPickerCallback,
|
||||
)
|
||||
fun showCheckmarkDialog(
|
||||
value: Int,
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
date: LocalDate,
|
||||
preferences: Preferences,
|
||||
color: PaletteColor,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback,
|
||||
|
||||
Reference in New Issue
Block a user