Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
xenonnn4w committed Oct 2, 2024
1 parent 6cd2a40 commit b5d9633
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class DeckPickerWidget : AnalyticsWidgetProvider() {
deckIds: LongArray
) {
remoteViews.removeAllViews(R.id.deckCollection)

val deckData = getDeckNamesAndStats(deckIds.toList())
for (deck in deckData) {
val deckView = RemoteViews(context.packageName, R.layout.widget_item_deck_main)
Expand Down Expand Up @@ -171,10 +170,22 @@ class DeckPickerWidget : AnalyticsWidgetProvider() {
appWidgetId: AppWidgetId,
remoteViews: RemoteViews
) {
remoteViews.setTextViewText(R.id.empty_widget, context.getString(R.string.app_not_initialized_new))
remoteViews.setTextViewText(R.id.empty_widget, context.getString(R.string.empty_collection))
remoteViews.setViewVisibility(R.id.empty_widget, View.VISIBLE)
remoteViews.setViewVisibility(R.id.deckCollection, View.GONE)

val configIntent = Intent(context, DeckPickerWidgetConfig::class.java).apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val configPendingIntent = PendingIntent.getActivity(
context,
appWidgetId,
configIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
remoteViews.setOnClickPendingIntent(R.id.empty_widget, configPendingIntent)

appWidgetManager.updateAppWidget(appWidgetId, remoteViews)
}

Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/08-widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
<item quantity="other">You can select up to %d decks.</item>
</plurals>
<string name="empty_widget" comment="To denote the widget is empty">Missing deck. Click to reconfigure</string>
<string name="empty_collection" comment="To denote the collection is empty">Collection is empty, use app to add decks then reconfigure</string>"

</resources>

0 comments on commit b5d9633

Please sign in to comment.