Fix date and time picker theme issues

pull/757/head
Alex Baker 6 years ago
parent 0538744004
commit 650d0e0ea7

@ -160,9 +160,7 @@ dependencies {
implementation('org.scala-saddle:google-rfc-2445:20110304') { implementation('org.scala-saddle:google-rfc-2445:20110304') {
transitive = false transitive = false
} }
implementation('com.wdullaer:materialdatetimepicker:3.6.1') { implementation('com.wdullaer:materialdatetimepicker:4.0.1')
exclude group: 'com.android.support', module: 'support-v4'
}
implementation "me.leolin:ShortcutBadger:1.1.22@aar" implementation "me.leolin:ShortcutBadger:1.1.22@aar"
implementation 'com.google.apis:google-api-services-tasks:v1-rev52-1.23.0' 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' implementation 'com.google.api-client:google-api-client-android:1.23.0'

@ -47,12 +47,13 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity
} }
} }
FragmentManager fragmentManager = getFragmentManager();
if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) {
newNativeDatePickerDialog(initial).show(fragmentManager, FRAG_TAG_DATE_PICKER); newNativeDatePickerDialog(initial).show(fragmentManager, FRAG_TAG_DATE_PICKER);
} }
} else { } else {
androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager();
MyDatePickerDialog datePickerDialog = MyDatePickerDialog datePickerDialog =
(MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER); (MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER);
if (datePickerDialog == null) { if (datePickerDialog == null) {

@ -3,14 +3,14 @@ package org.tasks.activities;
import static org.tasks.dialogs.NativeDatePickerDialog.newNativeDatePickerDialog; import static org.tasks.dialogs.NativeDatePickerDialog.newNativeDatePickerDialog;
import static org.tasks.time.DateTimeUtils.currentTimeMillis; import static org.tasks.time.DateTimeUtils.currentTimeMillis;
import android.app.FragmentManager;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.MyDatePickerDialog; 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.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity; import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
@ -19,8 +19,7 @@ import org.tasks.themes.ThemeBase;
import org.tasks.time.DateTime; import org.tasks.time.DateTime;
public class DatePickerActivity extends InjectingAppCompatActivity public class DatePickerActivity extends InjectingAppCompatActivity
implements DatePickerDialog.OnDateSetListener, implements DatePickerDialog.OnDateSetListener, NativeDatePickerDialogCallback {
NativeDatePickerDialog.NativeDatePickerDialogCallback {
public static final String EXTRA_TIMESTAMP = "extra_timestamp"; public static final String EXTRA_TIMESTAMP = "extra_timestamp";
private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker"; private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker";
@ -31,17 +30,16 @@ public class DatePickerActivity extends InjectingAppCompatActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
long timestamp = getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()); long timestamp = getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis());
DateTime initial = (timestamp > 0 ? new DateTime(timestamp) : new DateTime()).startOfDay(); DateTime initial = (timestamp > 0 ? new DateTime(timestamp) : new DateTime()).startOfDay();
FragmentManager fragmentManager = getFragmentManager();
if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) {
android.app.FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) {
newNativeDatePickerDialog(initial).show(fragmentManager, FRAG_TAG_DATE_PICKER); newNativeDatePickerDialog(initial).show(fragmentManager, FRAG_TAG_DATE_PICKER);
} }
} else { } else {
FragmentManager fragmentManager = getSupportFragmentManager();
MyDatePickerDialog dialog = MyDatePickerDialog dialog =
(MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER); (MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER);
if (dialog == null) { if (dialog == null) {

@ -37,12 +37,13 @@ public class TimePickerActivity extends InjectingAppCompatActivity
initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis())); initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()));
FragmentManager fragmentManager = getFragmentManager();
if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) { if (preferences.getBoolean(R.string.p_use_native_datetime_pickers, false)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER) == null) { if (fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER) == null) {
newNativeTimePickerDialog(initial).show(fragmentManager, FRAG_TAG_TIME_PICKER); newNativeTimePickerDialog(initial).show(fragmentManager, FRAG_TAG_TIME_PICKER);
} }
} else { } else {
androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager();
MyTimePickerDialog dialog = MyTimePickerDialog dialog =
(MyTimePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER); (MyTimePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER);
if (dialog == null) { if (dialog == null) {

@ -6,6 +6,7 @@ import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.widget.DatePicker; import android.widget.DatePicker;
@ -47,9 +48,11 @@ public class NativeDatePickerDialog extends InjectingNativeDialogFragment
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments(); Bundle args = getArguments();
Context context = getActivity();
theme.applyToContext(context);
DatePickerDialog datePickerDialog = DatePickerDialog datePickerDialog =
new DatePickerDialog( new DatePickerDialog(
theme.wrap(getActivity()), context,
this, this,
args.getInt(EXTRA_YEAR), args.getInt(EXTRA_YEAR),
args.getInt(EXTRA_MONTH), args.getInt(EXTRA_MONTH),

@ -40,8 +40,9 @@ public class NativeTimePickerDialog extends InjectingNativeDialogFragment
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = theme.wrap(getActivity());
Bundle args = getArguments(); Bundle args = getArguments();
Context context = getActivity();
theme.applyToContext(context);
TimePickerDialog timePickerDialog = TimePickerDialog timePickerDialog =
new TimePickerDialog( new TimePickerDialog(
context, context,

@ -5,5 +5,5 @@
<style name="DayNightAlert" parent="Theme.MaterialComponents.Dialog.Alert"/> <style name="DayNightAlert" parent="Theme.MaterialComponents.Dialog.Alert"/>
<style name="popup_overlay" parent="ThemeOverlay.AppCompat"/> <style name="popup_overlay" parent="ThemeOverlay.MaterialComponents"/>
</resources> </resources>

@ -9,7 +9,8 @@
<item name="android:paddingRight">0dp</item> <item name="android:paddingRight">0dp</item>
</style> </style>
<style name="TranslucentDialog" parent="Theme.MaterialComponents.Light.Dialog"> <style name="TranslucentDialog" parent="DayNightDialog">
<item name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item> <item name="android:colorBackgroundCacheHint">@null</item>

Loading…
Cancel
Save