mirror of https://github.com/tasks/tasks
Move appearance preferences to main preferences
parent
2a4fa3c6d1
commit
9c5efc36ab
@ -1,191 +0,0 @@
|
|||||||
package org.tasks.preferences;
|
|
||||||
|
|
||||||
import static org.tasks.dialogs.NativeSeekBarDialog.newSeekBarDialog;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import com.todoroo.astrid.activity.BeastModePreferences;
|
|
||||||
import com.todoroo.astrid.api.Filter;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import org.tasks.LocalBroadcastManager;
|
|
||||||
import org.tasks.R;
|
|
||||||
import org.tasks.activities.FilterSelectionActivity;
|
|
||||||
import org.tasks.analytics.Tracker;
|
|
||||||
import org.tasks.analytics.Tracking;
|
|
||||||
import org.tasks.dialogs.NativeSeekBarDialog;
|
|
||||||
import org.tasks.injection.ActivityComponent;
|
|
||||||
import org.tasks.injection.InjectingPreferenceActivity;
|
|
||||||
import org.tasks.locale.Locale;
|
|
||||||
|
|
||||||
public class AppearancePreferences extends InjectingPreferenceActivity
|
|
||||||
implements NativeSeekBarDialog.SeekBarCallback {
|
|
||||||
|
|
||||||
public static final String EXTRA_RESTART = "extra_restart";
|
|
||||||
private static final String EXTRA_FILTERS_CHANGED = "extra_filters_changed";
|
|
||||||
private static final int REQUEST_CUSTOMIZE = 1004;
|
|
||||||
private static final int REQUEST_DEFAULT_LIST = 1005;
|
|
||||||
private static final int REQUEST_ROW_PADDING = 1006;
|
|
||||||
private static final int REQUEST_FONT_SIZE = 1007;
|
|
||||||
private static final String FRAG_TAG_ROW_PADDING_SEEKBAR = "frag_tag_row_padding_seekbar";
|
|
||||||
private static final String FRAG_TAG_FONT_SIZE_SEEKBAR = "frag_tag_font_size_seekbar";
|
|
||||||
private static final String EXTRA_BUNDLE = "extra_bundle";
|
|
||||||
@Inject Preferences preferences;
|
|
||||||
@Inject DefaultFilterProvider defaultFilterProvider;
|
|
||||||
@Inject Tracker tracker;
|
|
||||||
@Inject LocalBroadcastManager localBroadcastManager;
|
|
||||||
@Inject Locale locale;
|
|
||||||
|
|
||||||
private Bundle result;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
result = savedInstanceState == null ? new Bundle() : savedInstanceState.getBundle(EXTRA_BUNDLE);
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences_appearance);
|
|
||||||
|
|
||||||
setExtraOnChange(
|
|
||||||
EXTRA_RESTART,
|
|
||||||
R.string.p_fontSize,
|
|
||||||
R.string.p_rowPadding,
|
|
||||||
R.string.p_fullTaskTitle,
|
|
||||||
R.string.p_show_description,
|
|
||||||
R.string.p_show_full_description,
|
|
||||||
R.string.p_linkify_task_list,
|
|
||||||
R.string.p_show_list_indicators);
|
|
||||||
setExtraOnChange(R.string.p_show_today_filter, EXTRA_FILTERS_CHANGED);
|
|
||||||
setExtraOnChange(R.string.p_show_recently_modified_filter, EXTRA_FILTERS_CHANGED);
|
|
||||||
setExtraOnChange(R.string.p_show_not_in_list_filter, EXTRA_FILTERS_CHANGED);
|
|
||||||
findPreference(getString(R.string.customize_edit_screen))
|
|
||||||
.setOnPreferenceClickListener(
|
|
||||||
preference -> {
|
|
||||||
startActivityForResult(
|
|
||||||
new Intent(AppearancePreferences.this, BeastModePreferences.class),
|
|
||||||
REQUEST_CUSTOMIZE);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
findPreference(R.string.p_fontSize)
|
|
||||||
.setOnPreferenceClickListener(
|
|
||||||
preference -> {
|
|
||||||
newSeekBarDialog(
|
|
||||||
R.layout.dialog_font_size_seekbar,
|
|
||||||
10,
|
|
||||||
48,
|
|
||||||
preferences.getFontSize(),
|
|
||||||
REQUEST_FONT_SIZE)
|
|
||||||
.show(getFragmentManager(), FRAG_TAG_FONT_SIZE_SEEKBAR);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
updateFontSize();
|
|
||||||
|
|
||||||
findPreference(R.string.p_rowPadding)
|
|
||||||
.setOnPreferenceClickListener(
|
|
||||||
preference -> {
|
|
||||||
newSeekBarDialog(
|
|
||||||
R.layout.dialog_font_size_seekbar,
|
|
||||||
0,
|
|
||||||
16,
|
|
||||||
preferences.getRowPadding(),
|
|
||||||
REQUEST_ROW_PADDING)
|
|
||||||
.show(getFragmentManager(), FRAG_TAG_ROW_PADDING_SEEKBAR);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
updateRowPadding();
|
|
||||||
Preference defaultList = findPreference(getString(R.string.p_default_list));
|
|
||||||
Filter filter = defaultFilterProvider.getDefaultFilter();
|
|
||||||
defaultList.setSummary(filter.listingTitle);
|
|
||||||
defaultList.setOnPreferenceClickListener(
|
|
||||||
preference -> {
|
|
||||||
Intent intent = new Intent(AppearancePreferences.this, FilterSelectionActivity.class);
|
|
||||||
intent.putExtra(
|
|
||||||
FilterSelectionActivity.EXTRA_FILTER, defaultFilterProvider.getDefaultFilter());
|
|
||||||
intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
|
|
||||||
startActivityForResult(intent, REQUEST_DEFAULT_LIST);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
|
|
||||||
outState.putBundle(EXTRA_BUNDLE, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finish() {
|
|
||||||
Intent data = new Intent();
|
|
||||||
data.putExtras(result);
|
|
||||||
setResult(RESULT_OK, data);
|
|
||||||
super.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
if (requestCode == REQUEST_CUSTOMIZE) {
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
result.putBoolean(EXTRA_RESTART, true);
|
|
||||||
}
|
|
||||||
} else if (requestCode == REQUEST_DEFAULT_LIST) {
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
Filter filter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
|
|
||||||
defaultFilterProvider.setDefaultFilter(filter);
|
|
||||||
findPreference(getString(R.string.p_default_list)).setSummary(filter.listingTitle);
|
|
||||||
localBroadcastManager.broadcastRefresh();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setExtraOnChange(final int resId, final String extra) {
|
|
||||||
findPreference(getString(resId))
|
|
||||||
.setOnPreferenceChangeListener(
|
|
||||||
(preference, newValue) -> {
|
|
||||||
tracker.reportEvent(Tracking.Events.SET_PREFERENCE, resId, newValue.toString());
|
|
||||||
result.putBoolean(extra, true);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setExtraOnChange(final String extra, final int... resIds) {
|
|
||||||
for (int resId : resIds) {
|
|
||||||
setExtraOnChange(resId, extra);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inject(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void valueSelected(int value, int requestCode) {
|
|
||||||
int resId = 0;
|
|
||||||
if (requestCode == REQUEST_ROW_PADDING) {
|
|
||||||
preferences.setInt(R.string.p_rowPadding, value);
|
|
||||||
updateRowPadding();
|
|
||||||
resId = R.string.p_rowPadding;
|
|
||||||
} else if (requestCode == REQUEST_FONT_SIZE) {
|
|
||||||
preferences.setInt(R.string.p_fontSize, value);
|
|
||||||
updateFontSize();
|
|
||||||
resId = R.string.p_fontSize;
|
|
||||||
}
|
|
||||||
if (resId > 0) {
|
|
||||||
result.putBoolean(EXTRA_RESTART, true);
|
|
||||||
tracker.reportEvent(Tracking.Events.SET_PREFERENCE, resId, Integer.toString(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateFontSize() {
|
|
||||||
findPreference(R.string.p_fontSize).setSummary(locale.formatNumber(preferences.getFontSize()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateRowPadding() {
|
|
||||||
findPreference(R.string.p_rowPadding)
|
|
||||||
.setSummary(locale.formatNumber(preferences.getRowPadding()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:title="@string/EPr_appearance_header">
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/task_list_options">
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilinePreference
|
|
||||||
android:key="@string/p_default_list"
|
|
||||||
android:title="@string/default_list"/>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:defaultValue="16"
|
|
||||||
android:key="@string/p_fontSize"
|
|
||||||
android:title="@string/font_size"/>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:defaultValue="16"
|
|
||||||
android:key="@string/p_rowPadding"
|
|
||||||
android:title="@string/row_spacing"/>
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilineCheckboxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/p_fullTaskTitle"
|
|
||||||
android:title="@string/EPr_fullTask_title"/>
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/p_show_description"
|
|
||||||
android:title="@string/show_description" />
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/p_show_full_description"
|
|
||||||
android:dependency="@string/p_show_description"
|
|
||||||
android:title="@string/show_full_description" />
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/p_show_list_indicators"
|
|
||||||
android:title="@string/show_list_indicators" />
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/p_linkify_task_list"
|
|
||||||
android:title="@string/linkify"
|
|
||||||
android:summary="@string/linkify_description"/>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/EPr_edit_screen_options">
|
|
||||||
<Preference
|
|
||||||
android:key="@string/customize_edit_screen"
|
|
||||||
android:title="@string/customize_edit_screen"/>
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilineCheckboxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/p_back_button_saves_task"
|
|
||||||
android:title="@string/back_button_saves_task"/>
|
|
||||||
|
|
||||||
<com.todoroo.astrid.ui.MultilineCheckboxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/p_show_task_edit_comments"
|
|
||||||
android:title="@string/EPr_show_task_edit_comments"/>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/EPr_filters_to_show_title">
|
|
||||||
<com.todoroo.astrid.ui.MultilineCheckboxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/p_show_today_filter"
|
|
||||||
android:title="@string/today"/>
|
|
||||||
<com.todoroo.astrid.ui.MultilineCheckboxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/p_show_recently_modified_filter"
|
|
||||||
android:title="@string/BFE_Recent"/>
|
|
||||||
<com.todoroo.astrid.ui.MultilineCheckboxPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/p_show_not_in_list_filter"
|
|
||||||
android:title="@string/tag_FEx_untagged"/>
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
||||||
Loading…
Reference in New Issue