mirror of https://github.com/M66B/FairEmail.git
Widget sync: show connected state
This commit is contained in:
parent
0082fad647
commit
ffaf4bd22c
|
@ -241,6 +241,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
|
||||
liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() {
|
||||
private boolean fts = false;
|
||||
private boolean lastConnected = false;
|
||||
private int lastEventId = 0;
|
||||
private int lastQuitId = -1;
|
||||
private List<Long> initialized = new ArrayList<>();
|
||||
|
@ -264,6 +265,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
liveAccountNetworkState.removeObserver(this);
|
||||
} else {
|
||||
int accounts = 0;
|
||||
int enabled = 0;
|
||||
int operations = 0;
|
||||
boolean event = false;
|
||||
boolean runService = false;
|
||||
|
@ -275,9 +277,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
if (current.accountState.shouldRun(current.enabled))
|
||||
runService = true;
|
||||
if (!current.accountState.isTransient(ServiceSynchronize.this) &&
|
||||
("connected".equals(current.accountState.state) || current.accountState.backoff_until != null))
|
||||
accounts++;
|
||||
if (!current.accountState.isTransient(ServiceSynchronize.this)) {
|
||||
if (current.accountState.isEnabled(current.enabled))
|
||||
enabled++;
|
||||
if ("connected".equals(current.accountState.state) || current.accountState.backoff_until != null)
|
||||
accounts++;
|
||||
}
|
||||
if (current.accountState.synchronize)
|
||||
operations += current.accountState.operations;
|
||||
|
||||
|
@ -382,6 +387,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
}
|
||||
|
||||
boolean connected = (enabled > 0 && accounts == enabled);
|
||||
if (lastConnected != connected) {
|
||||
lastConnected = connected;
|
||||
prefs.edit().putBoolean("connected", connected).apply();
|
||||
WidgetSync.update(ServiceSynchronize.this);
|
||||
}
|
||||
|
||||
if (event) {
|
||||
lastEventId++;
|
||||
EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Scheduling,
|
||||
|
|
|
@ -39,6 +39,7 @@ public class WidgetSync extends AppWidgetProvider {
|
|||
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean enabled = prefs.getBoolean("enabled", true);
|
||||
boolean connected = prefs.getBoolean("connected", false);
|
||||
|
||||
try {
|
||||
Intent intent = new Intent(context, ServiceSynchronize.class)
|
||||
|
@ -62,6 +63,7 @@ public class WidgetSync extends AppWidgetProvider {
|
|||
views.setOnClickPendingIntent(R.id.ivSync, pi);
|
||||
|
||||
views.setImageViewResource(R.id.ivSync, enabled ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24);
|
||||
views.setFloat(R.id.ivSync, "setAlpha", !enabled || connected ? 1.0f : Helper.LOW_LIGHT);
|
||||
|
||||
if (!daynight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
views.setColorStateListAttr(R.id.background, "setBackgroundTintList", 0);
|
||||
|
|
Loading…
Reference in New Issue