Update badger and bundle settings

pull/574/head
Alex Baker 7 years ago
parent aedfaf7309
commit 17faea2400

@ -18,14 +18,20 @@ import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import com.todoroo.astrid.api.Filter;
import org.tasks.LocalBroadcastManager;
import org.tasks.R;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.activities.TimePickerActivity;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.preferences.ActivityPermissionRequestor;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Device;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.PermissionRequestor;
import org.tasks.receivers.Badger;
import org.tasks.scheduling.GeofenceSchedulingIntentService;
import org.tasks.scheduling.NotificationSchedulerIntentService;
import org.tasks.time.DateTime;
@ -44,10 +50,14 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
private static final int REQUEST_QUIET_START = 10001;
private static final int REQUEST_QUIET_END = 10002;
private static final int REQUEST_DEFAULT_REMIND = 10003;
private static final int REQUEST_BADGE_LIST = 10004;
@Inject Device device;
@Inject ActivityPermissionRequestor permissionRequestor;
@Inject PermissionChecker permissionChecker;
@Inject Badger badger;
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject LocalBroadcastManager localBroadcastManager;
private CheckBoxPreference fieldMissedCalls;
@ -84,6 +94,28 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
return true;
});
findPreference(R.string.p_badges_enabled).setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue != null) {
boolean enabled = (boolean) newValue;
badger.setEnabled(enabled);
if (enabled) {
showRestartDialog();
}
return true;
}
return false;
});
Preference badgePreference = findPreference(getString(R.string.p_badge_list));
Filter filter = defaultFilterProvider.getBadgeFilter();
badgePreference.setSummary(filter.listingTitle);
badgePreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(ReminderPreferences.this, FilterSelectionActivity.class);
intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
startActivityForResult(intent, REQUEST_BADGE_LIST);
return true;
});
requires(device.supportsLocationServices(), R.string.geolocation_reminders);
requires(atLeastOreo(), R.string.notification_channel_settings);
requires(atLeastMarshmallow(), R.string.battery_optimization_settings);
@ -179,6 +211,13 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
if (resultCode == RESULT_OK) {
getDefaultRemindTimePreference().handleTimePickerActivityIntent(data);
}
} else if (requestCode == REQUEST_BADGE_LIST) {
if (resultCode == RESULT_OK) {
Filter filter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
defaultFilterProvider.setBadgeFilter(filter);
findPreference(getString(R.string.p_badge_list)).setSummary(filter.listingTitle);
localBroadcastManager.broadcastRefresh();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}

@ -1,6 +1,7 @@
package org.tasks.injection;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.Preference;
@ -12,24 +13,31 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.jakewharton.processphoenix.ProcessPhoenix;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.api.Filter;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.locale.Locale;
import org.tasks.preferences.AppCompatPreferenceActivity;
import org.tasks.themes.Theme;
import org.tasks.ui.MenuColorizer;
import javax.inject.Inject;
import timber.log.Timber;
public abstract class InjectingPreferenceActivity extends AppCompatPreferenceActivity implements InjectingActivity {
private ActivityComponent activityComponent;
private Toolbar toolbar;
protected InjectingPreferenceActivity() {
Locale.getInstance(this).applyOverrideConfiguration(this);
}
@Inject DialogBuilder dialogBuilder;
@Override
public void onCreate(Bundle savedInstanceState) {
activityComponent = ((InjectingApplication) getApplication())
@ -51,7 +59,7 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
toolbarContainer.addView(content);
root.addView(toolbarContainer);
toolbar = toolbarContainer.findViewById(R.id.toolbar);
Toolbar toolbar = toolbarContainer.findViewById(R.id.toolbar);
try {
ComponentName componentName = new ComponentName(this, getClass());
ActivityInfo activityInfo = getPackageManager().getActivityInfo(componentName, 0);
@ -107,4 +115,16 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
//noinspection deprecation
return super.findPreference(key);
}
protected void showRestartDialog() {
dialogBuilder.newDialog()
.setMessage(R.string.restart_required)
.setPositiveButton(R.string.restart_now, (dialogInterface, i) -> {
Intent nextIntent = new Intent(InjectingPreferenceActivity.this, TaskListActivity.class);
nextIntent.putExtra(TaskListActivity.OPEN_FILTER, (Filter) null);
ProcessPhoenix.triggerRebirth(InjectingPreferenceActivity.this, nextIntent);
})
.setNegativeButton(R.string.restart_later, null)
.show();
}
}

@ -8,17 +8,12 @@ import android.preference.Preference;
import android.preference.TwoStatePreference;
import com.google.common.base.Strings;
import com.jakewharton.processphoenix.ProcessPhoenix;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.OldTaskPreferences;
import com.todoroo.astrid.reminders.ReminderPreferences;
import org.tasks.BuildConfig;
import org.tasks.LocalBroadcastManager;
import org.tasks.R;
import org.tasks.activities.ColorPickerActivity;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.billing.PurchaseHelper;
@ -30,7 +25,6 @@ import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.locale.Locale;
import org.tasks.locale.LocalePickerDialog;
import org.tasks.receivers.Badger;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeCache;
@ -63,7 +57,6 @@ public class BasicPreferences extends InjectingPreferenceActivity implements
private static final int REQUEST_CODE_BACKUP_DIR = 10005;
private static final int REQUEST_PICKER = 10006;
public static final int REQUEST_PURCHASE = 10007;
private static final int REQUEST_BADGE_LIST = 10008;
@Inject Tracker tracker;
@Inject Preferences preferences;
@ -73,10 +66,7 @@ public class BasicPreferences extends InjectingPreferenceActivity implements
@Inject DialogBuilder dialogBuilder;
@Inject Locale locale;
@Inject ThemeCache themeCache;
@Inject Badger badger;
@Inject PurchaseHelper purchaseHelper;
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject LocalBroadcastManager localBroadcastManager;
private Bundle result;
@ -157,28 +147,6 @@ public class BasicPreferences extends InjectingPreferenceActivity implements
return false;
});
Preference defaultList = findPreference(getString(R.string.p_badge_list));
Filter filter = defaultFilterProvider.getBadgeFilter();
defaultList.setSummary(filter.listingTitle);
defaultList.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(BasicPreferences.this, FilterSelectionActivity.class);
intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
startActivityForResult(intent, REQUEST_BADGE_LIST);
return true;
});
findPreference(R.string.p_badges_enabled).setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue != null) {
boolean enabled = (boolean) newValue;
badger.setEnabled(enabled);
if (enabled) {
showRestartDialog();
}
return true;
}
return false;
});
findPreference(R.string.p_purchased_tasker).setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_tasker)) {
purchaseHelper.purchase(BasicPreferences.this, getString(R.string.sku_tasker), getString(R.string.p_purchased_tasker), REQUEST_PURCHASE, BasicPreferences.this);
@ -291,13 +259,6 @@ public class BasicPreferences extends InjectingPreferenceActivity implements
}
} else if (requestCode == REQUEST_PURCHASE) {
purchaseHelper.handleActivityResult(this, requestCode, resultCode, data);
} else if (requestCode == REQUEST_BADGE_LIST) {
if (resultCode == RESULT_OK) {
Filter filter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
defaultFilterProvider.setBadgeFilter(filter);
findPreference(getString(R.string.p_badge_list)).setSummary(filter.listingTitle);
localBroadcastManager.broadcastRefresh();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
@ -318,18 +279,6 @@ public class BasicPreferences extends InjectingPreferenceActivity implements
}
}
private void showRestartDialog() {
dialogBuilder.newDialog()
.setMessage(R.string.restart_required)
.setPositiveButton(R.string.restart_now, (dialogInterface, i) -> {
Intent nextIntent = new Intent(BasicPreferences.this, TaskListActivity.class);
nextIntent.putExtra(TaskListActivity.OPEN_FILTER, (Filter) null);
ProcessPhoenix.triggerRebirth(BasicPreferences.this, nextIntent);
})
.setNegativeButton(R.string.restart_later, null)
.show();
}
private void updateLocale() {
Preference languagePreference = findPreference(getString(R.string.p_language));
String preference = preferences.getStringValue(R.string.p_language);

@ -446,7 +446,6 @@
<string name="notification_disable_battery_optimizations_description">Оптимизациите на батерията могат да забавят уведомленията</string>
<string name="bundle_notifications">Обединяване на уведомленията</string>
<string name="badges">Значки</string>
<string name="launcher_support_required">Изисква се поддръжка от лаунчера</string>
<string name="list">Списък</string>
<string name="repeats_from">Повтаряй от</string>
<string name="repeats_single">Повтаряй %s</string>

@ -440,7 +440,6 @@
<string name="notification_disable_battery_optimizations_description">Optimizaciones de batería pueden retrasar notificaciones</string>
<string name="bundle_notifications">Agrupar notificaciones</string>
<string name="badges">Insignias</string>
<string name="launcher_support_required">Se requiere soporte de launcher</string>
<string name="list">Lista</string>
<string name="repeats_minutely">cada minuto</string>
<string name="repeats_hourly">cada hora</string>

@ -424,7 +424,6 @@
<string name="battery_optimization_settings">Gérer les optimisations de la batterie</string>
<string name="notification_disable_battery_optimizations_description">Optimisations de la batterie avec des notifications par délais</string>
<string name="bundle_notifications">Paquet de notifications</string>
<string name="launcher_support_required">Support d\'un lanceur requis</string>
<string name="list">Liste</string>
<string name="repeats_from">Répétitions depuis</string>
<string name="repeats_single">Répétitions %s</string>

@ -446,7 +446,6 @@
<string name="notification_disable_battery_optimizations_description">Az akkumulátor optimalizálási funkciók késleltethetik az értesítéseket</string>
<string name="bundle_notifications">Értesítések összevonása</string>
<string name="badges">Szimbólumok</string>
<string name="launcher_support_required">Launcher támogatás szükséges</string>
<string name="list">Lista</string>
<string name="repeats_minutely">percenként</string>
<string name="repeats_hourly">óránként</string>

@ -380,6 +380,5 @@
<string name="notification_disable_battery_optimizations_description">L\'ottimizzazione consumi può ritardare le notifiche</string>
<string name="bundle_notifications">Gruppo di notifiche</string>
<string name="badges">Badge</string>
<string name="launcher_support_required">Richiesto il supporto al lanciatore</string>
<string name="list">Lista</string>
</resources>

@ -444,7 +444,6 @@
<string name="notification_disable_battery_optimizations_description">バッテリー最適化をすると通知が遅れることがあります</string>
<string name="bundle_notifications">バンドル通知</string>
<string name="badges">バッジ</string>
<string name="launcher_support_required">ランチャーサポートが必要です</string>
<string name="list">リスト</string>
<string name="repeats_from">繰り返し開始</string>
<string name="repeats_single">%s を繰り返し</string>

@ -448,7 +448,6 @@
<string name="notification_disable_battery_optimizations_description">배터리 최적화 시 알림이 지연될 수 있습니다. </string>
<string name="bundle_notifications">여러 알림 하나로 묶어서 보기</string>
<string name="badges">배지</string>
<string name="launcher_support_required">런처 지원을 필요로 합니다.</string>
<string name="list">목록</string>
<string name="repeats_from">부터 반복</string>
<string name="repeats_single">%s 반복</string>

@ -434,7 +434,6 @@
<string name="notification_disable_battery_optimizations_description">Batterij optimalisatie kan meldingen vertragen</string>
<string name="bundle_notifications">Notificaties samenvoegen</string>
<string name="badges">Sets</string>
<string name="launcher_support_required">Launcher ondersteuning vereist</string>
<string name="list">Lijst</string>
<string name="repeats_from">Herhalen van</string>
<string name="repeats_single">Herhalen %s</string>

@ -400,6 +400,5 @@
<string name="notification_disable_battery_optimizations_description">Оптимизация расхода может задерживать уведомления</string>
<string name="bundle_notifications">Перечень уведомлений</string>
<string name="badges">Бейджи</string>
<string name="launcher_support_required">Требуется поддержка оболочки</string>
<string name="list">Список</string>
</resources>

@ -408,6 +408,5 @@
<string name="battery_optimization_settings">Pil optimizasyonlarını yönet</string>
<string name="notification_disable_battery_optimizations_description">Pil optimizasyonları bildirimleri geciktirebilir</string>
<string name="badges">İşaretler</string>
<string name="launcher_support_required">Başlatıcı desteği gerekiyor</string>
<string name="list">Liste</string>
</resources>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="default_bundle_notifications">true</bool>
</resources>

@ -3,4 +3,5 @@
<bool name="two_pane_layout">false</bool>
<bool name="location_enabled">false</bool>
<bool name="google_play_store_available">false</bool>
<bool name="default_bundle_notifications">false</bool>
</resources>

@ -835,7 +835,6 @@ File %1$s contained %2$s.\n\n
<string name="notification_disable_battery_optimizations_description">Battery optimizations may delay notifications</string>
<string name="bundle_notifications">Bundle notifications</string>
<string name="badges">Badges</string>
<string name="launcher_support_required">Launcher support required</string>
<string name="list">List</string>
<string name="repeats_from">Repeats from</string>
<string name="repeats_single">Repeats %s</string>
@ -859,4 +858,6 @@ File %1$s contained %2$s.\n\n
<string name="list_separator_with_space">,\u0020</string>
<string name="dont_add_to_calendar">Don\'t add to calendar</string>
<string name="default_calendar">Default calendar</string>
<string name="badges_description">Display a task count on Tasks launcher icon. Not all launchers support badges.</string>
<string name="bundle_notifications_summary">Combine multiple notifications into a single notification</string>
</resources>

@ -61,19 +61,6 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/badges">
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/p_badges_enabled"
android:title="@string/enabled"
android:summary="@string/launcher_support_required" />
<com.todoroo.astrid.ui.MultilinePreference
android:dependency="@string/p_badges_enabled"
android:key="@string/p_badge_list"
android:title="@string/list" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/backup_BPr_header">

@ -36,10 +36,11 @@
android:summary="@string/persistent_notifications_description"
android:title="@string/persistent_notifications" />
<CheckBoxPreference
android:defaultValue="true"
android:defaultValue="@bool/default_bundle_notifications"
android:dependency="@string/p_rmd_enabled"
android:key="@string/p_bundle_notifications"
android:title="@string/bundle_notifications" />
android:title="@string/bundle_notifications"
android:summary="@string/bundle_notifications_summary" />
<CheckBoxPreference
android:defaultValue="true"
android:dependency="@string/p_rmd_enabled"
@ -63,6 +64,18 @@
android:title="@string/rmd_EPr_rmd_time_title"
tasks:summary="@string/rmd_EPr_rmd_time_desc" />
<PreferenceCategory android:title="@string/badges">
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/p_badges_enabled"
android:title="@string/enabled"
android:summary="@string/badges_description" />
<com.todoroo.astrid.ui.MultilinePreference
android:dependency="@string/p_badges_enabled"
android:key="@string/p_badge_list"
android:title="@string/list" />
</PreferenceCategory>
<PreferenceCategory
android:key="@string/geolocation_reminders"
android:title="@string/geolocation_reminders">

Loading…
Cancel
Save