Always show popups at the center of the screen; remove ScreenLocation

pull/1370/head
Alinson S. Xavier 3 years ago
parent 25aeafb759
commit d2d45991b0
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -45,7 +45,7 @@ class EntryButtonViewTest : BaseViewTest() {
value = Entry.NO value = Entry.NO
color = PaletteUtils.getAndroidTestColor(5) color = PaletteUtils.getAndroidTestColor(5)
onToggle = { _, _, _ -> toggled = true } onToggle = { _, _, _ -> toggled = true }
onEdit = { _ -> edited = true } onEdit = { edited = true }
} }
measureView(view, dpToPixels(48), dpToPixels(48)) measureView(view, dpToPixels(48), dpToPixels(48))
} }

@ -76,7 +76,7 @@ class NumberPanelViewTest : BaseViewTest() {
@Test @Test
fun testEdit() { fun testEdit() {
val timestamps = mutableListOf<Timestamp>() val timestamps = mutableListOf<Timestamp>()
view.onEdit = { _, t -> timestamps.plusAssign(t) } view.onEdit = { t -> timestamps.plusAssign(t) }
view.buttons[0].performLongClick() view.buttons[0].performLongClick()
view.buttons[2].performLongClick() view.buttons[2].performLongClick()
view.buttons[3].performLongClick() view.buttons[3].performLongClick()
@ -87,7 +87,7 @@ class NumberPanelViewTest : BaseViewTest() {
fun testEdit_withOffset() { fun testEdit_withOffset() {
val timestamps = mutableListOf<Timestamp>() val timestamps = mutableListOf<Timestamp>()
view.dataOffset = 3 view.dataOffset = 3
view.onEdit = { _, t -> timestamps += t } view.onEdit = { t -> timestamps += t }
view.buttons[0].performLongClick() view.buttons[0].performLongClick()
view.buttons[2].performLongClick() view.buttons[2].performLongClick()
view.buttons[3].performLongClick() view.buttons[3].performLongClick()

@ -27,7 +27,6 @@ import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.widget.PopupWindow import android.widget.PopupWindow
import org.isoron.platform.gui.ScreenLocation
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
@ -100,7 +99,7 @@ class CheckmarkPopup(
view.notes.setText(notes) view.notes.setText(notes)
} }
fun show(location: ScreenLocation) { fun show() {
val popup = PopupWindow() val popup = PopupWindow()
popup.contentView = view.root popup.contentView = view.root
popup.width = view.root.dp(POPUP_WIDTH).toInt() popup.width = view.root.dp(POPUP_WIDTH).toInt()
@ -118,12 +117,7 @@ class CheckmarkPopup(
popup.setOnDismissListener { popup.setOnDismissListener {
onToggle(value, view.notes.text.toString()) onToggle(value, view.notes.text.toString())
} }
popup.showAtLocation( popup.showAtLocation(anchor, Gravity.CENTER, 0, 0)
anchor,
Gravity.NO_GRAVITY,
view.root.dp(location.x.toFloat()).toInt(),
view.root.dp(location.y.toFloat()).toInt(),
)
popup.dimBehind() popup.dimBehind()
} }
} }

@ -28,7 +28,6 @@ import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.widget.PopupWindow import android.widget.PopupWindow
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.core.models.Entry import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.databinding.CheckmarkPopupBinding import org.isoron.uhabits.databinding.CheckmarkPopupBinding
@ -72,7 +71,7 @@ class NumberPopup(
) )
} }
fun show(location: ScreenLocation) { fun show() {
val popup = PopupWindow() val popup = PopupWindow()
popup.contentView = view.root popup.contentView = view.root
popup.width = view.root.dp(POPUP_WIDTH).toInt() popup.width = view.root.dp(POPUP_WIDTH).toInt()
@ -94,12 +93,7 @@ class NumberPopup(
view.value.setText((Entry.SKIP.toDouble() / 1000).toString()) view.value.setText((Entry.SKIP.toDouble() / 1000).toString())
popup.dismiss() popup.dismiss()
} }
popup.showAtLocation( popup.showAtLocation(anchor, Gravity.CENTER, 0, 0)
anchor,
Gravity.NO_GRAVITY,
view.root.dp(location.x.toFloat()).toInt(),
view.root.dp(location.y.toFloat()).toInt(),
)
view.value.requestFocusWithKeyboard() view.value.requestFocusWithKeyboard()
popup.dimBehind() popup.dimBehind()
} }

@ -24,14 +24,12 @@ 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.gui.ScreenLocation
import org.isoron.platform.gui.toInt import org.isoron.platform.gui.toInt
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.activities.common.dialogs.CheckmarkPopup import org.isoron.uhabits.activities.common.dialogs.CheckmarkPopup
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
import org.isoron.uhabits.activities.common.dialogs.NumberPopup import org.isoron.uhabits.activities.common.dialogs.NumberPopup
import org.isoron.uhabits.activities.common.dialogs.POPUP_WIDTH
import org.isoron.uhabits.activities.habits.edit.HabitTypeDialog import org.isoron.uhabits.activities.habits.edit.HabitTypeDialog
import org.isoron.uhabits.activities.habits.list.views.HabitCardListAdapter import org.isoron.uhabits.activities.habits.list.views.HabitCardListAdapter
import org.isoron.uhabits.core.commands.ArchiveHabitsCommand import org.isoron.uhabits.core.commands.ArchiveHabitsCommand
@ -232,7 +230,6 @@ class ListHabitsScreen
override fun showNumberPopup( override fun showNumberPopup(
value: Double, value: Double,
notes: String, notes: String,
location: ScreenLocation,
callback: ListHabitsBehavior.NumberPickerCallback callback: ListHabitsBehavior.NumberPickerCallback
) { ) {
val view = rootView.get() val view = rootView.get()
@ -244,7 +241,7 @@ class ListHabitsScreen
value = value, value = value,
).apply { ).apply {
onToggle = { value, notes -> callback.onNumberPicked(value, notes) } onToggle = { value, notes -> callback.onNumberPicked(value, notes) }
show(getPopupLocation(location)) show()
} }
} }
@ -252,7 +249,6 @@ class ListHabitsScreen
selectedValue: Int, selectedValue: Int,
notes: String, notes: String,
color: PaletteColor, color: PaletteColor,
location: ScreenLocation,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback
) { ) {
val view = rootView.get() val view = rootView.get()
@ -265,15 +261,10 @@ class ListHabitsScreen
value = selectedValue, value = selectedValue,
).apply { ).apply {
onToggle = { value, notes -> callback.onNotesSaved(value, notes) } onToggle = { value, notes -> callback.onNotesSaved(value, notes) }
show(getPopupLocation(location)) show()
} }
} }
private fun getPopupLocation(clickLocation: ScreenLocation) = ScreenLocation(
x = clickLocation.x - POPUP_WIDTH / 2,
y = clickLocation.y
)
private fun getExecuteString(command: Command): String? { private fun getExecuteString(command: Command): String? {
when (command) { when (command) {
is ArchiveHabitsCommand -> { is ArchiveHabitsCommand -> {

@ -28,7 +28,6 @@ import android.text.TextPaint
import android.view.HapticFeedbackConstants import android.view.HapticFeedbackConstants
import android.view.View import android.view.View
import android.view.View.MeasureSpec.EXACTLY import android.view.View.MeasureSpec.EXACTLY
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.Entry.Companion.NO import org.isoron.uhabits.core.models.Entry.Companion.NO
@ -39,7 +38,6 @@ import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.inject.ActivityContext import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.drawNotesIndicator import org.isoron.uhabits.utils.drawNotesIndicator
import org.isoron.uhabits.utils.getCenter
import org.isoron.uhabits.utils.getFontAwesome import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.sp import org.isoron.uhabits.utils.sp
import org.isoron.uhabits.utils.sres import org.isoron.uhabits.utils.sres
@ -83,7 +81,7 @@ class CheckmarkButtonView(
var onToggle: (Int, String, Long) -> Unit = { _, _, _ -> } var onToggle: (Int, String, Long) -> Unit = { _, _, _ -> }
var onEdit: (ScreenLocation) -> Unit = { _ -> } var onEdit: () -> Unit = { }
private var drawer = Drawer() private var drawer = Drawer()
@ -105,11 +103,11 @@ class CheckmarkButtonView(
override fun onClick(v: View) { override fun onClick(v: View) {
if (preferences.isShortToggleEnabled) performToggle(TOGGLE_DELAY_MILLIS) if (preferences.isShortToggleEnabled) performToggle(TOGGLE_DELAY_MILLIS)
else onEdit(getCenter()) else onEdit()
} }
override fun onLongClick(v: View): Boolean { override fun onLongClick(v: View): Boolean {
if (preferences.isShortToggleEnabled) onEdit(getCenter()) if (preferences.isShortToggleEnabled) onEdit()
else performToggle(TOGGLE_DELAY_MILLIS) else performToggle(TOGGLE_DELAY_MILLIS)
return true return true
} }

@ -20,7 +20,6 @@
package org.isoron.uhabits.activities.habits.list.views package org.isoron.uhabits.activities.habits.list.views
import android.content.Context import android.content.Context
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
import org.isoron.uhabits.core.models.Timestamp import org.isoron.uhabits.core.models.Timestamp
import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.Preferences
@ -67,7 +66,7 @@ class CheckmarkPanelView(
setupButtons() setupButtons()
} }
var onEdit: (ScreenLocation, Timestamp) -> Unit = { _, _ -> } var onEdit: (Timestamp) -> Unit = { _ -> }
set(value) { set(value) {
field = value field = value
setupButtons() setupButtons()
@ -91,7 +90,7 @@ class CheckmarkPanelView(
} }
button.color = color button.color = color
button.onToggle = { value, notes, delay -> onToggle(timestamp, value, notes, delay) } button.onToggle = { value, notes, delay -> onToggle(timestamp, value, notes, delay) }
button.onEdit = { location -> onEdit(location, timestamp) } button.onEdit = { onEdit(timestamp) }
} }
} }
} }

@ -167,17 +167,17 @@ class HabitCardView(
{ runPendingToggles(taskId) }.delay(delay) { runPendingToggles(taskId) }.delay(delay)
} }
} }
onEdit = { location, timestamp -> onEdit = { timestamp ->
triggerRipple(timestamp) triggerRipple(timestamp)
habit?.let { behavior.onEdit(location, it, timestamp) } habit?.let { behavior.onEdit(it, timestamp) }
} }
} }
numberPanel = numberPanelFactory.create().apply { numberPanel = numberPanelFactory.create().apply {
visibility = GONE visibility = GONE
onEdit = { location, timestamp -> onEdit = { timestamp ->
triggerRipple(timestamp) triggerRipple(timestamp)
habit?.let { behavior.onEdit(location, it, timestamp) } habit?.let { behavior.onEdit(it, timestamp) }
} }
} }

@ -28,7 +28,6 @@ import android.text.TextPaint
import android.view.View import android.view.View
import android.view.View.OnClickListener import android.view.View.OnClickListener
import android.view.View.OnLongClickListener import android.view.View.OnLongClickListener
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST
@ -38,7 +37,6 @@ import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils.getDimension import org.isoron.uhabits.utils.InterfaceUtils.getDimension
import org.isoron.uhabits.utils.dim import org.isoron.uhabits.utils.dim
import org.isoron.uhabits.utils.drawNotesIndicator import org.isoron.uhabits.utils.drawNotesIndicator
import org.isoron.uhabits.utils.getCenter
import org.isoron.uhabits.utils.getFontAwesome import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.sres import org.isoron.uhabits.utils.sres
import java.text.DecimalFormat import java.text.DecimalFormat
@ -110,7 +108,7 @@ class NumberButtonView(
invalidate() invalidate()
} }
var onEdit: (ScreenLocation) -> Unit = { _ -> } var onEdit: () -> Unit = { }
private var drawer: Drawer = Drawer(context) private var drawer: Drawer = Drawer(context)
@ -120,11 +118,11 @@ class NumberButtonView(
} }
override fun onClick(v: View) { override fun onClick(v: View) {
onEdit(getCenter()) onEdit()
} }
override fun onLongClick(v: View): Boolean { override fun onLongClick(v: View): Boolean {
onEdit(getCenter()) onEdit()
return true return true
} }

@ -20,7 +20,6 @@
package org.isoron.uhabits.activities.habits.list.views package org.isoron.uhabits.activities.habits.list.views
import android.content.Context import android.content.Context
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.core.models.NumericalHabitType import org.isoron.uhabits.core.models.NumericalHabitType
import org.isoron.uhabits.core.models.Timestamp import org.isoron.uhabits.core.models.Timestamp
import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.Preferences
@ -79,7 +78,7 @@ class NumberPanelView(
setupButtons() setupButtons()
} }
var onEdit: (ScreenLocation, Timestamp) -> Unit = { _, _ -> } var onEdit: (Timestamp) -> Unit = { _ -> }
set(value) { set(value) {
field = value field = value
setupButtons() setupButtons()
@ -105,7 +104,7 @@ class NumberPanelView(
button.targetType = targetType button.targetType = targetType
button.threshold = threshold button.threshold = threshold
button.units = units button.units = units
button.onEdit = { location -> onEdit(location, timestamp) } button.onEdit = { onEdit(timestamp) }
} }
} }
} }

@ -28,7 +28,6 @@ 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.gui.ScreenLocation
import org.isoron.platform.gui.toInt import org.isoron.platform.gui.toInt
import org.isoron.uhabits.AndroidDirFinder import org.isoron.uhabits.AndroidDirFinder
import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.HabitsApplication
@ -39,7 +38,6 @@ 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.NumberPopup import org.isoron.uhabits.activities.common.dialogs.NumberPopup
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
import org.isoron.uhabits.core.models.Habit import org.isoron.uhabits.core.models.Habit
@ -52,7 +50,6 @@ import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter
import org.isoron.uhabits.core.ui.views.OnDateClickedListener import org.isoron.uhabits.core.ui.views.OnDateClickedListener
import org.isoron.uhabits.intents.IntentFactory import org.isoron.uhabits.intents.IntentFactory
import org.isoron.uhabits.utils.currentTheme import org.isoron.uhabits.utils.currentTheme
import org.isoron.uhabits.utils.getTopLeftCorner
import org.isoron.uhabits.utils.showMessage import org.isoron.uhabits.utils.showMessage
import org.isoron.uhabits.utils.showSendFileScreen import org.isoron.uhabits.utils.showSendFileScreen
import org.isoron.uhabits.widgets.WidgetUpdater import org.isoron.uhabits.widgets.WidgetUpdater
@ -173,7 +170,6 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
value: Double, value: Double,
notes: String, notes: String,
preferences: Preferences, preferences: Preferences,
location: ScreenLocation,
callback: ListHabitsBehavior.NumberPickerCallback callback: ListHabitsBehavior.NumberPickerCallback
) { ) {
val anchor = getPopupAnchor() ?: return val anchor = getPopupAnchor() ?: return
@ -185,7 +181,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
value = value, value = value,
).apply { ).apply {
onToggle = { v, n -> callback.onNumberPicked(v, n) } onToggle = { v, n -> callback.onNumberPicked(v, n) }
show(computePopupLocation(anchor, location)) show()
} }
} }
@ -194,7 +190,6 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
notes: String, notes: String,
preferences: Preferences, preferences: Preferences,
color: PaletteColor, color: PaletteColor,
location: ScreenLocation,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback
) { ) {
val anchor = getPopupAnchor() ?: return val anchor = getPopupAnchor() ?: return
@ -207,7 +202,7 @@ 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(computePopupLocation(anchor, location)) show()
} }
} }
@ -216,14 +211,6 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
return dialog?.dataView 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))
} }

@ -47,7 +47,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import org.isoron.platform.gui.ScreenLocation
import org.isoron.platform.gui.toInt import org.isoron.platform.gui.toInt
import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R import org.isoron.uhabits.R
@ -231,34 +230,6 @@ fun PopupWindow.dimBehind() {
wm.updateViewLayout(container, p) wm.updateViewLayout(container, p)
} }
/**
* Returns the absolute screen coordinates for the center of this view (in density-independent
* pixels).
*/
fun View.getCenter(): ScreenLocation {
val density = resources.displayMetrics.density
val loc = IntArray(2)
this.getLocationInWindow(loc)
return ScreenLocation(
x = ((loc[0] + width / 2) / density).toDouble(),
y = ((loc[1] + height / 2) / density).toDouble(),
)
}
/**
* Returns the absolute screen coordinates for the top left corner of this view (in
* density-independent pixels).
*/
fun View.getTopLeftCorner(): ScreenLocation {
val density = resources.displayMetrics.density
val loc = IntArray(2)
this.getLocationInWindow(loc)
return ScreenLocation(
x = (loc[0] / density).toDouble(),
y = (loc[1] / density).toDouble(),
)
}
fun View.requestFocusWithKeyboard() { fun View.requestFocusWithKeyboard() {
// For some reason, Android does not open the soft keyboard by default when view.requestFocus // For some reason, Android does not open the soft keyboard by default when view.requestFocus
// is called. Several online solutions suggest using InputMethodManager, but these solutions // is called. Several online solutions suggest using InputMethodManager, but these solutions

@ -25,18 +25,14 @@ import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.FrameLayout import android.widget.FrameLayout
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.activities.AndroidThemeSwitcher import org.isoron.uhabits.activities.AndroidThemeSwitcher
import org.isoron.uhabits.activities.common.dialogs.NumberPopup import org.isoron.uhabits.activities.common.dialogs.NumberPopup
import org.isoron.uhabits.activities.common.dialogs.POPUP_HEIGHT
import org.isoron.uhabits.activities.common.dialogs.POPUP_WIDTH
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.core.ui.widgets.WidgetBehavior import org.isoron.uhabits.core.ui.widgets.WidgetBehavior
import org.isoron.uhabits.core.utils.DateUtils import org.isoron.uhabits.core.utils.DateUtils
import org.isoron.uhabits.intents.IntentParser import org.isoron.uhabits.intents.IntentParser
import org.isoron.uhabits.utils.SystemUtils import org.isoron.uhabits.utils.SystemUtils
import org.isoron.uhabits.utils.getCenter
import org.isoron.uhabits.widgets.WidgetUpdater import org.isoron.uhabits.widgets.WidgetUpdater
class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback { class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback {
@ -95,13 +91,7 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
finish() finish()
overridePendingTransition(0, 0) overridePendingTransition(0, 0)
} }
val center = rootView.getCenter() show()
show(
ScreenLocation(
x = center.x - POPUP_WIDTH / 2,
y = center.y - POPUP_HEIGHT / 2
)
)
} }
} }

@ -18,7 +18,6 @@
*/ */
package org.isoron.uhabits.core.ui.screens.habits.list package org.isoron.uhabits.core.ui.screens.habits.list
import org.isoron.platform.gui.ScreenLocation
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
@ -49,11 +48,11 @@ open class ListHabitsBehavior @Inject constructor(
screen.showHabitScreen(h) screen.showHabitScreen(h)
} }
fun onEdit(location: ScreenLocation, habit: Habit, timestamp: Timestamp?) { fun onEdit(habit: Habit, timestamp: Timestamp?) {
val entry = habit.computedEntries.get(timestamp!!) val entry = habit.computedEntries.get(timestamp!!)
if (habit.type == HabitType.NUMERICAL) { if (habit.type == HabitType.NUMERICAL) {
val oldValue = entry.value.toDouble() / 1000 val oldValue = entry.value.toDouble() / 1000
screen.showNumberPopup(oldValue, entry.notes, location) { newValue: Double, newNotes: String -> screen.showNumberPopup(oldValue, entry.notes) { newValue: Double, newNotes: String ->
val value = (newValue * 1000).roundToInt() val value = (newValue * 1000).roundToInt()
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes)) commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
} }
@ -62,7 +61,6 @@ open class ListHabitsBehavior @Inject constructor(
entry.value, entry.value,
entry.notes, entry.notes,
habit.color, habit.color,
location,
) { newValue, newNotes -> ) { newValue, newNotes ->
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes)) commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes))
} }
@ -158,14 +156,12 @@ open class ListHabitsBehavior @Inject constructor(
fun showNumberPopup( fun showNumberPopup(
value: Double, value: Double,
notes: String, notes: String,
location: ScreenLocation,
callback: NumberPickerCallback callback: NumberPickerCallback
) )
fun showCheckmarkPopup( fun showCheckmarkPopup(
selectedValue: Int, selectedValue: Int,
notes: String, notes: String,
color: PaletteColor, color: PaletteColor,
location: ScreenLocation,
callback: CheckMarkDialogCallback callback: CheckMarkDialogCallback
) )
fun showSendBugReportToDeveloperScreen(log: String) fun showSendBugReportToDeveloperScreen(log: String)

@ -19,7 +19,6 @@
package org.isoron.uhabits.core.ui.screens.habits.show.views package org.isoron.uhabits.core.ui.screens.habits.show.views
import org.isoron.platform.gui.ScreenLocation
import org.isoron.platform.time.DayOfWeek import org.isoron.platform.time.DayOfWeek
import org.isoron.platform.time.LocalDate import org.isoron.platform.time.LocalDate
import org.isoron.uhabits.core.commands.CommandRunner import org.isoron.uhabits.core.commands.CommandRunner
@ -65,36 +64,35 @@ class HistoryCardPresenter(
val screen: Screen, val screen: Screen,
) : OnDateClickedListener { ) : OnDateClickedListener {
override fun onDateLongPress(location: ScreenLocation, date: LocalDate) { override fun onDateLongPress(date: LocalDate) {
val timestamp = Timestamp.fromLocalDate(date) val timestamp = Timestamp.fromLocalDate(date)
screen.showFeedback() screen.showFeedback()
if (habit.isNumerical) { if (habit.isNumerical) {
showNumberPopup(location, timestamp) showNumberPopup(timestamp)
} else { } else {
if (preferences.isShortToggleEnabled) showCheckmarkPopup(location, timestamp) if (preferences.isShortToggleEnabled) showCheckmarkPopup(timestamp)
else toggle(timestamp) else toggle(timestamp)
} }
} }
override fun onDateShortPress(location: ScreenLocation, date: LocalDate) { override fun onDateShortPress(date: LocalDate) {
val timestamp = Timestamp.fromLocalDate(date) val timestamp = Timestamp.fromLocalDate(date)
screen.showFeedback() screen.showFeedback()
if (habit.isNumerical) { if (habit.isNumerical) {
showNumberPopup(location, timestamp) showNumberPopup(timestamp)
} else { } else {
if (preferences.isShortToggleEnabled) toggle(timestamp) if (preferences.isShortToggleEnabled) toggle(timestamp)
else showCheckmarkPopup(location, timestamp) else showCheckmarkPopup(timestamp)
} }
} }
private fun showCheckmarkPopup(location: ScreenLocation, timestamp: Timestamp) { private fun showCheckmarkPopup(timestamp: Timestamp) {
val entry = habit.computedEntries.get(timestamp) val entry = habit.computedEntries.get(timestamp)
screen.showCheckmarkPopup( screen.showCheckmarkPopup(
entry.value, entry.value,
entry.notes, entry.notes,
preferences, preferences,
habit.color, habit.color,
location,
) { newValue, newNotes -> ) { newValue, newNotes ->
commandRunner.run( commandRunner.run(
CreateRepetitionCommand( CreateRepetitionCommand(
@ -126,14 +124,13 @@ class HistoryCardPresenter(
) )
} }
private fun showNumberPopup(location: ScreenLocation, timestamp: Timestamp) { private fun showNumberPopup(timestamp: Timestamp) {
val entry = habit.computedEntries.get(timestamp) val entry = habit.computedEntries.get(timestamp)
val oldValue = entry.value val oldValue = entry.value
screen.showNumberPopup( screen.showNumberPopup(
value = oldValue / 1000.0, value = oldValue / 1000.0,
notes = entry.notes, notes = entry.notes,
preferences = preferences, preferences = preferences,
location = location,
) { newValue: Double, newNotes: String -> ) { newValue: Double, newNotes: String ->
val thousands = (newValue * 1000).roundToInt() val thousands = (newValue * 1000).roundToInt()
commandRunner.run( commandRunner.run(
@ -207,7 +204,6 @@ class HistoryCardPresenter(
value: Double, value: Double,
notes: String, notes: String,
preferences: Preferences, preferences: Preferences,
location: ScreenLocation,
callback: ListHabitsBehavior.NumberPickerCallback, callback: ListHabitsBehavior.NumberPickerCallback,
) )
fun showCheckmarkPopup( fun showCheckmarkPopup(
@ -215,7 +211,6 @@ class HistoryCardPresenter(
notes: String, notes: String,
preferences: Preferences, preferences: Preferences,
color: PaletteColor, color: PaletteColor,
location: ScreenLocation,
callback: ListHabitsBehavior.CheckMarkDialogCallback, callback: ListHabitsBehavior.CheckMarkDialogCallback,
) )
} }

@ -22,7 +22,6 @@ package org.isoron.uhabits.core.ui.views
import org.isoron.platform.gui.Canvas import org.isoron.platform.gui.Canvas
import org.isoron.platform.gui.Color import org.isoron.platform.gui.Color
import org.isoron.platform.gui.DataView import org.isoron.platform.gui.DataView
import org.isoron.platform.gui.ScreenLocation
import org.isoron.platform.gui.TextAlign import org.isoron.platform.gui.TextAlign
import org.isoron.platform.time.DayOfWeek import org.isoron.platform.time.DayOfWeek
import org.isoron.platform.time.LocalDate import org.isoron.platform.time.LocalDate
@ -34,8 +33,8 @@ import kotlin.math.min
import kotlin.math.round import kotlin.math.round
interface OnDateClickedListener { interface OnDateClickedListener {
fun onDateShortPress(location: ScreenLocation, date: LocalDate) {} fun onDateShortPress(date: LocalDate) {}
fun onDateLongPress(location: ScreenLocation, date: LocalDate) {} fun onDateLongPress(date: LocalDate) {}
} }
class HistoryChart( class HistoryChart(
@ -91,11 +90,10 @@ class HistoryChart(
if (x - padding < 0 || row == 0 || row > 7 || col == nColumns) return if (x - padding < 0 || row == 0 || row > 7 || col == nColumns) return
val clickedDate = topLeftDate.plus(offset) val clickedDate = topLeftDate.plus(offset)
if (clickedDate.isNewerThan(today)) return if (clickedDate.isNewerThan(today)) return
val location = ScreenLocation(x, y)
if (isLongClick) { if (isLongClick) {
onDateClickedListener.onDateLongPress(location, clickedDate) onDateClickedListener.onDateLongPress(clickedDate)
} else { } else {
onDateClickedListener.onDateShortPress(location, clickedDate) onDateClickedListener.onDateShortPress(clickedDate)
} }
} }

@ -31,7 +31,6 @@ import junit.framework.Assert.assertTrue
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsEqual.equalTo import org.hamcrest.core.IsEqual.equalTo
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.core.BaseUnitTest import org.isoron.uhabits.core.BaseUnitTest
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
@ -79,11 +78,10 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
@Test @Test
fun testOnEdit() { fun testOnEdit() {
behavior.onEdit(ScreenLocation(0.0, 0.0), habit2, getToday()) behavior.onEdit(habit2, getToday())
verify(screen).showNumberPopup( verify(screen).showNumberPopup(
eq(0.1), eq(0.1),
eq(""), eq(""),
any(),
picker.capture() picker.capture()
) )
picker.lastValue.onNumberPicked(100.0, "") picker.lastValue.onNumberPicked(100.0, "")

@ -24,7 +24,6 @@ import com.nhaarman.mockitokotlin2.reset
import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.isoron.platform.gui.ScreenLocation
import org.isoron.platform.gui.assertRenders import org.isoron.platform.gui.assertRenders
import org.isoron.platform.time.DayOfWeek import org.isoron.platform.time.DayOfWeek
import org.isoron.platform.time.DayOfWeek.SUNDAY import org.isoron.platform.time.DayOfWeek.SUNDAY
@ -90,32 +89,20 @@ class HistoryChartTest {
// Click top left date // Click top left date
view.onClick(20.0, 46.0) view.onClick(20.0, 46.0)
verify(dateClickedListener).onDateShortPress( verify(dateClickedListener).onDateShortPress(LocalDate(2014, 10, 26))
ScreenLocation(20.0, 46.0),
LocalDate(2014, 10, 26)
)
reset(dateClickedListener) reset(dateClickedListener)
view.onClick(2.0, 28.0) view.onClick(2.0, 28.0)
verify(dateClickedListener).onDateShortPress( verify(dateClickedListener).onDateShortPress(LocalDate(2014, 10, 26))
ScreenLocation(2.0, 28.0),
LocalDate(2014, 10, 26)
)
reset(dateClickedListener) reset(dateClickedListener)
// Click date in the middle // Click date in the middle
view.onClick(163.0, 113.0) view.onClick(163.0, 113.0)
verify(dateClickedListener).onDateShortPress( verify(dateClickedListener).onDateShortPress(LocalDate(2014, 12, 10))
ScreenLocation(163.0, 113.0),
LocalDate(2014, 12, 10)
)
reset(dateClickedListener) reset(dateClickedListener)
// Click today // Click today
view.onClick(336.0, 37.0) view.onClick(336.0, 37.0)
verify(dateClickedListener).onDateShortPress( verify(dateClickedListener).onDateShortPress(LocalDate(2015, 1, 25))
ScreenLocation(336.0, 37.0),
LocalDate(2015, 1, 25)
)
reset(dateClickedListener) reset(dateClickedListener)
// Click header // Click header
@ -133,32 +120,20 @@ class HistoryChartTest {
// Click top left date // Click top left date
view.onLongClick(20.0, 46.0) view.onLongClick(20.0, 46.0)
verify(dateClickedListener).onDateLongPress( verify(dateClickedListener).onDateLongPress(LocalDate(2014, 10, 26))
ScreenLocation(20.0, 46.0),
LocalDate(2014, 10, 26)
)
reset(dateClickedListener) reset(dateClickedListener)
view.onLongClick(2.0, 28.0) view.onLongClick(2.0, 28.0)
verify(dateClickedListener).onDateLongPress( verify(dateClickedListener).onDateLongPress(LocalDate(2014, 10, 26))
ScreenLocation(2.0, 28.0),
LocalDate(2014, 10, 26)
)
reset(dateClickedListener) reset(dateClickedListener)
// Click date in the middle // Click date in the middle
view.onLongClick(163.0, 113.0) view.onLongClick(163.0, 113.0)
verify(dateClickedListener).onDateLongPress( verify(dateClickedListener).onDateLongPress(LocalDate(2014, 12, 10))
ScreenLocation(163.0, 113.0),
LocalDate(2014, 12, 10)
)
reset(dateClickedListener) reset(dateClickedListener)
// Click today // Click today
view.onLongClick(336.0, 37.0) view.onLongClick(336.0, 37.0)
verify(dateClickedListener).onDateLongPress( verify(dateClickedListener).onDateLongPress(LocalDate(2015, 1, 25))
ScreenLocation(336.0, 37.0),
LocalDate(2015, 1, 25)
)
reset(dateClickedListener) reset(dateClickedListener)
// Click header // Click header

Loading…
Cancel
Save