Skip to content

Commit

Permalink
[Mobile] Fixed bug which prevented tram notifications from scheduling…
Browse files Browse the repository at this point in the history
…. Also fixed Firebase Messaging issue which prevented notifications from displaying.

[Trivial] Bumped version numbers for release v0.109.
  • Loading branch information
thecosmicfrog committed Jun 18, 2018
1 parent 5e33129 commit 0f170a4
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 36 deletions.
8 changes: 4 additions & 4 deletions mobile/build.gradle
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.thecosmicfrog.luasataglance" applicationId "org.thecosmicfrog.luasataglance"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 26
versionCode 103 versionCode 109
versionName "0.103" versionName "0.109"
} }
buildTypes { buildTypes {
release { release {
Expand All @@ -30,8 +30,8 @@ dependencies {
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:support-v4:26.1.0' compile 'com.android.support:support-v4:26.1.0'
compile 'com.google.android.gms:play-services-maps:11.8.0' compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0' api 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0' api 'com.google.firebase:firebase-messaging:11.8.0'
} }


// Firebase // Firebase
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
import android.widget.Button; import android.widget.Button;
import android.widget.Spinner; import android.widget.Spinner;


import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.iid.FirebaseInstanceId;

import org.thecosmicfrog.luasataglance.R; import org.thecosmicfrog.luasataglance.R;
import org.thecosmicfrog.luasataglance.object.NotifyTimesMap; import org.thecosmicfrog.luasataglance.object.NotifyTimesMap;
import org.thecosmicfrog.luasataglance.receiver.NotifyTimesReceiver;
import org.thecosmicfrog.luasataglance.util.Analytics; import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant; import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Preferences; import org.thecosmicfrog.luasataglance.util.Preferences;
Expand Down Expand Up @@ -99,6 +97,8 @@ public void onClick(View v) {
* LineFragment. * LineFragment.
*/ */
Intent intent = new Intent(); Intent intent = new Intent();
intent.setPackage(getPackageName());
intent.setClass(getApplicationContext(), NotifyTimesReceiver.class);
intent.setAction(NotifyTimeActivity.class.getName()); intent.setAction(NotifyTimeActivity.class.getName());
intent.putExtra( intent.putExtra(
Constant.NOTIFY_STOP_NAME, Constant.NOTIFY_STOP_NAME,
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@


import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.widget.Toast; import android.widget.Toast;
Expand Down Expand Up @@ -143,6 +145,7 @@ public void onReceive(Context context, Intent intent) {
* stop-to-notify-for as a String extra. * stop-to-notify-for as a String extra.
*/ */
Intent intentOpenMainActivity = new Intent(context, MainActivity.class); Intent intentOpenMainActivity = new Intent(context, MainActivity.class);
intentOpenMainActivity.setPackage(context.getPackageName());
intentOpenMainActivity.setAction(NotifyTimesReceiver.class.getName()); intentOpenMainActivity.setAction(NotifyTimesReceiver.class.getName());
intentOpenMainActivity.setFlags( intentOpenMainActivity.setFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
Expand All @@ -156,14 +159,42 @@ public void onReceive(Context context, Intent intent) {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
); );


/*
* Create a NotificationManager.
*/
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE
);


/* Android Oreo and above require a NotificationChannel to be created. */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel =
new NotificationChannel(
"notifyTimes",
"Notify Times",
NotificationManager.IMPORTANCE_HIGH
);

/* Configure notification channel. */
notificationChannel.setDescription("Notify Times");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(context.getColor(R.color.luas_purple));
notificationChannel.setVibrationPattern(new long[] {100, 1000, 1000, 1000, 1000});
notificationChannel.enableVibration(true);

notificationManager.createNotificationChannel(notificationChannel);
}

/* /*
* Create the NotificationBuilder, setting an appropriate title and the message * Create the NotificationBuilder, setting an appropriate title and the message
* built in the StringBuilder. The default notification sound should be played * built in the StringBuilder. The default notification sound should be played
* and the device should vibrate twice for 1 second with a 1 second delay * and the device should vibrate twice for 1 second with a 1 second delay
* between them. Setting MAX priority due to the time-sensitive nature of trams. * between them. Setting MAX priority due to the time-sensitive nature of trams.
*/ */
NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context) new NotificationCompat.Builder(context, "notifyTimes")
.setPriority(Notification.PRIORITY_MAX) .setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pendingIntentOpenMainActivity) .setContentIntent(pendingIntentOpenMainActivity)
.setContentTitle( .setContentTitle(
Expand All @@ -181,13 +212,7 @@ public void onReceive(Context context, Intent intent) {
) )
.setAutoCancel(true); .setAutoCancel(true);


/* /* Display notification. */
* Create a NotificationManager and display the notification to the user.
*/
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE
);
notificationManager.notify(1, notificationBuilder.build()); notificationManager.notify(1, notificationBuilder.build());
} }
}; };
Expand All @@ -200,7 +225,7 @@ public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent = PendingIntent.getBroadcast( PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, context,
REQUEST_CODE_SCHEDULE_NOTIFICATION, REQUEST_CODE_SCHEDULE_NOTIFICATION,
new Intent("org.thecosmicfrog.luasataglance"), new Intent(context.getPackageName()),
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
); );


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
package org.thecosmicfrog.luasataglance.util; package org.thecosmicfrog.luasataglance.util;


import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.os.Build;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;


Expand Down Expand Up @@ -122,10 +124,34 @@ public static void showNotification(Context context, RemoteMessage remoteMessage
); );


/* /*
* Prepare the notification. * Create a NotificationManager.
*/ */
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE
);

/* Android Oreo and above require a NotificationChannel to be created. */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel =
new NotificationChannel(
"fcmNotification",
"Firebase Cloud Messaging notification",
NotificationManager.IMPORTANCE_HIGH
);

/* Configure notification channel. */
notificationChannel.setDescription("Firebase Cloud Messaging notification");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(context.getColor(R.color.luas_purple));
notificationChannel.setVibrationPattern(new long[] {100, 1000, 1000, 1000, 1000});
notificationChannel.enableVibration(true);

notificationManager.createNotificationChannel(notificationChannel);
}

NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context) new NotificationCompat.Builder(context, "fcmNotification")
.setPriority(Notification.PRIORITY_DEFAULT) .setPriority(Notification.PRIORITY_DEFAULT)
.setContentIntent(pendingIntentOpenActivity) .setContentIntent(pendingIntentOpenActivity)
.setContentTitle(remoteMessage.getNotification().getTitle()) .setContentTitle(remoteMessage.getNotification().getTitle())
Expand All @@ -139,13 +165,7 @@ public static void showNotification(Context context, RemoteMessage remoteMessage
) )
.setAutoCancel(true); .setAutoCancel(true);


/* /* Display notification. */
* Create a NotificationManager and display the notification to the user.
*/
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE
);
notificationManager.notify(1, notificationBuilder.build()); notificationManager.notify(1, notificationBuilder.build());
} }
} }
12 changes: 6 additions & 6 deletions mobile/src/main/res/values/strings.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
App App
--> -->
<string name="app_name">Luas at a Glance</string> <string name="app_name">Luas at a Glance</string>
<string name="version_code" translatable="false">103</string> <string name="version_code" translatable="false">109</string>
<string name="version_name" translatable="false">0.103</string> <string name="version_name" translatable="false">0.109</string>


<!-- <!--
Activities Activities
Expand Down Expand Up @@ -161,12 +161,12 @@
<!-- <!--
What's New What's New
--> -->
<string name="whatsnew_title_current" translatable="false">Version 0.103 (9th January 2018) <string name="whatsnew_title_current" translatable="false">Version 0.109 (18th June 2018)
</string> </string>
<string name="whatsnew_content_current" translatable="false">\u2022 [FIXED] Fixed bug where stop <string name="whatsnew_content_current" translatable="false">\u2022 [FIXED] Fixed bug where stop
forecast would not display on Android Wear devices. Thanks to everyone who reported this! forecast would not display on Wear OS (Android Wear) devices. Thanks to everyone who
\nIf you have an Android Wear smartwatch, you can install Luas at a Glance from the Play reported this!\nIf you have a Wear OS smartwatch, you can install Luas at a Glance from the
Store on your watch. Play Store on your watch.
</string> </string>
<string name="whatsnew_title_previous" translatable="false">Version 0.100 (8th December 2017) <string name="whatsnew_title_previous" translatable="false">Version 0.100 (8th December 2017)
</string> </string>
Expand Down
6 changes: 3 additions & 3 deletions wear/build.gradle
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.thecosmicfrog.luasataglance" applicationId "org.thecosmicfrog.luasataglance"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 26 targetSdkVersion 26
versionCode 10300 versionCode 10900
versionName "0.103" versionName "0.109"
} }
buildTypes { buildTypes {
release { release {
Expand All @@ -23,7 +23,7 @@ android {
productFlavors { productFlavors {
wear2 { wear2 {
minSdkVersion 25 minSdkVersion 25
versionCode 10301 versionCode 10901
} }
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions wear/src/main/res/values/strings.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
App App
--> -->
<string name="app_name">Luas at a Glance</string> <string name="app_name">Luas at a Glance</string>
<string name="version_code" translatable="false">103</string> <string name="version_code" translatable="false">109</string>
<string name="version_name" translatable="false">0.103</string> <string name="version_name" translatable="false">0.109</string>


<!-- <!--
Activities Activities
Expand Down

0 comments on commit 0f170a4

Please sign in to comment.