Add get/set list and user to gtasks preferences

pull/189/head
Alex Baker 11 years ago
parent ff00d710f4
commit fa67d940f2

@ -8,9 +8,7 @@ package com.todoroo.astrid.gtasks;
import android.content.Context;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.MetadataService;
@ -18,6 +16,7 @@ import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.tasks.injection.TestModule;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
@ -29,7 +28,11 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
@Module(addsTo = TestModule.class, injects = {GtasksMetadataServiceTest.class})
static class GtasksMetadataServiceTestModule {
private final GtasksTestPreferenceService service = new GtasksTestPreferenceService();
private final GtasksTestPreferenceService service;
public GtasksMetadataServiceTestModule(Context context) {
service = new GtasksTestPreferenceService(new Preferences(context));
}
@Provides
public GtasksTestPreferenceService getGtasksTestPreferenceService() {
@ -51,6 +54,15 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
private Metadata metadata;
private TodorooCursor<Task> cursor;
@Override
public void setUp() {
super.setUp();
if (preferences.getDefaultList() == null) {
preferences.setDefaultList("list");
}
}
public void testMetadataFound() {
givenTask(taskWithMetadata(null));
@ -178,21 +190,8 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
return task;
}
@Override
public void setContext(Context context) {
super.setContext(context);
if (!isSet(GtasksPreferenceService.PREF_DEFAULT_LIST))
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, "list");
}
@Override
protected Object getModule() {
return new GtasksMetadataServiceTestModule();
}
/** @return true if given preference is set */
public static boolean isSet(String key) {
Context context = ContextManager.getContext();
return Preferences.getPrefs(context).contains(key);
return new GtasksMetadataServiceTestModule(getContext());
}
}

@ -5,11 +5,17 @@
*/
package com.todoroo.astrid.gtasks;
import org.tasks.preferences.Preferences;
public class GtasksTestPreferenceService extends GtasksPreferenceService {
private boolean loggedIn = false;
private long syncDate = 0;
public GtasksTestPreferenceService(Preferences preferences) {
super(preferences);
}
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}

@ -9,7 +9,6 @@ import android.content.Context;
import android.content.Intent;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.data.Metadata;
@ -67,7 +66,7 @@ public class GtasksDetailExposer extends InjectingBroadcastReceiver {
StringBuilder builder = new StringBuilder();
String listId = metadata.getValue(GtasksMetadata.LIST_ID);
if(listId == null || listId.equals(Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST))) {
if(listId == null || listId.equals(gtasksPreferenceService.getDefaultList())) {
return null;
}
String listName = gtasksListService.getListName(listId);

@ -8,6 +8,7 @@ package com.todoroo.astrid.gtasks;
import com.todoroo.astrid.sync.SyncProviderUtilities;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -23,9 +24,11 @@ public class GtasksPreferenceService extends SyncProviderUtilities {
/** add-on identifier */
public static final String IDENTIFIER = "gtasks"; //$NON-NLS-1$
private final Preferences preferences;
@Inject
public GtasksPreferenceService() {
public GtasksPreferenceService(Preferences preferences) {
this.preferences = preferences;
}
@Override
@ -38,6 +41,22 @@ public class GtasksPreferenceService extends SyncProviderUtilities {
return R.string.gtasks_GPr_interval_key;
}
public String getDefaultList() {
return preferences.getStringValue(PREF_DEFAULT_LIST);
}
public void setDefaultList(String defaultList) {
preferences.setString(PREF_DEFAULT_LIST, defaultList);
}
public String getUserName() {
return preferences.getStringValue(PREF_USER_NAME);
}
public void setUserName(String userName) {
preferences.setString(PREF_USER_NAME, userName);
}
/** GTasks user's default list id */
public static final String PREF_DEFAULT_LIST = IDENTIFIER + "_defaultlist"; //$NON-NLS-1$

@ -24,7 +24,6 @@ import android.widget.Toast;
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
@ -140,7 +139,7 @@ public class GtasksLoginActivity extends InjectingListActivity {
private void onAuthTokenSuccess() {
gtasksPreferenceService.setToken(authToken);
Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, accountName);
gtasksPreferenceService.setUserName(accountName);
setResult(RESULT_OK);
finish();
}

@ -13,7 +13,6 @@ import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata;
@ -230,12 +229,12 @@ public class GtasksSyncService {
}
String remoteId;
String listId = Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST);
String listId = gtasksPreferenceService.getDefaultList();
if (listId == null) {
com.google.api.services.tasks.model.TaskList defaultList = invoker.getGtaskList(DEFAULT_LIST);
if (defaultList != null) {
listId = defaultList.getId();
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, listId);
gtasksPreferenceService.setDefaultList(listId);
} else {
listId = DEFAULT_LIST;
}

@ -94,7 +94,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
public void signOut() {
gtasksPreferenceService.clearLastSyncDate();
gtasksPreferenceService.setToken(null);
Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, null);
gtasksPreferenceService.setUserName(null);
gtasksMetadataService.clearMetadata();
}

Loading…
Cancel
Save