mirror of https://github.com/tasks/tasks
Replace Repeat Confirmation popup with snackbar
parent
35c16b3e37
commit
8265c5e1d1
@ -1,203 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.gcal.GCalHelper;
|
||||
import com.todoroo.astrid.repeats.RepeatTaskCompleteListener;
|
||||
import com.todoroo.astrid.service.TaskService;
|
||||
import com.todoroo.astrid.ui.DateAndTimeDialog.DateAndTimeDialogListener;
|
||||
import com.todoroo.astrid.utility.Flags;
|
||||
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.ForApplication;
|
||||
import org.tasks.preferences.ActivityPreferences;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastGingerbread;
|
||||
import static org.tasks.date.DateTimeUtils.newDate;
|
||||
|
||||
/**
|
||||
* Helper class that creates a dialog to confirm the results of a quick add markup
|
||||
* @author Sam
|
||||
*
|
||||
*/
|
||||
public class DateChangedAlerts {
|
||||
|
||||
/** Preference key for how many of these helper dialogs we've shown */
|
||||
private static final String PREF_NUM_HELPERS_SHOWN = "pref_num_date_helpers"; //$NON-NLS-1$
|
||||
|
||||
/** Preference key for whether or not we should show such dialogs */
|
||||
private static final int PREF_SHOW_HELPERS = R.string.p_showSmartConfirmation_key;
|
||||
|
||||
/** Start showing the option to hide future notifs after this many confirmation dialogs */
|
||||
private static final int HIDE_CHECKBOX_AFTER_SHOWS = 3;
|
||||
|
||||
private final Context context;
|
||||
private final ActivityPreferences preferences;
|
||||
|
||||
@Inject
|
||||
public DateChangedAlerts(@ForApplication Context context, ActivityPreferences preferences) {
|
||||
this.context = context;
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public void showRepeatTaskRescheduledDialog(final GCalHelper gcalHelper, final TaskService taskService, final Activity activity, final Task task,
|
||||
final long oldDueDate, final long newDueDate, final boolean lastTime) {
|
||||
if (!preferences.getBoolean(PREF_SHOW_HELPERS, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Dialog d = new Dialog(activity, R.style.ReminderDialog);
|
||||
|
||||
d.setContentView(R.layout.astrid_reminder_view);
|
||||
|
||||
Button okButton = (Button) d.findViewById(R.id.reminder_complete);
|
||||
Button undoButton = (Button) d.findViewById(R.id.reminder_edit);
|
||||
|
||||
Button keepGoing = (Button) d.findViewById(R.id.reminder_snooze);
|
||||
if (!lastTime) {
|
||||
keepGoing.setVisibility(View.GONE);
|
||||
} else {
|
||||
keepGoing.setText(R.string.repeat_keep_going);
|
||||
keepGoing.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
long startDate = 0;
|
||||
DateAndTimeDialog picker = new DateAndTimeDialog(preferences, activity, startDate, R.layout.repeat_until_dialog, R.string.repeat_until_title);
|
||||
picker.setDateAndTimeDialogListener(new DateAndTimeDialogListener() {
|
||||
@Override
|
||||
public void onDateAndTimeSelected(long date) {
|
||||
d.dismiss();
|
||||
task.setRepeatUntil(date);
|
||||
RepeatTaskCompleteListener.rescheduleTask(context, gcalHelper, taskService, task, newDueDate);
|
||||
Flags.set(Flags.REFRESH);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
okButton.setText(android.R.string.ok);
|
||||
undoButton.setText(R.string.DLG_undo);
|
||||
|
||||
int titleResource = lastTime ? R.string.repeat_rescheduling_dialog_title_last_time : R.string.repeat_rescheduling_dialog_title;
|
||||
((TextView) d.findViewById(R.id.reminder_title)).setText(
|
||||
activity.getString(titleResource, task.getTitle()));
|
||||
|
||||
String oldDueDateString = getRelativeDateAndTimeString(activity, oldDueDate);
|
||||
String newDueDateString = getRelativeDateAndTimeString(activity, newDueDate);
|
||||
String repeatUntilDateString = getRelativeDateAndTimeString(activity, task.getRepeatUntil());
|
||||
|
||||
String encouragement = "";
|
||||
|
||||
String speechBubbleText;
|
||||
if (lastTime) {
|
||||
speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble_last_time, repeatUntilDateString, encouragement);
|
||||
} else if (!TextUtils.isEmpty(oldDueDateString)) {
|
||||
speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble, encouragement, oldDueDateString, newDueDateString);
|
||||
} else {
|
||||
speechBubbleText = activity.getString(R.string.repeat_rescheduling_dialog_bubble_no_date, encouragement, newDueDateString);
|
||||
}
|
||||
|
||||
((TextView) d.findViewById(R.id.reminder_message)).setText(speechBubbleText);
|
||||
|
||||
setupOkAndDismissButtons(d);
|
||||
setupHideCheckbox(d);
|
||||
|
||||
undoButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
d.dismiss();
|
||||
task.setDueDate(oldDueDate);
|
||||
task.setCompletionDate(0L);
|
||||
long hideUntil = task.getHideUntil();
|
||||
if (hideUntil > 0) {
|
||||
task.setHideUntil(hideUntil - (newDueDate - oldDueDate));
|
||||
}
|
||||
taskService.save(task);
|
||||
Flags.set(Flags.REFRESH);
|
||||
}
|
||||
});
|
||||
|
||||
setupDialogLayoutParams(activity, d);
|
||||
|
||||
d.setOwnerActivity(activity);
|
||||
d.show();
|
||||
}
|
||||
|
||||
private void setupOkAndDismissButtons(final Dialog d) {
|
||||
d.findViewById(R.id.reminder_complete).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
d.dismiss();
|
||||
}
|
||||
});
|
||||
d.findViewById(R.id.dismiss).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
d.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupHideCheckbox(final Dialog d) {
|
||||
int numShows = preferences.getInt(PREF_NUM_HELPERS_SHOWN, 0);
|
||||
numShows++;
|
||||
if (numShows >= HIDE_CHECKBOX_AFTER_SHOWS) {
|
||||
CheckBox checkbox = (CheckBox) d.findViewById(R.id.reminders_should_show);
|
||||
checkbox.setVisibility(View.VISIBLE);
|
||||
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
preferences.setBoolean(PREF_SHOW_HELPERS, !isChecked);
|
||||
}
|
||||
});
|
||||
}
|
||||
preferences.setInt(PREF_NUM_HELPERS_SHOWN, numShows);
|
||||
}
|
||||
|
||||
private void setupDialogLayoutParams(Context context, Dialog d) {
|
||||
LayoutParams params = d.getWindow().getAttributes();
|
||||
params.width = LayoutParams.FILL_PARENT;
|
||||
params.height = LayoutParams.WRAP_CONTENT;
|
||||
Configuration config = context.getResources().getConfiguration();
|
||||
int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
|
||||
if (atLeastGingerbread() && size == Configuration.SCREENLAYOUT_SIZE_XLARGE || size == Configuration.SCREENLAYOUT_SIZE_LARGE) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
params.width = metrics.widthPixels / 2;
|
||||
}
|
||||
d.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
||||
|
||||
}
|
||||
|
||||
private String getRelativeDateAndTimeString(Context context, long date) {
|
||||
String dueString = date > 0 ? DateUtilities.getRelativeDay(context, date, false) : "";
|
||||
if(Task.hasDueTime(date)) {
|
||||
dueString = String.format("%s at %s", dueString, //$NON-NLS-1$
|
||||
DateUtilities.getTimeString(context, newDate(date)));
|
||||
}
|
||||
return dueString;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package org.tasks.receivers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.todoroo.andlib.data.Property;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.service.TaskService;
|
||||
import com.todoroo.astrid.utility.Flags;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.InjectingBroadcastReceiver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.tasks.date.DateTimeUtils.newDate;
|
||||
|
||||
public class RepeatConfirmationReceiver extends InjectingBroadcastReceiver {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RepeatConfirmationReceiver.class);
|
||||
|
||||
private final Property<?>[] REPEAT_RESCHEDULED_PROPERTIES =
|
||||
new Property<?>[]{
|
||||
Task.ID,
|
||||
Task.TITLE,
|
||||
Task.DUE_DATE,
|
||||
Task.HIDE_UNTIL,
|
||||
Task.REPEAT_UNTIL
|
||||
};
|
||||
|
||||
@Inject TaskService taskService;
|
||||
|
||||
private final Activity activity;
|
||||
|
||||
public RepeatConfirmationReceiver(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
super.onReceive(context, intent);
|
||||
|
||||
long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, 0);
|
||||
|
||||
if (taskId > 0) {
|
||||
long oldDueDate = intent.getLongExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, 0);
|
||||
long newDueDate = intent.getLongExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, 0);
|
||||
Task task = taskService.fetchById(taskId, REPEAT_RESCHEDULED_PROPERTIES);
|
||||
|
||||
try {
|
||||
showSnackbar(activity.findViewById(R.id.task_list_body), task, oldDueDate, newDueDate);
|
||||
} catch (WindowManager.BadTokenException e) { // Activity not running when tried to show dialog--rebroadcast
|
||||
log.error(e.getMessage(), e);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showSnackbar(View view, final Task task, final long oldDueDate, final long newDueDate) {
|
||||
String dueDateString = getRelativeDateAndTimeString(activity, newDueDate);
|
||||
String snackbarText = activity.getString(R.string.repeat_snackbar, task.getTitle(), dueDateString);
|
||||
|
||||
Snackbar.make(view, snackbarText, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.DLG_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
task.setDueDate(oldDueDate);
|
||||
task.setCompletionDate(0L);
|
||||
long hideUntil = task.getHideUntil();
|
||||
if (hideUntil > 0) {
|
||||
task.setHideUntil(hideUntil - (newDueDate - oldDueDate));
|
||||
}
|
||||
taskService.save(task);
|
||||
Flags.set(Flags.REFRESH);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private String getRelativeDateAndTimeString(Context context, long date) {
|
||||
String dueString = date > 0 ? DateUtilities.getRelativeDay(context, date, false) : "";
|
||||
if (Task.hasDueTime(date)) {
|
||||
// TODO: localize this
|
||||
dueString = String.format("%s at %s", dueString, //$NON-NLS-1$
|
||||
DateUtilities.getTimeString(context, newDate(date)));
|
||||
}
|
||||
return dueString;
|
||||
}
|
||||
}
|
@ -1,99 +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:id="@+id/reminder_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="15dip"
|
||||
android:layout_marginRight="15dip"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="260dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="20dip"
|
||||
android:layout_marginLeft="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/astrid_speech_bubble"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/reminders_should_show"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:text="@string/TLA_quickadd_confirm_hide_helpers"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="170dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
<ImageView
|
||||
android:id="@+id/dismiss"
|
||||
android:layout_width="25dip"
|
||||
android:layout_height="25dip"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:src="@drawable/ic_menu_close"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/TAd_actionEditTask"
|
||||
android:background="#707070"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_snooze"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/rmd_NoA_snooze"
|
||||
android:background="#707070"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_complete"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/rmd_NoA_done"
|
||||
android:background="?attr/asThemeTextColor"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1,85 +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:id="@+id/reminder_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dip"
|
||||
android:paddingRight="10dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="20dip"
|
||||
android:layout_marginLeft="5dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_weight="1"/>
|
||||
<ImageView
|
||||
android:id="@+id/dismiss"
|
||||
android:layout_width="25dip"
|
||||
android:layout_height="25dip"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_menu_close"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/astrid_speech_bubble"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/reminders_should_show"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:text="@string/TLA_quickadd_confirm_hide_helpers"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/reminder_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/TAd_actionEditTask"
|
||||
android:background="#707070"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_snooze"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/rmd_NoA_snooze"
|
||||
android:background="#707070"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_complete"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/rmd_NoA_done"
|
||||
android:background="?attr/asThemeTextColor"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue