Add easier way to use of emoji in notifications (#741)

* Add easier way to use of emoji in notifications

* Try to exclude org.json:json

* Fix lint
This commit is contained in:
chriss158 2020-08-17 03:57:47 +02:00 committed by GitHub
parent 47a88000e9
commit 6bc19488b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View file

@ -117,6 +117,9 @@ dependencies {
implementation(project(":domain"))
implementation(Config.Dependency.Misc.blurView)
implementation(Config.Dependency.Misc.emoji) {
exclude(group = "org.json", module = "json")
}
implementation(Config.Dependency.Kotlin.core)
implementation(Config.Dependency.Kotlin.coroutines)

View file

@ -18,6 +18,7 @@ import androidx.core.content.ContextCompat
import androidx.core.text.HtmlCompat
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.vdurmont.emoji.EmojiParser
import io.homeassistant.companion.android.R
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor
import io.homeassistant.companion.android.domain.authentication.AuthenticationUseCase
@ -273,7 +274,7 @@ class MessagingService : FirebaseMessagingService() {
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setStyle(
NotificationCompat.BigTextStyle()
.setSummaryText(getSpannedTextFromHtml(group.substring(GROUP_PREFIX.length))
.setSummaryText(prepareText(group.substring(GROUP_PREFIX.length))
)
)
.setGroup(group)
@ -410,7 +411,7 @@ class MessagingService : FirebaseMessagingService() {
data: Map<String, String>
) {
data[SUBJECT]?.let {
builder.setContentText(getSpannedTextFromHtml(it))
builder.setContentText(prepareText(it))
}
}
@ -419,19 +420,20 @@ class MessagingService : FirebaseMessagingService() {
data: Map<String, String>
) {
data[TITLE]?.let {
builder.setContentTitle(getSpannedTextFromHtml(it))
builder.setContentTitle(prepareText(it))
}
data[MESSAGE]?.let {
val text = getSpannedTextFromHtml(it)
val text = prepareText(it)
builder.setContentText(text)
builder.setStyle(NotificationCompat.BigTextStyle().bigText(text))
}
}
private fun getSpannedTextFromHtml(
private fun prepareText(
text: String
): Spanned {
return HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)
var emojiParsedText = EmojiParser.parseToUnicode(text)
return HtmlCompat.fromHtml(emojiParsedText, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
private suspend fun handleLargeIcon(

View file

@ -103,6 +103,7 @@ object Config {
const val threeTenAbp = "com.jakewharton.threetenabp:threetenabp:1.2.1"
const val javaxInject = "javax.inject:javax.inject:1"
const val blurView = "com.eightbitlab:blurview:1.6.3"
const val emoji = "com.vdurmont:emoji-java:5.1.1"
}
}