diff --git a/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationController.java b/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationController.java index 7b4a573..c2b7f42 100644 --- a/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationController.java +++ b/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationController.java @@ -111,8 +111,8 @@ public class NotificationController { private static final int NOTIFICATION_ID = 234; private static final String NOTIFICATION_CHANNEL_ID = "optymo_next_times_01"; - private static final CharSequence NOTIFICATION_CHANNEL_NAME = "optymo_next_times"; - private static final String NOTIFICATION_CHANNEL_DESCRIPTION = "Channel only used to show persistent next times notification"; + private static CharSequence NOTIFICATION_CHANNEL_NAME = "Next stops"; + private static String NOTIFICATION_CHANNEL_DESCRIPTION = "Persistent notification with next stops"; public static boolean isNotificationShown(Context context) { SharedPreferences preferences = context.getSharedPreferences("NotificationPrefs", Context.MODE_PRIVATE); @@ -154,9 +154,13 @@ void run(Context context) { // channel for greater versions than 8.0 NotificationChannel mChannel = null; // = null if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // set category description to current local + NOTIFICATION_CHANNEL_NAME = context.getResources().getString(R.string.notification_channel_title); + NOTIFICATION_CHANNEL_DESCRIPTION = context.getResources().getString(R.string.notification_channel_description); // cannot be stored as constant because require api 24 min - int importance = NotificationManager.IMPORTANCE_MIN; + // fix with low priority for Xiaomi where importance min is not allowed on the lock screen, set low or higher + int importance = NotificationManager.IMPORTANCE_DEFAULT; // I want to be sure to be displayed mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance); mChannel.setDescription(NOTIFICATION_CHANNEL_DESCRIPTION); mChannel.setShowBadge(false); @@ -190,11 +194,16 @@ void run(Context context) { .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setCustomBigContentView(notificationLayoutExpanded) .setOngoing(true) - .setPriority(Notification.PRIORITY_LOW) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) //to show content in lock screen .setContentTitle(context.getString(R.string.update_never)) .setContentIntent(resultPendingIntent) - .setContentText(context.getString(R.string.notification_content_text)); + .setContentText(context.getString(R.string.notification_content_text)) + .setNotificationSilent(); // have no sound for this notification + + // set importance was deprecated in API 26 + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + builder.setPriority(Notification.PRIORITY_DEFAULT); + } //noinspection ConstantConditions if (mChannel != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationService.java b/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationService.java index 7358d0d..d2c0c02 100644 --- a/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationService.java +++ b/app/src/main/java/com/therolf/optymoNext/controller/notifications/NotificationService.java @@ -21,7 +21,6 @@ public class NotificationService extends IntentService { public static final String REFRESH_ACTION = "refresh_action"; public static final String NEXT_SIX_GET = "next_six_get"; public static final String CANCEL_ACTION = "notification_cancel_all"; - private NotificationController notificationController = new NotificationController(); private int numberOfRequests; private ArrayList lastRequests = new ArrayList<>(); @@ -30,6 +29,10 @@ public NotificationService() { super("MyNotificationService"); } + private static NotificationController getNotificationController() { + return OnBoot.getNotificationController(); + } + @Override protected void onHandleIntent(@Nullable Intent workIntent) { if(workIntent != null && workIntent.getAction() != null) { @@ -44,6 +47,7 @@ private void handleAction(String action) { OptymoDirection[] fav = ((GlobalApplication) getApplication()).getFavoritesController().getFavorites(); // Log.d("optymo", "" + fav.length); + NotificationController notificationController = getNotificationController(); // if action is cancel we cancel if(action.equals(CANCEL_ACTION)) { notificationController.cancelNotification(this); @@ -83,8 +87,9 @@ private void handleAction(String action) { while(lastRequests.size() > 0) { NextTimeRequest request = lastRequests.get(0); request.cancel(true); - lastRequests.clear(); } + //noinspection RedundantOperationOnEmptyContainer + lastRequests.clear(); // make maximum 6 requests int rNumber = 0; @@ -158,11 +163,11 @@ protected void onPostExecute(OptymoNextTime nextTime) { service.numberOfRequests++; if (service.numberOfRequests >= service.lastRequests.size()) - service.notificationController.setUpdatedAtTitle(service); + getNotificationController().setUpdatedAtTitle(service); // add line to notification if first 6 if(service.numberOfRequests < 7) - service.notificationController.appendToNotificationBody(nextTime); + getNotificationController().appendToNotificationBody(nextTime); } } diff --git a/app/src/main/java/com/therolf/optymoNext/controller/notifications/OnBoot.java b/app/src/main/java/com/therolf/optymoNext/controller/notifications/OnBoot.java index bf4f583..e7087ec 100644 --- a/app/src/main/java/com/therolf/optymoNext/controller/notifications/OnBoot.java +++ b/app/src/main/java/com/therolf/optymoNext/controller/notifications/OnBoot.java @@ -9,6 +9,7 @@ public class OnBoot extends BroadcastReceiver { private static int index; + private static NotificationController nCon; public static int getIndex() { return index; @@ -22,6 +23,14 @@ public static void increaseIndex(int value) { OnBoot.index += value; } + public static NotificationController getNotificationController() { + if(nCon == null) { + nCon = new NotificationController(); + } + + return nCon; + } + @SuppressLint("UnsafeProtectedBroadcastReceiver") @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/res/layout/notification_expanded.xml b/app/src/main/res/layout/notification_expanded.xml index 0a990f5..bd33d07 100644 --- a/app/src/main/res/layout/notification_expanded.xml +++ b/app/src/main/res/layout/notification_expanded.xml @@ -5,22 +5,22 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:paddingBottom="@dimen/component_padding_half"> + android:textSize="16sp" /> - + + android:paddingStart="@dimen/notification_padding" + android:paddingTop="@dimen/component_padding_half" + android:paddingEnd="@dimen/notification_padding" + android:paddingBottom="@dimen/notification_padding"> Presionar para ver los proximos horarios URLs estáticos del %1$s Últimos pdfs en línea - Cargamento... + Cargamento… + Proximos horarios + Notificación persistente con los proximos horarios \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index df55f0f..2503a48 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -28,7 +28,7 @@ non Actualiser Étendre pour voir les favoris - Mise à jour en cours… + Mise à jour… Chercher un arrêt, un stop… Arrêts Prochains horaires @@ -55,5 +55,7 @@ Appuyer pour voir les prochains horaires URLs statiques du %1$s Derniers PDFs en ligne - Chargement... + Chargement… + Prochains arrêts + Notification persistente avec les prochains arrêts \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 61a17f1..9238f17 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,7 +33,7 @@ no Refresh Expand to see favorites - Update pending… + Updating… Search stop, line… Stops Next stops @@ -65,5 +65,7 @@ Tap on me to get next times Static URLs of %1$s Latest PDFs online - Loading... + Loading… + Next stops + Persistent notification with next stops