mirror of https://github.com/iSoron/uhabits.git
parent
162eac3bdf
commit
cb6843e08b
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.show
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.HapticFeedbackConstants
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialogFactory
|
||||
import org.isoron.uhabits.activities.common.dialogs.HistoryEditorDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.ui.callbacks.OnConfirmedCallback
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitBehavior
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuBehavior
|
||||
import org.isoron.uhabits.core.ui.views.OnDateClickedListener
|
||||
import org.isoron.uhabits.intents.IntentFactory
|
||||
import org.isoron.uhabits.utils.showMessage
|
||||
import org.isoron.uhabits.utils.showSendFileScreen
|
||||
import org.isoron.uhabits.widgets.WidgetUpdater
|
||||
|
||||
class ShowHabitScreen(
|
||||
val activity: ShowHabitActivity,
|
||||
val confirmDeleteDialogFactory: ConfirmDeleteDialogFactory,
|
||||
val habit: Habit,
|
||||
val intentFactory: IntentFactory,
|
||||
val numberPickerFactory: NumberPickerFactory,
|
||||
val widgetUpdater: WidgetUpdater,
|
||||
) : ShowHabitBehavior.Screen, ShowHabitMenuBehavior.Screen {
|
||||
|
||||
override fun showNumberPicker(
|
||||
value: Double,
|
||||
unit: String,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback,
|
||||
) {
|
||||
numberPickerFactory.create(value, unit, callback).show()
|
||||
}
|
||||
|
||||
override fun updateWidgets() {
|
||||
widgetUpdater.updateWidgets(habit.id)
|
||||
}
|
||||
|
||||
override fun refresh() {
|
||||
activity.refresh()
|
||||
}
|
||||
|
||||
override fun showHistoryEditorDialog(listener: OnDateClickedListener) {
|
||||
val dialog = HistoryEditorDialog()
|
||||
dialog.arguments = Bundle().apply {
|
||||
putLong("habit", habit.id!!)
|
||||
}
|
||||
dialog.setOnDateClickedListener(listener)
|
||||
dialog.show(activity.supportFragmentManager, "historyEditor")
|
||||
}
|
||||
|
||||
override fun touchFeedback() {
|
||||
activity.window.decorView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
}
|
||||
|
||||
override fun showEditHabitScreen(habit: Habit) {
|
||||
activity.startActivity(intentFactory.startEditActivity(activity, habit))
|
||||
}
|
||||
|
||||
override fun showMessage(m: ShowHabitMenuBehavior.Message?) {
|
||||
when (m) {
|
||||
ShowHabitMenuBehavior.Message.COULD_NOT_EXPORT -> {
|
||||
activity.showMessage(activity.resources.getString(R.string.could_not_export))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun showSendFileScreen(filename: String) {
|
||||
activity.showSendFileScreen(filename)
|
||||
}
|
||||
|
||||
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
|
||||
confirmDeleteDialogFactory.create(callback, 1).show()
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
activity.finish()
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.uhabits.core.ui.screens.habits.show
|
||||
|
||||
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.Entry
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
||||
import org.isoron.uhabits.core.ui.views.OnDateClickedListener
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class ShowHabitBehavior(
|
||||
private val habitList: HabitList,
|
||||
private val commandRunner: CommandRunner,
|
||||
private val habit: Habit,
|
||||
private val screen: Screen,
|
||||
private val preferences: Preferences,
|
||||
) : OnDateClickedListener {
|
||||
|
||||
fun onScoreCardSpinnerPosition(position: Int) {
|
||||
preferences.scoreCardSpinnerPosition = position
|
||||
screen.updateWidgets()
|
||||
screen.refresh()
|
||||
}
|
||||
|
||||
fun onBarCardBoolSpinnerPosition(position: Int) {
|
||||
preferences.barCardBoolSpinnerPosition = position
|
||||
screen.updateWidgets()
|
||||
screen.refresh()
|
||||
}
|
||||
|
||||
fun onBarCardNumericalSpinnerPosition(position: Int) {
|
||||
preferences.barCardNumericalSpinnerPosition = position
|
||||
screen.refresh()
|
||||
screen.updateWidgets()
|
||||
}
|
||||
|
||||
fun onClickEditHistory() {
|
||||
screen.showHistoryEditorDialog(this)
|
||||
}
|
||||
|
||||
override fun onDateClicked(date: LocalDate) {
|
||||
val timestamp = date.timestamp
|
||||
screen.touchFeedback()
|
||||
if (habit.isNumerical) {
|
||||
val entries = habit.computedEntries
|
||||
val oldValue = entries.get(timestamp).value
|
||||
screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double ->
|
||||
val thousands = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
thousands,
|
||||
),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val currentValue = habit.computedEntries.get(timestamp).value
|
||||
val nextValue = if (preferences.isSkipEnabled) {
|
||||
Entry.nextToggleValueWithSkip(currentValue)
|
||||
} else {
|
||||
Entry.nextToggleValueWithoutSkip(currentValue)
|
||||
}
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
nextValue,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface Screen {
|
||||
fun showNumberPicker(
|
||||
value: Double,
|
||||
unit: String,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback,
|
||||
)
|
||||
|
||||
fun updateWidgets()
|
||||
fun refresh()
|
||||
fun showHistoryEditorDialog(listener: OnDateClickedListener)
|
||||
fun touchFeedback()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue