Skip to content

Commit

Permalink
Getting OnEnable and OnDisable back.
Browse files Browse the repository at this point in the history
  • Loading branch information
xenonnn4w committed Jul 22, 2024
1 parent bd191dc commit db42fc4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ abstract class AnalyticsWidgetProvider : AppWidgetProvider() {
}

/**
* Abstract method to be implemented by subclasses to perform widget updates.
* <p>
* Note: When this method is executed, it is assumed that the storage access is granted.
* Override this method to implement Widget functionality
*
* Called when the [AnalyticsWidgetProvider] is asked to provide [RemoteViews] for a set of Widgets AND the Anki collection is accessible.
*
* @see AppWidgetProvider.onUpdate
*
* @param context The context in which the receiver is running.
* @param appWidgetManager The AppWidgetManager instance to use for updating widgets.
Expand Down
17 changes: 17 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/widget/AnkiDroidWidgetSmall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import android.view.View
import android.widget.RemoteViews
import androidx.core.app.PendingIntentCompat
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import com.ichi2.anki.AnkiDroidApp
import com.ichi2.anki.IntentHandler
import com.ichi2.anki.R
import com.ichi2.anki.analytics.UsageAnalytics
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.compat.CompatHelper.Companion.registerReceiverCompat
import com.ichi2.utils.KotlinCleanup
import timber.log.Timber
Expand All @@ -43,6 +45,21 @@ class AnkiDroidWidgetSmall : AnalyticsWidgetProvider() {
override fun performUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray, usageAnalytics: UsageAnalytics) {
WidgetStatus.updateInBackground(context)
}
override fun onEnabled(context: Context) {
super.onEnabled(context)
Timber.d("SmallWidget: Widget enabled")
val preferences = context.sharedPrefs()
preferences.edit(commit = true) { putBoolean("widgetSmallEnabled", true) }
UsageAnalytics.sendAnalyticsEvent(this.javaClass.simpleName, "enabled")
}

override fun onDisabled(context: Context) {
super.onDisabled(context)
Timber.d("SmallWidget: Widget disabled")
val preferences = context.sharedPrefs()
preferences.edit(commit = true) { putBoolean("widgetSmallEnabled", false) }
UsageAnalytics.sendAnalyticsEvent(this.javaClass.simpleName, "disabled")
}

override fun onReceive(context: Context, intent: Intent) {
if (intent.action.contentEquals("com.sec.android.widgetapp.APPWIDGET_RESIZE")) {
Expand Down

0 comments on commit db42fc4

Please sign in to comment.