about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <noreply@fakecake.org>2018-03-12 14:39:14 +0300
committerAndrew Dolgov <noreply@fakecake.org>2018-03-12 14:39:14 +0300
commitb7260f0d4b479f6a36962476ef6c93ba1102467d (patch)
treea6d2e764ae3c22c3c6d3a6ac29f5d5f76115dda4
parentad436b13c592454bddd7de2637329f7804ca1b29 (diff)
downloadtt-rss-android-b7260f0d4b479f6a36962476ef6c93ba1102467d.tar.gz
tt-rss-android-b7260f0d4b479f6a36962476ef6c93ba1102467d.tar.xz
implement notification channels for sdk 26
-rwxr-xr-x[-rw-r--r--]org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java26
-rwxr-xr-x[-rw-r--r--]org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java19
-rwxr-xr-x[-rw-r--r--]org.fox.ttrss/src/main/java/org/fox/ttrss/util/ImageCacheService.java27
-rwxr-xr-xtt-rss-android.iml1
4 files changed, 69 insertions, 4 deletions
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 6ab16bda..9c4eb9ac 100644..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,6 +3,7 @@ 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;
@@ -45,6 +46,8 @@ 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;
@@ -92,6 +95,21 @@ public class OfflineDownloadService extends Service {
 	public void onCreate() {
 		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());
  
@@ -136,6 +154,10 @@ public class OfflineDownloadService extends Service {
 					.addAction(R.drawable.ic_launcher, getString(R.string.cancel), cancelIntent);
         }
 
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+			builder.setChannelId(NOTIFICATION_CHANNEL_NORMAL);
+		}
+
         m_nmgr.notify(NOTIFY_DOWNLOADING, builder.build());
 	}
 
@@ -180,6 +202,10 @@ public class OfflineDownloadService extends Service {
 					.setGroup("org.fox.ttrss");
 		}
 
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+			builder.setChannelId(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 cba0914c..55df9063 100644..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,6 +2,7 @@ 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;
@@ -27,10 +28,11 @@ 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";
-	
+
 	private String m_sessionId;
 	private NotificationManager m_nmgr;
 	private boolean m_uploadInProgress = false;
@@ -45,6 +47,15 @@ public class OfflineUploadService extends IntentService {
 	public void onCreate() {
 		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();
 	}
 
@@ -82,7 +93,11 @@ public class OfflineUploadService extends IntentService {
 					.addAction(R.drawable.ic_launcher, getString(R.string.offline_sync_try_again), contentIntent);
         }
 
-        m_nmgr.notify(NOTIFY_UPLOADING, builder.build());
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+			builder.setChannelId(NOTIFICATION_CHANNEL_ID);
+		}
+
+		m_nmgr.notify(NOTIFY_UPLOADING, builder.build());
 	}
 	
 	private void updateNotification(int msgResId, int progress, int max, boolean showProgress, boolean isError) {
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 3b2f4302..955df21e 100644..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,17 +4,16 @@ 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;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.SharedPreferences;
 import android.graphics.BitmapFactory;
 import android.os.Build;
 import android.os.Environment;
-import android.preference.PreferenceManager;
 import android.support.v4.app.NotificationCompat;
 import android.util.Log;
 
@@ -36,6 +35,8 @@ 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;
@@ -71,6 +72,20 @@ 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) {
@@ -186,6 +201,10 @@ public class ImageCacheService extends IntentService {
 					.setGroup("org.fox.ttrss");
 		}
 
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+			builder.setChannelId(NOTIFICATION_CHANNEL_PRIORITY);
+		}
+
 		m_nmgr.notify(NOTIFY_DOWNLOAD_SUCCESS, builder.build());
 	}
 
@@ -224,6 +243,10 @@ public class ImageCacheService extends IntentService {
 					.addAction(R.drawable.ic_launcher, getString(R.string.cancel), cancelIntent);
 		}
 
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+			builder.setChannelId(NOTIFICATION_CHANNEL_NORMAL);
+		}
+
 		m_nmgr.notify(NOTIFY_DOWNLOADING, builder.build());
 	}
 
diff --git a/tt-rss-android.iml b/tt-rss-android.iml
index 2f7cbe57..f2dea2d3 100755
--- a/tt-rss-android.iml
+++ b/tt-rss-android.iml
@@ -12,6 +12,7 @@
     <exclude-output />
     <content url="file://$MODULE_DIR$">
       <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+      <excludeFolder url="file://$MODULE_DIR$/build" />
     </content>
     <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
     <orderEntry type="sourceFolder" forTests="false" />