|
|
|
|
@ -1,12 +1,15 @@
|
|
|
|
|
package com.todoroo.astrid.reminders;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.support.v4.app.DialogFragment;
|
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.Spinner;
|
|
|
|
|
|
|
|
|
|
@ -17,61 +20,98 @@ import com.todoroo.astrid.ui.NumberPicker;
|
|
|
|
|
|
|
|
|
|
import org.tasks.R;
|
|
|
|
|
|
|
|
|
|
public class SnoozeDialog extends FrameLayout implements DialogInterface.OnClickListener {
|
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
import butterknife.InjectView;
|
|
|
|
|
|
|
|
|
|
LinearLayout snoozePicker;
|
|
|
|
|
NumberPicker snoozeValue;
|
|
|
|
|
Spinner snoozeUnits;
|
|
|
|
|
SnoozeCallback snoozeCallback;
|
|
|
|
|
public class SnoozeDialog extends DialogFragment {
|
|
|
|
|
|
|
|
|
|
public SnoozeDialog(Activity activity, SnoozeCallback callback) {
|
|
|
|
|
super(activity);
|
|
|
|
|
this.snoozeCallback = callback;
|
|
|
|
|
@InjectView(R.id.snoozePicker) LinearLayout snoozePicker;
|
|
|
|
|
@InjectView(R.id.numberPicker) NumberPicker snoozeValue;
|
|
|
|
|
@InjectView(R.id.numberUnits) Spinner snoozeUnits;
|
|
|
|
|
|
|
|
|
|
LayoutInflater mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
mInflater.inflate(R.layout.snooze_dialog, this, true);
|
|
|
|
|
private SnoozeCallback snoozeCallback;
|
|
|
|
|
private DialogInterface.OnDismissListener onDismissListener;
|
|
|
|
|
private String title;
|
|
|
|
|
|
|
|
|
|
snoozePicker = (LinearLayout) findViewById(R.id.snoozePicker);
|
|
|
|
|
snoozeValue = (NumberPicker) findViewById(R.id.numberPicker);
|
|
|
|
|
snoozeUnits = (Spinner) findViewById(R.id.numberUnits);
|
|
|
|
|
@NonNull
|
|
|
|
|
@Override
|
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
|
|
LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
View layout = mInflater.inflate(R.layout.snooze_dialog, null);
|
|
|
|
|
ButterKnife.inject(this, layout);
|
|
|
|
|
|
|
|
|
|
snoozeValue.setIncrementBy(1);
|
|
|
|
|
snoozeValue.setRange(1, 99);
|
|
|
|
|
snoozeUnits.setSelection(RepeatControlSet.INTERVAL_HOURS);
|
|
|
|
|
snoozeUnits.setOnTouchListener(new OnTouchListener() {
|
|
|
|
|
snoozeUnits.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
AndroidUtilities.hideSoftInputForViews(getContext(), snoozePicker);
|
|
|
|
|
AndroidUtilities.hideSoftInputForViews(getActivity(), snoozePicker);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new AlertDialog.Builder(getActivity(), R.style.Tasks_Dialog)
|
|
|
|
|
.setTitle(title)
|
|
|
|
|
.setView(layout)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
long time = DateUtilities.now();
|
|
|
|
|
int value = snoozeValue.getCurrent();
|
|
|
|
|
switch (snoozeUnits.getSelectedItemPosition()) {
|
|
|
|
|
case RepeatControlSet.INTERVAL_DAYS:
|
|
|
|
|
time += value * DateUtilities.ONE_DAY;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_HOURS:
|
|
|
|
|
time += value * DateUtilities.ONE_HOUR;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_MINUTES:
|
|
|
|
|
time += value * DateUtilities.ONE_MINUTE;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_WEEKS:
|
|
|
|
|
time += value * 7 * DateUtilities.ONE_DAY;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_MONTHS:
|
|
|
|
|
time = DateUtilities.addCalendarMonthsToUnixtime(time, 1);
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_YEARS:
|
|
|
|
|
time = DateUtilities.addCalendarMonthsToUnixtime(time, 12);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snoozeCallback.snoozeForTime(time);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.setOnDismissListener(this)
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
long time = DateUtilities.now();
|
|
|
|
|
int value = snoozeValue.getCurrent();
|
|
|
|
|
switch(snoozeUnits.getSelectedItemPosition()) {
|
|
|
|
|
case RepeatControlSet.INTERVAL_DAYS:
|
|
|
|
|
time += value * DateUtilities.ONE_DAY;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_HOURS:
|
|
|
|
|
time += value * DateUtilities.ONE_HOUR;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_MINUTES:
|
|
|
|
|
time += value * DateUtilities.ONE_MINUTE;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_WEEKS:
|
|
|
|
|
time += value * 7 * DateUtilities.ONE_DAY;
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_MONTHS:
|
|
|
|
|
time = DateUtilities.addCalendarMonthsToUnixtime(time, 1);
|
|
|
|
|
break;
|
|
|
|
|
case RepeatControlSet.INTERVAL_YEARS:
|
|
|
|
|
time = DateUtilities.addCalendarMonthsToUnixtime(time, 12);
|
|
|
|
|
break;
|
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
|
super.onDismiss(dialog);
|
|
|
|
|
|
|
|
|
|
if (onDismissListener != null) {
|
|
|
|
|
onDismissListener.onDismiss(dialog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSnoozeCallback(SnoozeCallback snoozeCallback) {
|
|
|
|
|
this.snoozeCallback = snoozeCallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
|
|
|
|
|
this.onDismissListener = onDismissListener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snoozeCallback.snoozeForTime(time);
|
|
|
|
|
public void setTitle(String title) {
|
|
|
|
|
this.title = title;
|
|
|
|
|
}
|
|
|
|
|
}
|