From 29c86427925e7927f3e9a52f58fa9ec9d89ea38d Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 15 Mar 2017 09:00:00 -0500 Subject: [PATCH] Add pref for native or 3rd party date pickers --- .../java/org/tasks/activities/DatePickerActivity.java | 8 +++----- .../java/org/tasks/activities/TimePickerActivity.java | 6 ++++-- src/main/java/org/tasks/preferences/Device.java | 4 ---- src/main/res/values/keys.xml | 1 + src/main/res/values/strings.xml | 1 + src/main/res/xml/preferences_date_time.xml | 5 +++++ 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/tasks/activities/DatePickerActivity.java b/src/main/java/org/tasks/activities/DatePickerActivity.java index daec9d99e..a64a95691 100644 --- a/src/main/java/org/tasks/activities/DatePickerActivity.java +++ b/src/main/java/org/tasks/activities/DatePickerActivity.java @@ -6,11 +6,11 @@ import android.os.Bundle; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; +import org.tasks.R; import org.tasks.dialogs.MyDatePickerDialog; 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; @@ -18,8 +18,6 @@ import org.tasks.time.DateTime; import javax.inject.Inject; -import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; -import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow; import static org.tasks.dialogs.NativeDatePickerDialog.newNativeDatePickerDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; @@ -31,7 +29,6 @@ public class DatePickerActivity extends InjectingAppCompatActivity implements Da @Inject ThemeBase themeBase; @Inject ThemeAccent themeAccent; - @Inject Device device; @Inject Preferences preferences; @Override @@ -42,7 +39,8 @@ public class DatePickerActivity extends InjectingAppCompatActivity implements Da DateTime initial = (timestamp > 0 ? new DateTime(timestamp) : new DateTime()).startOfDay(); FragmentManager fragmentManager = getFragmentManager(); - if (atLeastMarshmallow() || (atLeastLollipop() && !device.isBaneOfMyExistence())) { + + if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { newNativeDatePickerDialog(initial) .show(fragmentManager, FRAG_TAG_DATE_PICKER); diff --git a/src/main/java/org/tasks/activities/TimePickerActivity.java b/src/main/java/org/tasks/activities/TimePickerActivity.java index 9ecbafd1d..44d7d8a68 100644 --- a/src/main/java/org/tasks/activities/TimePickerActivity.java +++ b/src/main/java/org/tasks/activities/TimePickerActivity.java @@ -7,17 +7,18 @@ import android.text.format.DateFormat; import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; +import org.tasks.R; import org.tasks.dialogs.MyTimePickerDialog; import org.tasks.dialogs.NativeTimePickerDialog; import org.tasks.injection.ActivityComponent; import org.tasks.injection.InjectingAppCompatActivity; +import org.tasks.preferences.Preferences; import org.tasks.themes.ThemeAccent; import org.tasks.themes.ThemeBase; import org.tasks.time.DateTime; import javax.inject.Inject; -import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; import static org.tasks.dialogs.NativeTimePickerDialog.newNativeTimePickerDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; @@ -30,6 +31,7 @@ public class TimePickerActivity extends InjectingAppCompatActivity implements Ti @Inject ThemeBase themeBase; @Inject ThemeAccent themeAccent; + @Inject Preferences preferences; private DateTime initial; @@ -40,7 +42,7 @@ public class TimePickerActivity extends InjectingAppCompatActivity implements Ti initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis())); FragmentManager fragmentManager = getFragmentManager(); - if (atLeastLollipop()) { + if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { if (fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER) == null) { newNativeTimePickerDialog(initial) .show(fragmentManager, FRAG_TAG_TIME_PICKER); diff --git a/src/main/java/org/tasks/preferences/Device.java b/src/main/java/org/tasks/preferences/Device.java index faf06b012..305259d3b 100644 --- a/src/main/java/org/tasks/preferences/Device.java +++ b/src/main/java/org/tasks/preferences/Device.java @@ -29,10 +29,6 @@ public class Device { this.locale = locale; } - public boolean isBaneOfMyExistence() { - return Build.MANUFACTURER.equalsIgnoreCase("samsung"); - } - public boolean hasCamera() { return context.getPackageManager().queryIntentActivities(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), 0).size() > 0; } diff --git a/src/main/res/values/keys.xml b/src/main/res/values/keys.xml index d52621fe7..afd6c4894 100644 --- a/src/main/res/values/keys.xml +++ b/src/main/res/values/keys.xml @@ -319,5 +319,6 @@ Debug rmd_show_description start_of_week + use_native_datetime_pickers diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index f0fa94e3a..128e1f83e 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -820,4 +820,5 @@ File %1$s contained %2$s.\n\n Date and time Start of week Use locale default + Use native date and time pickers diff --git a/src/main/res/xml/preferences_date_time.xml b/src/main/res/xml/preferences_date_time.xml index e7298ad4e..034ef6916 100644 --- a/src/main/res/xml/preferences_date_time.xml +++ b/src/main/res/xml/preferences_date_time.xml @@ -7,6 +7,11 @@ android:key="@string/p_start_of_week" android:title="@string/start_of_week" /> + +