From c22ac414173141e73abbe8e6b8323f1bbf82ec81 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 3 Aug 2016 08:08:54 -0500 Subject: [PATCH] Bug fixes * LED color picker icons * Dialog accent * File picker rotation issues * Calendar picker rotation and theme issues * Set title to "" instead of null --- .../activities/CalendarSelectionActivity.java | 7 ++--- .../activities/CalendarSelectionDialog.java | 28 +++++++++++++++---- .../org/tasks/dialogs/ColorPickerDialog.java | 2 +- .../tasks/dialogs/NativeDatePickerDialog.java | 2 +- .../tasks/dialogs/NativeTimePickerDialog.java | 2 +- .../java/org/tasks/files/FileExplore.java | 22 +++++++++------ .../injection/InjectingAppCompatActivity.java | 2 +- .../simple_list_item_single_choice_themed.xml | 2 +- src/main/res/values/theme.xml | 2 -- 9 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/tasks/activities/CalendarSelectionActivity.java b/src/main/java/org/tasks/activities/CalendarSelectionActivity.java index 7b01fbd8f..2a38ab3ef 100644 --- a/src/main/java/org/tasks/activities/CalendarSelectionActivity.java +++ b/src/main/java/org/tasks/activities/CalendarSelectionActivity.java @@ -8,6 +8,8 @@ import org.tasks.calendars.AndroidCalendar; import org.tasks.injection.ActivityComponent; import org.tasks.injection.InjectingAppCompatActivity; +import static org.tasks.activities.CalendarSelectionDialog.newCalendarSelectionDialog; + public class CalendarSelectionActivity extends InjectingAppCompatActivity implements CalendarSelectionDialog.CalendarSelectionHandler { private static final String FRAG_TAG_CALENDAR_PREFERENCE_SELECTION = "frag_tag_calendar_preference_selection"; @@ -22,10 +24,7 @@ public class CalendarSelectionActivity extends InjectingAppCompatActivity implem FragmentManager fragmentManager = getSupportFragmentManager(); CalendarSelectionDialog fragmentByTag = (CalendarSelectionDialog) fragmentManager.findFragmentByTag(FRAG_TAG_CALENDAR_PREFERENCE_SELECTION); if (fragmentByTag == null) { - fragmentByTag = new CalendarSelectionDialog(); - if (getIntent().getBooleanExtra(EXTRA_SHOW_NONE, false)) { - fragmentByTag.enableNone(); - } + fragmentByTag = newCalendarSelectionDialog(getIntent().getBooleanExtra(EXTRA_SHOW_NONE, false)); fragmentByTag.show(fragmentManager, FRAG_TAG_CALENDAR_PREFERENCE_SELECTION); } fragmentByTag.setCalendarSelectionHandler(this); diff --git a/src/main/java/org/tasks/activities/CalendarSelectionDialog.java b/src/main/java/org/tasks/activities/CalendarSelectionDialog.java index d702ce6fa..6839e4c6b 100644 --- a/src/main/java/org/tasks/activities/CalendarSelectionDialog.java +++ b/src/main/java/org/tasks/activities/CalendarSelectionDialog.java @@ -21,6 +21,7 @@ import org.tasks.injection.InjectingDialogFragment; import org.tasks.preferences.FragmentPermissionRequestor; import org.tasks.preferences.PermissionChecker; import org.tasks.preferences.PermissionRequestor; +import org.tasks.themes.Theme; import java.util.ArrayList; import java.util.List; @@ -32,17 +33,26 @@ import static org.tasks.PermissionUtil.verifyPermissions; public class CalendarSelectionDialog extends InjectingDialogFragment { + public static CalendarSelectionDialog newCalendarSelectionDialog(boolean enableNone) { + CalendarSelectionDialog dialog = new CalendarSelectionDialog(); + dialog.enableNone = enableNone; + return dialog; + } + public interface CalendarSelectionHandler { void selectedCalendar(AndroidCalendar calendar); void cancel(); } + private static final String EXTRA_NONE_ENABLED = "extra_none_enabled"; + @Inject DialogBuilder dialogBuilder; @Inject CalendarProvider calendarProvider; @Inject @ForActivity Context context; @Inject FragmentPermissionRequestor fragmentPermissionRequestor; @Inject PermissionChecker permissionChecker; + @Inject Theme theme; private CalendarSelectionHandler handler; private boolean enableNone; private ArrayAdapter adapter; @@ -54,9 +64,12 @@ public class CalendarSelectionDialog extends InjectingDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { if (savedInstanceState == null) { fragmentPermissionRequestor.requestCalendarPermissions(); + } else { + enableNone = savedInstanceState.getBoolean(EXTRA_NONE_ENABLED); } - adapter = new ArrayAdapter<>(context, R.layout.simple_list_item_single_choice_themed, calendarNames); + theme.applyToContext(getActivity()); + adapter = new ArrayAdapter<>(getActivity(), R.layout.simple_list_item_single_choice_themed, calendarNames); AlertDialogBuilder builder = dialogBuilder.newDialog() .setAdapter(adapter, new DialogInterface.OnClickListener() { @@ -98,7 +111,7 @@ public class CalendarSelectionDialog extends InjectingDialogFragment { } })); if (calendarNames.isEmpty()) { - Toast.makeText(context, R.string.no_calendars_found, Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity(), R.string.no_calendars_found, Toast.LENGTH_LONG).show(); handler.cancel(); } else { adapter.notifyDataSetChanged(); @@ -106,6 +119,13 @@ public class CalendarSelectionDialog extends InjectingDialogFragment { } } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putBoolean(EXTRA_NONE_ENABLED, enableNone); + } + @Override public void onCancel(DialogInterface dialog) { super.onCancel(dialog); @@ -129,10 +149,6 @@ public class CalendarSelectionDialog extends InjectingDialogFragment { component.inject(this); } - public void enableNone() { - enableNone = true; - } - public void setCalendarSelectionHandler(CalendarSelectionHandler handler) { this.handler = handler; } diff --git a/src/main/java/org/tasks/dialogs/ColorPickerDialog.java b/src/main/java/org/tasks/dialogs/ColorPickerDialog.java index a48cca9a7..752a468a6 100644 --- a/src/main/java/org/tasks/dialogs/ColorPickerDialog.java +++ b/src/main/java/org/tasks/dialogs/ColorPickerDialog.java @@ -73,7 +73,7 @@ public class ColorPickerDialog extends InjectingDialogFragment { TextView textView = (TextView) (convertView == null ? inflater.inflate(R.layout.color_selection_row, parent, false) : convertView); - Drawable original = context.getResources().getDrawable(preferences.hasPurchase(R.string.p_purchased_themes) || position < 2 + Drawable original = context.getResources().getDrawable(preferences.hasPurchase(R.string.p_purchased_themes) || position < getNumFree() ? R.drawable.ic_lens_black_24dp : R.drawable.ic_vpn_key_black_24dp); Drawable wrapped = DrawableCompat.wrap(original.mutate()); diff --git a/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java b/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java index bccdca4b5..d1d3b9754 100644 --- a/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java +++ b/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java @@ -39,7 +39,7 @@ public class NativeDatePickerDialog extends InjectingNativeDialogFragment implem if (initial != null) { datePickerDialog.updateDate(initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth()); } - datePickerDialog.setTitle(null); + datePickerDialog.setTitle(""); return datePickerDialog; } diff --git a/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java b/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java index a99a5af1e..d0eec4764 100644 --- a/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java +++ b/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java @@ -49,7 +49,7 @@ public class NativeTimePickerDialog extends InjectingNativeDialogFragment implem if (initial != null) { timePickerDialog.updateTime(initial.getHourOfDay(), initial.getMinuteOfHour()); } - timePickerDialog.setTitle(null); + timePickerDialog.setTitle(""); return timePickerDialog; } diff --git a/src/main/java/org/tasks/files/FileExplore.java b/src/main/java/org/tasks/files/FileExplore.java index 41e4dc090..1898595f1 100644 --- a/src/main/java/org/tasks/files/FileExplore.java +++ b/src/main/java/org/tasks/files/FileExplore.java @@ -37,12 +37,14 @@ public class FileExplore extends InjectingAppCompatActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Intent intent = getIntent(); - directoryMode = intent.getBooleanExtra(EXTRA_DIRECTORY_MODE, false); - startPath = intent.getStringExtra(EXTRA_START_PATH); + if (savedInstanceState == null) { + Intent intent = getIntent(); + directoryMode = intent.getBooleanExtra(EXTRA_DIRECTORY_MODE, false); + startPath = intent.getStringExtra(EXTRA_START_PATH); - if (permissionRequestor.requestFileWritePermission()) { - launchPicker(); + if (permissionRequestor.requestFileWritePermission()) { + launchPicker(); + } } } @@ -76,10 +78,12 @@ public class FileExplore extends InjectingAppCompatActivity { @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == PermissionRequestor.REQUEST_FILE_WRITE) { - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - launchPicker(); - } else { - finish(); + if (grantResults.length > 0) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + launchPicker(); + } else { + finish(); + } } } else { super.onRequestPermissionsResult(requestCode, permissions, grantResults); diff --git a/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java b/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java index edbd96749..c5d3a4bba 100644 --- a/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java +++ b/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java @@ -21,7 +21,7 @@ public abstract class InjectingAppCompatActivity extends AppCompatActivity imple protected void onCreate(Bundle savedInstanceState) { activityComponent = ((InjectingApplication) getApplication()).getComponent().plus(new ActivityModule(this)); inject(activityComponent); - setTitle(null); + setTitle(""); super.onCreate(savedInstanceState); } diff --git a/src/main/res/layout/simple_list_item_single_choice_themed.xml b/src/main/res/layout/simple_list_item_single_choice_themed.xml index bfd402403..e18519a5c 100644 --- a/src/main/res/layout/simple_list_item_single_choice_themed.xml +++ b/src/main/res/layout/simple_list_item_single_choice_themed.xml @@ -16,7 +16,7 @@ @color/background_color_dialog ?attr/colorAccentDialog - @color/blue_grey_400 @color/text_primary @color/icon_tint @@ -34,7 +33,6 @@