Skip to content

Commit

Permalink
Always show popups at the center of the screen; remove ScreenLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed May 13, 2022
1 parent 25aeafb commit d2d4599
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EntryButtonViewTest : BaseViewTest() {
value = Entry.NO
color = PaletteUtils.getAndroidTestColor(5)
onToggle = { _, _, _ -> toggled = true }
onEdit = { _ -> edited = true }
onEdit = { edited = true }
}
measureView(view, dpToPixels(48), dpToPixels(48))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NumberPanelViewTest : BaseViewTest() {
@Test
fun testEdit() {
val timestamps = mutableListOf<Timestamp>()
view.onEdit = { _, t -> timestamps.plusAssign(t) }
view.onEdit = { t -> timestamps.plusAssign(t) }
view.buttons[0].performLongClick()
view.buttons[2].performLongClick()
view.buttons[3].performLongClick()
Expand All @@ -87,7 +87,7 @@ class NumberPanelViewTest : BaseViewTest() {
fun testEdit_withOffset() {
val timestamps = mutableListOf<Timestamp>()
view.dataOffset = 3
view.onEdit = { _, t -> timestamps += t }
view.onEdit = { t -> timestamps += t }
view.buttons[0].performLongClick()
view.buttons[2].performLongClick()
view.buttons[3].performLongClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.PopupWindow
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry.Companion.NO
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
Expand Down Expand Up @@ -100,7 +99,7 @@ class CheckmarkPopup(
view.notes.setText(notes)
}

fun show(location: ScreenLocation) {
fun show() {
val popup = PopupWindow()
popup.contentView = view.root
popup.width = view.root.dp(POPUP_WIDTH).toInt()
Expand All @@ -118,12 +117,7 @@ class CheckmarkPopup(
popup.setOnDismissListener {
onToggle(value, view.notes.text.toString())
}
popup.showAtLocation(
anchor,
Gravity.NO_GRAVITY,
view.root.dp(location.x.toFloat()).toInt(),
view.root.dp(location.y.toFloat()).toInt(),
)
popup.showAtLocation(anchor, Gravity.CENTER, 0, 0)
popup.dimBehind()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.PopupWindow
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.databinding.CheckmarkPopupBinding
Expand Down Expand Up @@ -72,7 +71,7 @@ class NumberPopup(
)
}

fun show(location: ScreenLocation) {
fun show() {
val popup = PopupWindow()
popup.contentView = view.root
popup.width = view.root.dp(POPUP_WIDTH).toInt()
Expand All @@ -94,12 +93,7 @@ class NumberPopup(
view.value.setText((Entry.SKIP.toDouble() / 1000).toString())
popup.dismiss()
}
popup.showAtLocation(
anchor,
Gravity.NO_GRAVITY,
view.root.dp(location.x.toFloat()).toInt(),
view.root.dp(location.y.toFloat()).toInt(),
)
popup.showAtLocation(anchor, Gravity.CENTER, 0, 0)
view.value.requestFocusWithKeyboard()
popup.dimBehind()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import dagger.Lazy
import org.isoron.platform.gui.ScreenLocation
import org.isoron.platform.gui.toInt
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.common.dialogs.CheckmarkPopup
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
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.list.views.HabitCardListAdapter
import org.isoron.uhabits.core.commands.ArchiveHabitsCommand
Expand Down Expand Up @@ -232,7 +230,6 @@ class ListHabitsScreen
override fun showNumberPopup(
value: Double,
notes: String,
location: ScreenLocation,
callback: ListHabitsBehavior.NumberPickerCallback
) {
val view = rootView.get()
Expand All @@ -244,15 +241,14 @@ class ListHabitsScreen
value = value,
).apply {
onToggle = { value, notes -> callback.onNumberPicked(value, notes) }
show(getPopupLocation(location))
show()
}
}

override fun showCheckmarkPopup(
selectedValue: Int,
notes: String,
color: PaletteColor,
location: ScreenLocation,
callback: ListHabitsBehavior.CheckMarkDialogCallback
) {
val view = rootView.get()
Expand All @@ -265,15 +261,10 @@ class ListHabitsScreen
value = selectedValue,
).apply {
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? {
when (command) {
is ArchiveHabitsCommand -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.text.TextPaint
import android.view.HapticFeedbackConstants
import android.view.View
import android.view.View.MeasureSpec.EXACTLY
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.Entry.Companion.NO
Expand All @@ -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.inject.ActivityContext
import org.isoron.uhabits.utils.drawNotesIndicator
import org.isoron.uhabits.utils.getCenter
import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.sp
import org.isoron.uhabits.utils.sres
Expand Down Expand Up @@ -83,7 +81,7 @@ class CheckmarkButtonView(

var onToggle: (Int, String, Long) -> Unit = { _, _, _ -> }

var onEdit: (ScreenLocation) -> Unit = { _ -> }
var onEdit: () -> Unit = { }

private var drawer = Drawer()

Expand All @@ -105,11 +103,11 @@ class CheckmarkButtonView(

override fun onClick(v: View) {
if (preferences.isShortToggleEnabled) performToggle(TOGGLE_DELAY_MILLIS)
else onEdit(getCenter())
else onEdit()
}

override fun onLongClick(v: View): Boolean {
if (preferences.isShortToggleEnabled) onEdit(getCenter())
if (preferences.isShortToggleEnabled) onEdit()
else performToggle(TOGGLE_DELAY_MILLIS)
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.isoron.uhabits.activities.habits.list.views

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.Timestamp
import org.isoron.uhabits.core.preferences.Preferences
Expand Down Expand Up @@ -67,7 +66,7 @@ class CheckmarkPanelView(
setupButtons()
}

var onEdit: (ScreenLocation, Timestamp) -> Unit = { _, _ -> }
var onEdit: (Timestamp) -> Unit = { _ -> }
set(value) {
field = value
setupButtons()
Expand All @@ -91,7 +90,7 @@ class CheckmarkPanelView(
}
button.color = color
button.onToggle = { value, notes, delay -> onToggle(timestamp, value, notes, delay) }
button.onEdit = { location -> onEdit(location, timestamp) }
button.onEdit = { onEdit(timestamp) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ class HabitCardView(
{ runPendingToggles(taskId) }.delay(delay)
}
}
onEdit = { location, timestamp ->
onEdit = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onEdit(location, it, timestamp) }
habit?.let { behavior.onEdit(it, timestamp) }
}
}

numberPanel = numberPanelFactory.create().apply {
visibility = GONE
onEdit = { location, timestamp ->
onEdit = { timestamp ->
triggerRipple(timestamp)
habit?.let { behavior.onEdit(location, it, timestamp) }
habit?.let { behavior.onEdit(it, timestamp) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.text.TextPaint
import android.view.View
import android.view.View.OnClickListener
import android.view.View.OnLongClickListener
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST
Expand All @@ -38,7 +37,6 @@ import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils.getDimension
import org.isoron.uhabits.utils.dim
import org.isoron.uhabits.utils.drawNotesIndicator
import org.isoron.uhabits.utils.getCenter
import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.sres
import java.text.DecimalFormat
Expand Down Expand Up @@ -110,7 +108,7 @@ class NumberButtonView(
invalidate()
}

var onEdit: (ScreenLocation) -> Unit = { _ -> }
var onEdit: () -> Unit = { }

private var drawer: Drawer = Drawer(context)

Expand All @@ -120,11 +118,11 @@ class NumberButtonView(
}

override fun onClick(v: View) {
onEdit(getCenter())
onEdit()
}

override fun onLongClick(v: View): Boolean {
onEdit(getCenter())
onEdit()
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.isoron.uhabits.activities.habits.list.views

import android.content.Context
import org.isoron.platform.gui.ScreenLocation
import org.isoron.uhabits.core.models.NumericalHabitType
import org.isoron.uhabits.core.models.Timestamp
import org.isoron.uhabits.core.preferences.Preferences
Expand Down Expand Up @@ -79,7 +78,7 @@ class NumberPanelView(
setupButtons()
}

var onEdit: (ScreenLocation, Timestamp) -> Unit = { _, _ -> }
var onEdit: (Timestamp) -> Unit = { _ -> }
set(value) {
field = value
setupButtons()
Expand All @@ -105,7 +104,7 @@ class NumberPanelView(
button.targetType = targetType
button.threshold = threshold
button.units = units
button.onEdit = { location -> onEdit(location, timestamp) }
button.onEdit = { onEdit(timestamp) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.isoron.platform.gui.ScreenLocation
import org.isoron.platform.gui.toInt
import org.isoron.uhabits.AndroidDirFinder
import org.isoron.uhabits.HabitsApplication
Expand All @@ -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.HistoryEditorDialog
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.CommandRunner
import org.isoron.uhabits.core.models.Habit
Expand All @@ -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.intents.IntentFactory
import org.isoron.uhabits.utils.currentTheme
import org.isoron.uhabits.utils.getTopLeftCorner
import org.isoron.uhabits.utils.showMessage
import org.isoron.uhabits.utils.showSendFileScreen
import org.isoron.uhabits.widgets.WidgetUpdater
Expand Down Expand Up @@ -173,7 +170,6 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
value: Double,
notes: String,
preferences: Preferences,
location: ScreenLocation,
callback: ListHabitsBehavior.NumberPickerCallback
) {
val anchor = getPopupAnchor() ?: return
Expand All @@ -185,7 +181,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
value = value,
).apply {
onToggle = { v, n -> callback.onNumberPicked(v, n) }
show(computePopupLocation(anchor, location))
show()
}
}

Expand All @@ -194,7 +190,6 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
notes: String,
preferences: Preferences,
color: PaletteColor,
location: ScreenLocation,
callback: ListHabitsBehavior.CheckMarkDialogCallback
) {
val anchor = getPopupAnchor() ?: return
Expand All @@ -207,7 +202,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
value = selectedValue,
).apply {
onToggle = { v, n -> callback.onNotesSaved(v, n) }
show(computePopupLocation(anchor, location))
show()
}
}

Expand All @@ -216,14 +211,6 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
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) {
startActivity(IntentFactory().startEditActivity(this@ShowHabitActivity, habit))
}
Expand Down
Loading

0 comments on commit d2d4599

Please sign in to comment.