-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v1.3.8
- Loading branch information
Showing
115 changed files
with
2,385 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
app/src/main/java/team/aliens/dms/android/app/DmsApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package team.aliens.dms.android.app | ||
|
||
import android.app.Application | ||
import androidx.hilt.work.HiltWorkerFactory | ||
import androidx.work.Configuration | ||
import dagger.hilt.android.HiltAndroidApp | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class DmsApplication : Application() | ||
class DmsApplication : Application(), Configuration.Provider { | ||
|
||
@Inject | ||
lateinit var workFactory: HiltWorkerFactory | ||
|
||
override val workManagerConfiguration: Configuration | ||
get() = Configuration.Builder() | ||
.setWorkerFactory(workFactory) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/src/main/java/team/aliens/dms/android/app/NotificationManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package team.aliens.dms.android.app | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
import team.aliens.dms.android.core.designsystem.DmsIcon | ||
import team.aliens.dms.android.core.notification.notificationPermissionGranted | ||
|
||
private object Notifications { | ||
const val NOTIFICATION_ID = 0 | ||
const val NOTIFICATION_CHANNEL_ID = "dms" | ||
const val CHANNEL_NAME = "dms" | ||
const val CHANNEL_DESCRIPTION = "dms notification channel" | ||
} | ||
|
||
class NotificationManager( | ||
private val context: Context, | ||
) { | ||
|
||
init { | ||
createNotificationChannel() | ||
} | ||
|
||
private val notificationManagerCompat: NotificationManagerCompat by lazy { | ||
NotificationManagerCompat.from(context) | ||
} | ||
|
||
private val messageId = System.currentTimeMillis().toInt() | ||
private val intent = Intent(context, MainActivity::class.java) | ||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) | ||
private val pendingIntent = PendingIntent.getActivity( | ||
context, messageId, intent, PendingIntent.FLAG_IMMUTABLE | ||
) | ||
|
||
private val notificationBuilder: NotificationCompat.Builder by lazy { | ||
NotificationCompat.Builder(context, Notifications.NOTIFICATION_CHANNEL_ID) | ||
.setSmallIcon(DmsIcon.Notification) | ||
.setPriority(NotificationCompat.PRIORITY_HIGH) | ||
.setContentIntent(pendingIntent) | ||
} | ||
|
||
fun setNotificationContent( | ||
title: String?, | ||
body: String?, | ||
) { | ||
notificationBuilder.run { | ||
title?.run { setContentTitle(this) } | ||
body?.run { setContentText(this) } | ||
} | ||
} | ||
|
||
@SuppressLint("MissingPermission") | ||
fun sendNotification() { | ||
if (notificationPermissionGranted(context = context)) { | ||
notificationManagerCompat.notify( | ||
Notifications.NOTIFICATION_ID, | ||
notificationBuilder.build(), | ||
) | ||
} | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val importance = NotificationManager.IMPORTANCE_DEFAULT | ||
val channel = NotificationChannel( | ||
Notifications.NOTIFICATION_CHANNEL_ID, | ||
Notifications.CHANNEL_NAME, | ||
importance | ||
).apply { | ||
this.description = Notifications.CHANNEL_DESCRIPTION | ||
} | ||
val notificationManager = | ||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
notificationManager.createNotificationChannel(channel) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/src/main/java/team/aliens/dms/android/app/service/DmsMessagingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package team.aliens.dms.android.app.service | ||
|
||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import team.aliens.dms.android.core.notification.DeviceTokenManager | ||
import team.aliens.dms.android.app.NotificationManager | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class DmsMessagingService : FirebaseMessagingService() { | ||
|
||
@Inject | ||
lateinit var deviceTokenManager: DeviceTokenManager | ||
|
||
private val notificationManager: NotificationManager by lazy { | ||
NotificationManager(context = this) | ||
} | ||
|
||
override fun onNewToken(deviceToken: String) { | ||
super.onNewToken(deviceToken) | ||
CoroutineScope(Dispatchers.IO).launch { | ||
deviceTokenManager.saveDeviceToken(deviceToken = deviceToken) | ||
} | ||
} | ||
|
||
override fun onMessageReceived(message: RemoteMessage) { | ||
super.onMessageReceived(message) | ||
message.notification?.run { | ||
notificationManager.setNotificationContent( | ||
title = title, | ||
body = body, | ||
) | ||
} | ||
notificationManager.sendNotification() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name" translatable="false">DMS</string> | ||
<string name="default_notification_channel_id">team.aliens.dms.android</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.