|
|
@ -4,7 +4,6 @@ import android.app.Dialog;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import org.tasks.R;
|
|
|
|
import org.tasks.R;
|
|
|
@ -18,6 +17,7 @@ import org.tasks.preferences.FragmentPermissionRequestor;
|
|
|
|
import org.tasks.preferences.PermissionChecker;
|
|
|
|
import org.tasks.preferences.PermissionChecker;
|
|
|
|
import org.tasks.preferences.PermissionRequestor;
|
|
|
|
import org.tasks.preferences.PermissionRequestor;
|
|
|
|
import org.tasks.themes.Theme;
|
|
|
|
import org.tasks.themes.Theme;
|
|
|
|
|
|
|
|
import org.tasks.ui.SingleCheckedArrayAdapter;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -29,9 +29,12 @@ import static org.tasks.PermissionUtil.verifyPermissions;
|
|
|
|
|
|
|
|
|
|
|
|
public class CalendarSelectionDialog extends InjectingDialogFragment {
|
|
|
|
public class CalendarSelectionDialog extends InjectingDialogFragment {
|
|
|
|
|
|
|
|
|
|
|
|
public static CalendarSelectionDialog newCalendarSelectionDialog(boolean enableNone) {
|
|
|
|
public static CalendarSelectionDialog newCalendarSelectionDialog(boolean enableNone, String selected) {
|
|
|
|
CalendarSelectionDialog dialog = new CalendarSelectionDialog();
|
|
|
|
CalendarSelectionDialog dialog = new CalendarSelectionDialog();
|
|
|
|
dialog.enableNone = enableNone;
|
|
|
|
Bundle arguments = new Bundle();
|
|
|
|
|
|
|
|
arguments.putBoolean(EXTRA_NONE_ENABLED, enableNone);
|
|
|
|
|
|
|
|
arguments.putString(EXTRA_SELECTED, selected);
|
|
|
|
|
|
|
|
dialog.setArguments(arguments);
|
|
|
|
return dialog;
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -41,6 +44,7 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
|
|
|
|
void cancel();
|
|
|
|
void cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String EXTRA_SELECTED = "extra_selected";
|
|
|
|
private static final String EXTRA_NONE_ENABLED = "extra_none_enabled";
|
|
|
|
private static final String EXTRA_NONE_ENABLED = "extra_none_enabled";
|
|
|
|
|
|
|
|
|
|
|
|
@Inject DialogBuilder dialogBuilder;
|
|
|
|
@Inject DialogBuilder dialogBuilder;
|
|
|
@ -48,29 +52,29 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
|
|
|
|
@Inject FragmentPermissionRequestor fragmentPermissionRequestor;
|
|
|
|
@Inject FragmentPermissionRequestor fragmentPermissionRequestor;
|
|
|
|
@Inject PermissionChecker permissionChecker;
|
|
|
|
@Inject PermissionChecker permissionChecker;
|
|
|
|
@Inject Theme theme;
|
|
|
|
@Inject Theme theme;
|
|
|
|
|
|
|
|
|
|
|
|
private CalendarSelectionHandler handler;
|
|
|
|
private CalendarSelectionHandler handler;
|
|
|
|
private boolean enableNone;
|
|
|
|
private String selected;
|
|
|
|
private ArrayAdapter<String> adapter;
|
|
|
|
private SingleCheckedArrayAdapter adapter;
|
|
|
|
private final List<AndroidCalendar> calendars = new ArrayList<>();
|
|
|
|
private final List<AndroidCalendar> calendars = new ArrayList<>();
|
|
|
|
private final List<String> calendarNames = new ArrayList<>();
|
|
|
|
private final List<String> calendarNames = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
|
|
|
|
fragmentPermissionRequestor.requestCalendarPermissions();
|
|
|
|
fragmentPermissionRequestor.requestCalendarPermissions();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
enableNone = savedInstanceState.getBoolean(EXTRA_NONE_ENABLED);
|
|
|
|
Bundle arguments = getArguments();
|
|
|
|
}
|
|
|
|
selected = arguments.getString(EXTRA_SELECTED);
|
|
|
|
|
|
|
|
|
|
|
|
theme.applyToContext(getActivity());
|
|
|
|
theme.applyToContext(getActivity());
|
|
|
|
adapter = new ArrayAdapter<>(getActivity(), R.layout.simple_list_item_single_choice_themed, calendarNames);
|
|
|
|
adapter = new SingleCheckedArrayAdapter(getActivity(), calendarNames);
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialogBuilder builder = dialogBuilder.newDialog()
|
|
|
|
AlertDialogBuilder builder = dialogBuilder.newDialog()
|
|
|
|
.setAdapter(adapter, (dialog, which) -> handler.selectedCalendar(calendars.get(which)))
|
|
|
|
.setSingleChoiceItems(adapter, -1, (dialog, which) -> handler.selectedCalendar(calendars.get(which)))
|
|
|
|
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> handler.cancel());
|
|
|
|
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> handler.cancel());
|
|
|
|
if (enableNone) {
|
|
|
|
if (arguments.getBoolean(EXTRA_NONE_ENABLED)) {
|
|
|
|
builder.setNeutralButton(R.string.none, (dialog, which) -> handler.selectedCalendar(AndroidCalendar.NONE));
|
|
|
|
builder.setNeutralButton(R.string.none, (dialog, which) -> handler.selectedCalendar(new AndroidCalendar("-1", getString(R.string.none))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return builder.show();
|
|
|
|
return builder.show();
|
|
|
@ -89,18 +93,12 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
|
|
|
|
Toast.makeText(getActivity(), R.string.no_calendars_found, Toast.LENGTH_LONG).show();
|
|
|
|
Toast.makeText(getActivity(), R.string.no_calendars_found, Toast.LENGTH_LONG).show();
|
|
|
|
handler.cancel();
|
|
|
|
handler.cancel();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
adapter.setChecked(selected);
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outState.putBoolean(EXTRA_NONE_ENABLED, enableNone);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onCancel(DialogInterface dialog) {
|
|
|
|
public void onCancel(DialogInterface dialog) {
|
|
|
|
super.onCancel(dialog);
|
|
|
|
super.onCancel(dialog);
|
|
|
|