From 650d0e0ea75acac900e4c04ecace50a23897df19 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Fri, 26 Oct 2018 10:41:40 -0500 Subject: [PATCH] Fix date and time picker theme issues --- app/build.gradle | 4 +--- .../tasks/activities/DateAndTimePickerActivity.java | 3 ++- .../org/tasks/activities/DatePickerActivity.java | 12 +++++------- .../org/tasks/activities/TimePickerActivity.java | 3 ++- .../org/tasks/dialogs/NativeDatePickerDialog.java | 5 ++++- .../org/tasks/dialogs/NativeTimePickerDialog.java | 3 ++- app/src/main/res/values-night/styles.xml | 2 +- app/src/main/res/values/styles.xml | 3 ++- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 47431b267..700654752 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -160,9 +160,7 @@ dependencies { implementation('org.scala-saddle:google-rfc-2445:20110304') { transitive = false } - implementation('com.wdullaer:materialdatetimepicker:3.6.1') { - exclude group: 'com.android.support', module: 'support-v4' - } + implementation('com.wdullaer:materialdatetimepicker:4.0.1') implementation "me.leolin:ShortcutBadger:1.1.22@aar" implementation 'com.google.apis:google-api-services-tasks:v1-rev52-1.23.0' implementation 'com.google.api-client:google-api-client-android:1.23.0' diff --git a/app/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java b/app/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java index f0f5335a3..baa293571 100644 --- a/app/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java +++ b/app/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java @@ -47,12 +47,13 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity } } - FragmentManager fragmentManager = getFragmentManager(); if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { + FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { newNativeDatePickerDialog(initial).show(fragmentManager, FRAG_TAG_DATE_PICKER); } } else { + androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager(); MyDatePickerDialog datePickerDialog = (MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER); if (datePickerDialog == null) { diff --git a/app/src/main/java/org/tasks/activities/DatePickerActivity.java b/app/src/main/java/org/tasks/activities/DatePickerActivity.java index 11984ad8f..141528ddf 100644 --- a/app/src/main/java/org/tasks/activities/DatePickerActivity.java +++ b/app/src/main/java/org/tasks/activities/DatePickerActivity.java @@ -3,14 +3,14 @@ package org.tasks.activities; import static org.tasks.dialogs.NativeDatePickerDialog.newNativeDatePickerDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; -import android.app.FragmentManager; import android.content.Intent; import android.os.Bundle; +import androidx.fragment.app.FragmentManager; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; import javax.inject.Inject; import org.tasks.R; import org.tasks.dialogs.MyDatePickerDialog; -import org.tasks.dialogs.NativeDatePickerDialog; +import org.tasks.dialogs.NativeDatePickerDialog.NativeDatePickerDialogCallback; import org.tasks.injection.ActivityComponent; import org.tasks.injection.InjectingAppCompatActivity; import org.tasks.preferences.Preferences; @@ -19,8 +19,7 @@ import org.tasks.themes.ThemeBase; import org.tasks.time.DateTime; public class DatePickerActivity extends InjectingAppCompatActivity - implements DatePickerDialog.OnDateSetListener, - NativeDatePickerDialog.NativeDatePickerDialogCallback { + implements DatePickerDialog.OnDateSetListener, NativeDatePickerDialogCallback { public static final String EXTRA_TIMESTAMP = "extra_timestamp"; private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker"; @@ -31,17 +30,16 @@ public class DatePickerActivity extends InjectingAppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - long timestamp = getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()); DateTime initial = (timestamp > 0 ? new DateTime(timestamp) : new DateTime()).startOfDay(); - FragmentManager fragmentManager = getFragmentManager(); - if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { + android.app.FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { newNativeDatePickerDialog(initial).show(fragmentManager, FRAG_TAG_DATE_PICKER); } } else { + FragmentManager fragmentManager = getSupportFragmentManager(); MyDatePickerDialog dialog = (MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER); if (dialog == null) { diff --git a/app/src/main/java/org/tasks/activities/TimePickerActivity.java b/app/src/main/java/org/tasks/activities/TimePickerActivity.java index 72e1069d0..07e74296e 100644 --- a/app/src/main/java/org/tasks/activities/TimePickerActivity.java +++ b/app/src/main/java/org/tasks/activities/TimePickerActivity.java @@ -37,12 +37,13 @@ public class TimePickerActivity extends InjectingAppCompatActivity initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis())); - FragmentManager fragmentManager = getFragmentManager(); if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { + FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER) == null) { newNativeTimePickerDialog(initial).show(fragmentManager, FRAG_TAG_TIME_PICKER); } } else { + androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager(); MyTimePickerDialog dialog = (MyTimePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER); if (dialog == null) { diff --git a/app/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java b/app/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java index a6300c79d..5b907724a 100644 --- a/app/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java +++ b/app/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java @@ -6,6 +6,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.widget.DatePicker; @@ -47,9 +48,11 @@ public class NativeDatePickerDialog extends InjectingNativeDialogFragment @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments(); + Context context = getActivity(); + theme.applyToContext(context); DatePickerDialog datePickerDialog = new DatePickerDialog( - theme.wrap(getActivity()), + context, this, args.getInt(EXTRA_YEAR), args.getInt(EXTRA_MONTH), diff --git a/app/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java b/app/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java index e8db2d077..ed0c63504 100644 --- a/app/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java +++ b/app/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java @@ -40,8 +40,9 @@ public class NativeTimePickerDialog extends InjectingNativeDialogFragment @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - Context context = theme.wrap(getActivity()); Bundle args = getArguments(); + Context context = getActivity(); + theme.applyToContext(context); TimePickerDialog timePickerDialog = new TimePickerDialog( context, diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 623544c7c..4721abd9b 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -5,5 +5,5 @@ -