From 2662b5282b00abe4268a25369402d779fed35d38 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Thu, 15 Jul 2010 22:27:53 -0700 Subject: [PATCH] Added upgrade for RTM, got quick add box working better, other minor polishes --- astrid/res/values/keys.xml | 22 +--- astrid/res/values/strings-rmilk.xml | 4 +- astrid/res/xml/sync_preferences.xml | 37 ------- .../astrid/activities/SyncPreferences.java | 20 ++-- .../timsu/astrid/utilities/Preferences.java | 28 ++--- .../astrid/activity/TaskListActivity.java | 26 ++++- .../todoroo/astrid/adapter/TaskAdapter.java | 2 +- .../service/Astrid2To3UpgradeHelper.java | 100 +++++++++++++----- 8 files changed, 125 insertions(+), 114 deletions(-) delete mode 100644 astrid/res/xml/sync_preferences.xml diff --git a/astrid/res/values/keys.xml b/astrid/res/values/keys.xml index 0bfccd1af..912b1d1a5 100644 --- a/astrid/res/values/keys.xml +++ b/astrid/res/values/keys.xml @@ -4,27 +4,7 @@ These should not be translated --> - - - - - sync_rtm - sync_freq - sync_button - sync_dialogs - sync_bgwifi - - - - 0 - 1800 - 3600 - 43200 - 86400 - 302400 - 604800 - - + diff --git a/astrid/res/values/strings-rmilk.xml b/astrid/res/values/strings-rmilk.xml index 9c9205ddf..044bf1b81 100644 --- a/astrid/res/values/strings-rmilk.xml +++ b/astrid/res/values/strings-rmilk.xml @@ -73,7 +73,7 @@ Currently set to: %s - rmilk_interval + sync_freq Wifi Only Setting @@ -82,7 +82,7 @@ Background synchronization will always occur - rmilk_bgwifi + sync_bgwifi Actions diff --git a/astrid/res/xml/sync_preferences.xml b/astrid/res/xml/sync_preferences.xml deleted file mode 100644 index 4417a3d4d..000000000 --- a/astrid/res/xml/sync_preferences.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/astrid/src-legacy/com/timsu/astrid/activities/SyncPreferences.java b/astrid/src-legacy/com/timsu/astrid/activities/SyncPreferences.java index aa04880e4..65c9eb8ef 100644 --- a/astrid/src-legacy/com/timsu/astrid/activities/SyncPreferences.java +++ b/astrid/src-legacy/com/timsu/astrid/activities/SyncPreferences.java @@ -26,9 +26,7 @@ import android.app.Dialog; import android.content.DialogInterface; import android.content.res.Resources; import android.os.Bundle; -import android.preference.Preference; import android.preference.PreferenceActivity; -import android.preference.Preference.OnPreferenceChangeListener; import android.view.KeyEvent; import android.view.View; import android.widget.Button; @@ -59,17 +57,17 @@ public class SyncPreferences extends PreferenceActivity { oldRtmSyncPreference = Preferences.shouldSyncRTM(this); - addPreferencesFromResource(R.xml.sync_preferences); +// addPreferencesFromResource(R.xml.sync_preferences); // set up preferences - findPreference(getString(R.string.p_sync_interval)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if(Preferences.getSyncRTMToken(SyncPreferences.this) == null) - setResult(Constants.RESULT_SYNCHRONIZE); - return true; - } - }); +// findPreference(getString(R.string.p_sync_interval)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { +// @Override +// public boolean onPreferenceChange(Preference preference, Object newValue) { +// if(Preferences.getSyncRTMToken(SyncPreferences.this) == null) +// setResult(Constants.RESULT_SYNCHRONIZE); +// return true; +// } +// }); // set up footer getListView().addFooterView(getLayoutInflater().inflate( diff --git a/astrid/src-legacy/com/timsu/astrid/utilities/Preferences.java b/astrid/src-legacy/com/timsu/astrid/utilities/Preferences.java index d9dc40179..8ee5e8558 100644 --- a/astrid/src-legacy/com/timsu/astrid/utilities/Preferences.java +++ b/astrid/src-legacy/com/timsu/astrid/utilities/Preferences.java @@ -404,28 +404,32 @@ public class Preferences { /** Should sync with RTM? */ public static boolean shouldSyncRTM(Context context) { Resources r = context.getResources(); - return getPrefs(context).getBoolean(r.getString( - R.string.p_sync_rtm), false); +// return getPrefs(context).getBoolean(r.getString( +// R.string.p_sync_rtm), false); + return false; } /** Should display sync shortcut? */ public static boolean shouldDisplaySyncButton(Context context) { Resources r = context.getResources(); - return getPrefs(context).getBoolean(r.getString( - R.string.p_sync_button), false); +// return getPrefs(context).getBoolean(r.getString( +// R.string.p_sync_button), false); + return false; } /** Should hide sync dialog boxes? */ public static boolean shouldSuppressSyncDialogs(Context context) { - Resources r = context.getResources(); - return getPrefs(context).getBoolean(r.getString( - R.string.p_sync_quiet), false); +// Resources r = context.getResources(); +// return getPrefs(context).getBoolean(r.getString( +// R.string.p_sync_quiet), false); + return false; } /** Reads the frequency, in seconds, auto-sync should occur. * @return seconds duration, or null if not desired */ public static Integer getSyncAutoSyncFrequency(Context context) { - Integer time = getIntegerValue(context, R.string.p_sync_interval); + Integer time = 0; +// Integer time = getIntegerValue(context, R.string.p_sync_interval); if(time != null && time == 0) time = null; return time; @@ -433,10 +437,10 @@ public class Preferences { /** Sets the auto-sync frequency to the desired value */ public static void setSyncAutoSyncFrequency(Context context, int value) { - Editor editor = getPrefs(context).edit(); - editor.putString(context.getResources().getString(R.string.p_sync_interval), - Integer.toString(value)); - editor.commit(); +// Editor editor = getPrefs(context).edit(); +// editor.putString(context.getResources().getString(R.string.p_sync_interval), +// Integer.toString(value)); +// editor.commit(); } /** Last Auto-Sync Date, or null */ diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 8c301f256..d941c801e 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -18,6 +18,8 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.KeyEvent; @@ -227,6 +229,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener { ((TextView)findViewById(R.id.listLabel)).setText(filter.title); + // set listener for quick-changing task priority getListView().setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent event) { @@ -247,6 +250,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener { } }); + // set listener for pressing enter in quick-add box quickAddBox = (EditText) findViewById(R.id.quickAddText); quickAddBox.setOnEditorActionListener(new OnEditorActionListener() { /** @@ -262,16 +266,27 @@ public class TaskListActivity extends ListActivity implements OnScrollListener { } }); + // set listener for showing quick add button if text not empty quickAddButton = ((ImageButton)findViewById(R.id.quickAddButton)); - quickAddBox.setOnKeyListener(new OnKeyListener() { + quickAddBox.addTextChangedListener(new TextWatcher() { @Override - public boolean onKey(View v, int keyCode, KeyEvent event) { - if(event != null && event.isPrintingKey()) + public void afterTextChanged(Editable s) { + if(s.length() > 0) quickAddButton.setVisibility(View.VISIBLE); - return false; + } + @Override + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + // + } + @Override + public void onTextChanged(CharSequence s, int start, int before, + int count) { + // } }); + // set listener for quick add button quickAddButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if(quickAddBox.getText().length() > 0) { @@ -280,6 +295,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener { } }); + // set listener for extended add button ((ImageButton)findViewById(R.id.extendedAddButton)).setOnClickListener(new OnClickListener() { public void onClick(View v) { Task task = quickAddTask(quickAddBox.getText().toString(), false); @@ -289,6 +305,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener { } }); + // show reminder if necessary String reminder = getIntent().getStringExtra(TOKEN_REMINDER); if(reminder != null) { findViewById(R.id.reminderContainer).setVisibility(View.VISIBLE); @@ -328,7 +345,6 @@ public class TaskListActivity extends ListActivity implements OnScrollListener { TextView quickAdd = (TextView)findViewById(R.id.quickAddText); quickAdd.setText(""); //$NON-NLS-1$ - quickAddButton.setVisibility(View.GONE); if(selectNewTask) { loadTaskListContent(true); diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 998c08db5..e0daf891a 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -298,7 +298,7 @@ public class TaskAdapter extends CursorAdapter { activity.runOnUiThread(new Runnable() { public void run() { ViewHolder holder = (ViewHolder)view.getTag(); - if(holder != null && holder.task.getId() != taskId) + if(holder == null || holder.task.getId() != taskId) return; view.addView(detailToView(detail)); }; diff --git a/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java b/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java index 105b93aca..b33a4f9c2 100644 --- a/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java +++ b/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Map.Entry; +import java.util.StringTokenizer; import android.app.Activity; import android.app.ProgressDialog; @@ -12,8 +13,8 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; import com.google.ical.values.Frequency; @@ -40,6 +41,7 @@ import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Task; +import com.todoroo.astrid.rmilk.data.MilkTask; import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.utility.Preferences; @@ -69,6 +71,9 @@ public class Astrid2To3UpgradeHelper { @Autowired private String alertsTable; + @Autowired + private String syncTable; + @Autowired private DialogUtilities dialogUtilities; @@ -166,7 +171,8 @@ public class Astrid2To3UpgradeHelper { alarmsDatabase.getDao()); alarmsDatabase.close(); - // --- upgrade RTM sync mappings (?) + // --- upgrade RTM sync mappings + migrateSyncMappingToMetadata(); // --- clean up database metadataService.cleanup(); @@ -389,39 +395,83 @@ public class Astrid2To3UpgradeHelper { Cursor tagCursor = tagsDb.rawQuery("SELECT _id, name FROM " + tagsTable + " ORDER BY _id ASC", null); - Cursor mapCursor = tagTaskDb.rawQuery("SELECT tag, task FROM " + tagTaskTable + + Cursor mapCursor = null; + try { + mapCursor = tagTaskDb.rawQuery("SELECT tag, task FROM " + tagTaskTable + " ORDER BY tag ASC", null); + if(tagCursor.getCount() == 0) + return; + + Metadata metadata = new Metadata(); + metadata.setValue(Metadata.KEY, TagService.KEY); + long tagId = -1; + String tag = null; + for(mapCursor.moveToFirst(); !mapCursor.isAfterLast(); mapCursor.moveToNext()) { + long mapTagId = mapCursor.getLong(0); + + while(mapTagId > tagId && !tagCursor.isLast()) { + tagCursor.moveToNext(); + tagId = tagCursor.getLong(0); + tag = null; + } - if(tagCursor.getCount() == 0) + if(mapTagId == tagId) { + if(tag == null) + tag = tagCursor.getString(1); + long task = mapCursor.getLong(1); + metadata.setValue(Metadata.TASK, task); + metadata.setValue(Metadata.KEY, TagService.KEY); + metadata.setValue(TagService.TAG, tag); + metadataDao.createNew(metadata); + metadata.clearValue(Metadata.ID); + } + } + } finally { + tagCursor.close(); + if(mapCursor != null) + mapCursor.close(); + } + } + + /** + * Move data from sync table into metadata table. + */ + @SuppressWarnings("nls") + private void migrateSyncMappingToMetadata() { + Context context = ContextManager.getContext(); + + if(!checkIfDatabaseExists(context, syncTable)) return; - Metadata metadata = new Metadata(); - metadata.setValue(Metadata.KEY, TagService.KEY); - long tagId = -1; - String tag = null; - for(mapCursor.moveToFirst(); !mapCursor.isAfterLast(); mapCursor.moveToNext()) { - long mapTagId = mapCursor.getLong(0); - - while(mapTagId > tagId && !tagCursor.isLast()) { - tagCursor.moveToNext(); - tagId = tagCursor.getLong(0); - tag = null; - } + SQLiteDatabase syncDb = new Astrid2UpgradeHelper(context, syncTable, + null, 1).getReadableDatabase(); + + Cursor cursor = syncDb.rawQuery("SELECT task, remoteId FROM " + syncTable, null); + try { + if(cursor.getCount() == 0) + return; + + Metadata metadata = new Metadata(); + metadata.setValue(Metadata.KEY, MilkTask.METADATA_KEY); + for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { + long task = cursor.getLong(0); + String id = cursor.getString(1); + + StringTokenizer strtok = new StringTokenizer(id, "|"); + String taskId = strtok.nextToken(); + String taskSeriesId = strtok.nextToken(); + String listId = strtok.nextToken(); - if(mapTagId == tagId) { - if(tag == null) - tag = tagCursor.getString(1); - long task = mapCursor.getLong(1); metadata.setValue(Metadata.TASK, task); - metadata.setValue(Metadata.KEY, TagService.KEY); - metadata.setValue(TagService.TAG, tag); + metadata.setValue(MilkTask.LIST_ID, Long.parseLong(listId)); + metadata.setValue(MilkTask.TASK_SERIES_ID, Long.parseLong(taskSeriesId)); + metadata.setValue(MilkTask.TASK_ID, Long.parseLong(taskId)); metadataDao.createNew(metadata); metadata.clearValue(Metadata.ID); } + } finally { + cursor.close(); } - - tagCursor.close(); - mapCursor.close(); }