Validate account when checking if sync is enabled

pull/384/head
Alex Baker 8 years ago
parent 0f3ebfde91
commit b5d455f84b

@ -14,4 +14,8 @@ public class AccountManager {
public List<String> getAccounts() {
return Collections.emptyList();
}
public boolean hasAccount(String account) {
return false;
}
}

@ -31,7 +31,7 @@ public class GtasksBackgroundService extends RecurringIntervalIntentService {
Timber.d("aborting: sync ongoing");
return;
}
if(gtasksPreferenceService.isLoggedIn() && gtasksSyncV2Provider.isActive()) {
if(gtasksSyncV2Provider.isActive()) {
gtasksSyncV2Provider.synchronizeActiveTasks(new RecordSyncStatusCallback(gtasksPreferenceService, broadcaster));
}
}

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="sync_enabled">true</bool>
<bool name="sync_supported">true</bool>
<bool name="location_enabled">true</bool>
<bool name="google_play_store_available">true</bool>
</resources>

@ -9,16 +9,14 @@ import android.content.Context;
import com.todoroo.andlib.utility.DateUtilities;
import org.tasks.AccountManager;
import org.tasks.R;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
import javax.inject.Singleton;
import static com.google.common.base.Strings.isNullOrEmpty;
/**
* Methods for working with GTasks preferences
*
@ -28,9 +26,9 @@ import static com.google.common.base.Strings.isNullOrEmpty;
@Singleton
public class GtasksPreferenceService {
private Context context;
private final Context context;
private final Preferences preferences;
private PermissionChecker permissionChecker;
private final AccountManager accountManager;
public static final String IDENTIFIER = "gtasks"; //$NON-NLS-1$
@ -39,10 +37,10 @@ public class GtasksPreferenceService {
@Inject
public GtasksPreferenceService(@ForApplication Context context, Preferences preferences,
PermissionChecker permissionChecker) {
AccountManager accountManager) {
this.context = context;
this.preferences = preferences;
this.permissionChecker = permissionChecker;
this.accountManager = accountManager;
}
public String getDefaultList() {
@ -69,10 +67,9 @@ public class GtasksPreferenceService {
* @return true if we have a token for this user, false otherwise
*/
public boolean isLoggedIn() {
return context.getResources().getBoolean(R.bool.sync_enabled) &&
return context.getResources().getBoolean(R.bool.sync_supported) &&
preferences.getBoolean(R.string.sync_gtasks, false) &&
!isNullOrEmpty(preferences.getStringValue(PREF_USER_NAME)) &&
permissionChecker.canAccessAccounts();
accountManager.hasAccount(preferences.getStringValue(PREF_USER_NAME));
}
/** @return Last Successful Sync Date, or 0 */

@ -30,7 +30,7 @@ public class BasicPreferences extends InjectingPreferenceActivity {
result = savedInstanceState == null ? new Bundle() : savedInstanceState.getBundle(EXTRA_RESULT);
addPreferencesFromResource(R.xml.preferences);
if (!getResources().getBoolean(R.bool.sync_enabled)) {
if (!getResources().getBoolean(R.bool.sync_supported)) {
getPreferenceScreen().removePreference(findPreference(getString(R.string.synchronization)));
}
if (getResources().getBoolean(R.bool.google_play_store_available)) {

@ -23,7 +23,7 @@ public class BackgroundScheduler {
scheduleBackupService();
scheduleMidnightRefresh();
scheduleCalendarNotifications();
if (context.getResources().getBoolean(R.bool.sync_enabled)) {
if (context.getResources().getBoolean(R.bool.sync_supported)) {
scheduleGtaskSync();
}
}

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="two_pane_layout">false</bool>
<bool name="sync_enabled">false</bool>
<bool name="sync_supported">false</bool>
<bool name="location_enabled">false</bool>
<bool name="google_play_store_available">false</bool>
</resources>
Loading…
Cancel
Save