Added option refresh button / messages widget

This commit is contained in:
M66B
2021-09-01 08:36:14 +02:00
parent f094ca4c41
commit 386fb3361d
6 changed files with 85 additions and 4 deletions

View File

@@ -35,6 +35,8 @@ import android.widget.RemoteViews;
import androidx.core.graphics.ColorUtils;
import androidx.preference.PreferenceManager;
import java.util.Date;
public class WidgetUnified extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
@@ -49,6 +51,7 @@ public class WidgetUnified extends AppWidgetProvider {
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
int font = prefs.getInt("widget." + appWidgetId + ".font", 0);
int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
boolean refresh = prefs.getBoolean("widget." + appWidgetId + ".refresh", false);
boolean compose = prefs.getBoolean("widget." + appWidgetId + ".compose", false);
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
@@ -69,6 +72,13 @@ public class WidgetUnified extends AppWidgetProvider {
PendingIntent pi = PendingIntentCompat.getActivity(
context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT);
Intent sync = new Intent(context, ServiceUI.class);
sync.setAction("widget:" + appWidgetId);
sync.putExtra("account", account);
sync.putExtra("folder", folder);
PendingIntent piSync = PendingIntentCompat.getService(
context, appWidgetId, sync, PendingIntent.FLAG_UPDATE_CURRENT);
Intent edit = new Intent(context, ActivityCompose.class);
edit.setAction("widget:" + appWidgetId);
edit.putExtra("action", "new");
@@ -91,6 +101,15 @@ public class WidgetUnified extends AppWidgetProvider {
views.setOnClickPendingIntent(R.id.title, pi);
views.setViewVisibility(R.id.refresh, refresh ? View.VISIBLE : View.GONE);
views.setViewPadding(R.id.refresh, px, px, px, px);
views.setOnClickPendingIntent(R.id.refresh, piSync);
long refreshing = prefs.getLong("widget." + appWidgetId + ".sync", 0L);
views.setImageViewResource(R.id.refresh,
refreshing < new Date().getTime()
? R.drawable.twotone_sync_24 : R.drawable.twotone_compare_arrows_24);
views.setViewVisibility(R.id.compose, compose ? View.VISIBLE : View.GONE);
views.setViewPadding(R.id.compose, px, px, px, px);
views.setOnClickPendingIntent(R.id.compose, piCompose);