Commit 5323c2ad authored by Robert Hitt's avatar Robert Hitt

NotificationSettings are now saved to Realm

- Really not sure why I decided to save them to
SharedPreferences in the first place. Was pretty hacky
- Also changed some wording, and maybe some other stuff
parent a79578de
package srct.whatsopen.model;
public class NotificationSettings {
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class NotificationSettings extends RealmObject {
public NotificationSettings() {
}
public NotificationSettings(boolean opening, boolean closing, boolean interval_on, boolean interval_15, boolean interval_30, boolean interval_hour) {
public NotificationSettings(String name, boolean opening, boolean closing, boolean interval_on, boolean interval_15, boolean interval_30, boolean interval_hour) {
this.name = name;
this.opening = opening;
this.closing = closing;
this.interval_on = interval_on;
......@@ -15,6 +19,9 @@ public class NotificationSettings {
this.interval_hour = interval_hour;
}
@PrimaryKey
public String name;
public boolean opening;
public boolean closing;
public boolean interval_on;
......
......@@ -125,11 +125,13 @@ public class MainPresenter {
final String name = facility.getName();
realm.executeTransactionAsync((bgRealm) -> {
RealmResults<Facility> results = realm.where(Facility.class).equalTo("mName", name)
RealmResults<Facility> results = bgRealm.where(Facility.class).equalTo("mName", name)
.findAll();
results.deleteAllFromRealm();
});
realm.close();
}
// Sets the open status of each facility in the Realm instance
......
......@@ -25,6 +25,7 @@ import butterknife.OnClick;
import io.realm.Realm;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.NotificationSettings;
import srct.whatsopen.views.FacilityView;
import srct.whatsopen.presenters.FacilityPresenter;
import srct.whatsopen.views.fragments.NotificationDialogFragment;
......@@ -157,9 +158,10 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
// Sets the notification button text to edit if a Notification exists
private void setNotificationStatus() {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
Set<String> notificationSettings = pref.getStringSet(mFacility.getName()
+ "NotificationSettings", null);
Realm realm = Realm.getDefaultInstance();
NotificationSettings notificationSettings = realm.where(NotificationSettings.class)
.equalTo("name", mFacility.getName()).findFirst();
realm.close();
if (notificationSettings != null) {
inEditMode = true;
......
......@@ -81,6 +81,11 @@ public class NotificationDialogFragment extends DialogFragment implements Notifi
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
// Changes the Notification button text in DetailActivity
NotificationDialogListener listener = (NotificationDialogListener) getActivity();
if(listener != null) {
listener.onSetNotification();
}
}
@Nullable
......@@ -107,15 +112,11 @@ public class NotificationDialogFragment extends DialogFragment implements Notifi
@OnClick(R.id.save_button)
public void onSave() {
mPresenter.saveNotifications(mName, inEditMode, new NotificationSettings(
mPresenter.saveNotifications(inEditMode, new NotificationSettings(mName,
typeOpeningCheckBox.isChecked(), typeClosingCheckBox.isChecked(),
intervalOnCheckBox.isChecked(), interval15CheckBox.isChecked(),
interval30CheckBox.isChecked(), intervalHourCheckBox.isChecked()
));
// Changes the Notification button text in DetailActivity
NotificationDialogListener listener = (NotificationDialogListener) getActivity();
listener.onSetNotification();
}
@OnClick(R.id.cancel_button)
......@@ -127,10 +128,6 @@ public class NotificationDialogFragment extends DialogFragment implements Notifi
@OnClick(R.id.remove_button)
public void onRemove() {
mPresenter.removeNotifications(mName, true);
// Changes the Notification button text in DetailActivity
NotificationDialogListener listener = (NotificationDialogListener) getActivity();
listener.onSetNotification();
}
@Override
......
......@@ -85,7 +85,7 @@
<Button
android:id="@+id/remove_button"
android:text="Remove"
android:text="Remove All"
android:textColor="@color/colorPrimary"
android:layout_gravity="center_horizontal"
android:visibility="gone"
......
......@@ -131,7 +131,7 @@
<Button
android:id="@+id/remove_button"
android:text="Remove"
android:text="Remove All"
android:textColor="@color/colorPrimary"
android:layout_toRightOf="@id/save_button"
android:layout_toEndOf="@id/save_button"
......
......@@ -40,14 +40,6 @@ public class NotificationPresenterUnitTest {
assertFalse(hasPassed);
}
@Test
public void testParseTimeStringToMs() {
now.setTimeZone(TimeZone.getTimeZone("EST"));
Long timeInMs = mPresenter.parseTimeStringToMs("14:00:00", 3, now);
assertEquals(1484074800000L, timeInMs.longValue());
}
@Test
public void testSetFromNotificationSettings() {
NotificationSettings n = new NotificationSettings(true, true, true, true, true, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment