mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-14 04:17:27 -04:00
Rename from CatimaWidget to ListWidget
This makes the codebase easier to understand if we get more widget types in the future
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
android:localeConfig="@xml/locales_config">
|
||||
|
||||
<receiver
|
||||
android:name="CatimaWidget"
|
||||
android:name=".ListWidget"
|
||||
android:label="@string/card_list_widget_name"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/catima_widget_info" />
|
||||
android:resource="@xml/list_widget_info" />
|
||||
</receiver>
|
||||
|
||||
<activity
|
||||
|
||||
@@ -14,10 +14,10 @@ import android.widget.RemoteViews
|
||||
import androidx.core.widget.RemoteViewsCompat
|
||||
import protect.card_locker.DBHelper.LoyaltyCardArchiveFilter
|
||||
|
||||
class CatimaWidget : AppWidgetProvider() {
|
||||
class ListWidget : AppWidgetProvider() {
|
||||
fun updateAll(context: Context) {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val componentName = ComponentName(context, CatimaWidget::class.java)
|
||||
val componentName = ComponentName(context, ListWidget::class.java)
|
||||
onUpdate(
|
||||
context,
|
||||
appWidgetManager,
|
||||
@@ -31,45 +31,59 @@ class CatimaWidget : AppWidgetProvider() {
|
||||
appWidgetIds: IntArray
|
||||
) {
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
// Prepare generic widget
|
||||
val views = RemoteViews(context.packageName, R.layout.catima_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 database = DBHelper(context).readableDatabase
|
||||
|
||||
val loyaltyCardCursor = DBHelper.getLoyaltyCardCursor(
|
||||
database,
|
||||
"",
|
||||
null,
|
||||
order,
|
||||
orderDirection,
|
||||
LoyaltyCardArchiveFilter.Unarchived
|
||||
)
|
||||
// Default to empty widget
|
||||
var views = RemoteViews(context.packageName, R.layout.list_widget_empty)
|
||||
|
||||
// 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
|
||||
// If we have cards, replace with non-empty widget
|
||||
if (DBHelper.getLoyaltyCardCount(database) > 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)
|
||||
@@ -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();
|
||||
|
||||
@@ -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<ParseResult> parseResultList, String group, boolean closeAppOnNoBarcode) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- android:columnWidth must be kept in sync with catima_widget_item.xml -->
|
||||
<!-- android:columnWidth must be kept in sync with list_widget_item.xml -->
|
||||
<GridView
|
||||
android:id="@+id/grid_view"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -1,5 +1,6 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/widget_layout"
|
||||
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" />
|
||||
</LinearLayout>
|
||||
@@ -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="no_loyalty_cards">No loyalty cards</string>
|
||||
<string name="card_list_widget_empty">After you add some loyalty cards in Catima, they will appear here.</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:initialKeyguardLayout="@layout/catima_widget"
|
||||
android:initialLayout="@layout/catima_widget"
|
||||
android:initialKeyguardLayout="@layout/list_widget"
|
||||
android:initialLayout="@layout/list_widget"
|
||||
android:minWidth="245dp"
|
||||
android:minHeight="54dp"
|
||||
android:previewImage="@drawable/widget_preview"
|
||||
Reference in New Issue
Block a user