fix Account Spotlight widget
This commit is contained in:
2 files changed
+59
-3
No files matched your search
@@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -154,14 +155,24 @@ object RemainingWidgetUpdater {
|
||||
R.id.remaining_widget_image,
|
||||
data.account?.let { "Account Spotlight: ${it.name}" } ?: "Account Spotlight"
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.remaining_widget_root, openAppIntent(context, widgetId))
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.remaining_widget_root,
|
||||
if (data.account == null) {
|
||||
openConfigureIntent(context, widgetId, mutable = false)
|
||||
} else {
|
||||
openAppIntent(context, widgetId)
|
||||
}
|
||||
)
|
||||
appWidgetManager.updateAppWidget(widgetId, views)
|
||||
}.onFailure {
|
||||
val views = RemoteViews(context.packageName, R.layout.remaining_widget_chart)
|
||||
views.setViewVisibility(R.id.remaining_widget_image, View.GONE)
|
||||
views.setViewVisibility(R.id.remaining_widget_fallback, View.VISIBLE)
|
||||
views.setTextViewText(R.id.remaining_widget_fallback, "Choose account")
|
||||
views.setOnClickPendingIntent(R.id.remaining_widget_root, openAppIntent(context, widgetId))
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.remaining_widget_root,
|
||||
openConfigureIntent(context, widgetId, mutable = false)
|
||||
)
|
||||
appWidgetManager.updateAppWidget(widgetId, views)
|
||||
}
|
||||
}
|
||||
@@ -186,4 +197,26 @@ object RemainingWidgetUpdater {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
}
|
||||
|
||||
fun openConfigureIntent(
|
||||
context: Context,
|
||||
requestCode: Int,
|
||||
mutable: Boolean
|
||||
): PendingIntent {
|
||||
val intent = Intent(context, AccountWidgetConfigureActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, requestCode)
|
||||
}
|
||||
val mutabilityFlag = if (mutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
PendingIntent.FLAG_MUTABLE
|
||||
} else {
|
||||
PendingIntent.FLAG_IMMUTABLE
|
||||
}
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
requestCode,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or mutabilityFlag
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user