mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-02 23:26:12 +02:00
Show widget sync state
This commit is contained in:
@@ -130,10 +130,10 @@ public interface DaoFolder {
|
||||
" GROUP BY folder.id")
|
||||
LiveData<List<TupleFolderNav>> liveNavigation();
|
||||
|
||||
@Query("SELECT COUNT(id) FROM folder" +
|
||||
" WHERE sync_state = 'syncing'" +
|
||||
@Query("SELECT account, id AS folder, unified, sync_state FROM folder" +
|
||||
" WHERE sync_state IS NOT NULL" +
|
||||
" AND folder.type <> '" + EntityFolder.OUTBOX + "'")
|
||||
LiveData<Integer> liveSynchronizing();
|
||||
LiveData<List<TupleFolderSync>> liveSynchronizing();
|
||||
|
||||
@Query("SELECT folder.*" +
|
||||
", account.id AS accountId, account.pop AS accountProtocol, account.`order` AS accountOrder" +
|
||||
|
||||
@@ -24,7 +24,9 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@@ -604,14 +606,60 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
|
||||
final TwoStateOwner cowner = new TwoStateOwner(this, "liveUnseenNotify");
|
||||
|
||||
db.folder().liveSynchronizing().observe(this, new Observer<Integer>() {
|
||||
db.folder().liveSynchronizing().observe(this, new Observer<List<TupleFolderSync>>() {
|
||||
@Override
|
||||
public void onChanged(Integer count) {
|
||||
Log.i("Synchronizing folders=" + count);
|
||||
if (count == null || count == 0)
|
||||
public void onChanged(List<TupleFolderSync> syncs) {
|
||||
int syncing = 0;
|
||||
List<Long> accounts = new ArrayList<>();
|
||||
List<Long> folders = new ArrayList<>();
|
||||
if (syncs != null)
|
||||
for (TupleFolderSync sync : syncs) {
|
||||
if ("syncing".equals(sync.sync_state))
|
||||
syncing++;
|
||||
if (sync.unified && !accounts.contains(sync.account))
|
||||
accounts.add(sync.account);
|
||||
folders.add(sync.folder);
|
||||
}
|
||||
|
||||
Log.i("Syncing=" + syncing +
|
||||
" folders=" + folders.size() +
|
||||
" accounts=" + accounts.size());
|
||||
|
||||
if (syncing == 0)
|
||||
cowner.start();
|
||||
else
|
||||
cowner.stop();
|
||||
|
||||
for (String _key : prefs.getAll().keySet())
|
||||
if (_key.startsWith("widget.") && _key.endsWith(".refresh") &&
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ServiceUI extends IntentService {
|
||||
static final int PI_SNOOZE = 10;
|
||||
static final int PI_IGNORED = 11;
|
||||
|
||||
private static final long WIDGET_SYNC_DURATION = 500;
|
||||
private static final long WIDGET_SYNC_DURATION = 90 * 1000L;
|
||||
|
||||
public ServiceUI() {
|
||||
this(ServiceUI.class.getName());
|
||||
|
||||
27
app/src/main/java/eu/faircode/email/TupleFolderSync.java
Normal file
27
app/src/main/java/eu/faircode/email/TupleFolderSync.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
public class TupleFolderSync {
|
||||
public long account;
|
||||
public long folder;
|
||||
public boolean unified;
|
||||
public String sync_state;
|
||||
}
|
||||
@@ -101,16 +101,15 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||
|
||||
views.setOnClickPendingIntent(R.id.title, pi);
|
||||
|
||||
if (refresh) {
|
||||
long now = new Date().getTime();
|
||||
long refreshing = prefs.getLong("widget." + appWidgetId + ".sync", 0L);
|
||||
views.setViewVisibility(R.id.refresh, refreshing < now ? View.VISIBLE : View.INVISIBLE);
|
||||
} else
|
||||
views.setViewVisibility(R.id.refresh, View.GONE);
|
||||
|
||||
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 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);
|
||||
views.setViewVisibility(R.id.refresh, refresh ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user