mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-05 20:34:49 +01:00
Async widget sync state update
This commit is contained in:
@@ -658,29 +658,21 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
prefs.getBoolean(_key, false)) {
|
||||
int appWidgetId = Integer.parseInt(_key.split("\\.")[1]);
|
||||
|
||||
String key = "widget." + appWidgetId + ".sync";
|
||||
boolean sync = prefs.contains(key);
|
||||
if (!sync)
|
||||
continue;
|
||||
|
||||
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
|
||||
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
|
||||
|
||||
if (folder > 0) {
|
||||
if (!folders.contains(folder)) {
|
||||
prefs.edit().remove(key).apply();
|
||||
WidgetUnified.init(ServiceSynchronize.this, appWidgetId);
|
||||
}
|
||||
} else if (account > 0) {
|
||||
if (!accounts.contains(account)) {
|
||||
prefs.edit().remove(key).apply();
|
||||
WidgetUnified.init(ServiceSynchronize.this, appWidgetId);
|
||||
}
|
||||
} else {
|
||||
if (accounts.size() == 0) {
|
||||
prefs.edit().remove(key).apply();
|
||||
WidgetUnified.init(ServiceSynchronize.this, appWidgetId);
|
||||
}
|
||||
boolean state;
|
||||
if (folder > 0)
|
||||
state = folders.contains(folder);
|
||||
else if (account > 0)
|
||||
state = accounts.contains(account);
|
||||
else
|
||||
state = (accounts.size() > 0);
|
||||
|
||||
String key = "widget." + appWidgetId + ".syncing";
|
||||
if (state != prefs.getBoolean(key, false)) {
|
||||
prefs.edit().putBoolean(key, state).apply();
|
||||
WidgetUnified.init(ServiceSynchronize.this, appWidgetId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,6 @@ public class ServiceUI extends IntentService {
|
||||
static final int PI_SNOOZE = 10;
|
||||
static final int PI_IGNORED = 11;
|
||||
|
||||
private static final long WIDGET_SYNC_DURATION = 90 * 1000L;
|
||||
|
||||
public ServiceUI() {
|
||||
this(ServiceUI.class.getName());
|
||||
}
|
||||
@@ -491,23 +489,6 @@ public class ServiceUI extends IntentService {
|
||||
long aid = intent.getLongExtra("account", -1L);
|
||||
long fid = intent.getLongExtra("folder", -1L);
|
||||
onSync(aid, fid, fid < 0);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String key = "widget." + appWidgetId + ".sync";
|
||||
prefs.edit().putLong(key, new Date().getTime() + WIDGET_SYNC_DURATION).apply();
|
||||
WidgetUnified.init(this, appWidgetId);
|
||||
|
||||
ApplicationEx.getMainHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
prefs.edit().remove(key).apply();
|
||||
WidgetUnified.init(ServiceUI.this, appWidgetId);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
}, WIDGET_SYNC_DURATION);
|
||||
}
|
||||
|
||||
static void sync(Context context, Long account) {
|
||||
|
||||
@@ -105,9 +105,8 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||
views.setViewPadding(R.id.refresh, px, px, px, px);
|
||||
views.setOnClickPendingIntent(R.id.refresh, piSync);
|
||||
|
||||
long now = new Date().getTime();
|
||||
long refreshing = prefs.getLong("widget." + appWidgetId + ".sync", 0L);
|
||||
views.setImageViewResource(R.id.refresh, refreshing < now ? R.drawable.twotone_sync_24 : R.drawable.twotone_compare_arrows_24);
|
||||
boolean syncing = prefs.getBoolean("widget." + appWidgetId + ".syncing", false);
|
||||
views.setImageViewResource(R.id.refresh, syncing ? R.drawable.twotone_compare_arrows_24 : R.drawable.twotone_sync_24);
|
||||
views.setViewVisibility(R.id.refresh, refresh ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
views.setViewVisibility(R.id.compose, compose ? View.VISIBLE : View.GONE);
|
||||
|
||||
Reference in New Issue
Block a user