mirror of
https://github.com/etesync/android
synced 2025-01-11 16:21:10 +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;
|
package com.etesync.syncadapter.ui;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SyncStatusObserver;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
@ -26,20 +29,25 @@ import com.etesync.syncadapter.Constants;
|
|||||||
import com.etesync.syncadapter.R;
|
import com.etesync.syncadapter.R;
|
||||||
import com.etesync.syncadapter.ui.setup.LoginActivity;
|
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.BuildConfig.DEBUG;
|
||||||
import static com.etesync.syncadapter.Constants.serviceUrl;
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_accounts);
|
setContentView(R.layout.activity_accounts);
|
||||||
|
|
||||||
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
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(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||||
drawer.setDrawerListener(toggle);
|
drawer.setDrawerListener(toggle);
|
||||||
toggle.syncState();
|
toggle.syncState();
|
||||||
|
|
||||||
NavigationView navigationView = (NavigationView)findViewById(R.id.nav_view);
|
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
navigationView.setItemIconTintList(null);
|
navigationView.setItemIconTintList(null);
|
||||||
|
|
||||||
@ -71,9 +79,45 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
|||||||
PermissionsActivity.requestAllPermissions(this);
|
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
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
if (drawer.isDrawerOpen(GravityCompat.START))
|
if (drawer.isDrawerOpen(GravityCompat.START))
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
else
|
else
|
||||||
@ -106,7 +150,7 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/coordinator"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="com.etesync.syncadapter.ui.AccountsActivity">
|
tools:context="com.etesync.syncadapter.ui.AccountsActivity">
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
<string name="navigation_drawer_contact">Contact developer</string>
|
<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="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 -->
|
<!-- AccountUpdateService -->
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user