1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-07 21:37:02 +09:00

DROID-3637 Chats | Fix | From-notification-to-chat UX flow fixes (#2468)

This commit is contained in:
Evgenii Kozlov 2025-05-27 08:09:12 +02:00 committed by konstantiniiv
parent ad1492120e
commit ab2f0ea838
2 changed files with 15 additions and 5 deletions

View file

@ -7,12 +7,14 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import com.anytypeio.anytype.R
import com.anytypeio.anytype.core_models.DecryptedPushContent
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.ui.main.MainActivity
import kotlin.math.absoluteValue
class NotificationBuilder(
private val context: Context,
@ -71,14 +73,18 @@ class NotificationBuilder(
if (createdChannels.contains(channelId)) return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
channelId, channelName, NotificationManager.IMPORTANCE_HIGH
channelId,
channelName,
NotificationManager.IMPORTANCE_HIGH
).apply {
description = "New messages notifications"
enableLights(true)
enableVibration(true)
setShowBadge(true)
lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
group = CHANNEL_GROUP_ID
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
group = CHANNEL_GROUP_ID
}
}
notificationManager.createNotificationChannel(channel)
createdChannels.add(channelId)
@ -88,7 +94,7 @@ class NotificationBuilder(
/**
* Creates the tap-action intent and wraps it in a PendingIntent for notifications.
*/
fun createChatPendingIntent(
private fun createChatPendingIntent(
context: Context,
chatId: String,
spaceId: Id
@ -101,10 +107,13 @@ class NotificationBuilder(
putExtra(Relations.SPACE_ID, spaceId)
}
// A unique PendingIntent per chat target.
val requestCode = (chatId + spaceId).hashCode().absoluteValue
// 2) Wrap it in a one-shot immutable PendingIntent
return PendingIntent.getActivity(
context,
NOTIFICATION_REQUEST_CODE,
requestCode,
intent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
)
@ -125,7 +134,6 @@ class NotificationBuilder(
}
companion object {
private const val NOTIFICATION_REQUEST_CODE = 100
private const val CHANNEL_GROUP_ID = "chats_group"
private const val CHANNEL_GROUP_NAME = "Chats"
}

View file

@ -492,6 +492,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr
chatId = chatId,
spaceId = spaceId
)
// Clearing from-notification-to-chat intent.
intent.replaceExtras(Bundle())
} else {
// Do nothing, already there.
}