-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notifications related to UnifiedPush events
- Loading branch information
Showing
5 changed files
with
66 additions
and
8 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
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
46 changes: 46 additions & 0 deletions
46
app/src/unifiedpush/java/im/molly/unifiedpush/util/UnifiedPushNotificationBuilder.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,46 @@ | ||
package im.molly.unifiedpush.util | ||
|
||
import android.app.Notification | ||
import android.app.NotificationManager | ||
import android.content.Context | ||
import androidx.core.app.NotificationCompat | ||
import org.thoughtcrime.securesms.R | ||
import org.thoughtcrime.securesms.notifications.NotificationChannels | ||
|
||
class UnifiedPushNotificationBuilder(val context: Context) { | ||
|
||
private val NOTIFICATION_ID_UNIFIEDPUSH = 51215 | ||
|
||
private val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, NotificationChannels.getInstance().APP_ALERTS) | ||
.setSmallIcon(R.drawable.ic_notification) | ||
.setContentTitle(context.getString(R.string.UnifiedPushNotificationBuilder__title)) | ||
.setContentIntent(null) | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT) | ||
|
||
private fun getNotification(content: String): Notification { | ||
return builder.setContentText(content).setStyle( | ||
NotificationCompat.BigTextStyle() | ||
.bigText(content) | ||
).build() | ||
} | ||
|
||
fun setNotificationMollySocketRegistrationChanged() { | ||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) | ||
.notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__mollysocket_registration_changed))) | ||
} | ||
|
||
fun setNotificationEndpointChangedAirGaped() { | ||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) | ||
.notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__endpoint_changed_airgaped))) | ||
} | ||
|
||
fun setNotificationEndpointChangedError() { | ||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) | ||
.notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__endpoint_changed_error))) | ||
} | ||
|
||
fun setNotificationRegistrationFailed() { | ||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) | ||
.notify(NOTIFICATION_ID_UNIFIEDPUSH, getNotification(context.getString(R.string.UnifiedPushNotificationBuilder__registration_failed))) | ||
} | ||
} |
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