Add new notifications categories
MODIFY
.gitignore
.gitignore
@@ -63,6 +63,7 @@ captures/
.idea/dynamic.xml
.idea/uiDesigner.xml
.idea/runConfigurations.xml
+.idea/discord.xml
# Keystore files
*.jks

MODIFY
app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt
app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt
@@ -9,6 +9,12 @@ import dagger.Module
import dagger.Provides
import dagger.android.ContributesAndroidInjector
import dagger.multibindings.IntoSet
+import io.github.wulkanowy.services.sync.channels.Channel
+import io.github.wulkanowy.services.sync.channels.DebugChannel
+import io.github.wulkanowy.services.sync.channels.LuckyNumberChannel
+import io.github.wulkanowy.services.sync.channels.NewGradesChannel
+import io.github.wulkanowy.services.sync.channels.NewMessagesChannel
+import io.github.wulkanowy.services.sync.channels.NewNotesChannel
import io.github.wulkanowy.services.sync.works.AttendanceSummaryWork
import io.github.wulkanowy.services.sync.works.AttendanceWork
import io.github.wulkanowy.services.sync.works.CompletedLessonWork
@@ -100,4 +106,24 @@ abstract class ServicesModule {
@Binds
@IntoSet
abstract fun provideGradeStatistics(work: GradeStatisticsWork): Work
+
+ @Binds
+ @IntoSet
+ abstract fun provideDebugChannel(channel: DebugChannel): Channel
+
+ @Binds
+ @IntoSet
+ abstract fun provideLuckyNumberChannel(channel: LuckyNumberChannel): Channel
+
+ @Binds
+ @IntoSet
+ abstract fun provideNewGradesChannel(channel: NewGradesChannel): Channel
+
+ @Binds
+ @IntoSet
+ abstract fun provideNewMessageChannel(channel: NewMessagesChannel): Channel
+
+ @Binds
+ @IntoSet
+ abstract fun provideNewNotesChannel(channel: NewNotesChannel): Channel
}

MODIFY
app/src/main/java/io/github/wulkanowy/services/sync/SyncManager.kt
app/src/main/java/io/github/wulkanowy/services/sync/SyncManager.kt
@@ -2,6 +2,7 @@ package io.github.wulkanowy.services.sync
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.O
+import androidx.core.app.NotificationManagerCompat
import androidx.work.BackoffPolicy.EXPONENTIAL
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy.KEEP
@@ -13,8 +14,7 @@ import androidx.work.WorkManager
import io.github.wulkanowy.data.db.SharedPrefProvider
import io.github.wulkanowy.data.db.SharedPrefProvider.Companion.APP_VERSION_CODE_KEY
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
-import io.github.wulkanowy.services.sync.channels.DebugChannel
-import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
+import io.github.wulkanowy.services.sync.channels.Channel
import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.isHolidays
import org.threeten.bp.LocalDate.now
@@ -27,9 +27,9 @@ import javax.inject.Singleton
class SyncManager @Inject constructor(
private val workManager: WorkManager,
private val preferencesRepository: PreferencesRepository,
+ channels: Set<@JvmSuppressWildcards Channel>,
+ notificationManager: NotificationManagerCompat,
sharedPrefProvider: SharedPrefProvider,
- newEntriesChannel: NewEntriesChannel,
- debugChannel: DebugChannel,
appInfo: AppInfo
) {
@@ -37,8 +37,8 @@ class SyncManager @Inject constructor(
if (now().isHolidays) stopSyncWorker()
if (SDK_INT > O) {
- newEntriesChannel.create()
- if (appInfo.isDebug) debugChannel.create()
+ channels.forEach { it.create() }
+ notificationManager.deleteNotificationChannel("new_entries_channel")
}
if (sharedPrefProvider.getLong(APP_VERSION_CODE_KEY, -1L) != appInfo.versionCode.toLong()) {

ADD
app/src/main/java/io/github/wulkanowy/services/sync/channels/Channel.kt
+package io.github.wulkanowy.services.sync.channels
+
+interface Channel {
+
+ fun create()
+}

MODIFY
app/src/main/java/io/github/wulkanowy/services/sync/channels/DebugChannel.kt
app/src/main/java/io/github/wulkanowy/services/sync/channels/DebugChannel.kt
@@ -7,19 +7,22 @@ import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.content.Context
import androidx.core.app.NotificationManagerCompat
import io.github.wulkanowy.R
+import io.github.wulkanowy.utils.AppInfo
import javax.inject.Inject
@TargetApi(26)
class DebugChannel @Inject constructor(
private val notificationManager: NotificationManagerCompat,
- private val context: Context
-) {
+ private val context: Context,
+ private val appInfo: AppInfo
+) : Channel {
companion object {
const val CHANNEL_ID = "debug_channel"
}
- fun create() {
+ override fun create() {
+ if (appInfo.isDebug) return
notificationManager.createNotificationChannel(
NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_debug), IMPORTANCE_DEFAULT)
.apply {

ADD
app/src/main/java/io/github/wulkanowy/services/sync/channels/LuckyNumberChannel.kt
+package io.github.wulkanowy.services.sync.channels
+
+import android.annotation.TargetApi
+import android.app.Notification
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.content.Context
+import androidx.core.app.NotificationManagerCompat
+import io.github.wulkanowy.R
+import javax.inject.Inject
+
+@TargetApi(26)
+class LuckyNumberChannel @Inject constructor(
+ private val notificationManager: NotificationManagerCompat,
+ private val context: Context
+) : Channel {
+
+ companion object {
+ const val CHANNEL_ID = "lucky_number_channel"
+ }
+
+ override fun create() {
+ notificationManager.createNotificationChannel(
+ NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_lucky_number), NotificationManager.IMPORTANCE_HIGH)
+ .apply {
+ enableLights(true)
+ enableVibration(true)
+ lockscreenVisibility = Notification.VISIBILITY_PUBLIC
+ })
+ }
+}

ADD
app/src/main/java/io/github/wulkanowy/services/sync/channels/NewGradesChannel.kt
+package io.github.wulkanowy.services.sync.channels
+
+import android.annotation.TargetApi
+import android.app.Notification
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.content.Context
+import androidx.core.app.NotificationManagerCompat
+import io.github.wulkanowy.R
+import javax.inject.Inject
+
+@TargetApi(26)
+class NewGradesChannel @Inject constructor(
+ private val notificationManager: NotificationManagerCompat,
+ private val context: Context
+) : Channel {
+
+ companion object {
+ const val CHANNEL_ID = "new_grade_channel"
+ }
+
+ override fun create() {
+ notificationManager.createNotificationChannel(
+ NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_new_grades), NotificationManager.IMPORTANCE_HIGH)
+ .apply {
+ enableLights(true)
+ enableVibration(true)
+ lockscreenVisibility = Notification.VISIBILITY_PUBLIC
+ })
+ }
+}

ADD
app/src/main/java/io/github/wulkanowy/services/sync/channels/NewMessagesChannel.kt
+package io.github.wulkanowy.services.sync.channels
+
+import android.annotation.TargetApi
+import android.app.Notification
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.content.Context
+import androidx.core.app.NotificationManagerCompat
+import io.github.wulkanowy.R
+import javax.inject.Inject
+
+@TargetApi(26)
+class NewMessagesChannel @Inject constructor(
+ private val notificationManager: NotificationManagerCompat,
+ private val context: Context
+) : Channel {
+
+ companion object {
+ const val CHANNEL_ID = "new_message_channel"
+ }
+
+ override fun create() {
+ notificationManager.createNotificationChannel(
+ NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_new_message), NotificationManager.IMPORTANCE_HIGH)
+ .apply {
+ enableLights(true)
+ enableVibration(true)
+ lockscreenVisibility = Notification.VISIBILITY_PUBLIC
+ })
+ }
+}

RENAME
app/src/main/java/io/github/wulkanowy/services/sync/channels/NewEntriesChannel.kt
app/src/main/java/io/github/wulkanowy/services/sync/channels/NewNotesChannel.kt
package io.github.wulkanowy.services.sync.channels
import android.annotation.TargetApi
-import android.app.Notification.VISIBILITY_PUBLIC
+import android.app.Notification
import android.app.NotificationChannel
-import android.app.NotificationManager.IMPORTANCE_HIGH
+import android.app.NotificationManager
import android.content.Context
import androidx.core.app.NotificationManagerCompat
import io.github.wulkanowy.R
import javax.inject.Inject
@TargetApi(26)
-class NewEntriesChannel @Inject constructor(
+class NewNotesChannel @Inject constructor(
private val notificationManager: NotificationManagerCompat,
private val context: Context
-) {
+) : Channel {
companion object {
- const val CHANNEL_ID = "new_entries_channel"
+ const val CHANNEL_ID = "new_notes_channel"
}
- fun create() {
+ override fun create() {
notificationManager.createNotificationChannel(
- NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_new_entries), IMPORTANCE_HIGH)
+ NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_new_notes), NotificationManager.IMPORTANCE_HIGH)
.apply {
enableLights(true)
enableVibration(true)
- lockscreenVisibility = VISIBILITY_PUBLIC
+ lockscreenVisibility = Notification.VISIBILITY_PUBLIC
})
}
}

MODIFY
app/src/main/java/io/github/wulkanowy/services/sync/works/GradeWork.kt
app/src/main/java/io/github/wulkanowy/services/sync/works/GradeWork.kt
@@ -13,7 +13,7 @@ import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.grade.GradeRepository
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
-import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
+import io.github.wulkanowy.services.sync.channels.NewGradesChannel
import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.utils.getCompatColor
@@ -38,7 +38,7 @@ class GradeWork @Inject constructor(
}
private fun notify(grades: List<Grade>) {
- notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewEntriesChannel.CHANNEL_ID)
+ notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewGradesChannel.CHANNEL_ID)
.setContentTitle(context.resources.getQuantityString(R.plurals.grade_new_items, grades.size, grades.size))
.setContentText(context.resources.getQuantityString(R.plurals.grade_notify_new_items, grades.size, grades.size))
.setSmallIcon(R.drawable.ic_stat_grade)

MODIFY
app/src/main/java/io/github/wulkanowy/services/sync/works/LuckyNumberWork.kt
app/src/main/java/io/github/wulkanowy/services/sync/works/LuckyNumberWork.kt
@@ -13,7 +13,7 @@ import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
-import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
+import io.github.wulkanowy.services.sync.channels.LuckyNumberChannel
import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.utils.getCompatColor
@@ -38,7 +38,7 @@ class LuckyNumberWork @Inject constructor(
}
private fun notify(luckyNumber: LuckyNumber) {
- notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewEntriesChannel.CHANNEL_ID)
+ notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, LuckyNumberChannel.CHANNEL_ID)
.setContentTitle(context.getString(R.string.lucky_number_notify_new_item_title))
.setContentText(context.getString(R.string.lucky_number_notify_new_item, luckyNumber.luckyNumber))
.setSmallIcon(R.drawable.ic_stat_luckynumber)

MODIFY
app/src/main/java/io/github/wulkanowy/services/sync/works/MessageWork.kt
app/src/main/java/io/github/wulkanowy/services/sync/works/MessageWork.kt
@@ -14,7 +14,7 @@ import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.message.MessageFolder.RECEIVED
import io.github.wulkanowy.data.repositories.message.MessageRepository
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
-import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
+import io.github.wulkanowy.services.sync.channels.NewMessagesChannel
import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.utils.getCompatColor
@@ -39,7 +39,7 @@ class MessageWork @Inject constructor(
}
private fun notify(messages: List<Message>) {
- notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewEntriesChannel.CHANNEL_ID)
+ notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewMessagesChannel.CHANNEL_ID)
.setContentTitle(context.resources.getQuantityString(R.plurals.message_new_items, messages.size, messages.size))
.setContentText(context.resources.getQuantityString(R.plurals.message_notify_new_items, messages.size, messages.size))
.setSmallIcon(R.drawable.ic_stat_message)

MODIFY
app/src/main/java/io/github/wulkanowy/services/sync/works/NoteWork.kt
app/src/main/java/io/github/wulkanowy/services/sync/works/NoteWork.kt
@@ -13,7 +13,7 @@ import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.note.NoteRepository
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
-import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
+import io.github.wulkanowy.services.sync.channels.NewNotesChannel
import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.utils.getCompatColor
@@ -38,7 +38,7 @@ class NoteWork @Inject constructor(
}
private fun notify(notes: List<Note>) {
- notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewEntriesChannel.CHANNEL_ID)
+ notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewNotesChannel.CHANNEL_ID)
.setContentTitle(context.resources.getQuantityString(R.plurals.note_new_items, notes.size, notes.size))
.setContentText(context.resources.getQuantityString(R.plurals.note_notify_new_items, notes.size, notes.size))
.setSmallIcon(R.drawable.ic_stat_note)

MODIFY
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
<!--Notification Channels-->
<string name="channel_new_entries">New entries in register</string>
+ <string name="channel_new_grades">New grades</string>
+ <string name="channel_lucky_number">Lucky number</string>
+ <string name="channel_new_message">New messages</string>
+ <string name="channel_new_notes">New notes</string>
<string name="channel_debug">Debug</string>

Add new notifications categories (#685)