mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
AccountsActivity: show message when global sync is disabled
This commit is contained in:
parent
433484626f
commit
1295e4557e
@ -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,20 +29,25 @@ 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) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_accounts);
|
||||
|
||||
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@ -47,13 +55,13 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
||||
}
|
||||
});
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
NavigationView navigationView = (NavigationView)findViewById(R.id.nav_view);
|
||||
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
navigationView.setItemIconTintList(null);
|
||||
|
||||
@ -71,9 +79,45 @@ 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);
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
if (drawer.isDrawerOpen(GravityCompat.START))
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
else
|
||||
@ -106,7 +150,7 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
||||
break;
|
||||
}
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
@ -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">
|
||||
|
@ -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 -->
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user