Start week on Sunday or Monday

pull/511/head^2
Alex Baker 8 years ago
parent 8cc751da99
commit 561b069d8d

@ -127,6 +127,7 @@ dependencies {
compile "com.android.support:support-v13:${SUPPORT_VERSION}"
compile "com.android.support:cardview-v7:${SUPPORT_VERSION}"
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'com.jakewharton.threetenabp:threetenabp:1.0.5'
compile 'com.google.guava:guava:20.0'
compile 'com.jakewharton:process-phoenix:1.1.1'
compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0'

@ -75,17 +75,21 @@ public class Tracker {
}
public void reportEvent(Tracking.Events event, String label) {
reportEvent(event.category, event.action, label);
reportEvent(event, event.action, label);
}
public void reportEvent(Tracking.Events event, int action, String label) {
reportEvent(event, context.getString(action), label);
}
public void reportEvent(Tracking.Events event, String action, String label) {
reportEvent(event.category, action, label);
}
private void reportEvent(int category, int action, String label) {
private void reportEvent(int category, String action, String label) {
HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
.setCategory(context.getString(category))
.setAction(context.getString(action));
.setAction(action);
if (!Strings.isNullOrEmpty(label)) {
eventBuilder.setLabel(label);
}

@ -1,5 +1,6 @@
package org.tasks;
import com.jakewharton.threetenabp.AndroidThreeTen;
import com.todoroo.astrid.service.StartupService;
import org.tasks.analytics.Tracker;
@ -27,6 +28,8 @@ public class Tasks extends InjectingApplication {
tracker.setTrackingEnabled(preferences.isTrackingEnabled());
AndroidThreeTen.init(this);
if (!buildSetup.setup()) {
return;
}

@ -11,6 +11,7 @@ import org.tasks.dialogs.NativeDatePickerDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Device;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.time.DateTime;
@ -31,6 +32,7 @@ public class DatePickerActivity extends InjectingAppCompatActivity implements Da
@Inject ThemeBase themeBase;
@Inject ThemeAccent themeAccent;
@Inject Device device;
@Inject Preferences preferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -53,6 +55,10 @@ public class DatePickerActivity extends InjectingAppCompatActivity implements Da
dialog.setVersion(DatePickerDialog.Version.VERSION_2);
dialog.setThemeDark(themeBase.isDarkTheme(this));
dialog.setAccentColor(themeAccent.getAccentColor());
int firstDayOfWeek = preferences.getFirstDayOfWeek();
if (firstDayOfWeek >= 1 && firstDayOfWeek <= 7) {
dialog.setFirstDayOfWeek(firstDayOfWeek);
}
dialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}
dialog.setOnCancelListener(dialogInterface -> finish());

@ -1,5 +1,6 @@
package org.tasks.dialogs;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
@ -9,11 +10,14 @@ import android.widget.DatePicker;
import org.tasks.injection.InjectingNativeDialogFragment;
import org.tasks.injection.NativeDialogFragmentComponent;
import org.tasks.preferences.Preferences;
import org.tasks.themes.Theme;
import org.tasks.time.DateTime;
import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow;
public class NativeDatePickerDialog extends InjectingNativeDialogFragment implements DatePickerDialog.OnDateSetListener {
private static final String EXTRA_YEAR = "extra_year";
@ -37,6 +41,7 @@ public class NativeDatePickerDialog extends InjectingNativeDialogFragment implem
}
@Inject Theme theme;
@Inject Preferences preferences;
private NativeDatePickerDialogCallback callback;
@ -47,10 +52,15 @@ public class NativeDatePickerDialog extends InjectingNativeDialogFragment implem
setRetainInstance(true);
}
@SuppressLint("NewApi")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
DatePickerDialog datePickerDialog = new DatePickerDialog(theme.wrap(getActivity()), this, args.getInt(EXTRA_YEAR), args.getInt(EXTRA_MONTH), args.getInt(EXTRA_DAY));
int firstDayOfWeek = preferences.getFirstDayOfWeek();
if (firstDayOfWeek >= 1 && firstDayOfWeek <= 7 && atLeastMarshmallow()) {
datePickerDialog.getDatePicker().setFirstDayOfWeek(firstDayOfWeek);
}
datePickerDialog.setTitle("");
return datePickerDialog;
}

@ -2,15 +2,23 @@ package org.tasks.preferences;
import android.content.Intent;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.widget.Toast;
import org.tasks.injection.ActivityComponent;
import org.tasks.time.DateTime;
import org.tasks.R;
import org.tasks.activities.TimePickerActivity;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.locale.Locale;
import org.tasks.time.DateTime;
import org.tasks.ui.TimePreference;
import org.threeten.bp.DayOfWeek;
import org.threeten.bp.format.TextStyle;
import javax.inject.Inject;
public class DateTimePreferences extends InjectingPreferenceActivity implements Preference.OnPreferenceChangeListener {
@ -19,16 +27,38 @@ public class DateTimePreferences extends InjectingPreferenceActivity implements
private static final int REQUEST_EVENING = 10003;
private static final int REQUEST_NIGHT = 10004;
@Inject Locale locale;
@Inject Preferences preferences;
@Inject Tracker tracker;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences_date_time);
ListPreference startOfWeekPreference = getStartOfWeekPreference();
startOfWeekPreference.setEntries(getWeekdayEntries());
startOfWeekPreference.setOnPreferenceChangeListener(this);
initializeTimePreference(getMorningPreference(), REQUEST_MORNING);
initializeTimePreference(getAfternoonPreference(), REQUEST_AFTERNOON);
initializeTimePreference(getEveningPreference(), REQUEST_EVENING);
initializeTimePreference(getNightPreference(), REQUEST_NIGHT);
updateStartOfWeek(preferences.getStringValue(R.string.p_start_of_week));
}
String[] getWeekdayEntries() {
return new String[] {
getString(R.string.use_locale_default),
getWeekdayDisplayName(DayOfWeek.SUNDAY),
getWeekdayDisplayName(DayOfWeek.MONDAY)
};
}
private String getWeekdayDisplayName(DayOfWeek dayOfWeek) {
return dayOfWeek.getDisplayName(TextStyle.FULL, locale.getLocale());
}
private TimePreference getMorningPreference() {
@ -85,38 +115,42 @@ public class DateTimePreferences extends InjectingPreferenceActivity implements
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int millisOfDay = (int) newValue;
if (preference.equals(getMorningPreference())) {
if (millisOfDay >= getAfternoonPreference().getMillisOfDay()) {
mustComeBefore(R.string.date_shortcut_morning, R.string.date_shortcut_afternoon);
} else {
return true;
}
} else if (preference.equals(getAfternoonPreference())) {
if (millisOfDay <= getMorningPreference().getMillisOfDay()) {
mustComeAfter(R.string.date_shortcut_afternoon, R.string.date_shortcut_morning);
} else if (millisOfDay >= getEveningPreference().getMillisOfDay()) {
mustComeBefore(R.string.date_shortcut_afternoon, R.string.date_shortcut_evening);
} else {
return true;
}
} else if (preference.equals(getEveningPreference())) {
if (millisOfDay <= getAfternoonPreference().getMillisOfDay()) {
mustComeAfter(R.string.date_shortcut_evening, R.string.date_shortcut_afternoon);
} else if (millisOfDay >= getNightPreference().getMillisOfDay()) {
mustComeBefore(R.string.date_shortcut_evening, R.string.date_shortcut_night);
} else {
return true;
}
} else if (preference.equals(getNightPreference())) {
if (millisOfDay <= getEveningPreference().getMillisOfDay()) {
mustComeAfter(R.string.date_shortcut_night, R.string.date_shortcut_evening);
} else {
return true;
if (preference.equals(getStartOfWeekPreference())) {
updateStartOfWeek(newValue.toString());
} else {
int millisOfDay = (int) newValue;
if (preference.equals(getMorningPreference())) {
if (millisOfDay >= getAfternoonPreference().getMillisOfDay()) {
mustComeBefore(R.string.date_shortcut_morning, R.string.date_shortcut_afternoon);
return false;
}
} else if (preference.equals(getAfternoonPreference())) {
if (millisOfDay <= getMorningPreference().getMillisOfDay()) {
mustComeAfter(R.string.date_shortcut_afternoon, R.string.date_shortcut_morning);
return false;
} else if (millisOfDay >= getEveningPreference().getMillisOfDay()) {
mustComeBefore(R.string.date_shortcut_afternoon, R.string.date_shortcut_evening);
return false;
}
} else if (preference.equals(getEveningPreference())) {
if (millisOfDay <= getAfternoonPreference().getMillisOfDay()) {
mustComeAfter(R.string.date_shortcut_evening, R.string.date_shortcut_afternoon);
return false;
} else if (millisOfDay >= getNightPreference().getMillisOfDay()) {
mustComeBefore(R.string.date_shortcut_evening, R.string.date_shortcut_night);
return false;
}
} else if (preference.equals(getNightPreference())) {
if (millisOfDay <= getEveningPreference().getMillisOfDay()) {
mustComeAfter(R.string.date_shortcut_night, R.string.date_shortcut_evening);
return false;
}
}
}
return false;
tracker.reportEvent(Tracking.Events.SET_PREFERENCE, preference.getKey(), newValue.toString());
return true;
}
private void mustComeBefore(int settingResId, int relativeResId) {
@ -134,6 +168,17 @@ public class DateTimePreferences extends InjectingPreferenceActivity implements
.show();
}
private void updateStartOfWeek(String value) {
ListPreference preference = getStartOfWeekPreference();
int index = preference.findIndexOfValue(value);
String summary = getWeekdayEntries()[index];
preference.setSummary(summary);
}
private ListPreference getStartOfWeekPreference() {
return (ListPreference) findPreference(R.string.p_start_of_week);
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);

@ -104,6 +104,11 @@ public class Preferences {
return atLeastMarshmallow() && getBoolean(R.string.p_doze_notifications, false);
}
public int getFirstDayOfWeek() {
int firstDayOfWeek = getIntegerFromString(R.string.p_start_of_week, 0);
return firstDayOfWeek < 1 || firstDayOfWeek > 7 ? 0 : firstDayOfWeek;
}
public void clear() {
prefs
.edit()

@ -201,6 +201,5 @@
<string name="master_sync_warning">المزامنة التلقائية معطلة الآن من طرف أندرويد</string>
<string name="settings_localization">تخصيص اللغة و الجهة</string>
<string name="layout_direction">إتجاه التنسيق</string>
<string name="layout_direction_locale">إستخدام الإتجاه المحلي</string>
<string name="layout_direction_left_to_right">من اليمين إلى اليسار</string>
</resources>

@ -396,7 +396,6 @@
<string name="restart_later">По-късно</string>
<string name="settings_localization">Локализация</string>
<string name="layout_direction">Направление на изгледа</string>
<string name="layout_direction_locale">Използвай направление според местополжението</string>
<string name="layout_direction_left_to_right">Отляво надясно</string>
<string name="layout_direction_right_to_left">Отдясно наляво</string>
<string name="led_notification">LED нотификация</string>

@ -342,7 +342,6 @@
<string name="restart_later">Později</string>
<string name="settings_localization">Překlad</string>
<string name="layout_direction">Orientace</string>
<string name="layout_direction_locale">Použít lokální směr</string>
<string name="layout_direction_left_to_right">Zleva do prava</string>
<string name="layout_direction_right_to_left">Zprava do leva</string>
<string name="led_color">Barva LED</string>

@ -384,7 +384,6 @@
<string name="restart_later">Später</string>
<string name="settings_localization">Übersetzung</string>
<string name="layout_direction">Schreibrichtung</string>
<string name="layout_direction_locale">Aus Systemeinstellungen</string>
<string name="layout_direction_left_to_right">Links nach rechts</string>
<string name="layout_direction_right_to_left">Rechts nach links</string>
<string name="led_notification">Benachrichtigungs-LED</string>

@ -390,7 +390,6 @@
<string name="restart_later">Más tarde</string>
<string name="settings_localization">Configuración regional</string>
<string name="layout_direction">Sentido de la escritura</string>
<string name="layout_direction_locale">Usar disposición regional</string>
<string name="layout_direction_left_to_right">De izquierda a derecha</string>
<string name="layout_direction_right_to_left">De derecha a izquierda</string>
<string name="led_notification">Notificación de la LED</string>

@ -271,7 +271,6 @@
<string name="language">زبان</string>
<string name="settings_localization">محلی‌سازی</string>
<string name="layout_direction">چینش صفحه</string>
<string name="layout_direction_locale">از چینش محلی استفاده کن</string>
<string name="layout_direction_left_to_right">چپ به راست</string>
<string name="layout_direction_right_to_left">راست به چپ</string>
</resources>

@ -395,7 +395,6 @@
<string name="restart_later">Myöhemmin</string>
<string name="settings_localization">Paikallistaminen</string>
<string name="layout_direction">Asettelun suunta</string>
<string name="layout_direction_locale">Käytä paikallista asetusta</string>
<string name="layout_direction_left_to_right">Vasemmalta oikealle</string>
<string name="layout_direction_right_to_left">Oikealta vasemmalle</string>
<string name="led_notification">LED muistutus</string>

@ -382,7 +382,6 @@
<string name="restart_later">Plus tard</string>
<string name="settings_localization">Localisation</string>
<string name="layout_direction">Direction de lecture</string>
<string name="layout_direction_locale">Utiliser les directions locales</string>
<string name="layout_direction_left_to_right">Gauche à droite</string>
<string name="layout_direction_right_to_left">Droite à gauche</string>
<string name="led_notification">Notification de la LED</string>

@ -390,7 +390,6 @@
<string name="restart_later">Más tarde</string>
<string name="settings_localization">Configuración regional</string>
<string name="layout_direction">Sentido de la escritura</string>
<string name="layout_direction_locale">Usar disposición regional</string>
<string name="layout_direction_left_to_right">De izquierda a derecha</string>
<string name="layout_direction_right_to_left">De derecha a izquierda</string>
<string name="led_notification">Notificación de la LED</string>

@ -396,7 +396,6 @@
<string name="restart_later">Később</string>
<string name="settings_localization">Lokalizáció</string>
<string name="layout_direction">Szövegirány</string>
<string name="layout_direction_locale">Nyelv alapértelmezés használata</string>
<string name="layout_direction_left_to_right">Balról jobbra</string>
<string name="layout_direction_right_to_left">Jobbról balra</string>
<string name="led_notification">LED értesítés</string>

@ -393,7 +393,6 @@
<string name="restart_later">Dopo</string>
<string name="settings_localization">Localizzazione</string>
<string name="layout_direction">Direzione Layout</string>
<string name="layout_direction_locale">Utilizza la direzione locale</string>
<string name="layout_direction_left_to_right">Da sinistra a destra</string>
<string name="layout_direction_right_to_left">Da destra a sinistra</string>
<string name="led_notification">LED di notifica</string>

@ -394,7 +394,6 @@
<string name="restart_later">מאוחר יותר</string>
<string name="settings_localization">לוקאליזציה</string>
<string name="layout_direction">כיוון הממשק</string>
<string name="layout_direction_locale">לפי השפה</string>
<string name="layout_direction_left_to_right">משמאל לימין</string>
<string name="layout_direction_right_to_left">מימין לשמאל</string>
<string name="led_notification">תאורת התראות</string>

@ -394,7 +394,6 @@
<string name="restart_later">後で</string>
<string name="settings_localization">ローカライズ</string>
<string name="layout_direction">レイアウトの向き</string>
<string name="layout_direction_locale">ロケールの向きを使用する</string>
<string name="layout_direction_left_to_right">左から右</string>
<string name="layout_direction_right_to_left">右から左</string>
<string name="led_notification">LED 通知</string>

@ -384,7 +384,6 @@
<string name="restart_now">Herstart nu</string>
<string name="settings_localization">Vertalingen</string>
<string name="layout_direction">Layout richting</string>
<string name="layout_direction_locale">Gebruik lokale richting</string>
<string name="layout_direction_left_to_right">Links naar rechts</string>
<string name="layout_direction_right_to_left">Rechts naar links</string>
<string name="led_notification">LED notificatie</string>

@ -392,7 +392,6 @@
<string name="restart_later">Póżniej</string>
<string name="settings_localization">Ustawienia regionalne</string>
<string name="layout_direction">Kierunek tekstów</string>
<string name="layout_direction_locale">Użyj lokalnych ustawień</string>
<string name="layout_direction_left_to_right">Od lewa do prawa</string>
<string name="layout_direction_right_to_left">Od prawa do lewa</string>
<string name="led_notification">Powiadomienie LED</string>

@ -393,7 +393,6 @@
<string name="restart_later">Позже</string>
<string name="settings_localization">Локализация</string>
<string name="layout_direction">Ориентация интерфейса</string>
<string name="layout_direction_locale">Как в системе</string>
<string name="layout_direction_left_to_right">Слева направо</string>
<string name="layout_direction_right_to_left">Справа налево</string>
<string name="led_notification">LED уведомления</string>

@ -25,7 +25,6 @@
<string name="default_priority">Podrazumevano</string>
<string name="low_priority">Nisak</string>
<string name="layout_direction">Raspored komandi</string>
<string name="layout_direction_locale">Koristi sistemski raspored komandi</string>
<string name="layout_direction_left_to_right">Sleva nadesno</string>
<string name="layout_direction_right_to_left">Zdesna nalevo</string>
</resources>

@ -383,7 +383,6 @@
<string name="restart_now">Starta om nu</string>
<string name="restart_later">Senare</string>
<string name="settings_localization">Språk</string>
<string name="layout_direction_locale">Använd språkets standard</string>
<string name="layout_direction_left_to_right">Vänster till höger</string>
<string name="layout_direction_right_to_left">Höger till vänster</string>
<string name="led_notification">LED Notifiering</string>

@ -396,7 +396,6 @@
<string name="restart_later">Пізніше</string>
<string name="settings_localization">Локалізація</string>
<string name="layout_direction">Напрям письма</string>
<string name="layout_direction_locale">Використовувати напрям пристрою</string>
<string name="layout_direction_left_to_right">Зліва направо</string>
<string name="layout_direction_right_to_left">Зправа наліво</string>
<string name="led_notification">LED-сповіщення</string>

@ -245,7 +245,6 @@
<string name="settings_general">一般</string>
<string name="language">語言</string>
<string name="layout_direction">排版方向</string>
<string name="layout_direction_locale">使用當地方向</string>
<string name="layout_direction_left_to_right">由左至右</string>
<string name="layout_direction_right_to_left">由右至左</string>
<string name="led_color">LED 顏色</string>

@ -185,7 +185,7 @@
</string-array>
<string-array name="layout_direction_entries">
<item>@string/layout_direction_locale</item>
<item>@string/use_locale_default</item>
<item>@string/layout_direction_left_to_right</item>
<item>@string/layout_direction_right_to_left</item>
</string-array>
@ -253,4 +253,10 @@
<item>@string/repeat_type_due</item>
<item>@string/repeat_type_completion</item>
</string-array>
<string-array name="day_of_week_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

@ -318,5 +318,6 @@
<string name="debug_consume_purchases">Consume purchases</string>
<string name="debug">Debug</string>
<string name="p_rmd_show_description">rmd_show_description</string>
<string name="p_start_of_week">start_of_week</string>
</resources>

@ -797,7 +797,6 @@ File %1$s contained %2$s.\n\n
<string name="restart_later">Later</string>
<string name="settings_localization">Localization</string>
<string name="layout_direction">Layout direction</string>
<string name="layout_direction_locale">Use locale direction</string>
<string name="layout_direction_left_to_right">Left to right</string>
<string name="layout_direction_right_to_left">Right to left</string>
<string name="led_notification">LED notification</string>
@ -819,5 +818,6 @@ File %1$s contained %2$s.\n\n
<string name="delete_selected_tasks">Delete selected tasks?</string>
<string name="copy_selected_tasks">Copy selected tasks?</string>
<string name="date_and_time">Date and time</string>
<string name="start_of_week">Start of week</string>
<string name="use_locale_default">Use locale default</string>
</resources>

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:defaultValue="0"
android:entryValues="@array/day_of_week_values"
android:key="@string/p_start_of_week"
android:title="@string/start_of_week" />
<org.tasks.ui.TimePreference
android:defaultValue="@integer/default_morning"
android:key="@string/p_date_shortcut_morning"

Loading…
Cancel
Save