mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-03-31 13:51:52 -04:00
Various widget bugfixes
Widget now updates on sorting order change and no cards is correctly detected
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ Both multiplied by 1.25 to fit better
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/item_container_foreground"
|
||||
android:padding="4dp">
|
||||
android:id="@+id/item_container_foreground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/item_image"
|
||||
|
||||
@@ -364,5 +364,5 @@
|
||||
<string name="width">Width</string>
|
||||
<string name="card_list_widget_name">Card list</string>
|
||||
<string name="setBarcodeWidth">Set Barcode Width</string>
|
||||
<string name="card_list_widget_empty">After you add some loyalty cards in Catima, they will appear here.</string>
|
||||
<string name="card_list_widget_empty">After you add some loyalty cards in Catima, they will appear here. If you have cards, make sure they are not all archived.</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user