1
0
mirror of https://github.com/etesync/android synced 2024-11-15 12:28:57 +00:00

Show progress bar when synchronization is active

This commit is contained in:
Ricki Hirner 2016-09-26 22:57:45 +02:00
parent 68781fd96e
commit 054dba6ff8
2 changed files with 26 additions and 8 deletions

View File

@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.READ_SYNC_STATS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

View File

@ -24,6 +24,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.ServiceConnection;
import android.content.SyncStatusObserver;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
@ -74,6 +75,8 @@ import at.bitfire.davdroid.model.ServiceDB.Services;
import at.bitfire.ical4android.TaskProvider;
import lombok.Cleanup;
import static android.content.ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener, LoaderManager.LoaderCallbacks<AccountActivity.AccountInfo> {
public static final String EXTRA_ACCOUNT = "account";
@ -284,7 +287,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
@Override
public Loader<AccountInfo> onCreateLoader(int id, Bundle args) {
return new AccountLoader(this, account.name);
return new AccountLoader(this, account);
}
public void reload() {
@ -350,19 +353,22 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
}
private static class AccountLoader extends AsyncTaskLoader<AccountInfo> implements DavService.RefreshingStatusListener, ServiceConnection {
private final String accountName;
private static class AccountLoader extends AsyncTaskLoader<AccountInfo> implements DavService.RefreshingStatusListener, ServiceConnection, SyncStatusObserver {
private final Account account;
private final OpenHelper dbHelper;
private DavService.InfoBinder davService;
private Object syncStatusListener;
public AccountLoader(Context context, String accountName) {
public AccountLoader(Context context, Account account) {
super(context);
this.accountName = accountName;
this.account = account;
dbHelper = new OpenHelper(context);
}
@Override
protected void onStartLoading() {
syncStatusListener = ContentResolver.addStatusChangeListener(SYNC_OBSERVER_TYPE_ACTIVE, this);
getContext().bindService(new Intent(getContext(), DavService.class), this, Context.BIND_AUTO_CREATE);
}
@ -370,6 +376,9 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
protected void onStopLoading() {
davService.removeRefreshingStatusListener(this);
getContext().unbindService(this);
if (syncStatusListener != null)
ContentResolver.removeStatusChangeListener(syncStatusListener);
}
@Override
@ -390,6 +399,11 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
forceLoad();
}
@Override
public void onStatusChanged(int which) {
forceLoad();
}
@Override
public AccountInfo loadInBackground() {
AccountInfo info = new AccountInfo();
@ -399,7 +413,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
@Cleanup Cursor cursor = db.query(
Services._TABLE,
new String[] { Services.ID, Services.SERVICE },
Services.ACCOUNT_NAME + "=?", new String[] { accountName },
Services.ACCOUNT_NAME + "=?", new String[] { account.name },
null, null, null);
if (cursor.getCount() == 0)
@ -412,14 +426,16 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
if (Services.SERVICE_CARDDAV.equals(service)) {
info.carddav = new AccountInfo.ServiceInfo();
info.carddav.id = id;
info.carddav.refreshing = davService.isRefreshing(id);
info.carddav.refreshing = davService.isRefreshing(id) || ContentResolver.isSyncActive(account, ContactsContract.AUTHORITY);
info.carddav.hasHomeSets = hasHomeSets(db, id);
info.carddav.collections = readCollections(db, id);
} else if (Services.SERVICE_CALDAV.equals(service)) {
info.caldav = new AccountInfo.ServiceInfo();
info.caldav.id = id;
info.caldav.refreshing = davService.isRefreshing(id);
info.caldav.refreshing = davService.isRefreshing(id) ||
ContentResolver.isSyncActive(account, CalendarContract.AUTHORITY) ||
ContentResolver.isSyncActive(account, TaskProvider.ProviderName.OpenTasks.authority);
info.caldav.hasHomeSets = hasHomeSets(db, id);
info.caldav.collections = readCollections(db, id);
}
@ -447,6 +463,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
}
return collections;
}
}