Validate account when checking if sync is enabled

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

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

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

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

@ -9,16 +9,14 @@ import android.content.Context;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import org.tasks.AccountManager;
import org.tasks.R; import org.tasks.R;
import org.tasks.injection.ForApplication; import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import static com.google.common.base.Strings.isNullOrEmpty;
/** /**
* Methods for working with GTasks preferences * Methods for working with GTasks preferences
* *
@ -28,9 +26,9 @@ import static com.google.common.base.Strings.isNullOrEmpty;
@Singleton @Singleton
public class GtasksPreferenceService { public class GtasksPreferenceService {
private Context context; private final Context context;
private final Preferences preferences; private final Preferences preferences;
private PermissionChecker permissionChecker; private final AccountManager accountManager;
public static final String IDENTIFIER = "gtasks"; //$NON-NLS-1$ public static final String IDENTIFIER = "gtasks"; //$NON-NLS-1$
@ -39,10 +37,10 @@ public class GtasksPreferenceService {
@Inject @Inject
public GtasksPreferenceService(@ForApplication Context context, Preferences preferences, public GtasksPreferenceService(@ForApplication Context context, Preferences preferences,
PermissionChecker permissionChecker) { AccountManager accountManager) {
this.context = context; this.context = context;
this.preferences = preferences; this.preferences = preferences;
this.permissionChecker = permissionChecker; this.accountManager = accountManager;
} }
public String getDefaultList() { public String getDefaultList() {
@ -69,10 +67,9 @@ public class GtasksPreferenceService {
* @return true if we have a token for this user, false otherwise * @return true if we have a token for this user, false otherwise
*/ */
public boolean isLoggedIn() { 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) && preferences.getBoolean(R.string.sync_gtasks, false) &&
!isNullOrEmpty(preferences.getStringValue(PREF_USER_NAME)) && accountManager.hasAccount(preferences.getStringValue(PREF_USER_NAME));
permissionChecker.canAccessAccounts();
} }
/** @return Last Successful Sync Date, or 0 */ /** @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); result = savedInstanceState == null ? new Bundle() : savedInstanceState.getBundle(EXTRA_RESULT);
addPreferencesFromResource(R.xml.preferences); 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))); getPreferenceScreen().removePreference(findPreference(getString(R.string.synchronization)));
} }
if (getResources().getBoolean(R.bool.google_play_store_available)) { if (getResources().getBoolean(R.bool.google_play_store_available)) {

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

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