Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-android
Commits
77979569
Commit
77979569
authored
Jan 15, 2017
by
Robert Hitt
Browse files
Notification settings are now saved
- Also changed some wording, and added Tgrehawi to contributors
parent
4216ea5a
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/srct/whatsopen/presenters/FacilityPresenter.java
View file @
77979569
...
...
@@ -49,7 +49,7 @@ public class FacilityPresenter {
.
equalTo
(
"mName"
,
facilityName
).
findFirst
();
f
.
setFavorited
(
status
);
editor
.
putBoolean
(
facilityName
,
status
);
editor
.
putBoolean
(
facilityName
+
"FavoriteStatus"
,
status
);
editor
.
apply
();
},
null
,
null
);
...
...
@@ -68,7 +68,7 @@ public class FacilityPresenter {
if
(
facility
.
isOpen
())
{
if
(
facilityDoesNotClose
(
openTimesList
.
first
()))
{
return
"
This facility is always open
"
;
return
"
Open 24/7
"
;
}
String
closingTime
=
getCurrentEndTime
(
openTimesList
,
currentDay
);
...
...
app/src/main/java/srct/whatsopen/presenters/MainPresenter.java
View file @
77979569
...
...
@@ -36,7 +36,7 @@ public class MainPresenter {
public
void
attachView
(
MainView
view
)
{
this
.
mMainView
=
view
;
pref
=
PreferenceManager
.
getDefaultSharedPreferences
(
mMainView
.
getContext
());
pref
=
PreferenceManager
.
getDefaultSharedPreferences
(
mMainView
.
getContext
());
}
public
void
detachView
()
{
...
...
@@ -81,7 +81,7 @@ public class MainPresenter {
for
(
Facility
facility
:
facilities
)
{
// Query SharedReferences for each Facility's favorite status. defaults to false
facility
.
setFavorited
(
pref
.
getBoolean
(
facility
.
getName
(),
false
));
facility
.
setFavorited
(
pref
.
getBoolean
(
facility
.
getName
()
+
"FavoriteStatus"
,
false
));
facility
.
setOpen
(
getOpenStatus
(
facility
,
Calendar
.
getInstance
()));
}
...
...
app/src/main/java/srct/whatsopen/presenters/NotificationPresenter.java
0 → 100644
View file @
77979569
package
srct.whatsopen.presenters
;
import
android.content.SharedPreferences
;
import
android.preference.PreferenceManager
;
import
android.widget.Toast
;
import
java.util.HashSet
;
import
java.util.Set
;
import
srct.whatsopen.views.NotificationView
;
public
class
NotificationPresenter
{
private
NotificationView
mNotificationView
;
private
Set
<
String
>
mNotificationSettings
;
private
SharedPreferences
pref
;
public
void
attachView
(
NotificationView
view
)
{
mNotificationView
=
view
;
pref
=
PreferenceManager
.
getDefaultSharedPreferences
(
mNotificationView
.
getContext
());
}
public
void
detachView
()
{
mNotificationView
=
null
;
}
// Gets the notification settings from SharedPreferences, parses them to booleans,
// and passes them to the View
public
void
presentNotifications
(
String
name
)
{
mNotificationSettings
=
pref
.
getStringSet
(
name
+
"NotificationSettings"
,
null
);
boolean
opening
=
false
,
closing
=
false
,
interval_on
=
false
,
interval_15
=
false
,
interval_30
=
false
,
interval_hour
=
false
;
if
(
mNotificationSettings
!=
null
)
{
for
(
String
s
:
mNotificationSettings
)
{
switch
(
s
)
{
case
"opening"
:
opening
=
true
;
break
;
case
"closing"
:
closing
=
true
;
break
;
case
"interval_on"
:
interval_on
=
true
;
break
;
case
"interval_15"
:
interval_15
=
true
;
break
;
case
"interval_30"
:
interval_30
=
true
;
break
;
case
"interval_hour"
:
interval_hour
=
true
;
break
;
}
}
}
mNotificationView
.
setNotificationChecks
(
opening
,
closing
,
interval_on
,
interval_15
,
interval_30
,
interval_hour
);
}
// Saves the notification settings to SharedPreferences and schedules the Notifications
public
void
saveNotifications
(
String
name
,
boolean
inEditMode
,
boolean
opening
,
boolean
closing
,
boolean
interval_on
,
boolean
interval_15
,
boolean
interval_30
,
boolean
interval_hour
)
{
if
(
inEditMode
)
{
editNotifications
(
name
,
opening
,
closing
,
interval_on
,
interval_15
,
interval_30
,
interval_hour
);
}
else
{
setNotifications
(
"Notifications set."
,
name
,
opening
,
closing
,
interval_on
,
interval_15
,
interval_30
,
interval_hour
);
}
}
// If no checkboxes are set, removes Notifications. Else, sets new Notifications
private
void
editNotifications
(
String
name
,
boolean
opening
,
boolean
closing
,
boolean
interval_on
,
boolean
interval_15
,
boolean
interval_30
,
boolean
interval_hour
)
{
if
(!
opening
&&
!
closing
&&
!
interval_on
&&
!
interval_15
&&
!
interval_30
&&
!
interval_hour
)
{
removeNotifications
(
name
);
}
else
{
setNotifications
(
"Notifications edited."
,
name
,
opening
,
closing
,
interval_on
,
interval_15
,
interval_30
,
interval_hour
);
}
}
// Removes the Notification settings from SharedPreferences
private
void
removeNotifications
(
String
name
)
{
SharedPreferences
.
Editor
editor
=
pref
.
edit
();
editor
.
putStringSet
(
name
+
"NotificationSettings"
,
null
);
editor
.
apply
();
Toast
.
makeText
(
mNotificationView
.
getContext
(),
"Notifications removed."
,
Toast
.
LENGTH_SHORT
).
show
();
mNotificationView
.
dismiss
();
}
// Saves the Notification settings to SharedPreferences
private
void
setNotifications
(
String
message
,
String
name
,
boolean
opening
,
boolean
closing
,
boolean
interval_on
,
boolean
interval_15
,
boolean
interval_30
,
boolean
interval_hour
)
{
// if the Notifications are valid (i.e. one of each category is checked)
if
((
opening
||
closing
)
&&
(
interval_on
||
interval_15
||
interval_30
||
interval_hour
))
{
Set
<
String
>
set
=
setFromBooleans
(
opening
,
closing
,
interval_on
,
interval_15
,
interval_30
,
interval_hour
);
SharedPreferences
.
Editor
editor
=
pref
.
edit
();
editor
.
putStringSet
(
name
+
"NotificationSettings"
,
set
);
editor
.
apply
();
Toast
.
makeText
(
mNotificationView
.
getContext
(),
message
,
Toast
.
LENGTH_SHORT
).
show
();
mNotificationView
.
dismiss
();
}
else
{
// Show error message
Toast
.
makeText
(
mNotificationView
.
getContext
(),
"Invalid settings. One of each category must be selected."
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
// Returns a String set parsed from the given booleans
private
Set
<
String
>
setFromBooleans
(
boolean
opening
,
boolean
closing
,
boolean
interval_on
,
boolean
interval_15
,
boolean
interval_30
,
boolean
interval_hour
)
{
Set
<
String
>
set
=
new
HashSet
<>(
6
);
if
(
opening
)
set
.
add
(
"opening"
);
if
(
closing
)
set
.
add
(
"closing"
);
if
(
interval_on
)
set
.
add
(
"interval_on"
);
if
(
interval_15
)
set
.
add
(
"interval_15"
);
if
(
interval_30
)
set
.
add
(
"interval_30"
);
if
(
interval_hour
)
set
.
add
(
"interval_hour"
);
return
set
;
}
}
app/src/main/java/srct/whatsopen/views/NotificationView.java
0 → 100644
View file @
77979569
package
srct.whatsopen.views
;
import
android.content.Context
;
public
interface
NotificationView
{
public
Context
getContext
();
public
void
setNotificationChecks
(
boolean
opening
,
boolean
closing
,
boolean
intervalOn
,
boolean
interval_15
,
boolean
interval_30
,
boolean
intervalHour
);
public
void
dismiss
();
}
app/src/main/java/srct/whatsopen/views/activities/AboutActivity.java
View file @
77979569
...
...
@@ -38,7 +38,7 @@ public class AboutActivity extends MaterialAboutActivity {
contributorsCardBuilder
.
addItem
(
new
MaterialAboutActionItem
.
Builder
()
.
text
(
"Version 1.0"
)
.
icon
(
R
.
drawable
.
ic_people_black_24dp
)
.
subText
(
"Robert Hitt"
)
.
subText
(
"Robert Hitt
, Tanner Grehawick
"
)
.
build
());
MaterialAboutCard
.
Builder
aboutCardBuilder
=
new
MaterialAboutCard
.
Builder
();
...
...
app/src/main/java/srct/whatsopen/views/activities/DetailActivity.java
View file @
77979569
package
srct.whatsopen.views.activities
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.preference.PreferenceManager
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.NavUtils
;
import
android.support.v7.app.AppCompatActivity
;
...
...
@@ -13,6 +17,7 @@ import android.widget.Button;
import
android.widget.TextView
;
import
java.util.Calendar
;
import
java.util.Set
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
...
...
@@ -25,18 +30,25 @@ import srct.whatsopen.presenters.FacilityPresenter;
import
srct.whatsopen.views.fragments.NotificationDialogFragment
;
public
class
DetailActivity
extends
AppCompatActivity
implements
FacilityView
{
public
class
DetailActivity
extends
AppCompatActivity
implements
FacilityView
,
NotificationDialogFragment
.
NotificationDialogListener
{
@BindView
(
R
.
id
.
open_status
)
TextView
openStatusTextView
;
@BindView
(
R
.
id
.
open_duration
)
TextView
openDurationTextView
;
@BindView
(
R
.
id
.
location_text
)
TextView
locationTextView
;
@BindView
(
R
.
id
.
schedule_text
)
TextView
scheduleTextView
;
@BindView
(
R
.
id
.
notification_button
)
Button
notificationButton
;
MenuItem
mFavoriteMenuItem
;
@BindView
(
R
.
id
.
open_status
)
TextView
openStatusTextView
;
@BindView
(
R
.
id
.
open_duration
)
TextView
openDurationTextView
;
@BindView
(
R
.
id
.
location_text
)
TextView
locationTextView
;
@BindView
(
R
.
id
.
schedule_text
)
TextView
scheduleTextView
;
@BindView
(
R
.
id
.
notification_button
)
Button
notificationButton
;
private
MenuItem
mFavoriteMenuItem
;
private
FacilityPresenter
mPresenter
;
private
Facility
mFacility
;
private
boolean
inEditMode
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -53,6 +65,8 @@ public class DetailActivity extends AppCompatActivity implements FacilityView{
ButterKnife
.
bind
(
this
);
configureToolbar
();
fillTextViews
();
setNotificationStatus
();
}
@Override
...
...
@@ -73,7 +87,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView{
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
switch
(
item
.
getItemId
())
{
case
R
.
id
.
home
:
NavUtils
.
navigateUpFromSameTask
(
this
);
return
true
;
...
...
@@ -94,7 +108,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView{
@Override
public
void
changeFavoriteIcon
(
boolean
isFavorited
)
{
if
(
isFavorited
)
if
(
isFavorited
)
mFavoriteMenuItem
.
setIcon
(
R
.
drawable
.
ic_fav_button_on_24dp
);
else
mFavoriteMenuItem
.
setIcon
(
R
.
drawable
.
ic_fav_button_white_24dp
);
...
...
@@ -104,7 +118,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView{
public
void
showNotificationDialog
()
{
FragmentManager
fm
=
getSupportFragmentManager
();
NotificationDialogFragment
notificationDialogFragment
=
NotificationDialogFragment
.
newInstance
(
""
);
NotificationDialogFragment
.
newInstance
(
mFacility
.
getName
(),
inEditMode
);
notificationDialogFragment
.
show
(
fm
,
"fragment_notification_dialog"
);
}
...
...
@@ -140,4 +154,25 @@ public class DetailActivity extends AppCompatActivity implements FacilityView{
scheduleTextView
.
setText
(
Html
.
fromHtml
(
mPresenter
.
getSchedule
(
mFacility
,
Calendar
.
getInstance
())));
}
// 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
);
if
(
notificationSettings
!=
null
)
{
inEditMode
=
true
;
notificationButton
.
setText
(
"Edit Notifications"
);
}
else
{
inEditMode
=
false
;
notificationButton
.
setText
(
"Set Notifications"
);
}
}
// Allows the NotificationDialog to refresh the view on dismiss
@Override
public
void
onSetNotification
()
{
setNotificationStatus
();
}
}
app/src/main/java/srct/whatsopen/views/fragments/NotificationDialogFragment.java
View file @
77979569
package
srct.whatsopen.views.fragments
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.DialogFragment
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
...
...
@@ -14,10 +16,20 @@ import android.widget.Toast;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.OnClick
;
import
srct.whatsopen.R
;
import
srct.whatsopen.presenters.NotificationPresenter
;
import
srct.whatsopen.views.NotificationView
;
public
class
NotificationDialogFragment
extends
DialogFragment
implements
NotificationView
{
public
interface
NotificationDialogListener
{
void
onSetNotification
();
}
public
class
NotificationDialogFragment
extends
DialogFragment
{
private
static
final
String
ARG_MODE
=
"ARG_MODE"
;
private
static
final
String
ARG_NAME
=
"ARG_NAME"
;
@BindView
(
R
.
id
.
type_closing_check
)
CheckBox
typeClosingCheckBox
;
@BindView
(
R
.
id
.
type_opening_check
)
CheckBox
typeOpeningCheckBox
;
...
...
@@ -28,18 +40,49 @@ public class NotificationDialogFragment extends DialogFragment {
@BindView
(
R
.
id
.
save_button
)
Button
saveButton
;
@BindView
(
R
.
id
.
cancel_button
)
Button
cancelButton
;
private
String
mName
;
private
NotificationPresenter
mPresenter
;
private
boolean
inEditMode
;
private
Handler
mHandler
;
public
NotificationDialogFragment
()
{
}
public
static
NotificationDialogFragment
newInstance
(
String
titl
e
)
{
public
static
NotificationDialogFragment
newInstance
(
String
name
,
boolean
inEditMod
e
)
{
NotificationDialogFragment
frag
=
new
NotificationDialogFragment
();
Bundle
args
=
new
Bundle
();
args
.
putString
(
"title"
,
title
);
args
.
putString
(
ARG_NAME
,
name
);
args
.
putBoolean
(
ARG_MODE
,
inEditMode
);
frag
.
setArguments
(
args
);
return
frag
;
}
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
// Inflate arguments
mName
=
getArguments
().
getString
(
ARG_NAME
);
inEditMode
=
getArguments
().
getBoolean
(
ARG_MODE
);
// Set up presenter
mPresenter
=
new
NotificationPresenter
();
mPresenter
.
attachView
(
this
);
}
@Override
public
void
onDestroyView
()
{
mPresenter
.
detachView
();
super
.
onDestroyView
();
}
@Override
public
void
onDismiss
(
DialogInterface
dialog
)
{
super
.
onDismiss
(
dialog
);
}
@Nullable
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
...
...
@@ -52,17 +95,44 @@ public class NotificationDialogFragment extends DialogFragment {
super
.
onViewCreated
(
view
,
savedInstanceState
);
ButterKnife
.
bind
(
this
,
view
);
if
(
inEditMode
)
{
mPresenter
.
presentNotifications
(
mName
);
}
}
@OnClick
(
R
.
id
.
save_button
)
public
void
onSave
()
{
Toast
.
makeText
(
getContext
(),
"Notifications set."
,
Toast
.
LENGTH_SHORT
).
show
();
dismiss
();
mPresenter
.
saveNotifications
(
mName
,
inEditMode
,
typeOpeningCheckBox
.
isChecked
(),
typeClosingCheckBox
.
isChecked
(),
intervalOnCheckBox
.
isChecked
(),
interval15CheckBox
.
isChecked
(),
interval30CheckBox
.
isChecked
(),
intervalHourCheckBox
.
isChecked
());
NotificationDialogListener
listener
=
(
NotificationDialogListener
)
getActivity
();
listener
.
onSetNotification
();
}
@OnClick
(
R
.
id
.
cancel_button
)
public
void
onCancel
()
{
Toast
.
makeText
(
get
Context
(),
"Canceled."
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
get
Activity
(),
"Canceled."
,
Toast
.
LENGTH_SHORT
).
show
();
dismiss
();
}
@Override
public
void
setNotificationChecks
(
boolean
opening
,
boolean
closing
,
boolean
interval_on
,
boolean
interval_15
,
boolean
interval_30
,
boolean
interval_hour
)
{
typeOpeningCheckBox
.
setChecked
(
opening
);
typeClosingCheckBox
.
setChecked
(
closing
);
intervalOnCheckBox
.
setChecked
(
interval_on
);
interval15CheckBox
.
setChecked
(
interval_15
);
interval30CheckBox
.
setChecked
(
interval_30
);
intervalHourCheckBox
.
setChecked
(
interval_hour
);
}
@Override
public
Context
getContext
()
{
return
getActivity
();
}
}
app/src/test/java/srct/whatsopen/FacilityPresenterUnitTest.java
View file @
77979569
...
...
@@ -141,7 +141,7 @@ public class FacilityPresenterUnitTest {
String
statusDuration
=
mPresenter
.
getStatusDuration
(
mFacility
,
now
);
assertEquals
(
"
This facility is always open
"
,
statusDuration
);
assertEquals
(
"
Open 24/7
"
,
statusDuration
);
}
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment