mirror of https://github.com/iSoron/uhabits.git
parent
819a8d341f
commit
a201273781
@ -1,128 +0,0 @@
|
|||||||
package org.isoron.uhabits.notifications;
|
|
||||||
|
|
||||||
import android.app.*;
|
|
||||||
import android.content.*;
|
|
||||||
import android.os.*;
|
|
||||||
import android.support.v4.app.*;
|
|
||||||
import android.support.v7.view.*;
|
|
||||||
import android.text.format.*;
|
|
||||||
import android.util.*;
|
|
||||||
|
|
||||||
import com.android.datetimepicker.time.*;
|
|
||||||
import com.android.datetimepicker.time.TimePickerDialog;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.isoron.uhabits.core.utils.DateUtils;
|
|
||||||
import org.isoron.uhabits.receivers.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static org.isoron.uhabits.core.ui.ThemeSwitcher.THEME_DARK;
|
|
||||||
import static org.isoron.uhabits.core.utils.DateUtils.applyTimezone;
|
|
||||||
|
|
||||||
public class SnoozeDelayActivity extends FragmentActivity implements
|
|
||||||
TimePickerDialog.OnTimeSetListener, DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
|
|
||||||
|
|
||||||
public static final String ACTION_ASK_SNOOZE = "org.isoron.uhabits.ACTION_ASK_SNOOZE";
|
|
||||||
|
|
||||||
private static final String TAG = "SnoozeDelayActivity";
|
|
||||||
|
|
||||||
private AlertDialog activeDelayDialog;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle bundle)
|
|
||||||
{
|
|
||||||
super.onCreate(bundle);
|
|
||||||
Intent intent = getIntent();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
switch (intent.getAction())
|
|
||||||
{
|
|
||||||
case ACTION_ASK_SNOOZE:
|
|
||||||
AskSnooze();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (RuntimeException e)
|
|
||||||
{
|
|
||||||
Log.e(TAG, "could not process intent", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AskSnooze()
|
|
||||||
{
|
|
||||||
HabitsApplicationComponent component = ((HabitsApplication) getApplicationContext()).getComponent();
|
|
||||||
int theme = component.getPreferences().getTheme() == THEME_DARK
|
|
||||||
? R.style.Theme_AppCompat_Dialog_Alert : R.style.Theme_AppCompat_Light_Dialog_Alert;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, theme));
|
|
||||||
builder.setTitle(R.string.select_snooze_delay)
|
|
||||||
.setItems(R.array.snooze_interval_names_reminder, this);
|
|
||||||
AlertDialog dialog = builder.create();
|
|
||||||
dialog.setOnDismissListener(this);
|
|
||||||
activeDelayDialog = dialog;
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i)
|
|
||||||
{
|
|
||||||
int[] snoozeDelay = getResources().getIntArray(R.array.snooze_interval_values_reminder);
|
|
||||||
assert (i >= 0 && i <= snoozeDelay.length);
|
|
||||||
if( snoozeDelay[ i ] < 0 )
|
|
||||||
{
|
|
||||||
activeDelayDialog.setOnDismissListener(null);
|
|
||||||
AskCustomSnooze();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Intent intent = new Intent( ReminderReceiver.ACTION_SNOOZE_REMINDER_DELAY, getIntent().getData(),
|
|
||||||
this, ReminderReceiver.class );
|
|
||||||
intent.putExtra("snoozeDelay", snoozeDelay[ i ]);
|
|
||||||
sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AskCustomSnooze()
|
|
||||||
{
|
|
||||||
final Calendar calendar = Calendar.getInstance();
|
|
||||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
|
||||||
int minute = calendar.get(Calendar.MINUTE);
|
|
||||||
TimePickerDialog dialog;
|
|
||||||
dialog = TimePickerDialog.newInstance(this,
|
|
||||||
hour, minute, DateFormat.is24HourFormat(this));
|
|
||||||
HabitsApplicationComponent component = ((HabitsApplication) getApplicationContext()).getComponent();
|
|
||||||
dialog.setThemeDark(component.getPreferences().getTheme() == THEME_DARK);
|
|
||||||
dialog.setDismissListener(this);
|
|
||||||
dialog.show(getSupportFragmentManager(),"timePicker");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute)
|
|
||||||
{
|
|
||||||
Calendar calendar = DateUtils.getStartOfTodayCalendar();
|
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
|
||||||
calendar.set(Calendar.MINUTE, minute);
|
|
||||||
calendar.set(Calendar.SECOND, 0);
|
|
||||||
Long time = calendar.getTimeInMillis();
|
|
||||||
if (DateUtils.getLocalTime() > time)
|
|
||||||
time += DateUtils.DAY_LENGTH;
|
|
||||||
time = applyTimezone(time);
|
|
||||||
|
|
||||||
Intent intent = new Intent( ReminderReceiver.ACTION_SNOOZE_REMINDER_SET, getIntent().getData(),
|
|
||||||
this, ReminderReceiver.class );
|
|
||||||
intent.putExtra("reminderTime", time);
|
|
||||||
sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTimeCleared(RadialPickerLayout view)
|
|
||||||
{
|
|
||||||
Intent intent = new Intent( ReminderReceiver.ACTION_DISMISS_REMINDER, getIntent().getData(),
|
|
||||||
this, ReminderReceiver.class );
|
|
||||||
sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialogInterface)
|
|
||||||
{
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,85 @@
|
|||||||
|
package org.isoron.uhabits.notifications;
|
||||||
|
|
||||||
|
import android.os.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.support.v4.app.*;
|
||||||
|
import android.support.v7.app.*;
|
||||||
|
import android.text.format.*;
|
||||||
|
import android.view.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import com.android.datetimepicker.time.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.core.models.*;
|
||||||
|
import org.isoron.uhabits.receivers.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import butterknife.*;
|
||||||
|
|
||||||
|
import static android.content.ContentUris.*;
|
||||||
|
|
||||||
|
public class SnoozeDelayPickerActivity extends AppCompatActivity implements AdapterView
|
||||||
|
.OnItemClickListener
|
||||||
|
{
|
||||||
|
public static final String ACTION_ASK_SNOOZE = "org.isoron.uhabits.ACTION_ASK_SNOOZE";
|
||||||
|
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
private ReminderController reminderController;
|
||||||
|
|
||||||
|
@BindArray(R.array.snooze_picker_names)
|
||||||
|
protected String[] snoozeNames;
|
||||||
|
|
||||||
|
@BindArray(R.array.snooze_picker_values)
|
||||||
|
protected int[] snoozeValues;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle bundle)
|
||||||
|
{
|
||||||
|
super.onCreate(bundle);
|
||||||
|
if (getIntent() == null) finish();
|
||||||
|
if (getIntent().getData() == null) finish();
|
||||||
|
|
||||||
|
HabitsApplication app = (HabitsApplication) getApplicationContext();
|
||||||
|
HabitsApplicationComponent appComponent = app.getComponent();
|
||||||
|
reminderController = appComponent.getReminderController();
|
||||||
|
habit = appComponent.getHabitList().getById(parseId(getIntent().getData()));
|
||||||
|
if (habit == null) finish();
|
||||||
|
|
||||||
|
setTheme(R.style.Theme_AppCompat_Light_Dialog_Alert);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
ListView listView = new ListView(this);
|
||||||
|
listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
|
||||||
|
snoozeNames));
|
||||||
|
listView.setOnItemClickListener(this);
|
||||||
|
setContentView(listView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||||
|
{
|
||||||
|
if (snoozeValues[position] >= 0)
|
||||||
|
{
|
||||||
|
reminderController.onSnoozeDelayPicked(habit, snoozeValues[position]);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else showTimePicker();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showTimePicker()
|
||||||
|
{
|
||||||
|
final Calendar calendar = Calendar.getInstance();
|
||||||
|
int defaultHour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
int defaultMinute = calendar.get(Calendar.MINUTE);
|
||||||
|
TimePickerDialog dialog = TimePickerDialog.newInstance(
|
||||||
|
(view, hour, minute) ->
|
||||||
|
reminderController.onSnoozeTimePicked(habit, hour, minute),
|
||||||
|
defaultHour, defaultMinute, DateFormat.is24HourFormat(this));
|
||||||
|
|
||||||
|
dialog.show(getSupportFragmentManager(), "timePicker");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue