AlertDialogs in popup control sets

pull/321/head
Alex Baker 9 years ago
parent 8c9aa4f181
commit a8958ac287

@ -351,11 +351,11 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
timerAction = new TimerActionControlSet(notificationManager, taskService, getActivity(), getView()); timerAction = new TimerActionControlSet(notificationManager, taskService, getActivity(), getView());
controls.add(timerAction); controls.add(timerAction);
TagsControlSet tagsControlSet = new TagsControlSet(metadataDao, tagDataDao, preferences, tagService, getActivity()); TagsControlSet tagsControlSet = new TagsControlSet(metadataDao, tagDataDao, preferences, tagService, getActivity(), dialogBuilder);
controls.add(tagsControlSet); controls.add(tagsControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_lists_pref), tagsControlSet); controlSetMap.put(getString(R.string.TEA_ctrl_lists_pref), tagsControlSet);
RepeatControlSet repeatControls = new RepeatControlSet(preferences, getActivity()); RepeatControlSet repeatControls = new RepeatControlSet(preferences, getActivity(), dialogBuilder);
controlSetMap.put(getString(R.string.TEA_ctrl_repeat_pref), repeatControls); controlSetMap.put(getString(R.string.TEA_ctrl_repeat_pref), repeatControls);
GCalControlSet gcalControl = new GCalControlSet(gcalHelper, getActivity()); GCalControlSet gcalControl = new GCalControlSet(gcalHelper, getActivity());
@ -367,7 +367,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// deadline control, because // deadline control, because
// otherwise the correct date may not be written to the calendar event. // otherwise the correct date may not be written to the calendar event.
// Order matters! // Order matters!
DeadlineControlSet deadlineControl = new DeadlineControlSet(preferences, getActivity()); DeadlineControlSet deadlineControl = new DeadlineControlSet(preferences, getActivity(), dialogBuilder);
controlSetMap.put(getString(R.string.TEA_ctrl_when_pref), deadlineControl); controlSetMap.put(getString(R.string.TEA_ctrl_when_pref), deadlineControl);
controls.add(repeatControls); controls.add(repeatControls);
@ -397,12 +397,12 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// TODO: Fix the fact that hideUntil doesn't update accordingly with date changes when lazy loaded. Until then, don't lazy load. // TODO: Fix the fact that hideUntil doesn't update accordingly with date changes when lazy loaded. Until then, don't lazy load.
hideUntilControls.getView(); hideUntilControls.getView();
TimerControlSet timerControl = new TimerControlSet(preferences, getActivity()); TimerControlSet timerControl = new TimerControlSet(preferences, getActivity(), dialogBuilder);
timerAction.addListener(timerControl); timerAction.addListener(timerControl);
controls.add(timerControl); controls.add(timerControl);
controlSetMap.put(getString(R.string.TEA_ctrl_timer_pref), timerControl); controlSetMap.put(getString(R.string.TEA_ctrl_timer_pref), timerControl);
filesControlSet = new FilesControlSet(preferences, taskAttachmentDao, getActivity()); filesControlSet = new FilesControlSet(preferences, taskAttachmentDao, getActivity(), dialogBuilder);
controls.add(filesControlSet); controls.add(filesControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_files_pref), filesControlSet); controlSetMap.put(getString(R.string.TEA_ctrl_files_pref), filesControlSet);

@ -627,7 +627,7 @@ public class TaskListFragment extends InjectingListFragment implements SwipeRefr
@Override @Override
public void onCompletedTask(Task item, boolean newState) { public void onCompletedTask(Task item, boolean newState) {
} }
}); }, dialogBuilder);
} }
public static final String TAGS_METADATA_JOIN = "for_tags"; //$NON-NLS-1$ public static final String TAGS_METADATA_JOIN = "for_tags"; //$NON-NLS-1$

@ -54,6 +54,7 @@ import com.todoroo.astrid.ui.CheckableImageView;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import java.util.Collections; import java.util.Collections;
@ -145,6 +146,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
protected final Context context; protected final Context context;
protected final TaskListFragment fragment; protected final TaskListFragment fragment;
private DialogBuilder dialogBuilder;
protected final Resources resources; protected final Resources resources;
protected final HashMap<Object, Boolean> completedItems = new HashMap<>(0); protected final HashMap<Object, Boolean> completedItems = new HashMap<>(0);
protected OnCompletedTaskListener onCompletedTaskListener = null; protected OnCompletedTaskListener onCompletedTaskListener = null;
@ -164,7 +166,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
private final Map<Long, TaskAction> taskActionLoader = Collections.synchronizedMap(new HashMap<Long, TaskAction>()); private final Map<Long, TaskAction> taskActionLoader = Collections.synchronizedMap(new HashMap<Long, TaskAction>());
public TaskAdapter(Context context, ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, TaskService taskService, TaskListFragment fragment, public TaskAdapter(Context context, ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, TaskService taskService, TaskListFragment fragment,
Cursor c, AtomicReference<String> query, OnCompletedTaskListener onCompletedTaskListener) { Cursor c, AtomicReference<String> query, OnCompletedTaskListener onCompletedTaskListener, DialogBuilder dialogBuilder) {
super(context, c, false); super(context, c, false);
this.preferences = preferences; this.preferences = preferences;
this.taskAttachmentDao = taskAttachmentDao; this.taskAttachmentDao = taskAttachmentDao;
@ -172,6 +174,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
this.context = context; this.context = context;
this.query = query; this.query = query;
this.fragment = fragment; this.fragment = fragment;
this.dialogBuilder = dialogBuilder;
this.resources = fragment.getResources(); this.resources = fragment.getResources();
this.onCompletedTaskListener = onCompletedTaskListener; this.onCompletedTaskListener = onCompletedTaskListener;
inflater = (LayoutInflater) fragment.getActivity().getSystemService( inflater = (LayoutInflater) fragment.getActivity().getSystemService(
@ -450,39 +453,15 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
return; return;
} }
int theme = preferences.getEditDialogTheme(); dialogBuilder.newDialog()
final Dialog dialog = new Dialog(fragment.getActivity(), theme); .setMessage(notes)
dialog.setTitle(R.string.TEA_note_label); .setPositiveButton(android.R.string.ok, null)
View notesView = LayoutInflater.from(fragment.getActivity()).inflate(R.layout.notes_view_dialog, null); .show();
dialog.setContentView(notesView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
notesView.findViewById(R.id.edit_dlg_ok).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
final TextView notesField = (TextView) notesView.findViewById(R.id.notes);
notesField.setText(notes);
LayoutParams params = dialog.getWindow().getAttributes();
params.width = LayoutParams.FILL_PARENT;
params.height = LayoutParams.WRAP_CONTENT;
Configuration config = fragment.getResources().getConfiguration();
int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
if (atLeastGingerbread() && size == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
DisplayMetrics metrics = fragment.getResources().getDisplayMetrics();
params.width = metrics.widthPixels / 2;
}
dialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
dialog.show();
} }
private void showFilesDialog(Task task) { private void showFilesDialog(Task task) {
FilesControlSet filesControlSet = new FilesControlSet(preferences, taskAttachmentDao, FilesControlSet filesControlSet = new FilesControlSet(preferences, taskAttachmentDao,
fragment.getActivity()); fragment.getActivity(), dialogBuilder);
filesControlSet.readFromTask(task); filesControlSet.readFromTask(task);
filesControlSet.getView().performClick(); filesControlSet.getView().performClick();
} }

@ -51,8 +51,8 @@ public class FilesControlSet extends PopupControlSet {
private final DialogBuilder dialogBuilder; private final DialogBuilder dialogBuilder;
public FilesControlSet(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, public FilesControlSet(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao,
Activity activity) { Activity activity, DialogBuilder dialogBuilder) {
super(preferences, activity, R.layout.control_set_files_dialog, R.layout.control_set_files, R.string.TEA_control_files); super(preferences, activity, R.layout.control_set_files_dialog, R.layout.control_set_files, R.string.TEA_control_files, dialogBuilder);
this.taskAttachmentDao = taskAttachmentDao; this.taskAttachmentDao = taskAttachmentDao;
this.dialogBuilder = new DialogBuilder(activity, preferences); this.dialogBuilder = new DialogBuilder(activity, preferences);
fileDisplayList = (LinearLayout) getView().findViewById(R.id.files_list); fileDisplayList = (LinearLayout) getView().findViewById(R.id.files_list);

@ -55,7 +55,7 @@ public class GtasksListFragment extends SubtasksListFragment {
@Override @Override
protected OrderedListFragmentHelperInterface<?> createFragmentHelper() { protected OrderedListFragmentHelperInterface<?> createFragmentHelper() {
return new OrderedMetadataListFragmentHelper<>(preferences, taskAttachmentDao, taskService, metadataDao, this, gtasksTaskListUpdater); return new OrderedMetadataListFragmentHelper<>(preferences, taskAttachmentDao, taskService, metadataDao, this, gtasksTaskListUpdater, dialogBuilder);
} }
@Override @Override

@ -35,6 +35,7 @@ import com.todoroo.astrid.ui.DraggableListView;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,6 +51,7 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
private final DisplayMetrics metrics = new DisplayMetrics(); private final DisplayMetrics metrics = new DisplayMetrics();
private final OrderedMetadataListUpdater<LIST> updater; private final OrderedMetadataListUpdater<LIST> updater;
private DialogBuilder dialogBuilder;
private final TaskListFragment fragment; private final TaskListFragment fragment;
private final ActivityPreferences preferences; private final ActivityPreferences preferences;
@ -61,13 +63,17 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
private LIST list; private LIST list;
public OrderedMetadataListFragmentHelper(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, TaskService taskService, MetadataDao metadataDao, TaskListFragment fragment, OrderedMetadataListUpdater<LIST> updater) { public OrderedMetadataListFragmentHelper(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao,
TaskService taskService, MetadataDao metadataDao,
TaskListFragment fragment, OrderedMetadataListUpdater<LIST> updater,
DialogBuilder dialogBuilder) {
this.preferences = preferences; this.preferences = preferences;
this.taskAttachmentDao = taskAttachmentDao; this.taskAttachmentDao = taskAttachmentDao;
this.taskService = taskService; this.taskService = taskService;
this.metadataDao = metadataDao; this.metadataDao = metadataDao;
this.fragment = fragment; this.fragment = fragment;
this.updater = updater; this.updater = updater;
this.dialogBuilder = dialogBuilder;
} }
// --- ui component setup // --- ui component setup
@ -182,7 +188,7 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
public TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor, public TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) { AtomicReference<String> sqlQueryTemplate) {
taskAdapter = new DraggableTaskAdapter(context, preferences, fragment, cursor, sqlQueryTemplate); taskAdapter = new DraggableTaskAdapter(context, preferences, fragment, cursor, sqlQueryTemplate, dialogBuilder);
taskAdapter.addOnCompletedTaskListener(new OnCompletedTaskListener() { taskAdapter.addOnCompletedTaskListener(new OnCompletedTaskListener() {
@Override @Override
@ -197,8 +203,8 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
private final class DraggableTaskAdapter extends TaskAdapter { private final class DraggableTaskAdapter extends TaskAdapter {
private DraggableTaskAdapter(Context context, ActivityPreferences preferences, TaskListFragment activity, private DraggableTaskAdapter(Context context, ActivityPreferences preferences, TaskListFragment activity,
Cursor c, AtomicReference<String> query) { Cursor c, AtomicReference<String> query, DialogBuilder dialogBuilder) {
super(context, preferences, taskAttachmentDao, taskService, activity, c, query, null); super(context, preferences, taskAttachmentDao, taskService, activity, c, query, null, dialogBuilder);
} }
@Override @Override

@ -67,7 +67,6 @@ public abstract class TaskEditControlSetBase implements TaskEditControlSet {
if (viewLayout != -1) { if (viewLayout != -1) {
view = useTemplate ? inflateWithTemplate(viewLayout) : LayoutInflater.from(activity).inflate(viewLayout, null); view = useTemplate ? inflateWithTemplate(viewLayout) : LayoutInflater.from(activity).inflate(viewLayout, null);
afterInflate(); afterInflate();
setupOkButton(view);
} }
if (model != null) { if (model != null) {
readFromTaskOnInitialize(); readFromTaskOnInitialize();
@ -113,26 +112,4 @@ public abstract class TaskEditControlSetBase implements TaskEditControlSet {
* Called when views need to be inflated * Called when views need to be inflated
*/ */
protected abstract void afterInflate(); protected abstract void afterInflate();
/**
* Sets up ok button background. Subclasses can override to customize look and feel
*/
protected void setupOkButton(View view) {
Button ok = (Button) view.findViewById(R.id.edit_dlg_ok);
Theme theme = activity.getTheme();
TypedValue themeColor = new TypedValue();
theme.resolveAttribute(R.attr.asThemeTextColor, themeColor, false);
TypedValue inverseColor = new TypedValue();
theme.resolveAttribute(R.attr.asTextColorInverse, inverseColor, false);
if (ok != null) {
ok.setBackgroundDrawable(EditDialogOkBackground.getBg(activity.getResources().getColor(themeColor.data)));
int[][] states = new int[2][];
states[0] = new int[] { android.R.attr.state_pressed };
states[1] = new int[] { android.R.attr.state_enabled };
int[] colors = new int[] { inverseColor.data, activity.getResources().getColor(themeColor.data) };
ColorStateList csl = new ColorStateList(states, colors);
ok.setTextColor(csl);
}
}
} }

@ -8,6 +8,7 @@ package com.todoroo.astrid.repeats;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
@ -37,6 +38,7 @@ import com.todoroo.astrid.ui.PopupControlSet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
@ -93,8 +95,8 @@ public class RepeatControlSet extends PopupControlSet {
// --- implementation // --- implementation
public RepeatControlSet(ActivityPreferences preferences, Activity activity) { public RepeatControlSet(ActivityPreferences preferences, Activity activity, DialogBuilder dialogBuilder) {
super(preferences, activity, R.layout.control_set_repeat, R.layout.control_set_repeat_display, R.string.repeat_enabled); super(preferences, activity, R.layout.control_set_repeat, R.layout.control_set_repeat_display, R.string.repeat_enabled, dialogBuilder);
} }
/** Set up the repeat value button */ /** Set up the repeat value button */
@ -399,7 +401,6 @@ public class RepeatControlSet extends PopupControlSet {
@Override @Override
protected Dialog buildDialog(String title, final PopupDialogClickListener okListener, final DialogInterface.OnCancelListener cancelListener) { protected Dialog buildDialog(String title, final PopupDialogClickListener okListener, final DialogInterface.OnCancelListener cancelListener) {
PopupDialogClickListener doRepeatButton = new PopupDialogClickListener() { PopupDialogClickListener doRepeatButton = new PopupDialogClickListener() {
@Override @Override
public boolean onClick(DialogInterface d, int which) { public boolean onClick(DialogInterface d, int which) {
@ -411,22 +412,25 @@ public class RepeatControlSet extends PopupControlSet {
return okListener.onClick(d, which); return okListener.onClick(d, which);
} }
}; };
final Dialog d = super.buildDialog(title, doRepeatButton, cancelListener);
View.OnClickListener dontRepeatButton = new View.OnClickListener() { return super.buildDialog(title, doRepeatButton, cancelListener);
}
@Override
protected void additionalDialogSetup(AlertDialog.Builder builder) {
super.additionalDialogSetup(builder);
builder.setNeutralButton(R.string.repeat_dont, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(DialogInterface dialog, int which) {
doRepeat = false; doRepeat = false;
refreshDisplayView(); refreshDisplayView();
DialogUtilities.dismissDialog(activity, d); dialog.dismiss();
for (RepeatChangedListener l : listeners) { for (RepeatChangedListener l : listeners) {
l.repeatChanged(doRepeat); l.repeatChanged(doRepeat);
} }
} }
}; });
getDialogView().findViewById(R.id.edit_dont_repeat).setOnClickListener(dontRepeatButton);
return d;
} }
} }

@ -31,6 +31,7 @@ import com.todoroo.astrid.ui.DraggableListView;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import java.util.ArrayList; import java.util.ArrayList;
@ -45,6 +46,7 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
private final DisplayMetrics metrics = new DisplayMetrics(); private final DisplayMetrics metrics = new DisplayMetrics();
private final AstridOrderedListUpdater<LIST> updater; private final AstridOrderedListUpdater<LIST> updater;
private DialogBuilder dialogBuilder;
private final TaskListFragment fragment; private final TaskListFragment fragment;
private final ActivityPreferences preferences; private final ActivityPreferences preferences;
private final TaskAttachmentDao taskAttachmentDao; private final TaskAttachmentDao taskAttachmentDao;
@ -54,12 +56,15 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
private LIST list; private LIST list;
public AstridOrderedListFragmentHelper(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, TaskService taskService, TaskListFragment fragment, AstridOrderedListUpdater<LIST> updater) { public AstridOrderedListFragmentHelper(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao,
TaskService taskService, TaskListFragment fragment,
AstridOrderedListUpdater<LIST> updater, DialogBuilder dialogBuilder) {
this.preferences = preferences; this.preferences = preferences;
this.taskAttachmentDao = taskAttachmentDao; this.taskAttachmentDao = taskAttachmentDao;
this.taskService = taskService; this.taskService = taskService;
this.fragment = fragment; this.fragment = fragment;
this.updater = updater; this.updater = updater;
this.dialogBuilder = dialogBuilder;
} }
// --- ui component setup // --- ui component setup
@ -172,7 +177,7 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
public TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor, public TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) { AtomicReference<String> sqlQueryTemplate) {
taskAdapter = new DraggableTaskAdapter(context, preferences, fragment, cursor, sqlQueryTemplate); taskAdapter = new DraggableTaskAdapter(context, preferences, fragment, cursor, sqlQueryTemplate, dialogBuilder);
getTouchListView().setItemHightNormal(taskAdapter.computeFullRowHeight()); getTouchListView().setItemHightNormal(taskAdapter.computeFullRowHeight());
@ -189,8 +194,8 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
private final class DraggableTaskAdapter extends TaskAdapter { private final class DraggableTaskAdapter extends TaskAdapter {
private DraggableTaskAdapter(Context context, ActivityPreferences preferences, TaskListFragment activity, private DraggableTaskAdapter(Context context, ActivityPreferences preferences, TaskListFragment activity,
Cursor c, AtomicReference<String> query) { Cursor c, AtomicReference<String> query, DialogBuilder dialogBuilder) {
super(context, preferences, taskAttachmentDao, taskService, activity, c, query, null); super(context, preferences, taskAttachmentDao, taskService, activity, c, query, null, dialogBuilder);
} }
@Override @Override

@ -19,6 +19,7 @@ import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ForApplication; import org.tasks.injection.ForApplication;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
@ -41,6 +42,7 @@ public class SubtasksListFragment extends TaskListFragment {
@Inject TaskAttachmentDao taskAttachmentDao; @Inject TaskAttachmentDao taskAttachmentDao;
@Inject ActivityPreferences preferences; @Inject ActivityPreferences preferences;
@Inject @ForApplication Context context; @Inject @ForApplication Context context;
@Inject DialogBuilder dialogBuilder;
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
@ -50,7 +52,7 @@ public class SubtasksListFragment extends TaskListFragment {
} }
protected OrderedListFragmentHelperInterface<?> createFragmentHelper() { protected OrderedListFragmentHelperInterface<?> createFragmentHelper() {
return new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao, taskService, this, subtasksFilterUpdater); return new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao, taskService, this, subtasksFilterUpdater, dialogBuilder);
} }
@Override @Override

@ -19,6 +19,7 @@ import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ForApplication; import org.tasks.injection.ForApplication;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
@ -31,6 +32,7 @@ public class SubtasksTagListFragment extends TagViewFragment {
@Inject TaskAttachmentDao taskAttachmentDao; @Inject TaskAttachmentDao taskAttachmentDao;
@Inject ActivityPreferences preferences; @Inject ActivityPreferences preferences;
@Inject @ForApplication Context context; @Inject @ForApplication Context context;
@Inject DialogBuilder dialogBuilder;
private AstridOrderedListFragmentHelper<TaskListMetadata> helper; private AstridOrderedListFragmentHelper<TaskListMetadata> helper;
@ -40,7 +42,7 @@ public class SubtasksTagListFragment extends TagViewFragment {
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
helper = new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao, taskService, this, subtasksFilterUpdater); helper = new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao, taskService, this, subtasksFilterUpdater, dialogBuilder);
} }
@Override @Override

@ -6,6 +6,7 @@
package com.todoroo.astrid.tags; package com.todoroo.astrid.tags;
import android.app.Activity; import android.app.Activity;
import android.support.v7.app.AlertDialog;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -35,6 +36,7 @@ import com.todoroo.astrid.ui.PopupControlSet;
import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.utility.Flags;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import java.util.ArrayList; import java.util.ArrayList;
@ -70,8 +72,8 @@ public final class TagsControlSet extends PopupControlSet {
private final TagDataDao tagDataDao; private final TagDataDao tagDataDao;
private final TagService tagService; private final TagService tagService;
public TagsControlSet(MetadataDao metadataDao, TagDataDao tagDataDao, ActivityPreferences preferences, TagService tagService, Activity activity) { public TagsControlSet(MetadataDao metadataDao, TagDataDao tagDataDao, ActivityPreferences preferences, TagService tagService, Activity activity, DialogBuilder dialogBuilder) {
super(preferences, activity, R.layout.control_set_tag_list, R.layout.control_set_tags, R.string.TEA_tags_label_long); super(preferences, activity, R.layout.control_set_tag_list, R.layout.control_set_tags, R.string.TEA_tags_label_long, dialogBuilder);
this.metadataDao = metadataDao; this.metadataDao = metadataDao;
this.tagDataDao = tagDataDao; this.tagDataDao = tagDataDao;
this.tagService = tagService; this.tagService = tagService;
@ -276,12 +278,6 @@ public final class TagsControlSet extends PopupControlSet {
} }
} }
@Override
protected void additionalDialogSetup() {
super.additionalDialogSetup();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
@Override @Override
protected void afterInflate() { protected void afterInflate() {
TagData[] allTags = getTagArray(); TagData[] allTags = getTagArray();

@ -19,6 +19,7 @@ import com.todoroo.astrid.ui.PopupControlSet;
import com.todoroo.astrid.ui.TimeDurationControlSet; import com.todoroo.astrid.ui.TimeDurationControlSet;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
/** /**
@ -33,8 +34,8 @@ public class TimerControlSet extends PopupControlSet implements TimerActionListe
private final TextView displayEdit; private final TextView displayEdit;
private ActivityPreferences preferences; private ActivityPreferences preferences;
public TimerControlSet(ActivityPreferences preferences, final Activity activity) { public TimerControlSet(ActivityPreferences preferences, final Activity activity, DialogBuilder dialogBuilder) {
super(preferences, activity, R.layout.control_set_timers_dialog, R.layout.control_set_timers, R.string.TEA_timer_controls); super(preferences, activity, R.layout.control_set_timers_dialog, R.layout.control_set_timers, R.string.TEA_timer_controls, dialogBuilder);
this.preferences = preferences; this.preferences = preferences;
displayEdit = (TextView) getView().findViewById(R.id.display_row_edit); displayEdit = (TextView) getView().findViewById(R.id.display_row_edit);

@ -7,29 +7,23 @@ package com.todoroo.astrid.ui;
import android.app.Activity; import android.app.Activity;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
public class DeadlineControlSet extends PopupControlSet { public class DeadlineControlSet extends PopupControlSet {
private DateAndTimePicker dateAndTimePicker; private DateAndTimePicker dateAndTimePicker;
public DeadlineControlSet(ActivityPreferences preferences, Activity activity) { public DeadlineControlSet(ActivityPreferences preferences, Activity activity, DialogBuilder dialogBuilder) {
super(preferences, activity, R.layout.control_set_deadline_dialog, R.layout.control_set_deadline, 0); super(preferences, activity, R.layout.control_set_deadline_dialog, R.layout.control_set_deadline, 0, dialogBuilder);
} }
@Override @Override
@ -63,23 +57,6 @@ public class DeadlineControlSet extends PopupControlSet {
dateAndTimePicker = (DateAndTimePicker) getDialogView().findViewById(R.id.date_and_time); dateAndTimePicker = (DateAndTimePicker) getDialogView().findViewById(R.id.date_and_time);
LinearLayout body = (LinearLayout) getDialogView().findViewById(R.id.datetime_body); LinearLayout body = (LinearLayout) getDialogView().findViewById(R.id.datetime_body);
body.setGravity(Gravity.CENTER_HORIZONTAL); body.setGravity(Gravity.CENTER_HORIZONTAL);
Button okButton = (Button) LayoutInflater.from(activity).inflate(R.layout.control_dialog_ok, null);
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, (int) (45 * metrics.density));
body.addView(okButton, params);
}
@Override
protected void setupOkButton(View view) {
super.setupOkButton(view);
Button okButton = (Button) view.findViewById(R.id.edit_dlg_ok);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onOkClick();
DialogUtilities.dismissDialog(DeadlineControlSet.this.activity, DeadlineControlSet.this.dialog);
}
});
} }
@Override @Override

@ -8,11 +8,11 @@ package com.todoroo.astrid.ui;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button; import android.widget.Button;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
@ -20,13 +20,15 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSetBase; import com.todoroo.astrid.helper.TaskEditControlSetBase;
import org.tasks.R; import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
public abstract class PopupControlSet extends TaskEditControlSetBase { public abstract class PopupControlSet extends TaskEditControlSetBase {
protected final View displayView; protected final View displayView;
protected final ActivityPreferences preferences; protected final ActivityPreferences preferences;
protected Dialog dialog; private DialogBuilder dialogBuilder;
protected AlertDialog dialog;
private final String titleString; private final String titleString;
public interface PopupDialogClickListener { public interface PopupDialogClickListener {
@ -48,9 +50,11 @@ public abstract class PopupControlSet extends TaskEditControlSetBase {
} }
}; };
public PopupControlSet(ActivityPreferences preferences, Activity activity, int viewLayout, int taskEditViewLayout, final int title) { public PopupControlSet(ActivityPreferences preferences, Activity activity, int viewLayout,
int taskEditViewLayout, final int title, DialogBuilder dialogBuilder) {
super(activity, viewLayout, false); super(activity, viewLayout, false);
this.preferences = preferences; this.preferences = preferences;
this.dialogBuilder = dialogBuilder;
if (taskEditViewLayout != -1) { if (taskEditViewLayout != -1) {
this.displayView = inflateWithTemplate(taskEditViewLayout); this.displayView = inflateWithTemplate(taskEditViewLayout);
} else { } else {
@ -74,46 +78,20 @@ public abstract class PopupControlSet extends TaskEditControlSetBase {
} }
protected Dialog buildDialog(String title, final PopupDialogClickListener okClickListener, DialogInterface.OnCancelListener cancelClickListener) { protected Dialog buildDialog(String title, final PopupDialogClickListener okClickListener, DialogInterface.OnCancelListener cancelClickListener) {
dialog = new Dialog(activity, preferences.getEditDialogTheme()); AlertDialog.Builder builder = dialogBuilder.newDialog()
if (title.length() == 0) { .setView(getDialogView())
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
} else { @Override
dialog.setTitle(title); public void onClick(DialogInterface dialog, int which) {
} if (okClickListener.onClick(dialog, 0)) {
dialog.dismiss();
View v = getDialogView(); }
dialog.setContentView(v, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Button dismiss = (Button) v.findViewById(R.id.edit_dlg_ok);
if (dismiss != null) {
dismiss.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (okClickListener.onClick(dialog, 0)) {
DialogUtilities.dismissDialog(activity, dialog);
} }
} })
}); .setOnCancelListener(cancelClickListener);
}
LayoutParams params = dialog.getWindow().getAttributes();
params.width = LayoutParams.FILL_PARENT;
params.height = LayoutParams.WRAP_CONTENT;
if (ActivityPreferences.isTabletSized(activity)) {
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
if ((metrics.widthPixels / metrics.density) >= ActivityPreferences.MIN_TABLET_HEIGHT) {
params.width = (3 * metrics.widthPixels) / 5;
} else if ((metrics.widthPixels / metrics.density) >= ActivityPreferences.MIN_TABLET_WIDTH) {
params.width = (4 * metrics.widthPixels) / 5;
}
}
dialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
dialog.setOnCancelListener(cancelClickListener); additionalDialogSetup(builder);
dialog.setOwnerActivity(PopupControlSet.this.activity); dialog = builder.show();
additionalDialogSetup();
return dialog; return dialog;
} }
@ -129,7 +107,7 @@ public abstract class PopupControlSet extends TaskEditControlSetBase {
}; };
} }
protected void additionalDialogSetup() { protected void additionalDialogSetup(AlertDialog.Builder builder) {
// Will be called after dialog is set up. // Will be called after dialog is set up.
// Subclasses can override // Subclasses can override
} }

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/edit_dlg_ok"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_gravity="center_horizontal"
android:background="@null"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_alignParentBottom="true"
android:text="@android:string/ok"/>

@ -20,5 +20,4 @@
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</ScrollView> </ScrollView>
<include layout="@layout/control_dialog_ok" />
</LinearLayout> </LinearLayout>

@ -48,23 +48,10 @@
android:gravity="center"/> android:gravity="center"/>
</LinearLayout> </LinearLayout>
<LinearLayout <Button android:id="@+id/repeatUntil"
android:layout_width="fill_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:layout_weight="1"/>
<Button android:id="@+id/repeatUntil"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/edit_dont_repeat"
android:text="@string/repeat_dont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<include layout="@layout/control_dialog_ok" />
</LinearLayout> </LinearLayout>

@ -33,6 +33,5 @@
android:layout_marginLeft="3dip" android:layout_marginLeft="3dip"
android:layout_marginRight="3dip" android:layout_marginRight="3dip"
android:layout_weight="100"/> android:layout_weight="100"/>
<include layout="@layout/control_dialog_ok"/>
</LinearLayout> </LinearLayout>

@ -61,7 +61,6 @@
android:paddingLeft="10dip" android:paddingLeft="10dip"
android:textColor="?attr/asThemeTextColor" /> android:textColor="?attr/asThemeTextColor" />
</LinearLayout> </LinearLayout>
<include layout="@layout/control_dialog_ok"/>
</LinearLayout> </LinearLayout>

@ -51,12 +51,6 @@
android:orientation="vertical"/> android:orientation="vertical"/>
</LinearLayout> </LinearLayout>
<View
android:id="@+id/TEA_Separator"
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_marginTop="1dip"
android:background="?android:attr/listDivider" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</merge> </merge>

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- notes -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dip"
android:layout_marginRight="9dip"
android:layout_weight="100"
android:scrollbars="vertical"
android:gravity="top"
android:capitalize="sentences"
android:textSize="18sp"
android:singleLine="false" />
</LinearLayout>
</ScrollView>
<include layout="@layout/control_dialog_ok"/>
</LinearLayout>
Loading…
Cancel
Save