diff --git a/app/src/main/java/protect/card_locker/ListWidget.kt b/app/src/main/java/protect/card_locker/ListWidget.kt index 6286f4e83..226f437b4 100644 --- a/app/src/main/java/protect/card_locker/ListWidget.kt +++ b/app/src/main/java/protect/card_locker/ListWidget.kt @@ -33,12 +33,41 @@ class ListWidget : AppWidgetProvider() { for (appWidgetId in appWidgetIds) { val database = DBHelper(context).readableDatabase - // Default to empty widget + // Get cards + val order = Utils.getLoyaltyCardOrder(context); + val orderDirection = Utils.getLoyaltyCardOrderDirection(context); + + val loyaltyCardCursor = DBHelper.getLoyaltyCardCursor( + database, + "", + null, + order, + orderDirection, + LoyaltyCardArchiveFilter.Unarchived + ) + + // Bind every card to cell in the grid + var hasCards = false + val remoteCollectionItemsBuilder = RemoteViewsCompat.RemoteCollectionItems.Builder() + if (loyaltyCardCursor.moveToFirst()) { + do { + val loyaltyCard = LoyaltyCard.fromCursor(context, loyaltyCardCursor) + remoteCollectionItemsBuilder.addItem( + loyaltyCard.id.toLong(), + createRemoteViews( + context, loyaltyCard + ) + ) + hasCards = true + } while (loyaltyCardCursor.moveToNext()) + } + loyaltyCardCursor.close() + + // Create the base empty view var views = RemoteViews(context.packageName, R.layout.list_widget_empty) - // If we have cards, replace with non-empty widget - if (DBHelper.getLoyaltyCardCount(database) > 0) { - // Prepare generic widget + if (hasCards) { + // If we have cards, create the list views = RemoteViews(context.packageName, R.layout.list_widget) val templateIntent = Intent(context, LoyaltyCardViewActivity::class.java) val pendingIntent = PendingIntent.getActivity( @@ -49,33 +78,6 @@ class ListWidget : AppWidgetProvider() { ) views.setPendingIntentTemplate(R.id.grid_view, pendingIntent) - // Get cards - val order = Utils.getLoyaltyCardOrder(context); - val orderDirection = Utils.getLoyaltyCardOrderDirection(context); - - val loyaltyCardCursor = DBHelper.getLoyaltyCardCursor( - database, - "", - null, - order, - orderDirection, - LoyaltyCardArchiveFilter.Unarchived - ) - - // Bind every card to cell in the grid - val remoteCollectionItemsBuilder = RemoteViewsCompat.RemoteCollectionItems.Builder() - if (loyaltyCardCursor.moveToFirst()) { - do { - val loyaltyCard = LoyaltyCard.fromCursor(context, loyaltyCardCursor) - remoteCollectionItemsBuilder.addItem( - loyaltyCard.id.toLong(), - createRemoteViews( - context, loyaltyCard - ) - ) - } while (loyaltyCardCursor.moveToNext()) - } - RemoteViewsCompat.setRemoteAdapter( context, views, diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index cff585e93..4d7371573 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -699,6 +699,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard showReversed.isChecked() ? DBHelper.LoyaltyCardOrderDirection.Descending : DBHelper.LoyaltyCardOrderDirection.Ascending ); + new ListWidget().updateAll(this); + dialog.dismiss(); }); diff --git a/app/src/main/res/layout/list_widget_item.xml b/app/src/main/res/layout/list_widget_item.xml index c5449c07f..386b42ddb 100644 --- a/app/src/main/res/layout/list_widget_item.xml +++ b/app/src/main/res/layout/list_widget_item.xml @@ -16,8 +16,7 @@ Both multiplied by 1.25 to fit better + android:id="@+id/item_container_foreground"> Width Card list Set Barcode Width - After you add some loyalty cards in Catima, they will appear here. + After you add some loyalty cards in Catima, they will appear here. If you have cards, make sure they are not all archived.