diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 305d261a7..1ca7aaada 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -112,6 +112,7 @@ dependencies { implementation("androidx.appcompat:appcompat:1.7.1") implementation("androidx.constraintlayout:constraintlayout:2.2.1") implementation("androidx.core:core-ktx:1.16.0") + implementation("androidx.core:core-remoteviews:1.1.0") implementation("androidx.core:core-splashscreen:1.0.1") implementation("androidx.exifinterface:exifinterface:1.4.1") implementation("androidx.palette:palette:1.0.0") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98f978d98..346f97f5f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,20 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:localeConfig="@xml/locales_config"> + + + + + + + + + = 23) { + setInt(R.id.item_container_foreground, "setBackgroundColor", foreground) + setImageViewIcon(R.id.item_image, Icon.createWithBitmap(icon)) + setViewVisibility(R.id.item_text, View.INVISIBLE) + setViewVisibility(R.id.item_image, View.VISIBLE) + } else { + setImageViewBitmap(R.id.item_image, null) + setTextViewText(R.id.item_text, loyaltyCard.store) + setViewVisibility(R.id.item_text, View.VISIBLE) + setViewVisibility(R.id.item_image, View.INVISIBLE) + setTextColor( + R.id.item_text, + foreground + ) + } + + // Add the card ID to the intent template + val fillInIntent = Intent().apply { + putExtra(LoyaltyCardViewActivity.BUNDLE_ID, loyaltyCard.id) + } + + setOnClickFillInIntent(R.id.item_container, fillInIntent) + } + + return remoteViews + } +} \ No newline at end of file diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index eeb9383ba..ff5238236 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -880,6 +880,8 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements } else if (id == R.id.action_star_unstar) { DBHelper.updateLoyaltyCardStarStatus(database, loyaltyCardId, loyaltyCard.starStatus == 0 ? 1 : 0); + new ListWidget().updateAll(LoyaltyCardViewActivity.this); + // Re-init loyaltyCard with new data from DB onResume(); invalidateOptionsMenu(); @@ -890,6 +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 ListWidget().updateAll(LoyaltyCardViewActivity.this); // Re-init loyaltyCard with new data from DB onResume(); @@ -915,6 +918,7 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements DBHelper.deleteLoyaltyCard(database, LoyaltyCardViewActivity.this, loyaltyCardId); ShortcutHelper.removeShortcut(LoyaltyCardViewActivity.this, loyaltyCardId); + 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 dbcbd8a0d..4d7371573 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -2,6 +2,8 @@ package protect.card_locker; import android.app.Activity; import android.app.SearchManager; +import android.appwidget.AppWidgetManager; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -330,22 +332,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard selectedTab = activeTabPref.getInt(getString(R.string.sharedpreference_active_tab), 0); // Restore sort preferences from Shared Preferences - // If one of the sorting prefererences has never been set or is set to an invalid value, - // stick to the defaults. - SharedPreferences sortPref = getApplicationContext().getSharedPreferences( - getString(R.string.sharedpreference_sort), - Context.MODE_PRIVATE); - - String orderString = sortPref.getString(getString(R.string.sharedpreference_sort_order), null); - String orderDirectionString = sortPref.getString(getString(R.string.sharedpreference_sort_direction), null); - - if (orderString != null && orderDirectionString != null) { - try { - mOrder = DBHelper.LoyaltyCardOrder.valueOf(orderString); - mOrderDirection = DBHelper.LoyaltyCardOrderDirection.valueOf(orderDirectionString); - } catch (IllegalArgumentException ignored) { - } - } + mOrder = Utils.getLoyaltyCardOrder(this); + mOrderDirection = Utils.getLoyaltyCardOrderDirection(this); mGroup = null; @@ -442,6 +430,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard if (mCurrentActionMode != null) { mCurrentActionMode.finish(); } + + new ListWidget().updateAll(mAdapter.mContext); } private void processParseResultList(List parseResultList, String group, boolean closeAppOnNoBarcode) { @@ -709,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/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index a8eec2319..87a96371d 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -1176,4 +1177,40 @@ public class Utils { return ImageView.ScaleType.FIT_CENTER; } + + public static DBHelper.LoyaltyCardOrder getLoyaltyCardOrder(Context context) { + SharedPreferences sortPref = context.getSharedPreferences( + "sharedpreference_sort", + Context.MODE_PRIVATE + ); + + String orderString = sortPref.getString("sharedpreference_sort_order", null); + + if (orderString != null) { + try { + return DBHelper.LoyaltyCardOrder.valueOf(orderString); + } catch (IllegalArgumentException ignored) { + } + } + + return DBHelper.LoyaltyCardOrder.Alpha; + } + + public static DBHelper.LoyaltyCardOrderDirection getLoyaltyCardOrderDirection(Context context) { + SharedPreferences sortPref = context.getSharedPreferences( + "sharedpreference_sort", + Context.MODE_PRIVATE + ); + + String orderDirectionString = sortPref.getString("sharedpreference_sort_direction", null); + + if (orderDirectionString != null) { + try { + return DBHelper.LoyaltyCardOrderDirection.valueOf(orderDirectionString); + } catch (IllegalArgumentException ignored) { + } + } + + return DBHelper.LoyaltyCardOrderDirection.Ascending; + } } diff --git a/app/src/main/res/drawable-nodpi/widget_preview.png b/app/src/main/res/drawable-nodpi/widget_preview.png new file mode 100644 index 000000000..68cd4c43a Binary files /dev/null and b/app/src/main/res/drawable-nodpi/widget_preview.png differ diff --git a/app/src/main/res/layout/list_widget.xml b/app/src/main/res/layout/list_widget.xml new file mode 100644 index 000000000..71f055d87 --- /dev/null +++ b/app/src/main/res/layout/list_widget.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_widget_empty.xml b/app/src/main/res/layout/list_widget_empty.xml new file mode 100644 index 000000000..34be704c3 --- /dev/null +++ b/app/src/main/res/layout/list_widget_empty.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_widget_item.xml b/app/src/main/res/layout/list_widget_item.xml new file mode 100644 index 000000000..386b42ddb --- /dev/null +++ b/app/src/main/res/layout/list_widget_item.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d78a86dc2..95d450e9a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -362,5 +362,7 @@ This file is not supported Sorry, something went wrong, please try again... Width + Card list Set Barcode Width + After you add some loyalty cards in Catima, they will appear here. If you have cards, make sure they are not all archived. diff --git a/app/src/main/res/xml/list_widget_info.xml b/app/src/main/res/xml/list_widget_info.xml new file mode 100644 index 000000000..26fc5eb57 --- /dev/null +++ b/app/src/main/res/xml/list_widget_info.xml @@ -0,0 +1,12 @@ + +