|
|
@ -23,6 +23,7 @@ import android.os.Bundle
|
|
|
|
import android.view.HapticFeedbackConstants
|
|
|
|
import android.view.HapticFeedbackConstants
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
@ -38,6 +39,7 @@ import org.isoron.uhabits.activities.common.dialogs.CheckmarkPopup
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.HistoryEditorDialog
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.HistoryEditorDialog
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
|
|
|
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.NumberPopup
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.POPUP_WIDTH
|
|
|
|
import org.isoron.uhabits.activities.common.dialogs.POPUP_WIDTH
|
|
|
|
import org.isoron.uhabits.core.commands.Command
|
|
|
|
import org.isoron.uhabits.core.commands.Command
|
|
|
|
import org.isoron.uhabits.core.commands.CommandRunner
|
|
|
|
import org.isoron.uhabits.core.commands.CommandRunner
|
|
|
@ -187,6 +189,26 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
|
|
|
).show()
|
|
|
|
).show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun showNumberPopup(
|
|
|
|
|
|
|
|
value: Double,
|
|
|
|
|
|
|
|
notes: String,
|
|
|
|
|
|
|
|
preferences: Preferences,
|
|
|
|
|
|
|
|
location: ScreenLocation,
|
|
|
|
|
|
|
|
callback: ListHabitsBehavior.NumberPickerCallback
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
val anchor = getPopupAnchor() ?: return
|
|
|
|
|
|
|
|
NumberPopup(
|
|
|
|
|
|
|
|
context = this@ShowHabitActivity,
|
|
|
|
|
|
|
|
prefs = preferences,
|
|
|
|
|
|
|
|
notes = notes,
|
|
|
|
|
|
|
|
anchor = anchor,
|
|
|
|
|
|
|
|
value = value,
|
|
|
|
|
|
|
|
).apply {
|
|
|
|
|
|
|
|
onToggle = { v, n -> callback.onNumberPicked(v, n) }
|
|
|
|
|
|
|
|
show(computePopupLocation(anchor, location))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun showCheckmarkPopup(
|
|
|
|
override fun showCheckmarkPopup(
|
|
|
|
selectedValue: Int,
|
|
|
|
selectedValue: Int,
|
|
|
|
notes: String,
|
|
|
|
notes: String,
|
|
|
@ -195,11 +217,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
|
|
|
location: ScreenLocation,
|
|
|
|
location: ScreenLocation,
|
|
|
|
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
|
|
|
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
val dialog =
|
|
|
|
val anchor = getPopupAnchor() ?: return
|
|
|
|
supportFragmentManager.findFragmentByTag("historyEditor") as HistoryEditorDialog?
|
|
|
|
|
|
|
|
?: return
|
|
|
|
|
|
|
|
val view = dialog.dataView
|
|
|
|
|
|
|
|
val corner = view.getTopLeftCorner()
|
|
|
|
|
|
|
|
CheckmarkPopup(
|
|
|
|
CheckmarkPopup(
|
|
|
|
context = this@ShowHabitActivity,
|
|
|
|
context = this@ShowHabitActivity,
|
|
|
|
prefs = preferences,
|
|
|
|
prefs = preferences,
|
|
|
@ -209,15 +227,23 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
|
|
|
value = selectedValue,
|
|
|
|
value = selectedValue,
|
|
|
|
).apply {
|
|
|
|
).apply {
|
|
|
|
onToggle = { v, n -> callback.onNotesSaved(v, n) }
|
|
|
|
onToggle = { v, n -> callback.onNotesSaved(v, n) }
|
|
|
|
show(
|
|
|
|
show(computePopupLocation(anchor, location))
|
|
|
|
ScreenLocation(
|
|
|
|
|
|
|
|
x = corner.x + location.x - POPUP_WIDTH / 2,
|
|
|
|
|
|
|
|
y = corner.y + location.y,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getPopupAnchor(): View? {
|
|
|
|
|
|
|
|
val dialog = supportFragmentManager.findFragmentByTag("historyEditor") as HistoryEditorDialog?
|
|
|
|
|
|
|
|
return dialog?.dataView
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun computePopupLocation(anchor: View, clickLocation: ScreenLocation): ScreenLocation {
|
|
|
|
|
|
|
|
val corner = anchor.getTopLeftCorner()
|
|
|
|
|
|
|
|
return ScreenLocation(
|
|
|
|
|
|
|
|
x = corner.x + clickLocation.x - POPUP_WIDTH / 2,
|
|
|
|
|
|
|
|
y = corner.y + clickLocation.y,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun showEditHabitScreen(habit: Habit) {
|
|
|
|
override fun showEditHabitScreen(habit: Habit) {
|
|
|
|
startActivity(IntentFactory().startEditActivity(this@ShowHabitActivity, habit))
|
|
|
|
startActivity(IntentFactory().startEditActivity(this@ShowHabitActivity, habit))
|
|
|
|
}
|
|
|
|
}
|
|
|
|