Convert tasker settings to preference activity

pull/467/head
Alex Baker 8 years ago
parent ec1aaa62ef
commit 9e86ec66a1

@ -53,7 +53,7 @@
<activity
android:name="com.todoroo.astrid.gtasks.GtasksPreferences"
android:label="@string/synchronization"
android:theme="@style/BlueGrey" />
android:theme="@style/Tasks" />
<receiver android:name=".receivers.GoogleTaskPushReceiver">
<intent-filter>
@ -93,7 +93,7 @@
android:name=".locale.ui.activity.TaskerSettingsActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/BlueGrey"
android:theme="@style/Tasks"
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustResize"/>

@ -3,11 +3,11 @@ package org.tasks.locale.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
import org.tasks.injection.InjectingPreferenceActivity;
import timber.log.Timber;
public abstract class AbstractFragmentPluginAppCompatActivity extends ThemedInjectingAppCompatActivity {
public abstract class AbstractFragmentPluginAppCompatActivity extends InjectingPreferenceActivity {
boolean mIsCancelled = false;
@ -19,7 +19,7 @@ public abstract class AbstractFragmentPluginAppCompatActivity extends ThemedInje
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isLocalePluginIntent(getIntent())) {

@ -2,10 +2,8 @@ package org.tasks.locale.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;
import com.todoroo.astrid.api.Filter;
@ -18,16 +16,9 @@ import org.tasks.injection.ActivityComponent;
import org.tasks.locale.bundle.PluginBundleValues;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences;
import org.tasks.ui.MenuColorizer;
import java.util.Set;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompatActivity implements PurchaseHelperCallback, Toolbar.OnMenuItemClickListener {
private static final int REQUEST_SELECT_FILTER = 10124;
@ -35,9 +26,6 @@ public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompa
private static final String EXTRA_FILTER = "extra_filter";
private static final String EXTRA_PURCHASE_INITIATED = "extra_purchase_initiated";
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.text_view) TextView filterTitle;
@Inject Preferences preferences;
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject PurchaseHelper purchaseHelper;
@ -48,10 +36,10 @@ public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompa
private boolean purchaseInitiated;
@Override
protected void onCreate(final Bundle savedInstanceState) {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tasker_settings);
ButterKnife.bind(this);
addPreferencesFromResource(R.xml.preferences_tasker);
if (savedInstanceState != null) {
previousBundle = savedInstanceState.getParcelable(PluginBundleValues.BUNDLE_EXTRA_PREVIOUS_BUNDLE);
@ -60,42 +48,26 @@ public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompa
} else {
filter = defaultFilterProvider.getDefaultFilter();
}
updateView();
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_close_24dp));
toolbar.setOnMenuItemClickListener(this);
toolbar.setNavigationOnClickListener(view -> {
if (equalBundles(getResultBundle(), previousBundle)) {
cancel();
} else {
dialogBuilder.newMessageDialog(R.string.discard_changes)
.setPositiveButton(android.R.string.ok, (dialog, which) -> cancel())
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
})
.show();
}
findPreference(R.string.filter).setOnPreferenceClickListener(preference -> {
startActivityForResult(new Intent(TaskerSettingsActivity.this, FilterSelectionActivity.class) {{
putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
}}, REQUEST_SELECT_FILTER);
return false;
});
toolbar.inflateMenu(R.menu.tasker_menu);
MenuColorizer.colorToolbar(this, toolbar);
refreshPreferences();
if (!preferences.hasPurchase(R.string.p_purchased_tasker) && !purchaseInitiated) {
purchaseInitiated = purchaseHelper.purchase(dialogBuilder, this, getString(R.string.sku_tasker), getString(R.string.p_purchased_tasker), REQUEST_PURCHASE, this);
}
}
@OnClick(R.id.filter_selection)
void selectFilter() {
startActivityForResult(new Intent(TaskerSettingsActivity.this, FilterSelectionActivity.class) {{
putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
}}, REQUEST_SELECT_FILTER);
}
@Override
public void onPostCreateWithPreviousResult(final Bundle previousBundle, final String previousBlurb) {
this.previousBundle = previousBundle;
this.filter = defaultFilterProvider.getFilterFromPreference(PluginBundleValues.getFilter(previousBundle));
updateView();
refreshPreferences();
}
@Override
@ -118,45 +90,12 @@ public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompa
finish();
}
private boolean equalBundles(Bundle one, Bundle two) {
if (one == null) {
return two == null;
}
if (two == null) {
return false;
}
if(one.size() != two.size())
return false;
Set<String> setOne = one.keySet();
Object valueOne;
Object valueTwo;
for(String key : setOne) {
valueOne = one.get(key);
valueTwo = two.get(key);
if(valueOne instanceof Bundle && valueTwo instanceof Bundle &&
!equalBundles((Bundle) valueOne, (Bundle) valueTwo)) {
return false;
}
else if(valueOne == null) {
if(valueTwo != null || !two.containsKey(key))
return false;
}
else if(!valueOne.equals(valueTwo))
return false;
}
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_SELECT_FILTER) {
if (resultCode == RESULT_OK) {
filter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
updateView();
refreshPreferences();
}
} else if (requestCode == REQUEST_PURCHASE) {
purchaseHelper.handleActivityResult(this, requestCode, resultCode, data);
@ -182,8 +121,8 @@ public final class TaskerSettingsActivity extends AbstractFragmentPluginAppCompa
outState.putBoolean(EXTRA_PURCHASE_INITIATED, purchaseInitiated);
}
private void updateView() {
filterTitle.setText(filter.listingTitle);
private void refreshPreferences() {
findPreference(getString(R.string.filter)).setSummary(filter.listingTitle);
}
@Override

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<LinearLayout
android:id="@+id/filter_selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="100"
android:clickable="false"
android:text="@string/filter"
android:textSize="18sp" />
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:gravity="end"
android:hint="@string/select_filter"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_save"
android:title="@string/save"
android:icon="@drawable/ic_save_24dp"
app:showAsAction="always"/>
</menu>

@ -353,7 +353,6 @@
<string name="buy">Купи</string>
<string name="buy_dashclock_extension">Купи разширение</string>
<string name="billing_service_busy">Услугата за таксуване в приложението е заета, опитайте отново по-късно</string>
<string name="select_filter">Изберете Филтър</string>
<string name="filter">Филтър</string>
<string name="opacity">Непрозрачност</string>
<string name="theme">Тема</string>

@ -341,7 +341,6 @@
<string name="buy">Kaufen</string>
<string name="buy_dashclock_extension">Erweiterung kaufen</string>
<string name="billing_service_busy">Dienst für In-App Käufe ist beschäftigt, versuchen Sie es später noch einmal</string>
<string name="select_filter">Filter auswählen</string>
<string name="opacity">Durchsichtigkeit</string>
<string name="color">Farbe</string>
<string name="accent">Akzent</string>

@ -348,7 +348,6 @@
<string name="buy">Comprar</string>
<string name="buy_dashclock_extension">Comprar extensión</string>
<string name="billing_service_busy">El servicio de compra desde la aplicación está ocupado, inténtelo más tarde.</string>
<string name="select_filter">Seleccionar filtro</string>
<string name="filter">Filtro</string>
<string name="opacity">Opacidad</string>
<string name="theme">Tema</string>

@ -343,7 +343,6 @@
<string name="buy">Acheter</string>
<string name="buy_dashclock_extension">Acheter l\'extension</string>
<string name="billing_service_busy">Le service de facturation intégré à l\'application est surchargé, réessayez plus tard.</string>
<string name="select_filter">Sélectionner le filtre</string>
<string name="filter">Filtre</string>
<string name="opacity">Transparence</string>
<string name="theme">Thème</string>

@ -345,7 +345,6 @@
<string name="buy">Acquista</string>
<string name="buy_dashclock_extension">Acquista estensione</string>
<string name="billing_service_busy">Servizio fatturazione in-app è occupato, prova più tardi</string>
<string name="select_filter">Seleziona Filtro</string>
<string name="filter">Filtra</string>
<string name="opacity">Opacità</string>
<string name="theme">Tema</string>

@ -351,7 +351,6 @@
<string name="buy">רכישה</string>
<string name="buy_dashclock_extension">רכוש תוספת</string>
<string name="billing_service_busy">שרות רכישה עמוס, נסה מאוחר יותר</string>
<string name="select_filter">בחר מסנן</string>
<string name="filter">סינון</string>
<string name="opacity">אטימות</string>
<string name="theme">ערכת נושא</string>

@ -351,7 +351,6 @@
<string name="buy">購入</string>
<string name="buy_dashclock_extension">購入エクステンション</string>
<string name="billing_service_busy">アプリ内課金サービスがビジー状態です。後でもう一度試してください</string>
<string name="select_filter">フィルターの選択</string>
<string name="filter">フィルター</string>
<string name="opacity">透明度</string>
<string name="theme">テーマ</string>

@ -346,7 +346,6 @@
<string name="buy">구매</string>
<string name="buy_dashclock_extension">확장팩 구매</string>
<string name="billing_service_busy">인앱 결제 서비스가 혼잡합니다, 나중에 다시 시도하세요</string>
<string name="select_filter">필터 선택</string>
<string name="filter">필터</string>
<string name="opacity">불투명도</string>
<string name="theme">테마</string>

@ -345,7 +345,6 @@
<string name="buy">Kopen</string>
<string name="buy_dashclock_extension">Koop uitbreiding</string>
<string name="billing_service_busy">In-app rekening service is bezig, probeer later opnieuw</string>
<string name="select_filter">Kies Filter</string>
<string name="opacity">Transparantie</string>
<string name="theme">Thema</string>
<string name="color">Kleur</string>

@ -339,7 +339,6 @@
<string name="buy">Kup</string>
<string name="buy_dashclock_extension">Kup rozszerzenie</string>
<string name="billing_service_busy">Serwis zakupów w aplikacji jest zajęty, spróbuj później</string>
<string name="select_filter">Wybierz filtr</string>
<string name="filter">Filtr</string>
<string name="opacity">Przezroczystość</string>
<string name="theme">Motyw</string>

@ -349,7 +349,6 @@
<string name="buy">Купить</string>
<string name="buy_dashclock_extension">Купить расширение</string>
<string name="billing_service_busy">Встроенный сервис перегружен, попробуйте позже</string>
<string name="select_filter">Выберите Фильтр</string>
<string name="filter">Фильтр</string>
<string name="opacity">Прозрачность</string>
<string name="theme">Тема</string>

@ -348,7 +348,6 @@
<string name="buy">Köp</string>
<string name="buy_dashclock_extension">Köp tillägg</string>
<string name="billing_service_busy">Köp i appar tjänsten är upptagen, försök igen senare</string>
<string name="select_filter">Välj filter</string>
<string name="opacity">Opacitet</string>
<string name="theme">Tema</string>
<string name="color">Färg</string>

@ -348,7 +348,6 @@
<string name="buy">Придбати</string>
<string name="buy_dashclock_extension">Придбати розширення</string>
<string name="billing_service_busy">Сервіс оплати застосунку перевантажено, спробуйте пізніше.</string>
<string name="select_filter">Обрати фільтр</string>
<string name="filter">Фільтр</string>
<string name="opacity">Прозорість</string>
<string name="theme">Схема</string>

@ -759,7 +759,6 @@ File %1$s contained %2$s.\n\n
<string name="buy">Buy</string>
<string name="buy_dashclock_extension">Buy extension</string>
<string name="billing_service_busy">In-app billing service is busy, try again later</string>
<string name="select_filter">Select Filter</string>
<string name="filter">Filter</string>
<string name="opacity">Opacity</string>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.todoroo.astrid.ui.MultilinePreference
android:key="@string/filter"
android:title="@string/filter" />
</PreferenceScreen>
Loading…
Cancel
Save