Inject BeastModePreferences

pull/189/head
Alex Baker 11 years ago
parent 4700467574
commit ecba48a382

@ -5,7 +5,6 @@
*/ */
package com.todoroo.astrid.activity; package com.todoroo.astrid.activity;
import android.app.ListActivity;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
@ -19,15 +18,18 @@ import android.widget.TextView;
import com.commonsware.cwac.tlv.TouchListView; import com.commonsware.cwac.tlv.TouchListView;
import com.commonsware.cwac.tlv.TouchListView.DropListener; import com.commonsware.cwac.tlv.TouchListView.DropListener;
import com.todoroo.andlib.utility.Preferences;
import org.tasks.R; import org.tasks.R;
import org.tasks.injection.InjectingListActivity;
import org.tasks.preferences.Preferences;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
public class BeastModePreferences extends ListActivity { import javax.inject.Inject;
public class BeastModePreferences extends InjectingListActivity {
private ArrayAdapter<String> adapter; private ArrayAdapter<String> adapter;
@ -39,19 +41,7 @@ public class BeastModePreferences extends ListActivity {
private HashMap<String, String> prefsToDescriptions; private HashMap<String, String> prefsToDescriptions;
public static void setDefaultOrder(Context context) { @Inject Preferences preferences;
if (Preferences.getStringValue(BEAST_MODE_ORDER_PREF) != null) {
return;
}
ArrayList<String> list = constructOrderedControlList(context);
StringBuilder newSetting = new StringBuilder(30);
for (String item : list) {
newSetting.append(item);
newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
}
Preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString());
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -63,7 +53,7 @@ public class BeastModePreferences extends ListActivity {
buildDescriptionMap(getResources()); buildDescriptionMap(getResources());
TouchListView touchList = (TouchListView) getListView(); TouchListView touchList = (TouchListView) getListView();
items = constructOrderedControlList(this); items = constructOrderedControlList(preferences, this);
adapter = new ArrayAdapter<String>(this, R.layout.preference_draggable_row, R.id.text, items) { adapter = new ArrayAdapter<String>(this, R.layout.preference_draggable_row, R.id.text, items) {
@Override @Override
@ -124,12 +114,26 @@ public class BeastModePreferences extends ListActivity {
newSetting.append(adapter.getItem(i)); newSetting.append(adapter.getItem(i));
newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR); newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
} }
Preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString()); preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString());
super.finish(); super.finish();
} }
public static ArrayList<String> constructOrderedControlList(Context context) { public static void setDefaultOrder(Preferences preferences, Context context) {
String order = Preferences.getStringValue(BEAST_MODE_ORDER_PREF); if (preferences.getStringValue(BEAST_MODE_ORDER_PREF) != null) {
return;
}
ArrayList<String> list = constructOrderedControlList(preferences, context);
StringBuilder newSetting = new StringBuilder(30);
for (String item : list) {
newSetting.append(item);
newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
}
preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString());
}
public static ArrayList<String> constructOrderedControlList(Preferences preferences, Context context) {
String order = preferences.getStringValue(BEAST_MODE_ORDER_PREF);
ArrayList<String> list = new ArrayList<>(); ArrayList<String> list = new ArrayList<>();
String[] itemsArray; String[] itemsArray;
if (order == null) { if (order == null) {

@ -44,7 +44,6 @@ import android.widget.Toast;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.ActFmCameraModule; import com.todoroo.astrid.actfm.ActFmCameraModule;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback; import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.alarms.AlarmService; import com.todoroo.astrid.alarms.AlarmService;
@ -89,6 +88,7 @@ import org.slf4j.LoggerFactory;
import org.tasks.R; import org.tasks.R;
import org.tasks.injection.InjectingFragment; import org.tasks.injection.InjectingFragment;
import org.tasks.notifications.NotificationManager; import org.tasks.notifications.NotificationManager;
import org.tasks.preferences.Preferences;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -182,6 +182,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
@Inject NotificationManager notificationManager; @Inject NotificationManager notificationManager;
@Inject AlarmService alarmService; @Inject AlarmService alarmService;
@Inject GCalHelper gcalHelper; @Inject GCalHelper gcalHelper;
@Inject Preferences preferences;
// --- UI components // --- UI components
@ -241,7 +242,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
} }
} }
showEditComments = Preferences.getBoolean(R.string.p_show_task_edit_comments, true); showEditComments = preferences.getBoolean(R.string.p_show_task_edit_comments, true);
getActivity().setResult(Activity.RESULT_OK); getActivity().setResult(Activity.RESULT_OK);
} }
@ -457,7 +458,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
basicControls.removeAllViews(); basicControls.removeAllViews();
} }
ArrayList<String> controlOrder = BeastModePreferences.constructOrderedControlList(getActivity()); ArrayList<String> controlOrder = BeastModePreferences.constructOrderedControlList(preferences, getActivity());
String[] itemOrder = controlOrder.toArray(new String[controlOrder.size()]); String[] itemOrder = controlOrder.toArray(new String[controlOrder.size()]);
String hideAlwaysTrigger = getString(R.string.TEA_ctrl_hide_section_pref); String hideAlwaysTrigger = getString(R.string.TEA_ctrl_hide_section_pref);
@ -963,7 +964,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
item.setIcon(ThemeService.getDrawable(R.drawable.ic_action_discard)); item.setIcon(ThemeService.getDrawable(R.drawable.ic_action_discard));
setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS); setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
boolean useSaveAndCancel = Preferences.getBoolean(R.string.p_save_and_cancel, false); boolean useSaveAndCancel = preferences.getBoolean(R.string.p_save_and_cancel, false);
if (useSaveAndCancel || AstridPreferences.useTabletLayout(getActivity())) { if (useSaveAndCancel || AstridPreferences.useTabletLayout(getActivity())) {
if (useSaveAndCancel) { if (useSaveAndCancel) {

@ -82,7 +82,7 @@ public class AstridDefaultPreferenceSpec {
} }
preferences.setBoolean(dragDropTestInitialized, true); preferences.setBoolean(dragDropTestInitialized, true);
} }
BeastModePreferences.setDefaultOrder(context); BeastModePreferences.setDefaultOrder(preferences, context);
editor.commit(); editor.commit();

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import com.todoroo.astrid.actfm.TagSettingsActivity; import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.activity.BeastModePreferences;
import com.todoroo.astrid.activity.EditPreferences; import com.todoroo.astrid.activity.EditPreferences;
import com.todoroo.astrid.activity.FilterShortcutActivity; import com.todoroo.astrid.activity.FilterShortcutActivity;
import com.todoroo.astrid.activity.ShareLinkActivity; import com.todoroo.astrid.activity.ShareLinkActivity;
@ -67,7 +68,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
TimerFilterExposer.class, TimerFilterExposer.class,
CustomFilterExposer.class, CustomFilterExposer.class,
GtasksFilterExposer.class, GtasksFilterExposer.class,
TagFilterExposer.class TagFilterExposer.class,
BeastModePreferences.class
}) })
public class ActivityModule { public class ActivityModule {

Loading…
Cancel
Save