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

merge master

parents 7bed0279 32be32ca
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
## Steps to Reproduce the Behavior ## 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 http://www.apache.org/licenses/LICENSE-2.0
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:
The above copyright notice and this permission notice shall be included in all Unless required by applicable law or agreed to in writing, software
copies or substantial portions of the Software. distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR See the License for the specific language governing permissions and
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, limitations under the License.
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.
...@@ -37,10 +37,10 @@ dependencies { ...@@ -37,10 +37,10 @@ dependencies {
compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.android.support:appcompat-v7:25.1.0' compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:cardview-v7:25.1.0' compile 'com.android.support:cardview-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.0' compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.0' compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'io.reactivex:rxandroid:1.2.0' compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.4' compile 'io.reactivex:rxjava:1.1.4'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
...@@ -53,4 +53,5 @@ dependencies { ...@@ -53,4 +53,5 @@ dependencies {
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.2.0' compile 'com.github.castorflex.smoothprogressbar:library-circular:1.2.0'
compile 'io.reactivex:rxandroid:1.2.0' compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.4' compile 'io.reactivex:rxjava:1.1.4'
compile 'com.takisoft.fix:preference-v7:25.1.1.0'
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application <application
android:name=".MyApplication" android:name=".MyApplication"
android:allowBackup="true" android:allowBackup="true"
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
<activity android:name=".views.activities.DetailActivity" <activity android:name=".views.activities.DetailActivity"
android:parentActivityName=".views.activities.MainActivity"> android:parentActivityName=".views.activities.MainActivity">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".views.activities.MainActivity"/> android:value=".views.activities.MainActivity"/>
...@@ -32,11 +34,15 @@ ...@@ -32,11 +34,15 @@
<activity android:name=".views.activities.AboutActivity" <activity android:name=".views.activities.AboutActivity"
android:parentActivityName=".views.activities.MainActivity"> android:parentActivityName=".views.activities.MainActivity">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".views.activities.MainActivity"/> android:value=".views.activities.MainActivity"/>
</activity> </activity>
<activity android:name=".views.activities.SettingsActivity">
</activity>
<receiver android:name=".util.NotificationReceiver" <receiver android:name=".util.NotificationReceiver"
android:process=":remote" > android:process=":remote" >
</receiver> </receiver>
......
package srct.whatsopen; package srct.whatsopen;
import android.app.Activity;
import android.app.Application; 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; import com.squareup.leakcanary.LeakCanary;
...@@ -24,4 +29,21 @@ public class MyApplication extends Application { ...@@ -24,4 +29,21 @@ public class MyApplication extends Application {
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build(); RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(realmConfig); 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; ...@@ -4,6 +4,9 @@ import android.app.IntentService;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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.app.NotificationCompat;
import android.support.v4.content.WakefulBroadcastReceiver; import android.support.v4.content.WakefulBroadcastReceiver;
...@@ -22,16 +25,33 @@ public class NotificationService extends IntentService { ...@@ -22,16 +25,33 @@ public class NotificationService extends IntentService {
String text = intent.getStringExtra("text"); String text = intent.getStringExtra("text");
int id = intent.getIntExtra("id", 0); 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 = NotificationCompat.Builder builder =
new NotificationCompat.Builder(this) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_access_time_black_24dp) .setSmallIcon(R.drawable.ic_access_time_black_24dp)
.setContentTitle(title) .setContentTitle(title)
.setContentText(text); .setContentText(text);
NotificationManager notificationManager = (NotificationManager) NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE); getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, builder.build()); 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; ...@@ -11,6 +11,7 @@ import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
import com.danielstone.materialaboutlibrary.model.MaterialAboutList; import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
import com.danielstone.materialaboutlibrary.model.MaterialAboutTitleItem; import com.danielstone.materialaboutlibrary.model.MaterialAboutTitleItem;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R; import srct.whatsopen.R;
public class AboutActivity extends MaterialAboutActivity { public class AboutActivity extends MaterialAboutActivity {
...@@ -20,6 +21,12 @@ public class AboutActivity extends MaterialAboutActivity { ...@@ -20,6 +21,12 @@ public class AboutActivity extends MaterialAboutActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@Override
protected void onResume() {
super.onResume();
MyApplication.setRotation(this);
}
@Override @Override
protected MaterialAboutList getMaterialAboutList() { protected MaterialAboutList getMaterialAboutList() {
MaterialAboutCard.Builder appCardBuilder = new MaterialAboutCard.Builder(); MaterialAboutCard.Builder appCardBuilder = new MaterialAboutCard.Builder();
......
package srct.whatsopen.views.activities; package srct.whatsopen.views.activities;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
...@@ -23,6 +24,7 @@ import butterknife.BindView; ...@@ -23,6 +24,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import io.realm.Realm; import io.realm.Realm;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R; import srct.whatsopen.R;
import srct.whatsopen.model.Facility; import srct.whatsopen.model.Facility;
import srct.whatsopen.model.NotificationSettings; import srct.whatsopen.model.NotificationSettings;
...@@ -70,6 +72,12 @@ public class DetailActivity extends AppCompatActivity implements FacilityView, ...@@ -70,6 +72,12 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
setNotificationStatus(); setNotificationStatus();
} }
@Override
protected void onResume() {
super.onResume();
MyApplication.setRotation(this);
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
mPresenter.detachView(); mPresenter.detachView();
...@@ -89,13 +97,11 @@ public class DetailActivity extends AppCompatActivity implements FacilityView, ...@@ -89,13 +97,11 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_favorite: case R.id.action_favorite:
mPresenter.toggleFavorite(mFacility); mPresenter.toggleFavorite(mFacility);
return true; return true;
case R.id.action_settings: case R.id.action_settings:
expandSettingsActivity();
return true; return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
...@@ -176,4 +182,10 @@ public class DetailActivity extends AppCompatActivity implements FacilityView, ...@@ -176,4 +182,10 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
public void onSetNotification() { public void onSetNotification() {
setNotificationStatus(); 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; ...@@ -15,6 +15,7 @@ import com.astuetz.PagerSlidingTabStrip;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import srct.whatsopen.MyApplication;
import srct.whatsopen.R; import srct.whatsopen.R;
import srct.whatsopen.presenters.MainPresenter; import srct.whatsopen.presenters.MainPresenter;
import srct.whatsopen.views.MainView; import srct.whatsopen.views.MainView;
...@@ -48,15 +49,13 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -48,15 +49,13 @@ public class MainActivity extends AppCompatActivity implements MainView {
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar); Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
// Get the ViewPager and set its PagerAdapter setUpTabStrip();
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);
mViewPager.setCurrentItem(1); @Override
protected void onResume() {
super.onResume();
MyApplication.setRotation(this);
} }
@Override @Override
...@@ -78,6 +77,7 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -78,6 +77,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
mPresenter.loadFacilities(); mPresenter.loadFacilities();
return true; return true;
case R.id.action_settings: case R.id.action_settings:
expandSettingsActivity();
return true; return true;
case R.id.action_about: case R.id.action_about:
expandAboutActivity(); expandAboutActivity();
...@@ -87,6 +87,19 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -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 @Override
public void showProgressBar() { public void showProgressBar() {
mViewPager.setVisibility(View.INVISIBLE); mViewPager.setVisibility(View.INVISIBLE);
...@@ -109,4 +122,10 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -109,4 +122,10 @@ public class MainActivity extends AppCompatActivity implements MainView {
Intent i = new Intent(this, AboutActivity.class); Intent i = new Intent(this, AboutActivity.class);
startActivity(i); 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; ...@@ -3,8 +3,10 @@ package srct.whatsopen.views.adapters;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -57,28 +59,30 @@ public class FacilityListAdapter extends ...@@ -57,28 +59,30 @@ public class FacilityListAdapter extends
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
Facility facility = getData().get(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 // set the RV cell to be highlighted
holder.itemView.setBackgroundColor(ContextCompat holder.itemView.setBackgroundColor(ContextCompat
.getColor(context, R.color.facilityOpen)); .getColor(context, R.color.facilityOpen));
// show the duration that the facility will be open // show the duration that the facility will be open
setItemPaddingInDp(holder.textLayout, 8); // setItemPaddingInDp(holder.textLayout, 8);
holder.durationTextView.setVisibility(View.VISIBLE); holder.durationTextView.setVisibility(View.VISIBLE);
//holder.nameTextView.setTypeface(null, Typeface.BOLD); //holder.nameTextView.setTypeface(null, Typeface.BOLD);
} else { } else {
holder.itemView.setBackgroundColor(ContextCompat holder.itemView.setBackgroundColor(ContextCompat
.getColor(context, R.color.facilityClosed)); .getColor(context, R.color.facilityClosed));
setItemPaddingInDp(holder.textLayout, 15); // setItemPaddingInDp(holder.textLayout, 15);
holder.durationTextView.setVisibility(View.GONE); holder.durationTextView.setVisibility(View.GONE);
//holder.nameTextView.setTypeface(null, Typeface.NORMAL); //holder.nameTextView.setTypeface(null, Typeface.NORMAL);
} }
if(facility.isFavorited()) { if (facility.isFavorited()) {
holder.favoriteButton.setImageResource(R.drawable.ic_fav_button_on_24dp); holder.favoriteButton.setImageResource(R.drawable.ic_fav_button_on_24dp);
} } else {
else {
holder.favoriteButton.setImageResource(R.drawable.ic_fav_button_off_24dp); holder.favoriteButton.setImageResource(R.drawable.ic_fav_button_off_24dp);
} }
...@@ -87,12 +91,49 @@ public class FacilityListAdapter extends ...@@ -87,12 +91,49 @@ public class FacilityListAdapter extends
textView.setText(facility.getName()); 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());