Modern Apps git

← Modern-Apps.git

calculator: one file per widget

Commit
ac0f4308efe45e26d560499717d66fb71412948f
Author
Vayun Mathur <[email protected]>
When
2026-11-19 03:44 UTC (17 days ago)
Parents
432af7a
What: merge CalculatorGlanceWidgetReceiver and CalculatorKeyAction
into CalculatorGlanceWidget.kt, and UnitsGlanceWidgetReceiver and
UnitsWidgetActions into UnitsGlanceWidget.kt, keeping every class
name and the com.vayunmathur.calculator.widget package unchanged.
Move CalculatorWidgetSettingsActivity (an app Activity, not Glance
code) from widget/ to ui/, updating its package, the manifest
activity entry, the calculator_widget_info.xml configure entry,
and test imports. WidgetLogicTest gains the new ui import.

Why: owner mandate that each home-screen widget lives in exactly
one file under widget/ declaring its MaWidget subclass, with its
receiver and Glance helpers in the same file, and non-Glance app
helpers in a proper root package (docs/package-structure.md).

No behaviour changes: receiver class names and packages are
unchanged so manifest receiver entries and placed widgets keep
resolving; only the settings Activity component name changes,
which the manifest and widget-info XML now point at.

Verification: ./gradlew :calculator:lintDev
:calculator:testDevUnitTest -- BUILD SUCCESSFUL (lint green,
all unit tests pass).

Diff

calculator/src/main/AndroidManifest.xml
diff --git a/calculator/src/main/AndroidManifest.xml b/calculator/src/main/AndroidManifest.xmlindex ec63c6eedb..521665ed0d 100644--- a/calculator/src/main/AndroidManifest.xml+++ b/calculator/src/main/AndroidManifest.xml@@ -31,7 +31,7 @@         </activity>         <activity             android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"-            android:name=".widget.CalculatorWidgetSettingsActivity"+            android:name=".ui.CalculatorWidgetSettingsActivity"             android:exported="true"             android:label="@string/calculator_widget_label"             android:theme="@style/Theme.General">
calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorWidgetSettingsActivity.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorWidgetSettingsActivity.kt b/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorWidgetSettingsActivity.ktsimilarity index 95%rename from calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorWidgetSettingsActivity.ktrename to calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorWidgetSettingsActivity.ktindex b7b348bc19..bc624aff62 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorWidgetSettingsActivity.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/ui/CalculatorWidgetSettingsActivity.kt@@ -1,4 +1,4 @@-package com.vayunmathur.calculator.widget+package com.vayunmathur.calculator.ui  import android.appwidget.AppWidgetManager import android.content.Intent@@ -20,6 +20,9 @@ import androidx.glance.appwidget.state.getAppWidgetState import androidx.glance.appwidget.state.updateAppWidgetState import androidx.glance.state.PreferencesGlanceStateDefinition import com.vayunmathur.calculator.R+import com.vayunmathur.calculator.widget.CalculatorGlanceWidget+import com.vayunmathur.calculator.widget.CalculatorGlanceWidgetReceiver+import com.vayunmathur.calculator.widget.CalculatorTransparentKey import com.vayunmathur.library.ui.DetailScaffold import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.SettingsSection
calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidget.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidget.kt b/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidget.ktindex 480d3aacfd..123a40b03d 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidget.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidget.kt@@ -34,6 +34,21 @@ import androidx.glance.unit.ColorProvider import com.vayunmathur.calculator.MainActivity import com.vayunmathur.calculator.domain.renderInputForDisplay import com.vayunmathur.library.widgets.MaWidget+import android.os.Build+import android.os.VibrationEffect+import android.os.Vibrator+import android.os.VibratorManager+import androidx.datastore.preferences.core.booleanPreferencesKey+import androidx.datastore.preferences.core.doublePreferencesKey+import androidx.datastore.preferences.core.stringPreferencesKey+import androidx.glance.action.ActionParameters+import androidx.glance.appwidget.action.ActionCallback+import androidx.glance.appwidget.state.updateAppWidgetState+import com.vayunmathur.calculator.domain.Expression+import com.vayunmathur.calculator.domain.ExpressionError+import com.vayunmathur.calculator.domain.UnitRegistry+import com.vayunmathur.calculator.domain.formatQuantity+import com.vayunmathur.library.widgets.MaWidgetReceiver  /** How a key is coloured: digits recede, operators sit forward, `=` is the primary action. */ private enum class KeyEmphasis { Digit, Operator, Primary }@@ -193,3 +208,148 @@ private fun RowScope.KeypadKey(key: WidgetKey) {         }     } }++/** The in-progress expression, in the same re-parsable form the app's input line uses. */+internal val CalculatorInputKey = stringPreferencesKey("calculator_widget_input")++/** The last computed result, so `ans` resolves the same way it does in the app. */+internal val CalculatorAnswerKey = doublePreferencesKey("calculator_widget_answer")++/** Which key was tapped, as one of the `COMMAND_*` values below. */+internal val CalculatorKeyParam = ActionParameters.Key<String>("calculator_widget_key")++/**+ * Whether this instance drops its own surface and lets the wallpaper through. Per-widget+ * Glance state, so two copies of the widget can be styled differently.+ */+internal val CalculatorTransparentKey = booleanPreferencesKey("calculator_widget_transparent")++internal const val COMMAND_CLEAR = "clear"+internal const val COMMAND_BACKSPACE = "backspace"+internal const val COMMAND_EVALUATE = "evaluate"++/** Prefixed rather than bare so an appended "=" or "clear" could never be mistaken for a command. */+internal const val COMMAND_APPEND_PREFIX = "append:"++/**+ * Longest expression the widget keeps. Every tap appends to the stored input, which is then+ * re-read from DataStore, re-parsed for the live preview and shipped to the host as RemoteViews+ * text — so an unbounded string made each tap slower than the last until updates stalled (#641).+ * A few hundred chars is far beyond what the single-line display fits; anything longer only ever+ * came from unbounded growth. `take` (not `takeLast`) keeps the start of what was typed, and also+ * shrinks an already-oversized value left behind from before the cap on the next tap.+ */+internal const val MAX_WIDGET_INPUT_LENGTH = 200++/** Appends [text] to the widget [input], keeping the stored expression bounded. Pure for tests. */+internal fun appendWidgetInput(input: String, text: String): String =+    (input + text).take(MAX_WIDGET_INPUT_LENGTH)++/**+ * A result of the app's evaluator, in both the pretty form for the display and the ASCII+ * token form that re-parses so it can seed the next calculation.+ */+internal class WidgetResult(val display: String, val token: String, val value: Double)++/**+ * Evaluates [input] with [com.vayunmathur.calculator.domain.Expression], the same parser the+ * app uses. Returns null for a blank, unparsable or undefined expression, which the widget+ * renders as an empty result line.+ */+internal fun evaluateForWidget(input: String, ans: Double): WidgetResult? {+    if (input.isBlank()) return null+    val quantity = try {+        Expression.parse(input).evalQuantity(ans = ans)+    } catch (ignored: ExpressionError) {+        return null+    }+    // Non-finite results have no re-parsable token form; storing "∞" as+    // the widget input would strand it (the app's evaluate() does the same).+    if (!quantity.value.isFinite()) return null+    val unit = if (quantity.isDimensionless || quantity.instant) {+        null+    } else {+        UnitRegistry.defaultUnitFor(quantity.dimension)+    }+    return WidgetResult(+        display = formatQuantity(quantity, unit),+        token = formatQuantity(quantity, unit, useToken = true),+        value = quantity.value,+    )+}++/**+ * Handles every keypad tap. Glance dispatches this through the widget's own receiver, so the+ * only state that survives a tap is what gets written to the widget's preferences here.+ */+class CalculatorKeyAction : ActionCallback {+    override suspend fun onAction(+        context: Context,+        glanceId: GlanceId,+        parameters: ActionParameters,+    ) {+        val command = parameters[CalculatorKeyParam] ?: return+        // Glance has no LocalHapticFeedback, so tick directly — same EFFECT_TICK the+        // keyboard service uses. Fires before the state write so a slow update can't eat it.+        // Outside runCatching-style handling: an EFFECT_TICK tick is cosmetic, and the+        // vibrator service is known to throw (missing feature, dead binder, pre-Q effect)+        // on exactly the devices whose widgets must still work — a haptics failure must+        // never swallow the tap. Catch Throwable (not just Exception) and gate the+        // predefined effect to its Q+ API, with a legacy fallback beneath it.+        emitKeyTick(context)+        updateAppWidgetState(context, glanceId) { prefs ->+            // Clamp first: shrinks an already-oversized value left behind from before the+            // cap (#641) so every tap heals, not just appends.+            val rawInput = prefs[CalculatorInputKey].orEmpty()+            val input = rawInput.take(MAX_WIDGET_INPUT_LENGTH)+            if (input.length < rawInput.length) prefs[CalculatorInputKey] = input+            when {+                command == COMMAND_CLEAR -> prefs[CalculatorInputKey] = ""+                command == COMMAND_BACKSPACE -> prefs[CalculatorInputKey] = input.dropLast(1)+                command == COMMAND_EVALUATE -> {+                    val result = evaluateForWidget(input, prefs[CalculatorAnswerKey] ?: 0.0)+                    if (result != null) {+                        prefs[CalculatorInputKey] = result.token+                        prefs[CalculatorAnswerKey] = result.value+                    }+                }+                command.startsWith(COMMAND_APPEND_PREFIX) ->+                    prefs[CalculatorInputKey] = appendWidgetInput(+                        input,+                        command.removePrefix(COMMAND_APPEND_PREFIX),+                    )+            }+        }+        // Writing state alone does not reliably recompose; the explicit update does.+        CalculatorGlanceWidget().update(context, glanceId)+    }++    /** Haptics helper for widget key taps. */+    companion object {+        /**+         * Best-effort key tick. Never throws: every branch is guarded because this runs+         * before the widget state write, and a haptics failure must not swallow the tap.+         */+        @Suppress("TooGenericExceptionCaught", "Deprecation")+        private fun emitKeyTick(context: Context) {+            try {+                val vibrator = runCatching {+                    context.getSystemService(VibratorManager::class.java)?.defaultVibrator+                }.getOrNull() ?: return+                if (!vibrator.hasVibrator()) return+                vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))+            } catch (_: Throwable) {+                // Haptics are cosmetic; the tap has already been queued for handling.+            }+        }+    }+}++/** Glance receiver for the calculator home-screen widget, refreshed only on key taps. */+class CalculatorGlanceWidgetReceiver : MaWidgetReceiver<CalculatorGlanceWidget>(+    widgetClass = CalculatorGlanceWidget::class,+    receiverClass = CalculatorGlanceWidgetReceiver::class,+    // No periodic refresh: the keypad's content only changes when the user taps a key.+    hourly = false,+    widgetFactory = ::CalculatorGlanceWidget,+)
calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidgetReceiver.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidgetReceiver.kt b/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidgetReceiver.ktdeleted file mode 100644index 24d58d1760..0000000000--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorGlanceWidgetReceiver.kt+++ /dev/null@@ -1,12 +0,0 @@-package com.vayunmathur.calculator.widget--import com.vayunmathur.library.widgets.MaWidgetReceiver--/** Glance receiver for the calculator home-screen widget, refreshed only on key taps. */-class CalculatorGlanceWidgetReceiver : MaWidgetReceiver<CalculatorGlanceWidget>(-    widgetClass = CalculatorGlanceWidget::class,-    receiverClass = CalculatorGlanceWidgetReceiver::class,-    // No periodic refresh: the keypad's content only changes when the user taps a key.-    hourly = false,-    widgetFactory = ::CalculatorGlanceWidget,-)
calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorKeyAction.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorKeyAction.kt b/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorKeyAction.ktdeleted file mode 100644index ad729203c5..0000000000--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/CalculatorKeyAction.kt+++ /dev/null@@ -1,154 +0,0 @@-package com.vayunmathur.calculator.widget--import android.content.Context-import android.os.Build-import android.os.VibrationEffect-import android.os.Vibrator-import android.os.VibratorManager-import androidx.datastore.preferences.core.booleanPreferencesKey-import androidx.datastore.preferences.core.doublePreferencesKey-import androidx.datastore.preferences.core.stringPreferencesKey-import androidx.glance.GlanceId-import androidx.glance.action.ActionParameters-import androidx.glance.appwidget.action.ActionCallback-import androidx.glance.appwidget.state.updateAppWidgetState-import com.vayunmathur.calculator.domain.Expression-import com.vayunmathur.calculator.domain.ExpressionError-import com.vayunmathur.calculator.domain.UnitRegistry-import com.vayunmathur.calculator.domain.formatQuantity--/** The in-progress expression, in the same re-parsable form the app's input line uses. */-internal val CalculatorInputKey = stringPreferencesKey("calculator_widget_input")--/** The last computed result, so `ans` resolves the same way it does in the app. */-internal val CalculatorAnswerKey = doublePreferencesKey("calculator_widget_answer")--/** Which key was tapped, as one of the `COMMAND_*` values below. */-internal val CalculatorKeyParam = ActionParameters.Key<String>("calculator_widget_key")--/**- * Whether this instance drops its own surface and lets the wallpaper through. Per-widget- * Glance state, so two copies of the widget can be styled differently.- */-internal val CalculatorTransparentKey = booleanPreferencesKey("calculator_widget_transparent")--internal const val COMMAND_CLEAR = "clear"-internal const val COMMAND_BACKSPACE = "backspace"-internal const val COMMAND_EVALUATE = "evaluate"--/** Prefixed rather than bare so an appended "=" or "clear" could never be mistaken for a command. */-internal const val COMMAND_APPEND_PREFIX = "append:"--/**- * Longest expression the widget keeps. Every tap appends to the stored input, which is then- * re-read from DataStore, re-parsed for the live preview and shipped to the host as RemoteViews- * text — so an unbounded string made each tap slower than the last until updates stalled (#641).- * A few hundred chars is far beyond what the single-line display fits; anything longer only ever- * came from unbounded growth. `take` (not `takeLast`) keeps the start of what was typed, and also- * shrinks an already-oversized value left behind from before the cap on the next tap.- */-internal const val MAX_WIDGET_INPUT_LENGTH = 200--/** Appends [text] to the widget [input], keeping the stored expression bounded. Pure for tests. */-internal fun appendWidgetInput(input: String, text: String): String =-    (input + text).take(MAX_WIDGET_INPUT_LENGTH)--/**- * A result of the app's evaluator, in both the pretty form for the display and the ASCII- * token form that re-parses so it can seed the next calculation.- */-internal class WidgetResult(val display: String, val token: String, val value: Double)--/**- * Evaluates [input] with [com.vayunmathur.calculator.domain.Expression], the same parser the- * app uses. Returns null for a blank, unparsable or undefined expression, which the widget- * renders as an empty result line.- */-internal fun evaluateForWidget(input: String, ans: Double): WidgetResult? {-    if (input.isBlank()) return null-    val quantity = try {-        Expression.parse(input).evalQuantity(ans = ans)-    } catch (ignored: ExpressionError) {-        return null-    }-    // Non-finite results have no re-parsable token form; storing "∞" as-    // the widget input would strand it (the app's evaluate() does the same).-    if (!quantity.value.isFinite()) return null-    val unit = if (quantity.isDimensionless || quantity.instant) {-        null-    } else {-        UnitRegistry.defaultUnitFor(quantity.dimension)-    }-    return WidgetResult(-        display = formatQuantity(quantity, unit),-        token = formatQuantity(quantity, unit, useToken = true),-        value = quantity.value,-    )-}--/**- * Handles every keypad tap. Glance dispatches this through the widget's own receiver, so the- * only state that survives a tap is what gets written to the widget's preferences here.- */-class CalculatorKeyAction : ActionCallback {-    override suspend fun onAction(-        context: Context,-        glanceId: GlanceId,-        parameters: ActionParameters,-    ) {-        val command = parameters[CalculatorKeyParam] ?: return-        // Glance has no LocalHapticFeedback, so tick directly — same EFFECT_TICK the-        // keyboard service uses. Fires before the state write so a slow update can't eat it.-        // Outside runCatching-style handling: an EFFECT_TICK tick is cosmetic, and the-        // vibrator service is known to throw (missing feature, dead binder, pre-Q effect)-        // on exactly the devices whose widgets must still work — a haptics failure must-        // never swallow the tap. Catch Throwable (not just Exception) and gate the-        // predefined effect to its Q+ API, with a legacy fallback beneath it.-        emitKeyTick(context)-        updateAppWidgetState(context, glanceId) { prefs ->-            // Clamp first: shrinks an already-oversized value left behind from before the-            // cap (#641) so every tap heals, not just appends.-            val rawInput = prefs[CalculatorInputKey].orEmpty()-            val input = rawInput.take(MAX_WIDGET_INPUT_LENGTH)-            if (input.length < rawInput.length) prefs[CalculatorInputKey] = input-            when {-                command == COMMAND_CLEAR -> prefs[CalculatorInputKey] = ""-                command == COMMAND_BACKSPACE -> prefs[CalculatorInputKey] = input.dropLast(1)-                command == COMMAND_EVALUATE -> {-                    val result = evaluateForWidget(input, prefs[CalculatorAnswerKey] ?: 0.0)-                    if (result != null) {-                        prefs[CalculatorInputKey] = result.token-                        prefs[CalculatorAnswerKey] = result.value-                    }-                }-                command.startsWith(COMMAND_APPEND_PREFIX) ->-                    prefs[CalculatorInputKey] = appendWidgetInput(-                        input,-                        command.removePrefix(COMMAND_APPEND_PREFIX),-                    )-            }-        }-        // Writing state alone does not reliably recompose; the explicit update does.-        CalculatorGlanceWidget().update(context, glanceId)-    }--    /** Haptics helper for widget key taps. */-    companion object {-        /**-         * Best-effort key tick. Never throws: every branch is guarded because this runs-         * before the widget state write, and a haptics failure must not swallow the tap.-         */-        @Suppress("TooGenericExceptionCaught", "Deprecation")-        private fun emitKeyTick(context: Context) {-            try {-                val vibrator = runCatching {-                    context.getSystemService(VibratorManager::class.java)?.defaultVibrator-                }.getOrNull() ?: return-                if (!vibrator.hasVibrator()) return-                vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))-            } catch (_: Throwable) {-                // Haptics are cosmetic; the tap has already been queued for handling.-            }-        }-    }-}
calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidget.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidget.kt b/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidget.ktindex 763f772b75..71b7ce77af 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidget.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidget.kt@@ -48,6 +48,10 @@ import com.vayunmathur.calculator.platform.unitsFromKey import com.vayunmathur.calculator.platform.unitsToKey import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.library.widgets.MaWidget+import androidx.glance.action.ActionParameters+import androidx.glance.appwidget.action.ActionCallback+import androidx.glance.appwidget.state.updateAppWidgetState+import com.vayunmathur.library.widgets.MaWidgetReceiver  /** What the widget draws: the category it is on and the conversion for that category's unit pair. */ data class UnitsWidgetState(val categoryName: String, val conversion: String)@@ -277,3 +281,55 @@ class UnitsGlanceWidget : MaWidget<UnitsWidgetData>() {         }     } }++/**+ * Opens and closes the inline category list. Glance state survives widget updates, so the list+ * stays open across the recomposition this triggers.+ */+class ToggleUnitsCategoryListAction : ActionCallback {+    override suspend fun onAction(+        context: Context,+        glanceId: GlanceId,+        parameters: ActionParameters,+    ) {+        updateAppWidgetState(context, glanceId) { prefs ->+            prefs[UnitsGlanceWidget.EXPANDED] = prefs[UnitsGlanceWidget.EXPANDED] != true+        }+        UnitsGlanceWidget().update(context, glanceId)+    }+}++/** Switches the widget to a category and collapses the list again. */+class SelectUnitsCategoryAction : ActionCallback {+    override suspend fun onAction(+        context: Context,+        glanceId: GlanceId,+        parameters: ActionParameters,+    ) {+        val name = parameters[CATEGORY_NAME] ?: return+        // The preference the app restores on launch, so the converter reopens on this category too.+        DataStoreUtils.getInstance(context)+            .setString(KEY_UNITS_CATEGORY, name)+        updateAppWidgetState(context, glanceId) { prefs ->+            prefs[UnitsGlanceWidget.EXPANDED] = false+        }+        UnitsGlanceWidget().update(context, glanceId)+    }++    /** Action parameter keys for the units widget actions. */+    companion object {+        val CATEGORY_NAME = ActionParameters.Key<String>("categoryName")+    }+}++/**+ * No periodic update is scheduled: a conversion only changes when the user changes it, and both+ * sides push an update when they do — the converter through `CalculatorViewModel`, the widget+ * through its own action callbacks.+ */+class UnitsGlanceWidgetReceiver : MaWidgetReceiver<UnitsGlanceWidget>(+    widgetClass = UnitsGlanceWidget::class,+    receiverClass = UnitsGlanceWidgetReceiver::class,+    hourly = false,+    widgetFactory = ::UnitsGlanceWidget,+)
calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidgetReceiver.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidgetReceiver.kt b/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidgetReceiver.ktdeleted file mode 100644index 51fe2830a4..0000000000--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsGlanceWidgetReceiver.kt+++ /dev/null@@ -1,15 +0,0 @@-package com.vayunmathur.calculator.widget--import com.vayunmathur.library.widgets.MaWidgetReceiver--/**- * No periodic update is scheduled: a conversion only changes when the user changes it, and both- * sides push an update when they do — the converter through `CalculatorViewModel`, the widget- * through its own action callbacks.- */-class UnitsGlanceWidgetReceiver : MaWidgetReceiver<UnitsGlanceWidget>(-    widgetClass = UnitsGlanceWidget::class,-    receiverClass = UnitsGlanceWidgetReceiver::class,-    hourly = false,-    widgetFactory = ::UnitsGlanceWidget,-)
calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsWidgetActions.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsWidgetActions.kt b/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsWidgetActions.ktdeleted file mode 100644index a65a8e36fb..0000000000--- a/calculator/src/main/java/com/vayunmathur/calculator/widget/UnitsWidgetActions.kt+++ /dev/null@@ -1,49 +0,0 @@-package com.vayunmathur.calculator.widget--import android.content.Context-import androidx.glance.GlanceId-import androidx.glance.action.ActionParameters-import androidx.glance.appwidget.action.ActionCallback-import androidx.glance.appwidget.state.updateAppWidgetState-import com.vayunmathur.calculator.platform.KEY_UNITS_CATEGORY-import com.vayunmathur.library.util.DataStoreUtils--/**- * Opens and closes the inline category list. Glance state survives widget updates, so the list- * stays open across the recomposition this triggers.- */-class ToggleUnitsCategoryListAction : ActionCallback {-    override suspend fun onAction(-        context: Context,-        glanceId: GlanceId,-        parameters: ActionParameters,-    ) {-        updateAppWidgetState(context, glanceId) { prefs ->-            prefs[UnitsGlanceWidget.EXPANDED] = prefs[UnitsGlanceWidget.EXPANDED] != true-        }-        UnitsGlanceWidget().update(context, glanceId)-    }-}--/** Switches the widget to a category and collapses the list again. */-class SelectUnitsCategoryAction : ActionCallback {-    override suspend fun onAction(-        context: Context,-        glanceId: GlanceId,-        parameters: ActionParameters,-    ) {-        val name = parameters[CATEGORY_NAME] ?: return-        // The preference the app restores on launch, so the converter reopens on this category too.-        DataStoreUtils.getInstance(context)-            .setString(KEY_UNITS_CATEGORY, name)-        updateAppWidgetState(context, glanceId) { prefs ->-            prefs[UnitsGlanceWidget.EXPANDED] = false-        }-        UnitsGlanceWidget().update(context, glanceId)-    }--    /** Action parameter keys for the units widget actions. */-    companion object {-        val CATEGORY_NAME = ActionParameters.Key<String>("categoryName")-    }-}
calculator/src/main/res/xml/calculator_widget_info.xml
diff --git a/calculator/src/main/res/xml/calculator_widget_info.xml b/calculator/src/main/res/xml/calculator_widget_info.xmlindex 90e10948e7..fec1d6f019 100644--- a/calculator/src/main/res/xml/calculator_widget_info.xml+++ b/calculator/src/main/res/xml/calculator_widget_info.xml@@ -4,7 +4,7 @@     android:minHeight="180dp"     android:updatePeriodMillis="0"     android:initialLayout="@layout/glance_widget_initial_layout"-    android:configure="com.vayunmathur.calculator.widget.CalculatorWidgetSettingsActivity"+    android:configure="com.vayunmathur.calculator.ui.CalculatorWidgetSettingsActivity"     android:widgetFeatures="reconfigurable|configuration_optional"     android:description="@string/calculator_widget_description"     android:resizeMode="horizontal|vertical"
calculator/src/test/java/com/vayunmathur/calculator/NavigationAndActivityTest.kt
diff --git a/calculator/src/test/java/com/vayunmathur/calculator/NavigationAndActivityTest.kt b/calculator/src/test/java/com/vayunmathur/calculator/NavigationAndActivityTest.ktindex d9c2ced4fe..4c050fb53a 100644--- a/calculator/src/test/java/com/vayunmathur/calculator/NavigationAndActivityTest.kt+++ b/calculator/src/test/java/com/vayunmathur/calculator/NavigationAndActivityTest.kt@@ -2,7 +2,7 @@ package com.vayunmathur.calculator  import android.content.Intent import androidx.test.core.app.ApplicationProvider-import com.vayunmathur.calculator.widget.CalculatorWidgetSettingsActivity+import com.vayunmathur.calculator.ui.CalculatorWidgetSettingsActivity import android.appwidget.AppWidgetManager import kotlinx.serialization.json.Json import org.junit.Before
calculator/src/test/java/com/vayunmathur/calculator/ui/WidgetSettingsComposeTest.kt
diff --git a/calculator/src/test/java/com/vayunmathur/calculator/ui/WidgetSettingsComposeTest.kt b/calculator/src/test/java/com/vayunmathur/calculator/ui/WidgetSettingsComposeTest.ktindex 99e2e7cbe9..719bffae12 100644--- a/calculator/src/test/java/com/vayunmathur/calculator/ui/WidgetSettingsComposeTest.kt+++ b/calculator/src/test/java/com/vayunmathur/calculator/ui/WidgetSettingsComposeTest.kt@@ -7,7 +7,7 @@ import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.onNodeWithText import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.rules.ActivityScenarioRule-import com.vayunmathur.calculator.widget.CalculatorWidgetSettingsActivity+import com.vayunmathur.calculator.ui.CalculatorWidgetSettingsActivity import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner
calculator/src/test/java/com/vayunmathur/calculator/widget/WidgetLogicTest.kt
diff --git a/calculator/src/test/java/com/vayunmathur/calculator/widget/WidgetLogicTest.kt b/calculator/src/test/java/com/vayunmathur/calculator/widget/WidgetLogicTest.ktindex c89c69016f..f3fef0f27e 100644--- a/calculator/src/test/java/com/vayunmathur/calculator/widget/WidgetLogicTest.kt+++ b/calculator/src/test/java/com/vayunmathur/calculator/widget/WidgetLogicTest.kt@@ -1,6 +1,7 @@ package com.vayunmathur.calculator.widget  import android.content.Context+import com.vayunmathur.calculator.ui.CalculatorWidgetSettingsActivity import androidx.test.core.app.ApplicationProvider import org.junit.runner.RunWith import org.robolectric.Robolectric