forked from capcom6/android-sms-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[notifications] introduce notifications module
- Loading branch information
Showing
4 changed files
with
64 additions
and
30 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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/me/capcom/smsgateway/modules/notifications/Module.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,7 @@ | ||
package me.capcom.smsgateway.modules.notifications | ||
|
||
import org.koin.dsl.module | ||
|
||
val notificationsModule = module { | ||
single { NotificationsService(get()) } | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/me/capcom/smsgateway/modules/notifications/NotificationsService.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,45 @@ | ||
package me.capcom.smsgateway.modules.notifications | ||
|
||
import android.app.Notification | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.content.Context | ||
import android.os.Build | ||
import androidx.core.app.NotificationCompat | ||
import me.capcom.smsgateway.R | ||
|
||
class NotificationsService( | ||
context: Context | ||
) { | ||
private val notificationManager = | ||
context.getSystemService(Context.NOTIFICATION_SERVICE) as | ||
NotificationManager | ||
|
||
init { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val name = context.getString(R.string.sms_gateway) | ||
val descriptionText = context.getString(R.string.local_sms_gateway_notifications) | ||
val importance = NotificationManager.IMPORTANCE_LOW | ||
val mChannel = NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance) | ||
mChannel.description = descriptionText | ||
// Register the channel with the system; you can't change the importance | ||
// or other notification behaviors after this | ||
notificationManager.createNotificationChannel(mChannel) | ||
} | ||
} | ||
|
||
fun makeNotification(context: Context, contentText: String): Notification { | ||
return NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID) | ||
.setContentTitle(context.getText(R.string.notification_title)) | ||
.setContentText(contentText) | ||
.setSmallIcon(R.drawable.ic_sms) | ||
.build() | ||
} | ||
|
||
companion object { | ||
const val NOTIFICATION_CHANNEL_ID = "sms-gateway" | ||
|
||
const val NOTIFICATION_ID_LOCAL_SERVICE = 1 | ||
const val NOTIFICATION_ID_SEND_WORKER = 2 | ||
} | ||
} |