summaryrefslogtreecommitdiff
path: root/org.fox.ttrss/src/main/java
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-03-12 15:08:57 +0300
committerAndrew Dolgov <[email protected]>2018-03-12 15:08:57 +0300
commit7d41193070cf144bcdd1eda5e08e342967f5bf50 (patch)
tree1a1806b7d8ac2848fc2ef502dc1c6073b62375b1 /org.fox.ttrss/src/main/java
parentf3b313b46f30113900b616e75feb7083850e20ff (diff)
use two common notification channels instead of separate ones
Diffstat (limited to 'org.fox.ttrss/src/main/java')
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java29
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java22
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java15
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/util/ImageCacheService.java22
4 files changed, 37 insertions, 51 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
index 42df3bd1..1f702e5b 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
@@ -5,6 +5,8 @@ import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.Dialog;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
@@ -18,6 +20,7 @@ import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
@@ -65,7 +68,10 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
//public final static String THEME_AMBER = "THEME_AMBER";
public final static String THEME_DEFAULT = CommonActivity.THEME_LIGHT;
- public static final int EXCERPT_MAX_LENGTH = 256;
+ public final static String NOTIFICATION_CHANNEL_NORMAL = "channel_normal";
+ public final static String NOTIFICATION_CHANNEL_PRIORITY = "channel_priority";
+
+ public static final int EXCERPT_MAX_LENGTH = 256;
public static final int EXCERPT_MAX_QUERY_LENGTH = 2048;
public static final int PENDING_INTENT_CHROME_SHARE = 1;
@@ -218,6 +224,27 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc
@Override
public void onCreate(Bundle savedInstanceState) {
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationManager nmgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+
+ // todo: human readable names
+
+ NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_PRIORITY,
+ NOTIFICATION_CHANNEL_PRIORITY,
+ NotificationManager.IMPORTANCE_HIGH);
+ channel.setShowBadge(false);
+ channel.setSound(null, null);
+ nmgr.createNotificationChannel(channel);
+
+ channel = new NotificationChannel(NOTIFICATION_CHANNEL_NORMAL,
+ NOTIFICATION_CHANNEL_NORMAL,
+ NotificationManager.IMPORTANCE_DEFAULT);
+ channel.setShowBadge(false);
+ channel.setSound(null, null);
+ nmgr.createNotificationChannel(channel);
+ }
+
m_databaseHelper = DatabaseHelper.getInstance(this);
m_prefs = PreferenceManager
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java
index 9c4eb9ac..ad4b2241 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java
@@ -3,7 +3,6 @@ package org.fox.ttrss.offline;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.Notification;
-import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
@@ -27,6 +26,7 @@ import com.google.gson.reflect.TypeToken;
import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.BuildConfig;
+import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.R;
import org.fox.ttrss.types.Article;
@@ -46,8 +46,6 @@ import java.util.List;
public class OfflineDownloadService extends Service {
private final String TAG = this.getClass().getSimpleName();
- private final String NOTIFICATION_CHANNEL_NORMAL = TAG + ":Normal";
- private final String NOTIFICATION_CHANNEL_PRIORITY = TAG + ":Priority";
// enable downloading read articles in debug configuration for testing
private static boolean OFFLINE_DEBUG_READ = false;
@@ -96,20 +94,6 @@ public class OfflineDownloadService extends Service {
super.onCreate();
m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_PRIORITY, NOTIFICATION_CHANNEL_PRIORITY,
- NotificationManager.IMPORTANCE_HIGH);
- channel.setShowBadge(false);
- channel.setSound(null, null);
- m_nmgr.createNotificationChannel(channel);
-
- channel = new NotificationChannel(NOTIFICATION_CHANNEL_NORMAL, NOTIFICATION_CHANNEL_NORMAL,
- NotificationManager.IMPORTANCE_DEFAULT);
- channel.setShowBadge(false);
- channel.setSound(null, null);
- m_nmgr.createNotificationChannel(channel);
- }
-
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
@@ -155,7 +139,7 @@ public class OfflineDownloadService extends Service {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- builder.setChannelId(NOTIFICATION_CHANNEL_NORMAL);
+ builder.setChannelId(CommonActivity.NOTIFICATION_CHANNEL_NORMAL);
}
m_nmgr.notify(NOTIFY_DOWNLOADING, builder.build());
@@ -203,7 +187,7 @@ public class OfflineDownloadService extends Service {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- builder.setChannelId(NOTIFICATION_CHANNEL_PRIORITY);
+ builder.setChannelId(CommonActivity.NOTIFICATION_CHANNEL_PRIORITY);
}
m_nmgr.notify(NOTIFY_DOWNLOAD_SUCCESS, builder.build());
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java
index 55df9063..1ff3521d 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java
@@ -2,7 +2,6 @@ package org.fox.ttrss.offline;
import android.app.IntentService;
import android.app.Notification;
-import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@@ -18,6 +17,7 @@ import android.util.Log;
import com.google.gson.JsonElement;
import org.fox.ttrss.ApiRequest;
+import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.R;
import org.fox.ttrss.util.DatabaseHelper;
@@ -28,8 +28,7 @@ import java.util.List;
public class OfflineUploadService extends IntentService {
private final String TAG = this.getClass().getSimpleName();
- private final String NOTIFICATION_CHANNEL_ID = TAG;
-
+
public static final int NOTIFY_UPLOADING = 2;
public static final String INTENT_ACTION_SUCCESS = "org.fox.ttrss.intent.action.UploadComplete";
@@ -48,14 +47,6 @@ public class OfflineUploadService extends IntentService {
super.onCreate();
m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, TAG,
- NotificationManager.IMPORTANCE_DEFAULT);
- channel.setShowBadge(false);
- channel.setSound(null, null);
- m_nmgr.createNotificationChannel(channel);
- }
-
initDatabase();
}
@@ -94,7 +85,7 @@ public class OfflineUploadService extends IntentService {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- builder.setChannelId(NOTIFICATION_CHANNEL_ID);
+ builder.setChannelId(CommonActivity.NOTIFICATION_CHANNEL_NORMAL);
}
m_nmgr.notify(NOTIFY_UPLOADING, builder.build());
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ImageCacheService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ImageCacheService.java
index 955df21e..483df20c 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ImageCacheService.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ImageCacheService.java
@@ -4,7 +4,6 @@ import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.IntentService;
import android.app.Notification;
-import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@@ -17,6 +16,7 @@ import android.os.Environment;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
+import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.R;
import org.fox.ttrss.offline.OfflineDownloadService;
@@ -35,8 +35,6 @@ public class ImageCacheService extends IntentService {
@SuppressWarnings("unused")
private final String TAG = this.getClass().getSimpleName();
- private final String NOTIFICATION_CHANNEL_NORMAL = TAG + ":Normal";
- private final String NOTIFICATION_CHANNEL_PRIORITY = TAG + ":Priority";
public static final int NOTIFY_DOWNLOADING = 1;
public static final int NOTIFY_DOWNLOAD_SUCCESS = 2;
@@ -72,20 +70,6 @@ public class ImageCacheService extends IntentService {
super.onCreate();
m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_PRIORITY, NOTIFICATION_CHANNEL_PRIORITY,
- NotificationManager.IMPORTANCE_HIGH);
- channel.setShowBadge(false);
- channel.setSound(null, null);
- m_nmgr.createNotificationChannel(channel);
-
- channel = new NotificationChannel(NOTIFICATION_CHANNEL_NORMAL, NOTIFICATION_CHANNEL_NORMAL,
- NotificationManager.IMPORTANCE_DEFAULT);
- channel.setShowBadge(false);
- channel.setSound(null, null);
- m_nmgr.createNotificationChannel(channel);
- }
-
m_receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -202,7 +186,7 @@ public class ImageCacheService extends IntentService {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- builder.setChannelId(NOTIFICATION_CHANNEL_PRIORITY);
+ builder.setChannelId(CommonActivity.NOTIFICATION_CHANNEL_PRIORITY);
}
m_nmgr.notify(NOTIFY_DOWNLOAD_SUCCESS, builder.build());
@@ -244,7 +228,7 @@ public class ImageCacheService extends IntentService {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- builder.setChannelId(NOTIFICATION_CHANNEL_NORMAL);
+ builder.setChannelId(CommonActivity.NOTIFICATION_CHANNEL_NORMAL);
}
m_nmgr.notify(NOTIFY_DOWNLOADING, builder.build());