From 426c765b5317a229dfd09a4c9debbe492d58ffef Mon Sep 17 00:00:00 2001 From: Viachaslau Lyskouski Date: Tue, 3 Dec 2024 15:25:57 +0100 Subject: [PATCH] [#285] [NF] Screen Widgets. View preset --- .../java/com/tercad/fingrom/PaymentItem.kt | 8 +++ .../com/tercad/fingrom/PaymentsAppWidget.kt | 29 +++++----- .../tercad/fingrom/PaymentsWidgetFactory.kt | 51 ++++++++++++++++++ .../tercad/fingrom/PaymentsWidgetService.kt | 10 ++++ .../example_appwidget_preview.png | Bin 3522 -> 0 bytes .../payments_appwidget_preview.png | Bin 0 -> 3212 bytes .../src/main/res/layout/payment_list_item.xml | 42 +++++++++++++++ .../main/res/layout/payments_app_widget.xml | 21 ++++---- android/app/src/main/res/values/strings.xml | 2 +- .../res/xml-v31/payments_app_widget_info.xml | 2 +- .../main/res/xml/payments_app_widget_info.xml | 2 +- 11 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 android/app/src/main/java/com/tercad/fingrom/PaymentItem.kt create mode 100644 android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetFactory.kt create mode 100644 android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetService.kt delete mode 100644 android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png create mode 100644 android/app/src/main/res/drawable-nodpi/payments_appwidget_preview.png create mode 100644 android/app/src/main/res/layout/payment_list_item.xml diff --git a/android/app/src/main/java/com/tercad/fingrom/PaymentItem.kt b/android/app/src/main/java/com/tercad/fingrom/PaymentItem.kt new file mode 100644 index 0000000000..f487442f84 --- /dev/null +++ b/android/app/src/main/java/com/tercad/fingrom/PaymentItem.kt @@ -0,0 +1,8 @@ +package com.tercad.fingrom + +data class PaymentItem( + val type: String, + val amount: String, + val interval: String, + val color: String // Hex color string +) \ No newline at end of file diff --git a/android/app/src/main/java/com/tercad/fingrom/PaymentsAppWidget.kt b/android/app/src/main/java/com/tercad/fingrom/PaymentsAppWidget.kt index 7c26d62f91..d5d9763437 100644 --- a/android/app/src/main/java/com/tercad/fingrom/PaymentsAppWidget.kt +++ b/android/app/src/main/java/com/tercad/fingrom/PaymentsAppWidget.kt @@ -3,7 +3,9 @@ package com.tercad.fingrom import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider import android.content.Context +import android.content.Intent import android.widget.RemoteViews +import android.widget.AdapterView /** * Implementation of App Widget functionality. @@ -14,9 +16,18 @@ class PaymentsAppWidget : AppWidgetProvider() { appWidgetManager: AppWidgetManager, appWidgetIds: IntArray ) { - // There may be multiple widgets active, so update all of them for (appWidgetId in appWidgetIds) { - updateAppWidget(context, appWidgetManager, appWidgetId) + val intent = Intent(context, PaymentsWidgetService::class.java) + val remoteViews = RemoteViews(context.packageName, R.layout.payments_app_widget) + + // Set the adapter for the list view + remoteViews.setRemoteAdapter(R.id.list_view, intent) + + // Set the empty view if no data is available + remoteViews.setEmptyView(R.id.list_view, R.id.empty_view) + + // Update the widget + appWidgetManager.updateAppWidget(appWidgetId, remoteViews) } } @@ -28,17 +39,3 @@ class PaymentsAppWidget : AppWidgetProvider() { // Enter relevant functionality for when the last widget is disabled } } - -internal fun updateAppWidget( - context: Context, - appWidgetManager: AppWidgetManager, - appWidgetId: Int -) { - val widgetText = context.getString(R.string.appwidget_text) - // Construct the RemoteViews object - val views = RemoteViews(context.packageName, R.layout.payments_app_widget) - views.setTextViewText(R.id.appwidget_text, widgetText) - - // Instruct the widget manager to update the widget - appWidgetManager.updateAppWidget(appWidgetId, views) -} \ No newline at end of file diff --git a/android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetFactory.kt b/android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetFactory.kt new file mode 100644 index 0000000000..bcebab730f --- /dev/null +++ b/android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetFactory.kt @@ -0,0 +1,51 @@ +package com.tercad.fingrom + +import android.content.Context +import android.widget.RemoteViews +import android.widget.RemoteViewsService +import androidx.core.graphics.ColorUtils +import android.graphics.Color + +class PaymentsWidgetFactory(private val context: Context) : RemoteViewsService.RemoteViewsFactory { + + private val items = mutableListOf() + + override fun onCreate() { + // Initial data, including color in hex format + items.add(PaymentItem("Bill:", "-$100.00", "monthly", "#FFD700")) // Yellow for Bill + items.add(PaymentItem("Invoice:", "+$50.00", "weekly", "#FF0000")) // Red for Invoice + items.add(PaymentItem("Bill:", "-$20.00", "monthly", "#0000FF")) // Blue for Bill + } + + override fun onDataSetChanged() { + // Refresh or update data if needed + } + + override fun onDestroy() { + items.clear() + } + + override fun getCount(): Int = items.size + + override fun getViewAt(position: Int): RemoteViews { + val item = items[position] + + val rv = RemoteViews(context.packageName, R.layout.payment_list_item) + rv.setTextViewText(R.id.item_type, item.type) + rv.setTextViewText(R.id.item_amount, item.amount) + rv.setTextViewText(R.id.item_interval, item.interval) + + // Set background color directly using Color.parseColor + rv.setInt(R.id.color_bar, "setBackgroundColor", Color.parseColor(item.color)) + + return rv + } + + override fun getLoadingView(): RemoteViews? = null + + override fun getViewTypeCount(): Int = 1 + + override fun getItemId(position: Int): Long = position.toLong() + + override fun hasStableIds(): Boolean = true +} diff --git a/android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetService.kt b/android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetService.kt new file mode 100644 index 0000000000..0b42a18e85 --- /dev/null +++ b/android/app/src/main/java/com/tercad/fingrom/PaymentsWidgetService.kt @@ -0,0 +1,10 @@ +package com.tercad.fingrom + +import android.content.Intent +import android.widget.RemoteViewsService + +class PaymentsWidgetService : RemoteViewsService() { + override fun onGetViewFactory(intent: Intent): RemoteViewsFactory { + return PaymentsWidgetFactory(applicationContext) + } +} diff --git a/android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png b/android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png deleted file mode 100644 index 894b069a4907d258f60b1b2406b90f5a0fe1c35b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3522 zcmaJ^3piA3_a6@xDwm_1J~1d=T*eGD7*t{~G6s#392#aYX)b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k ze_Wsn^R%^1r+EAOI~gVf7^<(d;PIvyjGb0NR(7_AhQ_;diLd3ZX`Xv1NvOVSkAcqf zmbrXBZg!+aJ3l|4P#+EJs|~24s{2OHf;l$WNx_P^+5nY5y~A|R9(&pJnVEx!=b^XA z>$HJ7^3z`isdN9it74~PVBjJIi>cNci`_B4qe#w9R&C?Pr-XOY!uPjYlyqg@jE_ec z5}ahy!BFUrzmg_W*vBhqk7lZ0u9(x5IlP!i7peNYcgMg`0#bLN3c3@ntzdCS z$HkpxB_}6C0H*>iUkejqq$5G@!T2Yls2DlGXBmLEHmIJ*G2SYMB+u=BM0E7@gi)|t zn!kTL1Xos z!t%K0UEz*ZFwkLqXlTXO8+o~ch9R+79DiqB|I3%7V1ID}AKkw-=y8tE4&H$V1O!;K z=e%Xp8yc`If^ALjMS)-o=$y3AS#uS$b?8!80-w3-KwuyQ=(1Q;1k2JYAh9iT!%hPO zu3ybMV5=Do`0|QTVEBVK-D;q(KT-eY*|TQ^URZ`$>IJ!ntDyUQU?5v4bOdaio#op_ zB2O=`i#OW|FSFZ4oCJa9=FOYulPvDhC*>19ygHt`x_qq$ExZzaAQ|X+6vhLQ0)SIR wMJuCGluXwWz| + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/layout/payments_app_widget.xml b/android/app/src/main/res/layout/payments_app_widget.xml index 7a7bbac586..630cf62d56 100644 --- a/android/app/src/main/res/layout/payments_app_widget.xml +++ b/android/app/src/main/res/layout/payments_app_widget.xml @@ -4,16 +4,19 @@ android:layout_height="match_parent" android:theme="@style/Theme.Android.AppWidgetContainer"> + + + + + android:text="No items to display" + android:visibility="gone" + android:textColor="@android:color/black" /> + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index e554823761..17e2830f36 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -2,5 +2,5 @@ EXAMPLE Add widget - This is an app widget description + Add Payments List \ No newline at end of file diff --git a/android/app/src/main/res/xml-v31/payments_app_widget_info.xml b/android/app/src/main/res/xml-v31/payments_app_widget_info.xml index b9d75d275a..19c0ef3833 100644 --- a/android/app/src/main/res/xml-v31/payments_app_widget_info.xml +++ b/android/app/src/main/res/xml-v31/payments_app_widget_info.xml @@ -5,7 +5,7 @@ android:initialLayout="@layout/payments_app_widget" android:minWidth="180dp" android:minHeight="110dp" - android:previewImage="@drawable/example_appwidget_preview" + android:previewImage="@drawable/payments_appwidget_preview" android:previewLayout="@layout/payments_app_widget" android:resizeMode="horizontal|vertical" android:targetCellWidth="3" diff --git a/android/app/src/main/res/xml/payments_app_widget_info.xml b/android/app/src/main/res/xml/payments_app_widget_info.xml index e4acd9c5c1..396add59b7 100644 --- a/android/app/src/main/res/xml/payments_app_widget_info.xml +++ b/android/app/src/main/res/xml/payments_app_widget_info.xml @@ -5,7 +5,7 @@ android:initialLayout="@layout/payments_app_widget" android:minWidth="180dp" android:minHeight="110dp" - android:previewImage="@drawable/example_appwidget_preview" + android:previewImage="@drawable/payments_appwidget_preview" android:resizeMode="horizontal|vertical" android:updatePeriodMillis="360000" android:widgetCategory="home_screen" /> \ No newline at end of file