Remove setLong from old preferences

pull/189/head
Alex Baker 10 years ago
parent cec9ac0500
commit 0b276c4b65

@ -225,14 +225,4 @@ public class Preferences {
Context context = ContextManager.getContext();
return getPrefs(context).getLong(key, defValue);
}
/**
* Sets long preference
*/
public static void setLong(String key, long value) {
Context context = ContextManager.getContext();
Editor editor = getPrefs(context).edit();
editor.putLong(key, value);
editor.commit();
}
}

@ -7,13 +7,13 @@ package com.todoroo.astrid.backup;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.backup.BackupService.BackupDirectorySetting;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import java.io.File;
import java.io.IOException;
@ -29,6 +29,7 @@ public class BackupServiceTests extends DatabaseTestCase {
File temporaryDirectory = null;
@Autowired private TaskDao taskDao;
@Autowired private Preferences preferences;
BackupDirectorySetting setting = new BackupDirectorySetting() {
public File getBackupDirectory() {
@ -65,11 +66,11 @@ public class BackupServiceTests extends DatabaseTestCase {
}
private boolean getBackupSetting() {
return Preferences.getBoolean(R.string.backup_BPr_auto_key, true);
return preferences.getBoolean(R.string.backup_BPr_auto_key, true);
}
private void setBackupSetting(boolean setting) {
Preferences.setBoolean(R.string.backup_BPr_auto_key, setting);
preferences.setBoolean(R.string.backup_BPr_auto_key, setting);
}
/** Test backup works */
@ -79,7 +80,7 @@ public class BackupServiceTests extends DatabaseTestCase {
boolean backupSetting = getBackupSetting();
try {
setBackupSetting(true);
Preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0);
preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0);
// create a backup
BackupService service = new BackupService();
@ -94,8 +95,8 @@ public class BackupServiceTests extends DatabaseTestCase {
assertTrue(files[0].getName().matches(BackupService.BACKUP_FILE_NAME_REGEX));
// assert summary updated
assertTrue(Preferences.getLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0) > 0);
assertNull(Preferences.getStringValue(BackupPreferences.PREF_BACKUP_LAST_ERROR));
assertTrue(preferences.getLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0) > 0);
assertNull(preferences.getStringValue(BackupPreferences.PREF_BACKUP_LAST_ERROR));
} finally {
setBackupSetting(backupSetting);
}
@ -108,7 +109,7 @@ public class BackupServiceTests extends DatabaseTestCase {
boolean backupSetting = getBackupSetting();
try {
setBackupSetting(false);
Preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0);
preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0);
// create a backup
BackupService service = new BackupService();
@ -127,7 +128,7 @@ public class BackupServiceTests extends DatabaseTestCase {
assertEquals(0, files.length);
// assert summary not updated
assertEquals(0, Preferences.getLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0));
assertEquals(0, preferences.getLong(BackupPreferences.PREF_BACKUP_LAST_DATE, 0));
} finally {
setBackupSetting(backupSetting);
}

@ -48,7 +48,6 @@ import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.adapter.TaskAdapter.OnCompletedTaskListener;
@ -86,6 +85,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tasks.R;
import org.tasks.injection.InjectingListFragment;
import org.tasks.preferences.Preferences;
import java.util.List;
import java.util.Timer;
@ -145,6 +145,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
@Inject TaskDeleter taskDeleter;
@Inject TaskDuplicator taskDuplicator;
@Inject @ForActivity Context context;
@Inject Preferences preferences;
protected Resources resources;
protected TaskAdapter taskAdapter = null;
@ -276,7 +277,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
// We have a menu item to show in action bar.
resources = getResources();
setHasOptionsMenu(true);
syncActionHelper = new SyncActionHelper(syncService, getActivity(), this);
syncActionHelper = new SyncActionHelper(syncService, getActivity(), preferences, this);
setUpUiComponents();
initializeData();
setupQuickAddBar();
@ -292,9 +293,9 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
getListView().setItemsCanFocus(false);
}
if (Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1) {
if (preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1) {
upgradeService.showChangeLog(getActivity(),
Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
}
getListView().setOnItemClickListener(new OnItemClickListener() {
@ -357,7 +358,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
if (!TextUtils.isEmpty(filterId)) {
taskListMetadata = taskListMetadataDao.fetchByTagId(filterId, TaskListMetadata.PROPERTIES);
if (taskListMetadata == null) {
String defaultOrder = Preferences.getStringValue(prefId);
String defaultOrder = preferences.getStringValue(prefId);
if (TextUtils.isEmpty(defaultOrder)) {
defaultOrder = "[]"; //$NON-NLS-1$
}
@ -694,7 +695,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
TasksWidget.updateWidgets(getActivity());
return;
} else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
Preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login
preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login
}
}
@ -736,8 +737,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
syncActionHelper.request();
}
public static int getTaskRowResource() {
int rowStyle = Preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0);
public static int getTaskRowResource(int rowStyle) {
switch(rowStyle) {
case 1:
return R.layout.task_adapter_row_simple;
@ -751,7 +751,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) {
return new TaskAdapter(taskService, this, getTaskRowResource(),
return new TaskAdapter(taskService, this, getTaskRowResource(preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0)),
cursor, sqlQueryTemplate,
new OnCompletedTaskListener() {
@Override
@ -788,7 +788,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
}
public Property<?>[] taskProperties() {
if (Preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0) == 2) {
if (preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0) == 2) {
return TaskAdapter.BASIC_PROPERTIES;
}
return TaskAdapter.PROPERTIES;

@ -21,7 +21,6 @@ import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
@ -33,6 +32,7 @@ import com.todoroo.astrid.utility.AstridPreferences;
import org.tasks.R;
import org.tasks.injection.Injector;
import org.tasks.preferences.Preferences;
import org.xmlpull.v1.XmlSerializer;
import java.io.File;
@ -70,6 +70,7 @@ public class TasksXmlExporter {
@Inject TagDataService tagDataService;
@Inject MetadataService metadataService;
@Inject TaskService taskService;
@Inject Preferences preferences;
// 3 is started on Version 4.6.10
private static final int FORMAT = 3;
@ -129,8 +130,8 @@ public class TasksXmlExporter {
doTasksExport(output);
}
Preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, DateUtilities.now());
Preferences.setString(BackupPreferences.PREF_BACKUP_LAST_ERROR, null);
preferences.setLong(BackupPreferences.PREF_BACKUP_LAST_DATE, DateUtilities.now());
preferences.setString(BackupPreferences.PREF_BACKUP_LAST_ERROR, null);
if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
onFinishExport(output);

@ -20,7 +20,6 @@ import android.widget.ArrayAdapter;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.SyncAction;
@ -32,6 +31,7 @@ import com.todoroo.astrid.sync.SyncV2Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@ -58,19 +58,19 @@ public class SyncActionHelper {
public final SyncResultCallback syncResultCallback;
private final Activity activity;
private final Fragment fragment;
protected SyncActionReceiver syncActionReceiver = new SyncActionReceiver();
private final SyncV2Service syncService;
private final Activity activity;
private final Preferences preferences;
private final Fragment fragment;
// --- boilerplate
public SyncActionHelper(SyncV2Service syncService, final Activity activity, Fragment fragment) {
public SyncActionHelper(SyncV2Service syncService, final Activity activity, Preferences preferences, Fragment fragment) {
this.syncService = syncService;
this.activity = activity;
this.preferences = preferences;
this.fragment = fragment;
syncResultCallback = new ProgressBarSyncResultCallback(activity, fragment,
R.id.progressBar, new Runnable() {
@ -86,7 +86,7 @@ public class SyncActionHelper {
// --- automatic sync logic
public void initiateAutomaticSync() {
long tasksPushedAt = Preferences.getLong(PREF_LAST_AUTO_SYNC, 0);
long tasksPushedAt = preferences.getLong(PREF_LAST_AUTO_SYNC, 0);
if (DateUtilities.now() - tasksPushedAt > TaskListFragment.AUTOSYNC_INTERVAL) {
performSyncServiceV2Sync();
}
@ -139,7 +139,7 @@ public class SyncActionHelper {
protected void performSyncServiceV2Sync() {
boolean syncOccurred = syncService.synchronizeActiveTasks(false, syncResultCallback);
if (syncOccurred) {
Preferences.setLong(PREF_LAST_AUTO_SYNC, DateUtilities.now());
preferences.setLong(PREF_LAST_AUTO_SYNC, DateUtilities.now());
}
}

@ -188,7 +188,7 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
public TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) {
taskAdapter = new DraggableTaskAdapter(fragment, TaskListFragment.getTaskRowResource(),
taskAdapter = new DraggableTaskAdapter(fragment, TaskListFragment.getTaskRowResource(Preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0)),
cursor, sqlQueryTemplate);
getTouchListView().setItemHightNormal(taskAdapter.computeFullRowHeight());

@ -202,7 +202,7 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
public TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) {
taskAdapter = new DraggableTaskAdapter(fragment, TaskListFragment.getTaskRowResource(),
taskAdapter = new DraggableTaskAdapter(fragment, TaskListFragment.getTaskRowResource(Preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0)),
cursor, sqlQueryTemplate);
taskAdapter.addOnCompletedTaskListener(new OnCompletedTaskListener() {

@ -14,7 +14,6 @@ import android.os.Bundle;
import android.widget.RemoteViews;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskEditActivity;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.activity.TaskListActivity;
@ -34,6 +33,7 @@ import com.todoroo.astrid.widget.WidgetConfigActivity;
import com.todoroo.astrid.widget.WidgetUpdateService;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -71,10 +71,12 @@ public class WidgetHelper {
}
private final TagDataService tagDataService;
private final Preferences preferences;
@Inject
public WidgetHelper(TagDataService tagDataService) {
public WidgetHelper(TagDataService tagDataService, Preferences preferences) {
this.tagDataService = tagDataService;
this.preferences = preferences;
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@ -110,10 +112,10 @@ public class WidgetHelper {
public PendingIntent getListIntent(Context context, Filter filter, int widgetId) {
Intent listIntent = new Intent(context, TaskListActivity.class);
String customIntent = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
String customIntent = preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
+ widgetId);
if (customIntent != null) {
String serializedExtras = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
String serializedExtras = preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
+ widgetId);
Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
listIntent.putExtras(extras);
@ -182,49 +184,49 @@ public class WidgetHelper {
// base our filter off the inbox filter, replace stuff if we have it
Filter filter = CoreFilterExposer.buildInboxFilter(context.getResources());
String sql = Preferences.getStringValue(WidgetConfigActivity.PREF_SQL + widgetId);
String sql = preferences.getStringValue(WidgetConfigActivity.PREF_SQL + widgetId);
if (sql != null) {
filter.setSqlQuery(sql);
}
String title = Preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
String title = preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
if (title != null) {
filter.title = title;
}
String contentValues = Preferences.getStringValue(WidgetConfigActivity.PREF_VALUES + widgetId);
String contentValues = preferences.getStringValue(WidgetConfigActivity.PREF_VALUES + widgetId);
if (contentValues != null) {
filter.valuesForNewTasks = AndroidUtilities.contentValuesFromSerializedString(contentValues);
}
String customComponent = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
String customComponent = preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
+ widgetId);
if (customComponent != null) {
ComponentName component = ComponentName.unflattenFromString(customComponent);
filter = new FilterWithCustomIntent(filter.title, filter.title, filter.getSqlQuery(), filter.valuesForNewTasks);
((FilterWithCustomIntent) filter).customTaskList = component;
String serializedExtras = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
String serializedExtras = preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
+ widgetId);
((FilterWithCustomIntent) filter).customExtras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
}
// Validate tagData
long id = Preferences.getLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, 0);
long id = preferences.getLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, 0);
TagData tagData;
if (id > 0) {
tagData = tagDataService.fetchById(id, TagData.ID, TagData.NAME, TagData.TASK_COUNT, TagData.UUID, TagData.PICTURE, TagData.USER_ID, TagData.MEMBER_COUNT);
if (tagData != null && !tagData.getName().equals(filter.title)) { // Tag has been renamed; rebuild filter
filter = TagFilterExposer.filterFromTagData(context, tagData);
Preferences.setString(WidgetConfigActivity.PREF_SQL + widgetId, filter.getSqlQuery());
Preferences.setString(WidgetConfigActivity.PREF_TITLE + widgetId, filter.title);
preferences.setString(WidgetConfigActivity.PREF_SQL + widgetId, filter.getSqlQuery());
preferences.setString(WidgetConfigActivity.PREF_TITLE + widgetId, filter.title);
ContentValues newTaskValues = filter.valuesForNewTasks;
String contentValuesString = null;
if (newTaskValues != null) {
contentValuesString = AndroidUtilities.contentValuesToSerializedString(newTaskValues);
}
Preferences.setString(WidgetConfigActivity.PREF_VALUES + widgetId, contentValuesString);
preferences.setString(WidgetConfigActivity.PREF_VALUES + widgetId, contentValuesString);
if (filter != null) {
String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent) filter).customExtras);
if (flattenedExtras != null) {
Preferences.setString(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId,
preferences.setString(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId,
flattenedExtras);
}
}
@ -232,7 +234,7 @@ public class WidgetHelper {
} else {
tagData = tagDataService.getTagByName(filter.title, TagData.ID);
if (tagData != null) {
Preferences.setLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, tagData.getId());
preferences.setLong(WidgetConfigActivity.PREF_TAG_ID + widgetId, tagData.getId());
}
}

Loading…
Cancel
Save