mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Added archive and unarchive to the habit statistics page, visibility based on current state.
This commit is contained in:
@@ -35,6 +35,9 @@ class ShowHabitMenu(
|
|||||||
if (preferences.isDeveloper) {
|
if (preferences.isDeveloper) {
|
||||||
menu.findItem(R.id.action_randomize).isVisible = true
|
menu.findItem(R.id.action_randomize).isVisible = true
|
||||||
}
|
}
|
||||||
|
menu.findItem(R.id.action_archive_habit).isVisible = presenter.canArchive()
|
||||||
|
menu.findItem(R.id.action_unarchive_habit).isVisible = presenter.canUnarchive()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +47,15 @@ class ShowHabitMenu(
|
|||||||
presenter.onEditHabit()
|
presenter.onEditHabit()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
R.id.action_archive_habit -> {
|
||||||
|
presenter.onArchiveHabits()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.action_unarchive_habit -> {
|
||||||
|
presenter.onUnarchiveHabits()
|
||||||
|
return true
|
||||||
|
}
|
||||||
R.id.action_delete -> {
|
R.id.action_delete -> {
|
||||||
presenter.onDeleteHabit()
|
presenter.onDeleteHabit()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -26,6 +26,16 @@
|
|||||||
android:title="@string/export"
|
android:title="@string/export"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_archive_habit"
|
||||||
|
android:title="@string/archive"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_unarchive_habit"
|
||||||
|
android:title="@string/unarchive"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_delete"
|
android:id="@+id/action_delete"
|
||||||
android:title="@string/delete"
|
android:title="@string/delete"
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
package org.isoron.uhabits.core.ui.screens.habits.show
|
package org.isoron.uhabits.core.ui.screens.habits.show
|
||||||
|
|
||||||
import org.isoron.uhabits.core.commands.CommandRunner
|
import org.isoron.uhabits.core.commands.CommandRunner
|
||||||
|
import org.isoron.uhabits.core.commands.ArchiveHabitsCommand
|
||||||
|
import org.isoron.uhabits.core.commands.UnarchiveHabitsCommand
|
||||||
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
|
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
@@ -40,10 +42,23 @@ class ShowHabitMenuPresenter(
|
|||||||
private val system: System,
|
private val system: System,
|
||||||
private val taskRunner: TaskRunner
|
private val taskRunner: TaskRunner
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
fun canArchive(): Boolean {
|
||||||
|
return !(habit.isArchived)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun canUnarchive(): Boolean {
|
||||||
|
return habit.isArchived
|
||||||
|
}
|
||||||
|
|
||||||
fun onEditHabit() {
|
fun onEditHabit() {
|
||||||
screen.showEditHabitScreen(habit)
|
screen.showEditHabitScreen(habit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onArchiveHabits() {
|
||||||
|
commandRunner.run(ArchiveHabitsCommand(habitList,listOf(habit)))
|
||||||
|
}
|
||||||
|
|
||||||
fun onExportCSV() {
|
fun onExportCSV() {
|
||||||
val outputDir = system.getCSVOutputDir()
|
val outputDir = system.getCSVOutputDir()
|
||||||
taskRunner.execute(
|
taskRunner.execute(
|
||||||
@@ -64,6 +79,10 @@ class ShowHabitMenuPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onUnarchiveHabits() {
|
||||||
|
commandRunner.run(UnarchiveHabitsCommand(habitList,listOf(habit)))
|
||||||
|
}
|
||||||
|
|
||||||
fun onRandomize() {
|
fun onRandomize() {
|
||||||
val random = Random()
|
val random = Random()
|
||||||
habit.originalEntries.clear()
|
habit.originalEntries.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user