Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
flibbertigibbet committed Aug 14, 2018
2 parents 43474ec + d9d138c commit 0a26eaa
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 85 deletions.
7 changes: 3 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId "org.gophillygo.app"
minSdkVersion 19
targetSdkVersion 27
versionCode 13
versionName "1.0.10"
versionCode 14
versionName "1.1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
Expand Down Expand Up @@ -82,7 +82,6 @@ dependencies {

// Room
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation 'com.android.support:appcompat-v7:27.1.1'
annotationProcessor "android.arch.persistence.room:compiler:$roomVersion"

// Android UI libraries
Expand All @@ -98,7 +97,7 @@ dependencies {
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"

// Android WorkManager
implementation 'android.arch.work:work-runtime:1.0.0-alpha04'
implementation 'android.arch.work:work-runtime:1.0.0-alpha06'

// Carousel
implementation 'com.synnapps:carouselview:0.1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@ protected void onCreate(Bundle savedInstanceState) {
// Since we call `getDestination(...).observe(...)` every time the event is updated,
// we need to remove destination observer every time it is called
data.removeObservers(this);

// Check if flag set by notification to mark event as "been" and set flag if so
if (getIntent().hasExtra(GeofenceTransitionWorker.MARK_BEEN_KEY)) {
if(getIntent().getBooleanExtra(GeofenceTransitionWorker.MARK_BEEN_KEY, false) &&
!eventInfo.getFlag().getOption().id.equals(AttractionFlag.Option.Been.id)) {

updateFlag(AttractionFlag.Option.Been.id);
}
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class HomeActivity extends BaseAttractionActivity implements DestinationR
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Log.d(LOG_LABEL, "onCreate");
categories = new ArrayList<>(CategoryAttraction.PlaceCategories.size());

Toolbar toolbar = findViewById(R.id.home_toolbar);
Expand Down Expand Up @@ -94,7 +93,6 @@ public void locationOrDestinationsChanged() {
@Override
protected void onResume() {
super.onResume();
Log.d(LOG_LABEL, "onResume");
addScrollListener();
}

Expand Down Expand Up @@ -227,6 +225,9 @@ private void goToFilteredPlacesList(CategoryAttraction.PlaceCategories category)
case WatershedAlliance:
filter.setWatershedAlliance(true);
break;
case Been:
filter.setBeen(true);
break;
default:
Log.e(LOG_LABEL, "Unrecognized place category " + category.displayName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ protected void onCreate(Bundle savedInstanceState) {

this.destinationInfo = destinationInfo;

// Check if flag set by notification to mark event as "been" and set flag if so
if (getIntent().hasExtra(GeofenceTransitionWorker.MARK_BEEN_KEY)) {
if(getIntent().getBooleanExtra(GeofenceTransitionWorker.MARK_BEEN_KEY, false) &&
!destinationInfo.getFlag().getOption().id.equals(AttractionFlag.Option.Been.id)) {

updateFlag(AttractionFlag.Option.Been.id);
}
}

// set up data binding object
binding.setDestination(destinationInfo.getDestination());
binding.setDestinationInfo(destinationInfo);
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/gophillygo/app/data/DestinationDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public LiveData<List<CategoryAttraction>> getCategoryImages() {

LiveData<CategoryImage> educational = getRandomExerciseImages();
addSourceToRandomImagesLiveData(educational, CategoryAttraction.PlaceCategories.Educational, categoryAttractions, data);

LiveData<CategoryImage> been = getRandomImagesForFlag(AttractionFlag.Option.Been.code);
addSourceToRandomImagesLiveData(been, CategoryAttraction.PlaceCategories.Been, categoryAttractions, data);

return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public enum PlaceCategories {
WatershedAlliance(3, R.string.watershed_alliance_label, WATERSHED_ALLIANCE),
Nature(4, R.string.nature_category_label, NATURE_API_NAME),
Exercise(5, R.string.exercise_category_label, EXERCISE_API_NAME),
Educational(6, R.string.educational_category_label, EDUCATIONAL_API_NAME);
Educational(6, R.string.educational_category_label, EDUCATIONAL_API_NAME),
Been(7, R.string.place_been_option, AttractionFlag.Option.Been.apiName);

private static final SparseArray<PlaceCategories> map = new SparseArray<>();
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
import androidx.work.Data;
import androidx.work.Worker;

import static org.gophillygo.app.activities.AttractionDetailActivity.GEOFENCE_ID_KEY;
import static org.gophillygo.app.activities.AttractionDetailActivity.NOTIFICATION_ID_KEY;
import static org.gophillygo.app.tasks.GeofenceTransitionBroadcastReceiver.GEOFENCE_IMAGES_KEY;

public class GeofenceTransitionWorker extends Worker {

public static final String MARK_BEEN_KEY = "mark_been";
public static final String HAS_ERROR_KEY = "has_error";
public static final String ERROR_CODE_KEY = "error_code";
public static final String TRANSITION_KEY = "transition";
Expand All @@ -56,7 +53,6 @@ public class GeofenceTransitionWorker extends Worker {
private static final int NOTIFICATION_IMAGE_WIDTH = 1024;
private static final int NOTIFICATION_IMAGE_HEIGHT = 512;

private static final int BEEN_PENDING_INTENT_CODE = 101;
private static final int DETAIL_PENDING_INTENT_CODE = 102;

@NonNull
Expand Down Expand Up @@ -127,47 +123,28 @@ public Result doWork() {

// Get intent for the detail view to open on notification click.
Intent intent;
Intent beenIntent;

if (isEvent) {
intent = new Intent(context, EventDetailActivity.class);
intent.putExtra(EventDetailActivity.EVENT_ID_KEY, (long) geofenceId);
beenIntent = new Intent(context, EventDetailActivity.class);
beenIntent.putExtra(EventDetailActivity.EVENT_ID_KEY, (long) geofenceId);
} else {
intent = new Intent(context, PlaceDetailActivity.class);
intent.putExtra(PlaceDetailActivity.DESTINATION_ID_KEY, (long) geofenceId);
beenIntent = new Intent(context, PlaceDetailActivity.class);
beenIntent.putExtra(PlaceDetailActivity.DESTINATION_ID_KEY, (long) geofenceId);
}

// When opening detail activity from 'been' button, pass key to tell
// activity to mark its model as 'been' and the notification ID, to close it
beenIntent.putExtra(MARK_BEEN_KEY, true);
beenIntent.putExtra(NOTIFICATION_ID_KEY, notificationTag);
beenIntent.putExtra(GEOFENCE_ID_KEY, geofenceId);

// Add the intent to the stack builder, which inflates the back stack
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntentWithParentStack(intent);
// Get the PendingIntent containing the entire back stack
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(DETAIL_PENDING_INTENT_CODE, PendingIntent.FLAG_UPDATE_CURRENT);

// Create pending intent for marking place "been"
// Add the intent to the stack builder, which inflates the back stack
TaskStackBuilder beenStackBuilder = TaskStackBuilder.create(context);
beenStackBuilder.addNextIntentWithParentStack(beenIntent);
// Get the PendingIntent containing the entire back stack
PendingIntent beenPendingIntent =
beenStackBuilder.getPendingIntent(BEEN_PENDING_INTENT_CODE, PendingIntent.FLAG_UPDATE_CURRENT);

// Show notification on UI thread
handler.post(() -> {
String nearbyNotice = context.getString(R.string.place_nearby_notification, placeName);
createNotificationChannel(context);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
// TODO: use app icon of some sort
.setSmallIcon(R.drawable.ic_flag_blue_24dp)
.setOnlyAlertOnce(false)
.setContentTitle(placeName)
Expand All @@ -176,12 +153,8 @@ public Result doWork() {
.setAutoCancel(true) // close notification when tapped
.setGroup(GROUP_ID)
// alert for all notifications
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.addAction(R.drawable.ic_beenhere_blue_24dp,
context.getString(R.string.place_nearby_been_button),
beenPendingIntent)
.setGroupSummary(true);
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH);

if (imageBitmap != null) {
notificationBuilder = notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle()
Expand Down
61 changes: 33 additions & 28 deletions app/src/main/java/org/gophillygo/app/utils/GpgLocationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -95,36 +96,40 @@ public static boolean checkFineLocationPermissions(WeakReference<Activity> calle
return false; // up to the activity to start this service again when permissions granted
}

// Check location settings
// Check location settings on API < 28
// Geofencing requires high accuracy location to be enabled in settings on API < 28.
// This setting no longer exists on P/28, so do not prompt on 28+.
// https://developer.android.com/training/location/change-location-settings#get-settings
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
SettingsClient client = LocationServices.getSettingsClient(callingActivity);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnFailureListener(e -> {
if (e instanceof ResolvableApiException) {
try {
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(callingActivity, LOCATION_SETTINGS_REQUEST_ID);
} catch (IntentSender.SendIntentException e1) {
Log.e(LOG_LABEL, "Failed to prompt user for location settings changes");
e1.printStackTrace();
if (Build.VERSION.SDK_INT < 28) {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
SettingsClient client = LocationServices.getSettingsClient(callingActivity);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnFailureListener(e -> {
if (e instanceof ResolvableApiException) {
try {
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(callingActivity, LOCATION_SETTINGS_REQUEST_ID);
} catch (IntentSender.SendIntentException e1) {
Log.e(LOG_LABEL, "Failed to prompt user for location settings changes");
e1.printStackTrace();
}
} else {
Log.e(LOG_LABEL, "Received unresolvable location settings exception.");
e.printStackTrace();
}
} else {
Log.e(LOG_LABEL, "Received unresolvable location settings exception.");
e.printStackTrace();
}
}).addOnSuccessListener(locationSettingsResponse -> {
LocationSettingsStates states = locationSettingsResponse.getLocationSettingsStates();
if (!states.isNetworkLocationPresent() || !states.isNetworkLocationUsable()) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
// TODO: a dialog would be easier to read
Toast toast = Toast.makeText(callingActivity,
callingActivity.getString(R.string.location_network_permission_rationale),
Toast.LENGTH_LONG);
toast.show();
callingActivity.startActivity(intent);
}
});
}).addOnSuccessListener(locationSettingsResponse -> {
LocationSettingsStates states = locationSettingsResponse.getLocationSettingsStates();
if (!states.isNetworkLocationPresent() || !states.isNetworkLocationUsable()) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
// TODO: a dialog would be easier to read
Toast toast = Toast.makeText(callingActivity,
callingActivity.getString(R.string.location_network_permission_rationale),
Toast.LENGTH_LONG);
toast.show();
callingActivity.startActivity(intent);
}
});
}

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<string name="user_uuid_shared_preferences_key">gophillygo_user_uuid</string>
<string name="location_network_permission_rationale">Please set location mode to \"High Accuracy\" to receive notifications when places you like or want to go are nearby.</string>
<string name="channel_description">Nearby GoPhillyGo destinations you like or want to go visit</string>
<string name="place_nearby_notification">Are you visiting %1$s now? Learn more.</string>
<string name="place_nearby_notification">You are near %1$s. Learn more.</string>
<string name="place_nearby_been_button">I\'m there now</string>
<string name="home_grid_events">Upcoming events</string>
<string name="general_preference_category">General</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 0a26eaa

Please sign in to comment.