Commit 4b958335 authored by Jason Yeomans's avatar Jason Yeomans

merge master

parents 7bed0279 32be32ca
......@@ -4,4 +4,5 @@
## Steps to Reproduce the Behavior
## Helpful links
## Helpful links
(if applicable)
The MIT License (MIT)
Copyright (c) 2017 SRCT
Copyright (c) 2016 SRCT
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
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
http://www.apache.org/licenses/LICENSE-2.0
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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.
......@@ -37,10 +37,10 @@ dependencies {
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:cardview-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.4'
testCompile 'junit:junit:4.12'
......@@ -53,4 +53,5 @@ dependencies {
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.2.0'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.4'
compile 'com.takisoft.fix:preference-v7:25.1.1.0'
}
......@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
......@@ -25,6 +26,7 @@
<activity android:name=".views.activities.DetailActivity"
android:parentActivityName=".views.activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".views.activities.MainActivity"/>
......@@ -32,11 +34,15 @@
<activity android:name=".views.activities.AboutActivity"
android:parentActivityName=".views.activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".views.activities.MainActivity"/>
</activity>
<activity android:name=".views.activities.SettingsActivity">
</activity>
<receiver android:name=".util.NotificationReceiver"
android:process=":remote" >
</receiver>
......
package srct.whatsopen;
import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import com.squareup.leakcanary.LeakCanary;
......@@ -24,4 +29,21 @@ public class MyApplication extends Application {
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(realmConfig);
}
public static void setRotation(Activity activity) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
boolean rotationOff = preferences.getBoolean("turn_off_rotation_preference",
false);
if(rotationOff) {
int currentOrientation = activity.getResources().getConfiguration().orientation;
if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
}
}
......@@ -4,6 +4,9 @@ import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.WakefulBroadcastReceiver;
......@@ -22,16 +25,33 @@ public class NotificationService extends IntentService {
String text = intent.getStringExtra("text");
int id = intent.getIntExtra("id", 0);
displayNotification(title, text, id);
setVibration();
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
private void displayNotification(String title, String text, int id) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_access_time_black_24dp)
.setContentTitle(title)
.setContentText(text);
.setSmallIcon(R.drawable.ic_access_time_black_24dp)
.setContentTitle(title)
.setContentText(text);
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, builder.build());
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
private void setVibration() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean vibrationsOff = preferences.getBoolean("turn_off_vibrations_preference", false);
if(!vibrationsOff) {
Vibrator v = (Vibrator) this.getApplicationContext()
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(400);
}
}
}
......@@ -11,6 +11,7 @@ import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
import com.danielstone.materialaboutlibrary.model.MaterialAboutTitleItem;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R;
public class AboutActivity extends MaterialAboutActivity {
......@@ -20,6 +21,12 @@ public class AboutActivity extends MaterialAboutActivity {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
MyApplication.setRotation(this);
}
@Override
protected MaterialAboutList getMaterialAboutList() {
MaterialAboutCard.Builder appCardBuilder = new MaterialAboutCard.Builder();
......
package srct.whatsopen.views.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
......@@ -23,6 +24,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.realm.Realm;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.NotificationSettings;
......@@ -70,6 +72,12 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
setNotificationStatus();
}
@Override
protected void onResume() {
super.onResume();
MyApplication.setRotation(this);
}
@Override
protected void onDestroy() {
mPresenter.detachView();
......@@ -89,13 +97,11 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_favorite:
mPresenter.toggleFavorite(mFacility);
return true;
case R.id.action_settings:
expandSettingsActivity();
return true;
default:
return super.onOptionsItemSelected(item);
......@@ -176,4 +182,10 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
public void onSetNotification() {
setNotificationStatus();
}
// Opens the About page for the app
private void expandSettingsActivity() {
Intent i = new Intent(this, SettingsActivity.class);
startActivity(i);
}
}
......@@ -15,6 +15,7 @@ import com.astuetz.PagerSlidingTabStrip;
import butterknife.BindView;
import butterknife.ButterKnife;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R;
import srct.whatsopen.presenters.MainPresenter;
import srct.whatsopen.views.MainView;
......@@ -48,15 +49,13 @@ public class MainActivity extends AppCompatActivity implements MainView {
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
setSupportActionBar(toolbar);
// Get the ViewPager and set its PagerAdapter
mViewPager.setAdapter(new FacilityListFragmentPagerAdapter(getSupportFragmentManager()));
// Now give the TabStrip the ViewPager
PagerSlidingTabStrip tabStrip = ButterKnife.findById(this, R.id.tabs);
tabStrip.setTabPaddingLeftRight(0);
tabStrip.setViewPager(mViewPager);
setUpTabStrip();
}
mViewPager.setCurrentItem(1);
@Override
protected void onResume() {
super.onResume();
MyApplication.setRotation(this);
}
@Override
......@@ -78,6 +77,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
mPresenter.loadFacilities();
return true;
case R.id.action_settings:
expandSettingsActivity();
return true;
case R.id.action_about:
expandAboutActivity();
......@@ -87,6 +87,19 @@ public class MainActivity extends AppCompatActivity implements MainView {
}
}
private void setUpTabStrip() {
// Get the ViewPager and set its PagerAdapter
mViewPager.setAdapter(new FacilityListFragmentPagerAdapter(getSupportFragmentManager()));
// Now give the TabStrip the ViewPager
PagerSlidingTabStrip tabStrip = ButterKnife.findById(this, R.id.tabs);
tabStrip.setTabPaddingLeftRight(0);
tabStrip.setViewPager(mViewPager);
// Set the default tab to 'All'
mViewPager.setCurrentItem(1);
}
@Override
public void showProgressBar() {
mViewPager.setVisibility(View.INVISIBLE);
......@@ -109,4 +122,10 @@ public class MainActivity extends AppCompatActivity implements MainView {
Intent i = new Intent(this, AboutActivity.class);
startActivity(i);
}
// Opens the About page for the app
private void expandSettingsActivity() {
Intent i = new Intent(this, SettingsActivity.class);
startActivity(i);
}
}
package srct.whatsopen.views.activities;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import butterknife.ButterKnife;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R;
import srct.whatsopen.views.fragments.SettingsFragment;
public class SettingsActivity extends AppCompatActivity {
private SharedPreferences mSharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
configureToolbar();
getSupportFragmentManager().beginTransaction()
.replace(R.id.activity_settings, new SettingsFragment())
.commit();
setPreferenceChangeListener();
MyApplication.setRotation(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_settings, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void configureToolbar() {
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Settings");
// Display back button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
private void setPreferenceChangeListener() {
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.OnSharedPreferenceChangeListener prefListener =
new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if(key.equals("turn_off_rotation_preference")) {
MyApplication.setRotation(SettingsActivity.this);
}
}
};
mSharedPreferences.registerOnSharedPreferenceChangeListener(prefListener);
}
}
......@@ -3,8 +3,10 @@ package srct.whatsopen.views.adapters;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
......@@ -57,28 +59,30 @@ public class FacilityListAdapter extends
public void onBindViewHolder(ViewHolder holder, int position) {
Facility facility = getData().get(position);
if(facility.isOpen()) {
displayStatusDurationText(facility, holder);
// highlight the open facilities
if (facility.isOpen()) {
// set the RV cell to be highlighted
holder.itemView.setBackgroundColor(ContextCompat
.getColor(context, R.color.facilityOpen));
// show the duration that the facility will be open
setItemPaddingInDp(holder.textLayout, 8);
// setItemPaddingInDp(holder.textLayout, 8);
holder.durationTextView.setVisibility(View.VISIBLE);
//holder.nameTextView.setTypeface(null, Typeface.BOLD);
} else {
holder.itemView.setBackgroundColor(ContextCompat
.getColor(context, R.color.facilityClosed));
setItemPaddingInDp(holder.textLayout, 15);
// setItemPaddingInDp(holder.textLayout, 15);
holder.durationTextView.setVisibility(View.GONE);
//holder.nameTextView.setTypeface(null, Typeface.NORMAL);
}
if(facility.isFavorited()) {
if (facility.isFavorited()) {
holder.favoriteButton.setImageResource(R.drawable.ic_fav_button_on_24dp);
}
else {
} else {
holder.favoriteButton.setImageResource(R.drawable.ic_fav_button_off_24dp);
}
......@@ -87,12 +91,49 @@ public class FacilityListAdapter extends
textView.setText(facility.getName());
}
// Sets the duration text according to the user's settings
private void displayStatusDurationText(Facility facility, ViewHolder holder) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String setting = preferences.getString("list_view_information_preference",
"display_duration_both");
switch (setting) {
case "display_duration_open":
setStatusDurationText(holder, facility.isOpen());
break;
case "display_duration_closed":
setStatusDurationText(holder, !facility.isOpen());
break;
case "display_duration_none":
setStatusDurationText(holder, false);
break;
case "display_duration_both":
default:
setStatusDurationText(holder, true);
break;
}
}
private void setStatusDurationText(ViewHolder holder, boolean showDuration) {
if (showDuration) {
// display the duration text
setItemPaddingInDp(holder.textLayout, 8);
holder.durationTextView.setVisibility(View.VISIBLE);
holder.nameTextView.setTypeface(null, Typeface.BOLD);
} else {
setItemPaddingInDp(holder.textLayout, 15);
holder.durationTextView.setVisibility(View.GONE);
holder.nameTextView.setTypeface(null, Typeface.NORMAL);
}
}
// Helper method to set the facility item layout's padding
// Have to convert from pixels to dp
private void setItemPaddingInDp(LinearLayout layout, int paddingPx) {
float scale = context.getResources().getDisplayMetrics().density;
int paddingTop = (int) (paddingPx*scale + 0.5f);
int paddingBottom = (int) (paddingPx*scale + 0.5f);
int paddingTop = (int) (paddingPx * scale + 0.5f);
int paddingBottom = (int) (paddingPx * scale + 0.5f);
layout.setPadding(0, paddingTop, 0, paddingBottom);
}
......@@ -100,10 +141,14 @@ public class FacilityListAdapter extends
// Set up for the Recycler View cells
public class ViewHolder extends RecyclerView.ViewHolder implements FacilityView {
@BindView(R.id.facility_name) TextView nameTextView;
@BindView(R.id.favorite_button) ImageButton favoriteButton;
@BindView(R.id.facility_duration) TextView durationTextView;
@BindView(R.id.text_layout) LinearLayout textLayout;
@BindView(R.id.facility_name)
TextView nameTextView;
@BindView(R.id.favorite_button)
ImageButton favoriteButton;
@BindView(R.id.facility_duration)
TextView durationTextView;
@BindView(R.id.text_layout)
LinearLayout textLayout;
private FacilityPresenter mPresenter;
private Facility data;
......
package srct.whatsopen.views.fragments;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
......@@ -32,6 +34,7 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
private MainPresenter mPresenter;
private RecyclerView mRecyclerView;
private SwipeRefreshLayout mSwipeContainer;
private SharedPreferences.OnSharedPreferenceChangeListener mListener;
public static FacilityListFragment newInstance(String mode) {
Bundle args = new Bundle();
......@@ -50,6 +53,8 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
mRealm = Realm.getDefaultInstance();
mPresenter = new MainPresenter();
mPresenter.attachView(this);
setPreferenceChangeListener();
}
@Override
......@@ -134,4 +139,19 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
public Context getContext() {
return getActivity();
}
// Redraws RecyclerView if the settings have changed for it
private void setPreferenceChangeListener() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("list_view_information_preference")) {
mRecyclerView.getAdapter().notifyDataSetChanged();
}
}
};
preferences.registerOnSharedPreferenceChangeListener(mListener);
}
}
package srct.whatsopen.views.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
import srct.whatsopen.R;
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.settings, rootKey);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_settings">
<include
layout="@layout/toolbar_main"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
</menu>
\ No newline at end of file
......@@ -9,6 +9,7 @@
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorControlHighlight">@color/tabButtonPressed</item>
<item name="android:homeAsUpIndicator">@drawable/ic_arrow_back_white</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
</resources>
\ No newline at end of file
......@@ -2,4 +2,25 @@
<string name="app_name">What\'s Open</string>
<string name="toast_set_favorite">Added %s to Favorites</string>
<string name="toast_unset_favorite">Removed %s from Favorites</string>
<!-- Strings from PreferenceFragment -->
<string name="title_list_view">List View Preferences</string>
<string name="title_list_view_information">Duration display</string>