mirror of https://github.com/tasks/tasks
New snooze dialog
parent
4f999bf5fc
commit
739b6df9f0
@ -1,117 +0,0 @@
|
||||
package com.todoroo.astrid.reminders;
|
||||
|
||||
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.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.repeats.RepeatControlSet;
|
||||
import com.todoroo.astrid.ui.NumberPicker;
|
||||
|
||||
import org.tasks.R;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
public class SnoozeDialog extends DialogFragment {
|
||||
|
||||
@InjectView(R.id.snoozePicker) LinearLayout snoozePicker;
|
||||
@InjectView(R.id.numberPicker) NumberPicker snoozeValue;
|
||||
@InjectView(R.id.numberUnits) Spinner snoozeUnits;
|
||||
|
||||
private SnoozeCallback snoozeCallback;
|
||||
private DialogInterface.OnDismissListener onDismissListener;
|
||||
private String title;
|
||||
|
||||
@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 View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
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 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;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package org.tasks.reminders;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.todoroo.astrid.reminders.SnoozeCallback;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.tasks.R;
|
||||
import org.tasks.activities.DateAndTimePickerActivity;
|
||||
import org.tasks.injection.ForApplication;
|
||||
import org.tasks.injection.InjectingDialogFragment;
|
||||
import org.tasks.preferences.Preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static com.todoroo.andlib.utility.DateUtilities.getTimeString;
|
||||
|
||||
public class SnoozeDialog extends InjectingDialogFragment {
|
||||
|
||||
public static final int REQUEST_DATE_TIME = 10101;
|
||||
|
||||
@Inject Preferences preferences;
|
||||
@Inject @ForApplication Context context;
|
||||
|
||||
private DateTime now = new DateTime();
|
||||
private SnoozeCallback snoozeCallback;
|
||||
private DialogInterface.OnCancelListener onCancelListener;
|
||||
private List<Long> snoozeTimes = new ArrayList<>();
|
||||
private ArrayAdapter<String> adapter;
|
||||
|
||||
private DateTime getDateTimeShortcut(int resId, long def) {
|
||||
return now.withMillisOfDay(preferences.getInt(getString(resId), (int) def));
|
||||
}
|
||||
|
||||
private void add(int resId, DateTime dateTime) {
|
||||
adapter.add(getString(resId, getTimeString(context, dateTime.toDate())));
|
||||
snoozeTimes.add(dateTime.getMillis());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1);
|
||||
DateTime morning = getDateTimeShortcut(R.string.p_date_shortcut_morning, TimeUnit.HOURS.toMillis(9));
|
||||
DateTime afternoon = getDateTimeShortcut(R.string.p_date_shortcut_afternoon, TimeUnit.HOURS.toMillis(13));
|
||||
DateTime evening = getDateTimeShortcut(R.string.p_date_shortcut_evening, TimeUnit.HOURS.toMillis(17));
|
||||
DateTime night = getDateTimeShortcut(R.string.p_date_shortcut_night, TimeUnit.HOURS.toMillis(20));
|
||||
DateTime tomorrowMorning = morning.plusDays(1);
|
||||
DateTime tomorrowAfternoon = afternoon.plusDays(1);
|
||||
|
||||
adapter.add(getString(R.string.date_shortcut_hour));
|
||||
snoozeTimes.add(0L);
|
||||
|
||||
DateTime hourCutoff = new DateTime().plusMinutes(75);
|
||||
|
||||
if (morning.isAfter(hourCutoff)) {
|
||||
add(R.string.date_shortcut_morning, morning);
|
||||
add(R.string.date_shortcut_afternoon, afternoon);
|
||||
} else if (afternoon.isAfter(hourCutoff)) {
|
||||
add(R.string.date_shortcut_afternoon, afternoon);
|
||||
add(R.string.date_shortcut_evening, evening);
|
||||
} else if (evening.isAfter(hourCutoff)) {
|
||||
add(R.string.date_shortcut_evening, evening);
|
||||
add(R.string.date_shortcut_night, night);
|
||||
} else if (night.isAfter(hourCutoff)) {
|
||||
add(R.string.date_shortcut_night, night);
|
||||
add(R.string.date_shortcut_tomorrow_morning, tomorrowMorning);
|
||||
} else {
|
||||
add(R.string.date_shortcut_tomorrow_morning, tomorrowMorning);
|
||||
add(R.string.date_shortcut_tomorrow_afternoon, tomorrowAfternoon);
|
||||
}
|
||||
adapter.add(getString(R.string.pick_a_date_and_time));
|
||||
|
||||
return new AlertDialog.Builder(getActivity(), R.style.Tasks_Dialog)
|
||||
.setTitle(R.string.rmd_NoA_snooze)
|
||||
.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
snoozeCallback.snoozeForTime(new DateTime().plusHours(1).getMillis());
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
snoozeCallback.snoozeForTime(snoozeTimes.get(which));
|
||||
break;
|
||||
case 3:
|
||||
dialog.dismiss();
|
||||
getActivity().startActivityForResult(new Intent(context, DateAndTimePickerActivity.class) {{
|
||||
putExtra(DateAndTimePickerActivity.EXTRA_TIMESTAMP, new DateTime().plusMinutes(30).getMillis());
|
||||
}}, REQUEST_DATE_TIME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
|
||||
if (onCancelListener != null) {
|
||||
onCancelListener.onCancel(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSnoozeCallback(SnoozeCallback snoozeCallback) {
|
||||
this.snoozeCallback = snoozeCallback;
|
||||
}
|
||||
|
||||
public void setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
|
||||
this.onCancelListener = onCancelListener;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
**
|
||||
** Copyright 2007, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<TimePicker android:id="@+id/timePicker"
|
||||
android:visibility="gone"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<LinearLayout android:id="@+id/snoozePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.todoroo.astrid.ui.NumberPicker android:id="@+id/numberPicker"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Spinner android:id="@+id/numberUnits"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:entries="@array/repeat_interval"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue