Migration to a better system for beast mode

pull/14/head
Sam Bosley 13 years ago
parent 01170b9ca1
commit dde0d7258b

@ -352,4 +352,29 @@
<item>@string/TEA_control_share</item>
</string-array>
<string name="TEA_ctrl_title_pref">TEA_ctrl_title_pref</string>
<string name="TEA_ctrl_who_pref">TEA_ctrl_who_pref</string>
<string name="TEA_ctrl_when_pref">TEA_ctrl_when_pref</string>
<string name="TEA_ctrl_more_pref">TEA_ctrl_more_pref</string>
<string name="TEA_ctrl_importance_pref">TEA_ctrl_importance_pref</string>
<string name="TEA_ctrl_lists_pref">TEA_ctrl_lists_pref</string>
<string name="TEA_ctrl_notes_pref">TEA_ctrl_notes_pref</string>
<string name="TEA_ctrl_reminders_pref">TEA_ctrl_reminders_pref</string>
<string name="TEA_ctrl_timer_pref">TEA_ctrl_timer_pref</string>
<string name="TEA_ctrl_share_pref">TEA_ctrl_share_pref</string>
<string-array name="TEA_control_sets_prefs">
<item>@string/TEA_ctrl_title_pref</item>
<item>@string/TEA_ctrl_who_pref</item>
<item>@string/TEA_ctrl_when_pref</item>
<item>@string/TEA_ctrl_more_pref</item>
<item>@string/TEA_ctrl_importance_pref</item>
<item>@string/TEA_ctrl_lists_pref</item>
<item>@string/TEA_ctrl_notes_pref</item>
<item>@string/TEA_ctrl_reminders_pref</item>
<item>@string/TEA_ctrl_timer_pref</item>
<item>@string/TEA_ctrl_share_pref</item>
</string-array>
</resources>

@ -355,7 +355,7 @@
<string name="TEA_control_title">Task Title</string>
<string name="TEA_control_who">Who</string>
<string name="TEA_control_when">When</string>
<string name="TEA_control_more_section">More Section</string>
<string name="TEA_control_more_section">----More Section----</string>
<string name="TEA_control_importance">Importance</string>
<string name="TEA_control_lists">Lists</string>
<string name="TEA_control_notes">Notes</string>

@ -3,6 +3,7 @@ package com.todoroo.astrid.activity;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
@ -26,6 +27,65 @@ public class BeastModePreferenceActivity extends ListActivity {
public static final String BEAST_MODE_PREF_ITEM_SEPARATOR = ";"; //$NON-NLS-1$
private static final String BEAST_MODE_MORE_ITEM_SPECIAL_CHAR = "-*"; //$NON-NLS-1$
private static final String BEAST_MODE_MIGRATE_PREF = "beast_mode_migrate"; //$NON-NLS-1$
// Migration function to fix the fact that I stupidly chose to use the control
// set names (which are localized and subject to change) as the values in the beast
// mode preferences
public static void migrateBeastModePreferences(Context context) {
boolean hasMigratedBeastMode = Preferences.getBoolean(BEAST_MODE_MIGRATE_PREF, false);
if (hasMigratedBeastMode) return;
String setPref = Preferences.getStringValue(BEAST_MODE_ORDER_PREF);
if (setPref == null) {
Preferences.setBoolean(BEAST_MODE_MIGRATE_PREF, true);
return;
}
ArrayList<String> defaults = new ArrayList<String>();
String[] defaultOrder = context.getResources().getStringArray(R.array.TEA_control_sets);
for (String s : defaultOrder) {
if (s.contains(BEAST_MODE_MORE_ITEM_SPECIAL_CHAR)) {
String[] stripped = s.split(BEAST_MODE_MORE_ITEM_SPECIAL_CHAR);
s = stripped[0];
}
defaults.add(s);
}
ArrayList<String> setOrder = new ArrayList<String>();
String[] setOrderArray = setPref.split(BEAST_MODE_PREF_ITEM_SEPARATOR);
for (String s : setOrderArray) {
setOrder.add(s);
}
String[] prefKeys = context.getResources().getStringArray(R.array.TEA_control_sets_prefs);
StringBuilder newPref = new StringBuilder();
//Try to match old preference string to new preference string by index in defaults array
for (String pref : setOrder) {
int index = defaults.indexOf(pref);
if (index > -1 && index < prefKeys.length) {
newPref.append(prefKeys[index]);
newPref.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
} else { // Should never get here--weird error if we do
// Failed to successfully migrate--reset to defaults
StringBuilder resetToDefaults = new StringBuilder();
for (String s : prefKeys) {
resetToDefaults.append(s);
resetToDefaults.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
}
Preferences.setString(BEAST_MODE_ORDER_PREF, resetToDefaults.toString());
Preferences.setBoolean(BEAST_MODE_MIGRATE_PREF, true);
return;
}
}
Preferences.setString(BEAST_MODE_ORDER_PREF, newPref.toString());
Preferences.setBoolean(BEAST_MODE_MIGRATE_PREF, true);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@ -265,14 +265,14 @@ public final class TaskEditActivity extends Activity {
title = (EditText) editTitle.getView().findViewById(R.id.title);
controls.add(editTitle);
//basicControls.addView(editTitle.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_title), editTitle);
controlSetMap.put(getString(R.string.TEA_ctrl_title_pref), editTitle);
TimerActionControlSet timerAction = new TimerActionControlSet(this, editTitle.getView());
controls.add(timerAction);
controls.add(peopleControlSet = new EditPeopleControlSet(TaskEditActivity.this, R.layout.control_set_assigned, R.layout.control_set_assigned_display, R.string.actfm_EPA_assign_label, REQUEST_LOG_IN));
//basicControls.addView(peopleControlSet.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_who), peopleControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_who_pref), peopleControlSet);
DeadlineControlSet deadlineControl = new DeadlineControlSet(TaskEditActivity.this, R.layout.control_set_deadline, R.layout.control_set_deadline_display, whenHeader, R.id.aux_date, R.id.when_shortcut_container, R.id.when_label, R.id.when_image);
controls.add(deadlineControl);
@ -294,29 +294,29 @@ public final class TaskEditActivity extends Activity {
controls.add(importanceControl);
importanceControl.addListener(editTitle);
//moreControls.addView(importanceControl.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_importance), importanceControl);
controlSetMap.put(getString(R.string.TEA_ctrl_importance_pref), importanceControl);
TagsControlSet tagsControl = new TagsControlSet(TaskEditActivity.this, R.layout.control_set_tags, R.layout.control_set_tags_display, R.string.TEA_tags_label);
controls.add(tagsControl);
//moreControls.addView(tagsControl.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_lists), tagsControl);
controlSetMap.put(getString(R.string.TEA_ctrl_lists_pref), tagsControl);
notesControlSet = new EditNotesControlSet(TaskEditActivity.this, R.layout.control_set_notes, R.layout.control_set_notes_display);
notesEditText = (EditText) notesControlSet.getView().findViewById(R.id.notes);
controls.add(notesControlSet);
//moreControls.addView(notesControlSet.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_notes), notesControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_notes_pref), notesControlSet);
ReminderControlSet reminderControl = new ReminderControlSet(TaskEditActivity.this, R.layout.control_set_reminders, R.layout.control_set_reminders_display);
controls.add(reminderControl);
//moreControls.addView(reminderControl.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_reminders), reminderControl);
controlSetMap.put(getString(R.string.TEA_ctrl_reminders_pref), reminderControl);
TimerControlSet timerControl = new TimerControlSet(TaskEditActivity.this, R.layout.control_set_timers, R.layout.control_set_timers_extras_display, R.string.TEA_timer_controls);
timerAction.setListener(timerControl);
controls.add(timerControl);
//moreControls.addView(timerControl.getDisplayView());
controlSetMap.put(getString(R.string.TEA_control_timer), timerControl);
controlSetMap.put(getString(R.string.TEA_ctrl_timer_pref), timerControl);
//moreControls.addView(peopleControlSet.getSharedWithRow());
@ -351,10 +351,10 @@ public final class TaskEditActivity extends Activity {
itemOrder = orderPreference.split(BeastModePreferenceActivity.BEAST_MODE_PREF_ITEM_SEPARATOR);
else
itemOrder = getResources().getStringArray(R.array.TEA_control_sets);
String moreSectionTrigger = getString(R.string.TEA_control_more_section);
String whenViewDescriptor = getString(R.string.TEA_control_when);
String moreSectionTrigger = getString(R.string.TEA_ctrl_more_pref);
String whenViewDescriptor = getString(R.string.TEA_ctrl_when_pref);
View whenView = findViewById(R.id.when_container);
String shareViewDescriptor = getString(R.string.TEA_control_share);
String shareViewDescriptor = getString(R.string.TEA_ctrl_share_pref);
LinearLayout section = basicControls;
for (int i = 0; i < itemOrder.length; i++) {
String item = itemOrder[i];

@ -32,6 +32,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.BeastModePreferenceActivity;
import com.todoroo.astrid.backup.BackupConstants;
import com.todoroo.astrid.backup.BackupService;
import com.todoroo.astrid.backup.TasksXmlImporter;
@ -145,6 +146,7 @@ public class StartupService {
abChooser.setChoiceForOption(ABOptions.AB_THEME_KEY, 0);
Preferences.setLong(AstridPreferences.P_FIRST_LAUNCH, 0);
}
BeastModePreferenceActivity.migrateBeastModePreferences(context);
int version = 0;
try {

Loading…
Cancel
Save