Skip to content

Commit

Permalink
Fixed DatePicker spinner dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Djonique committed Nov 2, 2017
1 parent dc4c243 commit 86c7da2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.djonique.birdays.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.SharedPreferences;
import android.os.Build;
Expand All @@ -30,15 +31,18 @@ public class DatePickerManager {

private Activity activity;
private Calendar calendar;
private SharedPreferences preferences;

public DatePickerManager(Activity activity, Calendar calendar) {
this.activity = activity;
this.calendar = calendar;
preferences = PreferenceManager.getDefaultSharedPreferences(activity);
}

/**
* Shows material calendar on API 24 devices instead of spinner
*/

public void showDialog(DatePickerDialog.OnDateSetListener androidCallback,
com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener libCallback) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
Expand All @@ -51,9 +55,11 @@ public void showDialog(DatePickerDialog.OnDateSetListener androidCallback,
/**
* Configures android DatePickerDialog
*/

private void showDatePickerDialog(DatePickerDialog.OnDateSetListener callback) {
android.app.DatePickerDialog datePickerDialog = new android.app.DatePickerDialog(
activity,
setTheme(isNightMode()),
callback,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
Expand All @@ -64,6 +70,7 @@ private void showDatePickerDialog(DatePickerDialog.OnDateSetListener callback) {
/**
* Configures DatePickerDialog by Wouter Dullaert
*/

private void showMdtpDialog(com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener callback) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
com.wdullaer.materialdatetimepicker.date.DatePickerDialog dpd =
Expand All @@ -76,4 +83,20 @@ private void showMdtpDialog(com.wdullaer.materialdatetimepicker.date.DatePickerD
dpd.setThemeDark(preferences.getBoolean(Constants.NIGHT_MODE_KEY, false));
dpd.show(activity.getFragmentManager(), DATE_PICKER_FRAGMENT_TAG);
}

/**
* Set correct theme for day/night modes
*/

private int setTheme(boolean nightMode) {
if (nightMode) {
return AlertDialog.THEME_HOLO_DARK;
} else {
return AlertDialog.THEME_HOLO_LIGHT;
}
}

private boolean isNightMode() {
return preferences.getBoolean(Constants.NIGHT_MODE_KEY, false);
}
}
1 change: 0 additions & 1 deletion app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<item name="colorAccent">@color/color_accent</item>
<item name="colorControlHighlight">@color/ripple</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:datePickerStyle">@android:style/Widget.Holo.DatePicker</item>
</style>

<style name="Material.Primary.TextView" parent="Primary.TextView">
Expand Down

0 comments on commit 86c7da2

Please sign in to comment.