1
0
mirror of https://github.com/etesync/android synced 2025-01-11 08:10:58 +00:00

AccountsActivity: show message when global sync is disabled

This commit is contained in:
Ricki Hirner 2017-03-02 23:25:01 +01:00 committed by Tom Hacohen
parent 433484626f
commit 1295e4557e
3 changed files with 54 additions and 7 deletions

View File

@ -8,10 +8,13 @@
package com.etesync.syncadapter.ui;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SyncStatusObserver;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
@ -26,10 +29,15 @@ import com.etesync.syncadapter.Constants;
import com.etesync.syncadapter.R;
import com.etesync.syncadapter.ui.setup.LoginActivity;
import static android.content.ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS;
import static com.etesync.syncadapter.BuildConfig.DEBUG;
import static com.etesync.syncadapter.Constants.serviceUrl;
public class AccountsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public class AccountsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, SyncStatusObserver {
private Snackbar syncStatusSnackbar;
private Object syncStatusObserver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -71,6 +79,42 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
PermissionsActivity.requestAllPermissions(this);
}
@Override
protected void onResume() {
super.onResume();
onStatusChanged(SYNC_OBSERVER_TYPE_SETTINGS);
syncStatusObserver = ContentResolver.addStatusChangeListener(SYNC_OBSERVER_TYPE_SETTINGS, this);
}
@Override
protected void onPause() {
super.onPause();
if (syncStatusObserver != null) {
ContentResolver.removeStatusChangeListener(syncStatusObserver);
syncStatusObserver = null;
}
}
@Override
public void onStatusChanged(int which) {
if (syncStatusSnackbar != null) {
syncStatusSnackbar.dismiss();
syncStatusSnackbar = null;
}
if (!ContentResolver.getMasterSyncAutomatically()) {
syncStatusSnackbar = Snackbar.make(findViewById(R.id.coordinator), R.string.accounts_global_sync_disabled, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.accounts_global_sync_enable, new View.OnClickListener() {
@Override
public void onClick(View v) {
ContentResolver.setMasterSyncAutomatically(true);
}
});
syncStatusSnackbar.show();
}
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

View File

@ -11,6 +11,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.etesync.syncadapter.ui.AccountsActivity">

View File

@ -50,6 +50,8 @@
<string name="navigation_drawer_contact">Contact developer</string>
<string name="account_list_empty">Welcome to EteSync!\n\nAdd an account to start.</string>
<string name="accounts_global_sync_disabled">System-wide automatic synchronization is disabled</string>
<string name="accounts_global_sync_enable">Enable</string>
<!-- AccountUpdateService -->