CheckmarkDialog: Format date using current locale

pull/1260/head
Alinson S. Xavier 4 years ago
parent feeb4f057d
commit d875af8a8e
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -8,6 +8,8 @@ import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
import android.widget.Button import android.widget.Button
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import org.isoron.platform.gui.toInt 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.R
import org.isoron.uhabits.core.models.Entry.Companion.NO import org.isoron.uhabits.core.models.Entry.Companion.NO
import org.isoron.uhabits.core.models.Entry.Companion.SKIP 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.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils import org.isoron.uhabits.utils.InterfaceUtils
import org.isoron.uhabits.utils.StyledResources import org.isoron.uhabits.utils.StyledResources
import java.util.Locale
import javax.inject.Inject import javax.inject.Inject
class CheckmarkDialog class CheckmarkDialog
@ -36,9 +39,9 @@ class CheckmarkDialog
private var selectedButton: Button? = null private var selectedButton: Button? = null
fun create( fun create(
value: Int, selectedValue: Int,
notes: String, notes: String,
dateString: String, date: LocalDate,
paletteColor: PaletteColor, paletteColor: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback, callback: ListHabitsBehavior.CheckMarkDialogCallback,
theme: Theme, theme: Theme,
@ -46,11 +49,11 @@ class CheckmarkDialog
binding = CheckmarkDialogBinding.inflate(LayoutInflater.from(context)) binding = CheckmarkDialogBinding.inflate(LayoutInflater.from(context))
fontAwesome = InterfaceUtils.getFontAwesome(context)!! fontAwesome = InterfaceUtils.getFontAwesome(context)!!
binding.etNotes.append(notes) binding.etNotes.append(notes)
setUpButtons(value, theme.color(paletteColor).toInt()) setUpButtons(selectedValue, theme.color(paletteColor).toInt())
val dialog = AlertDialog.Builder(context) val dialog = AlertDialog.Builder(context)
.setView(binding.root) .setView(binding.root)
.setTitle(dateString) .setTitle(JavaLocalDateFormatter(Locale.getDefault()).longFormat(date))
.setPositiveButton(R.string.save) { _, _ -> .setPositiveButton(R.string.save) { _, _ ->
val newValue = when (selectedButton?.id) { val newValue = when (selectedButton?.id) {
R.id.yesBtn -> YES_MANUAL R.id.yesBtn -> YES_MANUAL

@ -24,6 +24,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import dagger.Lazy import dagger.Lazy
import org.isoron.platform.time.LocalDate
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.activities.common.dialogs.CheckmarkDialog import org.isoron.uhabits.activities.common.dialogs.CheckmarkDialog
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory
@ -235,16 +236,17 @@ class ListHabitsScreen
} }
override fun showCheckmarkDialog( override fun showCheckmarkDialog(
value: Int, selectedValue: Int,
notes: String, notes: String,
date: LocalDate,
dateString: String, dateString: String,
color: PaletteColor, color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback
) { ) {
checkMarkDialog.create( checkMarkDialog.create(
value, selectedValue,
notes, notes,
dateString, date,
color, color,
callback, callback,
themeSwitcher.currentTheme!!, themeSwitcher.currentTheme!!,

@ -27,6 +27,7 @@ import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.isoron.platform.time.LocalDate
import org.isoron.uhabits.AndroidDirFinder import org.isoron.uhabits.AndroidDirFinder
import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R import org.isoron.uhabits.R
@ -174,17 +175,17 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
} }
override fun showCheckmarkDialog( override fun showCheckmarkDialog(
value: Int, selectedValue: Int,
notes: String, notes: String,
dateString: String, date: LocalDate,
preferences: Preferences, preferences: Preferences,
color: PaletteColor, color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback
) { ) {
CheckmarkDialog(this@ShowHabitActivity, preferences).create( CheckmarkDialog(this@ShowHabitActivity, preferences).create(
value, selectedValue,
notes, notes,
dateString, date,
color, color,
callback, callback,
themeSwitcher.currentTheme!!, themeSwitcher.currentTheme!!,

@ -19,6 +19,7 @@
package org.isoron.platform.time package org.isoron.platform.time
import java.text.DateFormat
import java.util.Calendar.DAY_OF_MONTH import java.util.Calendar.DAY_OF_MONTH
import java.util.Calendar.DAY_OF_WEEK import java.util.Calendar.DAY_OF_WEEK
import java.util.Calendar.HOUR_OF_DAY import java.util.Calendar.HOUR_OF_DAY
@ -66,4 +67,10 @@ class JavaLocalDateFormatter(private val locale: Locale) : LocalDateFormatter {
val cal = date.toGregorianCalendar() val cal = date.toGregorianCalendar()
return cal.getDisplayName(DAY_OF_WEEK, SHORT, locale) 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 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.CommandRunner
import org.isoron.uhabits.core.commands.CreateRepetitionCommand import org.isoron.uhabits.core.commands.CreateRepetitionCommand
import org.isoron.uhabits.core.models.Habit import org.isoron.uhabits.core.models.Habit
@ -65,6 +66,7 @@ open class ListHabitsBehavior @Inject constructor(
screen.showCheckmarkDialog( screen.showCheckmarkDialog(
entry.value, entry.value,
entry.notes, entry.notes,
timestamp.toLocalDate(),
timestamp.toDialogDateString(), timestamp.toDialogDateString(),
habit.color, habit.color,
) { newValue, newNotes -> ) { newValue, newNotes ->
@ -168,8 +170,9 @@ open class ListHabitsBehavior @Inject constructor(
callback: NumberPickerCallback callback: NumberPickerCallback
) )
fun showCheckmarkDialog( fun showCheckmarkDialog(
value: Int, selectedValue: Int,
notes: String, notes: String,
date: LocalDate,
dateString: String, dateString: String,
color: PaletteColor, color: PaletteColor,
callback: CheckMarkDialogCallback callback: CheckMarkDialogCallback

@ -93,7 +93,7 @@ class HistoryCardPresenter(
screen.showCheckmarkDialog( screen.showCheckmarkDialog(
entry.value, entry.value,
entry.notes, entry.notes,
timestamp.toDialogDateString(), timestamp.toLocalDate(),
preferences, preferences,
habit.color, habit.color,
) { newValue, newNotes -> ) { newValue, newNotes ->
@ -206,9 +206,9 @@ class HistoryCardPresenter(
callback: ListHabitsBehavior.NumberPickerCallback, callback: ListHabitsBehavior.NumberPickerCallback,
) )
fun showCheckmarkDialog( fun showCheckmarkDialog(
value: Int, selectedValue: Int,
notes: String, notes: String,
dateString: String, date: LocalDate,
preferences: Preferences, preferences: Preferences,
color: PaletteColor, color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback, callback: ListHabitsBehavior.CheckMarkDialogCallback,

Loading…
Cancel
Save