diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index adb39906a..346f97f5f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ android:localeConfig="@xml/locales_config"> @@ -41,7 +41,7 @@ + android:resource="@xml/list_widget_info" /> 0) { + // Prepare generic widget + views = RemoteViews(context.packageName, R.layout.list_widget) + val templateIntent = Intent(context, LoyaltyCardViewActivity::class.java) + val pendingIntent = PendingIntent.getActivity( + context, + 0, + templateIntent, + PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + ) + 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()) + } while (loyaltyCardCursor.moveToNext()) + } + + RemoteViewsCompat.setRemoteAdapter( + context, + views, + appWidgetId, + R.id.grid_view, + remoteCollectionItemsBuilder.build() + ) } - RemoteViewsCompat.setRemoteAdapter(context, views, appWidgetId, R.id.grid_view, remoteCollectionItemsBuilder.build()) // Let Android know the widget is ready for display appWidgetManager.updateAppWidget(appWidgetId, views) @@ -79,7 +93,7 @@ class CatimaWidget : AppWidgetProvider() { private fun createRemoteViews(context: Context, loyaltyCard: LoyaltyCard): RemoteViews { // Create a single cell for the grid view, bind it to open in the LoyaltyCardViewActivity // Note: Android 5 will not use bitmaps - val remoteViews = RemoteViews(context.packageName, R.layout.catima_widget_item).apply { + val remoteViews = RemoteViews(context.packageName, R.layout.list_widget_item).apply { val headerColor = Utils.getHeaderColor(context, loyaltyCard) val foreground = if (Utils.needsDarkForeground(headerColor)) Color.BLACK else Color.WHITE setInt(R.id.item_container_foreground, "setBackgroundColor", headerColor) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index 4317c4f11..ff5238236 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -880,7 +880,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements } else if (id == R.id.action_star_unstar) { DBHelper.updateLoyaltyCardStarStatus(database, loyaltyCardId, loyaltyCard.starStatus == 0 ? 1 : 0); - new CatimaWidget().updateAll(LoyaltyCardViewActivity.this); + new ListWidget().updateAll(LoyaltyCardViewActivity.this); // Re-init loyaltyCard with new data from DB onResume(); @@ -892,7 +892,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements Toast.makeText(LoyaltyCardViewActivity.this, R.string.archived, Toast.LENGTH_LONG).show(); ShortcutHelper.removeShortcut(LoyaltyCardViewActivity.this, loyaltyCardId); - new CatimaWidget().updateAll(LoyaltyCardViewActivity.this); + new ListWidget().updateAll(LoyaltyCardViewActivity.this); // Re-init loyaltyCard with new data from DB onResume(); @@ -918,7 +918,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements DBHelper.deleteLoyaltyCard(database, LoyaltyCardViewActivity.this, loyaltyCardId); ShortcutHelper.removeShortcut(LoyaltyCardViewActivity.this, loyaltyCardId); - new CatimaWidget().updateAll(LoyaltyCardViewActivity.this); + new ListWidget().updateAll(LoyaltyCardViewActivity.this); finish(); dialog.dismiss(); diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 70f49638b..cff585e93 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -431,7 +431,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard mCurrentActionMode.finish(); } - new CatimaWidget().updateAll(mAdapter.mContext); + new ListWidget().updateAll(mAdapter.mContext); } private void processParseResultList(List parseResultList, String group, boolean closeAppOnNoBarcode) { diff --git a/app/src/main/res/layout/catima_widget.xml b/app/src/main/res/layout/list_widget.xml similarity index 85% rename from app/src/main/res/layout/catima_widget.xml rename to app/src/main/res/layout/list_widget.xml index 1a7a6e53c..71f055d87 100644 --- a/app/src/main/res/layout/catima_widget.xml +++ b/app/src/main/res/layout/list_widget.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - + @@ -8,5 +9,9 @@ android:id="@+id/no_cards_view" android:layout_width="match_parent" android:layout_height="match_parent" - android:text="@string/no_loyalty_cards" /> + android:text="@string/card_list_widget_empty" + app:autoSizeTextType="uniform" + app:autoSizeMinTextSize="12sp" + app:autoSizeMaxTextSize="100sp" + app:autoSizeStepGranularity="2sp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/catima_widget_item.xml b/app/src/main/res/layout/list_widget_item.xml similarity index 100% rename from app/src/main/res/layout/catima_widget_item.xml rename to app/src/main/res/layout/list_widget_item.xml diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 420f84b2f..caa8684be 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -364,5 +364,5 @@ Width Card list Set Barcode Width - No loyalty cards + After you add some loyalty cards in Catima, they will appear here. diff --git a/app/src/main/res/xml/catima_widget_info.xml b/app/src/main/res/xml/list_widget_info.xml similarity index 79% rename from app/src/main/res/xml/catima_widget_info.xml rename to app/src/main/res/xml/list_widget_info.xml index 2efb897aa..26fc5eb57 100644 --- a/app/src/main/res/xml/catima_widget_info.xml +++ b/app/src/main/res/xml/list_widget_info.xml @@ -1,7 +1,7 @@