|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
package org.isoron.uhabits.activities.common.dialogs
|
|
|
|
|
|
|
|
|
|
import android.app.Dialog
|
|
|
|
|
import android.content.DialogInterface
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import androidx.appcompat.app.AppCompatDialogFragment
|
|
|
|
|
import org.isoron.platform.gui.AndroidDataView
|
|
|
|
@ -35,6 +36,7 @@ import org.isoron.uhabits.core.ui.views.HistoryChart
|
|
|
|
|
import org.isoron.uhabits.core.ui.views.LightTheme
|
|
|
|
|
import org.isoron.uhabits.core.ui.views.OnDateClickedListener
|
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils
|
|
|
|
|
import org.isoron.uhabits.inject.HabitsApplicationComponent
|
|
|
|
|
import java.util.Locale
|
|
|
|
|
import kotlin.math.min
|
|
|
|
|
|
|
|
|
@ -49,12 +51,13 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
|
|
|
|
private var onDateClickedListener: OnDateClickedListener? = null
|
|
|
|
|
|
|
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
|
|
|
val component = (activity!!.application as HabitsApplication).component
|
|
|
|
|
clearCurrentDialog()
|
|
|
|
|
val component = (requireActivity().application as HabitsApplication).component
|
|
|
|
|
commandRunner = component.commandRunner
|
|
|
|
|
habit = component.habitList.getById(arguments!!.getLong("habit"))!!
|
|
|
|
|
habit = component.habitList.getById(requireArguments().getLong("habit"))!!
|
|
|
|
|
preferences = component.preferences
|
|
|
|
|
|
|
|
|
|
val themeSwitcher = AndroidThemeSwitcher(activity!!, preferences)
|
|
|
|
|
val themeSwitcher = AndroidThemeSwitcher(requireActivity(), preferences)
|
|
|
|
|
themeSwitcher.apply()
|
|
|
|
|
|
|
|
|
|
chart = HistoryChart(
|
|
|
|
@ -69,15 +72,23 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
|
|
|
|
onDateClickedListener = onDateClickedListener ?: object : OnDateClickedListener {},
|
|
|
|
|
padding = 10.0,
|
|
|
|
|
)
|
|
|
|
|
dataView = AndroidDataView(context!!, null)
|
|
|
|
|
dataView = AndroidDataView(requireContext(), null)
|
|
|
|
|
dataView.view = chart!!
|
|
|
|
|
|
|
|
|
|
return Dialog(context!!).apply {
|
|
|
|
|
val dialog = Dialog(requireContext()).apply {
|
|
|
|
|
val metrics = resources.displayMetrics
|
|
|
|
|
val maxHeight = resources.getDimensionPixelSize(R.dimen.history_editor_max_height)
|
|
|
|
|
setContentView(dataView)
|
|
|
|
|
window!!.setLayout(metrics.widthPixels, min(metrics.heightPixels, maxHeight))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentDialog = dialog
|
|
|
|
|
return dialog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDismiss(dialog: DialogInterface) {
|
|
|
|
|
super.onDismiss(dialog)
|
|
|
|
|
currentDialog = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
@ -111,4 +122,14 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
|
|
|
|
override fun onCommandFinished(command: Command) {
|
|
|
|
|
refreshData()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
// HistoryEditorDialog handles multiple dialogs on its own,
|
|
|
|
|
// because sometimes we want it to be shown under another dialog (e.g. NumberPopup)
|
|
|
|
|
var currentDialog: Dialog? = null
|
|
|
|
|
fun clearCurrentDialog() {
|
|
|
|
|
currentDialog?.dismiss()
|
|
|
|
|
currentDialog = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|