mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Use NumberPopup in widgets
This commit is contained in:
@@ -125,7 +125,7 @@
|
||||
android:exported="true"
|
||||
android:label="NumericalCheckmarkWidget"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/Theme.AppCompat.Light.Dialog">
|
||||
android:theme="@style/Theme.Transparent">
|
||||
<intent-filter>
|
||||
<action android:name="org.isoron.uhabits.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY" />
|
||||
</intent-filter>
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
import android.view.WindowManager
|
||||
import android.widget.EditText
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM
|
||||
|
||||
@@ -22,16 +22,21 @@ package org.isoron.uhabits.widgets.activities
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.Window
|
||||
import android.view.View
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.widget.FrameLayout
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.uhabits.HabitsApplication
|
||||
import org.isoron.uhabits.activities.AndroidThemeSwitcher
|
||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
||||
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.widgets.WidgetBehavior
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.intents.IntentParser
|
||||
import org.isoron.uhabits.utils.SystemUtils
|
||||
import org.isoron.uhabits.utils.getCenter
|
||||
import org.isoron.uhabits.widgets.WidgetUpdater
|
||||
|
||||
class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback {
|
||||
@@ -39,11 +44,13 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
||||
private lateinit var behavior: WidgetBehavior
|
||||
private lateinit var data: IntentParser.CheckmarkIntentData
|
||||
private lateinit var widgetUpdater: WidgetUpdater
|
||||
private lateinit var rootView: View
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
setContentView(FrameLayout(this))
|
||||
rootView = FrameLayout(this)
|
||||
rootView.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||
setContentView(rootView)
|
||||
val app = this.applicationContext as HabitsApplication
|
||||
val component = app.component
|
||||
val parser = app.component.intentParser
|
||||
@@ -55,8 +62,9 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
||||
component.preferences
|
||||
)
|
||||
widgetUpdater = component.widgetUpdater
|
||||
rootView.post {
|
||||
showNumberSelector(this)
|
||||
|
||||
}
|
||||
SystemUtils.unlockScreen(this)
|
||||
}
|
||||
|
||||
@@ -73,17 +81,28 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
||||
private fun showNumberSelector(context: Context) {
|
||||
val app = this.applicationContext as HabitsApplication
|
||||
AndroidThemeSwitcher(this, app.component.preferences).apply()
|
||||
val numberPickerFactory = NumberPickerFactory(context)
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
val entry = data.habit.computedEntries.get(today)
|
||||
numberPickerFactory.create(
|
||||
entry.value / 1000.0,
|
||||
data.habit.unit,
|
||||
entry.notes,
|
||||
today.toDialogDateString(),
|
||||
data.habit.frequency,
|
||||
this
|
||||
).show()
|
||||
NumberPopup(
|
||||
context = context,
|
||||
prefs = app.component.preferences,
|
||||
anchor = rootView,
|
||||
notes = entry.notes,
|
||||
value = entry.value / 1000.0,
|
||||
).apply {
|
||||
onToggle = { value, notes ->
|
||||
onNumberPicked(value, notes)
|
||||
finish()
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
val center = rootView.getCenter()
|
||||
show(
|
||||
ScreenLocation(
|
||||
x = center.x - POPUP_WIDTH / 2,
|
||||
y = center.y - POPUP_HEIGHT / 2
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -413,4 +413,13 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Transparent" parent="android:Theme">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:backgroundDimEnabled">false</item>
|
||||
<item name="android:windowAnimationStyle">@null</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user