Defined Alarm contracts for MVP

This commit is contained in:
Phillip Hsu 2016-06-03 00:05:53 -07:00
parent 19856e1981
commit 70992a7cbd
4 changed files with 87 additions and 1 deletions

View File

@ -0,0 +1,20 @@
package com.philliphsu.clock2.editalarm;
/**
* Created by Phillip Hsu on 6/2/2016.
*/
interface AlarmContract {
interface View {
void showTime(String time);
void showLabel(String label);
void showEnabled(boolean enabled);
void showCanDismissNow();
void showSnoozed(String message);
}
interface Presenter {
void dismissNow();
void endSnoozing();
}
}

View File

@ -0,0 +1,26 @@
package com.philliphsu.clock2.editalarm;
/**
* Created by Phillip Hsu on 6/2/2016.
*/
public interface AlarmEditor {
interface View extends AlarmContract.View {
void showRecurringDays(int weekDay, boolean recurs);
void showRingtone(String ringtone);
void showVibrates(boolean vibrates);
void showEditorClosed();
int getHour();
int getMinutes();
boolean isEnabled();
boolean isRecurringDay(int weekDay);
String getLabel();
String getRingtone();
boolean vibrates();
}
interface Presenter extends AlarmContract.Presenter {
void save();
void delete();
}
}

View File

@ -0,0 +1,16 @@
package com.philliphsu.clock2.editalarm;
/**
* Created by Phillip Hsu on 6/2/2016.
*/
public interface AlarmItem {
interface View extends AlarmContract.View {
void showCountdown(long remainingTime);
void showRecurringDays(String recurringDays);
}
interface Presenter extends AlarmContract.Presenter {
void setEnabled(boolean enabled);
}
}

View File

@ -11,6 +11,7 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -230,6 +231,16 @@ public class EditAlarmActivity extends BaseActivity implements AlarmNumpad.KeyLi
@OnClick(R.id.save) @OnClick(R.id.save)
void save() { void save() {
int hour;
int minutes;
try {
hour = mNumpad.getHours();
minutes = mNumpad.getMinutes();
} catch (IllegalStateException e) {
Log.e(TAG, e.getMessage());
return;
}
boolean[] days = new boolean[NUM_DAYS]; boolean[] days = new boolean[NUM_DAYS];
for (int i = SUNDAY; i <= SATURDAY; i++) { for (int i = SUNDAY; i <= SATURDAY; i++) {
// What position in the week is this day located at? // What position in the week is this day located at?
@ -238,7 +249,8 @@ public class EditAlarmActivity extends BaseActivity implements AlarmNumpad.KeyLi
days[i] = mDays[pos].isChecked(); days[i] = mDays[pos].isChecked();
} }
Alarm a = Alarm.builder() Alarm a = Alarm.builder()
// TODO: set hour and minute .hour(hour)
.minutes(minutes)
.ringtone(mSelectedRingtoneUri.toString()) .ringtone(mSelectedRingtoneUri.toString())
.recurringDays(days) // TODO: See https://github.com/google/auto/blob/master/value/userguide/howto.md#mutable_property .recurringDays(days) // TODO: See https://github.com/google/auto/blob/master/value/userguide/howto.md#mutable_property
.label(mLabel.getText().toString()) .label(mLabel.getText().toString())
@ -289,6 +301,18 @@ public class EditAlarmActivity extends BaseActivity implements AlarmNumpad.KeyLi
} }
} }
@OnClick(R.id.numpad)
void captureClickEvent() {
/*
* ====================== DO NOT IMPLEMENT =====================================
* A stray click in the vicinity of the persistent footer buttons, even while
* they are covered by the numpad, will still have the click event call through
* to those buttons. This captures the buttons' click events as long as the numpad
* is in view.
* =============================================================================
*/
}
private void setWeekDaysText() { private void setWeekDaysText() {
for (int i = 0; i < mDays.length; i++) { for (int i = 0; i < mDays.length; i++) {
int weekDay = DaysOfWeek.getInstance(this).weekDayAt(i); int weekDay = DaysOfWeek.getInstance(this).weekDayAt(i);