#1840 Enable/disable feed notification

This commit is contained in:
sictiru 2023-12-23 13:16:31 -08:00
parent 5a3bde4508
commit d62924aefb
2 changed files with 75 additions and 0 deletions

View file

@ -23,6 +23,7 @@ object FeedExt {
fun Feed.disableNotification() {
notificationFilter = null
disableNotificationType(NOTIFY_ANDROID)
}
@JvmStatic
@ -39,10 +40,12 @@ object FeedExt {
fun Feed.setNotifyFocus() {
notificationFilter = Feed.NOTIFY_FILTER_FOCUS
enableNotificationType(NOTIFY_ANDROID)
}
fun Feed.setNotifyUnread() {
notificationFilter = Feed.NOTIFY_FILTER_UNREAD
enableNotificationType(NOTIFY_ANDROID)
}
private fun Feed.isNotify(type: String): Boolean = notificationTypes?.contains(type) ?: false

View file

@ -0,0 +1,72 @@
package com.newsblur
import com.newsblur.domain.Feed
import com.newsblur.util.FeedExt.NOTIFY_ANDROID
import com.newsblur.util.FeedExt.disableNotification
import com.newsblur.util.FeedExt.disableNotificationType
import com.newsblur.util.FeedExt.enableNotificationType
import com.newsblur.util.FeedExt.setNotifyFocus
import com.newsblur.util.FeedExt.setNotifyUnread
import org.junit.Assert
import org.junit.Test
class FeedNotificationPrefsTest {
@Test
fun enableUnreadNotif() {
val feed = Feed.getZeroFeed()
Assert.assertEquals(null, feed.notificationFilter)
Assert.assertEquals(null, feed.notificationTypes)
feed.setNotifyUnread()
Assert.assertEquals(Feed.NOTIFY_FILTER_UNREAD, feed.notificationFilter)
Assert.assertTrue(feed.notificationTypes.contains(NOTIFY_ANDROID))
}
@Test
fun enableFocusNotif() {
val feed = Feed.getZeroFeed()
Assert.assertEquals(null, feed.notificationFilter)
Assert.assertEquals(null, feed.notificationTypes)
feed.setNotifyFocus()
Assert.assertEquals(Feed.NOTIFY_FILTER_FOCUS, feed.notificationFilter)
Assert.assertTrue(feed.notificationTypes.contains(NOTIFY_ANDROID))
}
@Test
fun disableNotif() {
val feed = Feed.getZeroFeed()
Assert.assertEquals(null, feed.notificationFilter)
Assert.assertEquals(null, feed.notificationTypes)
feed.setNotifyFocus()
Assert.assertEquals(Feed.NOTIFY_FILTER_FOCUS, feed.notificationFilter)
Assert.assertTrue(feed.notificationTypes.contains(NOTIFY_ANDROID))
feed.disableNotification()
Assert.assertEquals(null, feed.notificationFilter)
Assert.assertFalse(feed.notificationTypes.contains(NOTIFY_ANDROID))
}
@Test
fun enableNotificationTypeTest() {
val feed = Feed.getZeroFeed()
Assert.assertEquals(null, feed.notificationTypes)
feed.enableNotificationType(NOTIFY_ANDROID)
Assert.assertTrue(feed.notificationTypes.contains(NOTIFY_ANDROID))
}
@Test
fun disableNotificationTypeTest() {
val feed = Feed.getZeroFeed()
Assert.assertEquals(null, feed.notificationTypes)
feed.enableNotificationType(NOTIFY_ANDROID)
Assert.assertTrue(feed.notificationTypes.contains(NOTIFY_ANDROID))
feed.disableNotificationType(NOTIFY_ANDROID)
Assert.assertFalse(feed.notificationTypes.contains(NOTIFY_ANDROID))
}
}