Fixed beast mode bugs and cleaned up some unecessary beast mode code

pull/14/head
Sam Bosley 13 years ago
parent 896f40d9a3
commit 947f0fe1b7

@ -355,8 +355,9 @@
<item >@string/TEA_control_reminders</item>
<item >@string/TEA_control_timer</item>
<item >@string/TEA_control_share</item>
</string-array><string-array name="TEA_control_sets">
</string-array>
<string-array name="TEA_control_sets">
<item>@string/TEA_control_title</item>
<item>@string/TEA_control_who</item>
<item>@string/TEA_control_when</item>
@ -369,8 +370,7 @@
<item>@string/TEA_control_share</item>
</string-array>
<string name="TEA_ctrl_title_pref">TEA_ctrl_title_pref</string>
<string name="TEA_ctrl_title_pref">TEA_ctrl_title_pref</string> <!-- Deprecated -->
<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>
@ -382,7 +382,6 @@
<string name="TEA_ctrl_share_pref">TEA_ctrl_share_pref</string>
<string-array name="TEA_control_sets_prefs">
<item>@string/TEA_ctrl_who_pref</item>
<item>@string/TEA_ctrl_when_pref</item>
<item>@string/TEA_ctrl_more_pref</item>

@ -4,10 +4,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
@ -32,74 +30,8 @@ public class BeastModePreferences 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$
private HashMap<String, String> prefsToDescriptions;
// 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 (int i = 1; i < defaultOrder.length; i++) {
String s = defaultOrder[i];
if (s.contains(BEAST_MODE_MORE_ITEM_SPECIAL_CHAR)) {
String[] split = s.split(BEAST_MODE_MORE_ITEM_SPECIAL_CHAR);
for (String component : split) {
if (!TextUtils.isEmpty(component)) {
s = component;
break;
}
}
}
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);
@ -120,9 +52,8 @@ public class BeastModePreferences extends ListActivity {
items = new ArrayList<String>();
for (String s : itemsArray) {
if (!s.equals(getResources().getString(R.string.TEA_control_title))){
items.add(s);
if (!s.equals(getResources().getString(R.string.TEA_ctrl_title_pref))){
items.add(s);
}
}
@ -163,7 +94,7 @@ public class BeastModePreferences extends ListActivity {
private void buildDescriptionMap(Resources r) {
String[] keys = r.getStringArray(R.array.TEA_control_sets_prefs);
String[] descriptions = r.getStringArray(R.array.TEA_control_sets);
String[] descriptions = r.getStringArray(R.array.TEA_control_sets_beast);
for (int i = 0; i < keys.length && i < descriptions.length; i++) {
prefsToDescriptions.put(keys[i], descriptions[i]);
}

@ -570,7 +570,6 @@ public final class TaskEditFragment extends Fragment implements
R.array.TEA_control_sets_prefs);
String moreSectionTrigger = getString(R.string.TEA_ctrl_more_pref);
String shareViewDescriptor = getString(R.string.TEA_ctrl_share_pref);
String titleViewDescriptor = getString(R.string.TEA_ctrl_title_pref);
LinearLayout section = basicControls;
for (int i = 0; i < itemOrder.length; i++) {
@ -581,9 +580,7 @@ public final class TaskEditFragment extends Fragment implements
View control_set = null;
TaskEditControlSet curr = controlSetMap.get(item);
if (item.equals(titleViewDescriptor))
control_set = curr.getDisplayView();
else if (item.equals(shareViewDescriptor))
if (item.equals(shareViewDescriptor))
control_set = peopleControlSet.getSharedWithRow();
else if (curr != null)
control_set = (LinearLayout) curr.getDisplayView();

@ -31,7 +31,6 @@ 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.BeastModePreferences;
import com.todoroo.astrid.backup.BackupConstants;
import com.todoroo.astrid.backup.BackupService;
import com.todoroo.astrid.backup.TasksXmlImporter;
@ -138,7 +137,6 @@ public class StartupService {
} else {
Preferences.setLong(AstridPreferences.P_FIRST_LAUNCH, 0);
}
BeastModePreferences.migrateBeastModePreferences(context);
int version = 0;
try {

Loading…
Cancel
Save