Added upgrade for RTM, got quick add box working better, other minor polishes

pull/14/head
Tim Su 15 years ago
parent 3dddbd7e1d
commit 2662b5282b

@ -5,26 +5,6 @@
--> -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- ============================================================= SYNC == -->
<!-- sync -->
<string name="p_sync_rtm">sync_rtm</string>
<string name="p_sync_interval">sync_freq</string>
<string name="p_sync_button">sync_button</string>
<string name="p_sync_quiet">sync_dialogs</string>
<string name="p_sync_bgwifi">sync_bgwifi</string>
<string-array name="sync_interval_values">
<!-- sync_interval_values: interval in seconds for sync entries (do not edit) -->
<item>0</item>
<item>1800</item>
<item>3600</item>
<item>43200</item>
<item>86400</item>
<item>302400</item>
<item>604800</item>
</string-array>
<!-- ======================================================== REMINDERS == --> <!-- ======================================================== REMINDERS == -->
<!-- hour to start quiet hours (inclusive) --> <!-- hour to start quiet hours (inclusive) -->

@ -73,7 +73,7 @@
<!-- Synchronization Interval Description (%s => setting) --> <!-- Synchronization Interval Description (%s => setting) -->
<string name="rmilk_MPr_interval_desc">Currently set to: %s</string> <string name="rmilk_MPr_interval_desc">Currently set to: %s</string>
<!-- Preference Key (do not translate) --> <!-- Preference Key (do not translate) -->
<string name="rmilk_MPr_interval_key">rmilk_interval</string> <string name="rmilk_MPr_interval_key">sync_freq</string>
<!-- Background Wifi Title --> <!-- Background Wifi Title -->
<string name="rmilk_MPr_bgwifi_title">Wifi Only Setting</string> <string name="rmilk_MPr_bgwifi_title">Wifi Only Setting</string>
@ -82,7 +82,7 @@
<!-- Background Wifi Description (disabled) --> <!-- Background Wifi Description (disabled) -->
<string name="rmilk_MPr_bgwifi_desc_disabled">Background synchronization will always occur</string> <string name="rmilk_MPr_bgwifi_desc_disabled">Background synchronization will always occur</string>
<!-- Preference Key (do not translate) --> <!-- Preference Key (do not translate) -->
<string name="rmilk_MPr_bgwifi_key">rmilk_bgwifi</string> <string name="rmilk_MPr_bgwifi_key">sync_bgwifi</string>
<!-- Actions Group Label --> <!-- Actions Group Label -->
<string name="rmilk_MPr_group_actions">Actions</string> <string name="rmilk_MPr_group_actions">Actions</string>

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/sync_pref_group">
<CheckBoxPreference
android:key="@string/p_sync_rtm"
android:title="@string/sync_rtm_title"
android:summary="@string/sync_rtm_desc" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/sync_pref_group_options">
<ListPreference
android:key="@string/p_sync_interval"
android:entries="@array/sync_interval_entries"
android:entryValues="@array/sync_interval_values"
android:title="@string/sync_interval_title"
android:summary="@string/sync_interval_desc" />
<CheckBoxPreference
android:key="@string/p_sync_button"
android:title="@string/sync_button_title"
android:summary="@string/sync_button_desc" />
<CheckBoxPreference
android:key="@string/p_sync_quiet"
android:title="@string/sync_quiet_title"
android:summary="@string/sync_quiet_desc" />
</PreferenceCategory>
</PreferenceScreen>

@ -26,9 +26,7 @@ import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -59,17 +57,17 @@ public class SyncPreferences extends PreferenceActivity {
oldRtmSyncPreference = Preferences.shouldSyncRTM(this); oldRtmSyncPreference = Preferences.shouldSyncRTM(this);
addPreferencesFromResource(R.xml.sync_preferences); // addPreferencesFromResource(R.xml.sync_preferences);
// set up preferences // set up preferences
findPreference(getString(R.string.p_sync_interval)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { // findPreference(getString(R.string.p_sync_interval)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override // @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { // public boolean onPreferenceChange(Preference preference, Object newValue) {
if(Preferences.getSyncRTMToken(SyncPreferences.this) == null) // if(Preferences.getSyncRTMToken(SyncPreferences.this) == null)
setResult(Constants.RESULT_SYNCHRONIZE); // setResult(Constants.RESULT_SYNCHRONIZE);
return true; // return true;
} // }
}); // });
// set up footer // set up footer
getListView().addFooterView(getLayoutInflater().inflate( getListView().addFooterView(getLayoutInflater().inflate(

@ -404,28 +404,32 @@ public class Preferences {
/** Should sync with RTM? */ /** Should sync with RTM? */
public static boolean shouldSyncRTM(Context context) { public static boolean shouldSyncRTM(Context context) {
Resources r = context.getResources(); Resources r = context.getResources();
return getPrefs(context).getBoolean(r.getString( // return getPrefs(context).getBoolean(r.getString(
R.string.p_sync_rtm), false); // R.string.p_sync_rtm), false);
return false;
} }
/** Should display sync shortcut? */ /** Should display sync shortcut? */
public static boolean shouldDisplaySyncButton(Context context) { public static boolean shouldDisplaySyncButton(Context context) {
Resources r = context.getResources(); Resources r = context.getResources();
return getPrefs(context).getBoolean(r.getString( // return getPrefs(context).getBoolean(r.getString(
R.string.p_sync_button), false); // R.string.p_sync_button), false);
return false;
} }
/** Should hide sync dialog boxes? */ /** Should hide sync dialog boxes? */
public static boolean shouldSuppressSyncDialogs(Context context) { public static boolean shouldSuppressSyncDialogs(Context context) {
Resources r = context.getResources(); // Resources r = context.getResources();
return getPrefs(context).getBoolean(r.getString( // return getPrefs(context).getBoolean(r.getString(
R.string.p_sync_quiet), false); // R.string.p_sync_quiet), false);
return false;
} }
/** Reads the frequency, in seconds, auto-sync should occur. /** Reads the frequency, in seconds, auto-sync should occur.
* @return seconds duration, or null if not desired */ * @return seconds duration, or null if not desired */
public static Integer getSyncAutoSyncFrequency(Context context) { 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) if(time != null && time == 0)
time = null; time = null;
return time; return time;
@ -433,10 +437,10 @@ public class Preferences {
/** Sets the auto-sync frequency to the desired value */ /** Sets the auto-sync frequency to the desired value */
public static void setSyncAutoSyncFrequency(Context context, int value) { public static void setSyncAutoSyncFrequency(Context context, int value) {
Editor editor = getPrefs(context).edit(); // Editor editor = getPrefs(context).edit();
editor.putString(context.getResources().getString(R.string.p_sync_interval), // editor.putString(context.getResources().getString(R.string.p_sync_interval),
Integer.toString(value)); // Integer.toString(value));
editor.commit(); // editor.commit();
} }
/** Last Auto-Sync Date, or null */ /** Last Auto-Sync Date, or null */

@ -18,6 +18,8 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -227,6 +229,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
((TextView)findViewById(R.id.listLabel)).setText(filter.title); ((TextView)findViewById(R.id.listLabel)).setText(filter.title);
// set listener for quick-changing task priority
getListView().setOnKeyListener(new OnKeyListener() { getListView().setOnKeyListener(new OnKeyListener() {
@Override @Override
public boolean onKey(View view, int keyCode, KeyEvent event) { 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 = (EditText) findViewById(R.id.quickAddText);
quickAddBox.setOnEditorActionListener(new OnEditorActionListener() { 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)); quickAddButton = ((ImageButton)findViewById(R.id.quickAddButton));
quickAddBox.setOnKeyListener(new OnKeyListener() { quickAddBox.addTextChangedListener(new TextWatcher() {
@Override @Override
public boolean onKey(View v, int keyCode, KeyEvent event) { public void afterTextChanged(Editable s) {
if(event != null && event.isPrintingKey()) if(s.length() > 0)
quickAddButton.setVisibility(View.VISIBLE); 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() { quickAddButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
if(quickAddBox.getText().length() > 0) { 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() { ((ImageButton)findViewById(R.id.extendedAddButton)).setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
Task task = quickAddTask(quickAddBox.getText().toString(), false); 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); String reminder = getIntent().getStringExtra(TOKEN_REMINDER);
if(reminder != null) { if(reminder != null) {
findViewById(R.id.reminderContainer).setVisibility(View.VISIBLE); 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); TextView quickAdd = (TextView)findViewById(R.id.quickAddText);
quickAdd.setText(""); //$NON-NLS-1$ quickAdd.setText(""); //$NON-NLS-1$
quickAddButton.setVisibility(View.GONE);
if(selectNewTask) { if(selectNewTask) {
loadTaskListContent(true); loadTaskListContent(true);

@ -298,7 +298,7 @@ public class TaskAdapter extends CursorAdapter {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
public void run() { public void run() {
ViewHolder holder = (ViewHolder)view.getTag(); ViewHolder holder = (ViewHolder)view.getTag();
if(holder != null && holder.task.getId() != taskId) if(holder == null || holder.task.getId() != taskId)
return; return;
view.addView(detailToView(detail)); view.addView(detailToView(detail));
}; };

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.StringTokenizer;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
@ -12,8 +13,8 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log; import android.util.Log;
import com.google.ical.values.Frequency; 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.dao.TaskDao;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.rmilk.data.MilkTask;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
@ -69,6 +71,9 @@ public class Astrid2To3UpgradeHelper {
@Autowired @Autowired
private String alertsTable; private String alertsTable;
@Autowired
private String syncTable;
@Autowired @Autowired
private DialogUtilities dialogUtilities; private DialogUtilities dialogUtilities;
@ -166,7 +171,8 @@ public class Astrid2To3UpgradeHelper {
alarmsDatabase.getDao()); alarmsDatabase.getDao());
alarmsDatabase.close(); alarmsDatabase.close();
// --- upgrade RTM sync mappings (?) // --- upgrade RTM sync mappings
migrateSyncMappingToMetadata();
// --- clean up database // --- clean up database
metadataService.cleanup(); metadataService.cleanup();
@ -389,9 +395,10 @@ public class Astrid2To3UpgradeHelper {
Cursor tagCursor = tagsDb.rawQuery("SELECT _id, name FROM " + tagsTable + Cursor tagCursor = tagsDb.rawQuery("SELECT _id, name FROM " + tagsTable +
" ORDER BY _id ASC", null); " 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); " ORDER BY tag ASC", null);
if(tagCursor.getCount() == 0) if(tagCursor.getCount() == 0)
return; return;
@ -419,10 +426,53 @@ public class Astrid2To3UpgradeHelper {
metadata.clearValue(Metadata.ID); metadata.clearValue(Metadata.ID);
} }
} }
} finally {
tagCursor.close(); tagCursor.close();
if(mapCursor != null)
mapCursor.close(); mapCursor.close();
} }
}
/**
* Move data from sync table into metadata table.
*/
@SuppressWarnings("nls")
private void migrateSyncMappingToMetadata() {
Context context = ContextManager.getContext();
if(!checkIfDatabaseExists(context, syncTable))
return;
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();
metadata.setValue(Metadata.TASK, task);
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();
}
}
} }

Loading…
Cancel
Save