Открытие экрана Tasks при нажатии на уведомление

This commit is contained in:
2026-05-11 22:28:07 +03:00
parent 61bcaa95d8
commit 88a13080e5
3 changed files with 53 additions and 4 deletions

View File

@@ -2,11 +2,13 @@ package com.github.nullptroma.wallenc.app
import android.Manifest
import android.content.pm.PackageManager
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.mutableIntStateOf
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.github.nullptroma.wallenc.app.auth.YandexSignInService
@@ -22,6 +24,8 @@ class MainActivity : ComponentActivity() {
@Inject
lateinit var yandexSignInService: YandexSignInService
private val openTaskPipelineFromNotification = mutableIntStateOf(0)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
yandexSignInService.registerWith(this)
@@ -30,11 +34,27 @@ class MainActivity : ComponentActivity() {
Timber.plant(Timber.DebugTree())
consumeOpenTaskPipelineIntent(intent)
setContent {
WallencUi()
WallencUi(
taskPipelineOpenRequestCount = openTaskPipelineFromNotification.intValue,
)
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
consumeOpenTaskPipelineIntent(intent)
}
private fun consumeOpenTaskPipelineIntent(intent: Intent?) {
if (intent?.getBooleanExtra(EXTRA_OPEN_TASK_PIPELINE, false) != true) return
intent.removeExtra(EXTRA_OPEN_TASK_PIPELINE)
openTaskPipelineFromNotification.intValue += 1
}
override fun onDestroy() {
yandexSignInService.unregister(this)
super.onDestroy()
@@ -55,6 +75,9 @@ class MainActivity : ComponentActivity() {
}
companion object {
const val EXTRA_OPEN_TASK_PIPELINE =
"com.github.nullptroma.wallenc.app.EXTRA_OPEN_TASK_PIPELINE"
private const val NOTIFICATION_PERMISSION_REQUEST_CODE = 100
}
}

View File

@@ -11,6 +11,7 @@ import android.os.IBinder
import android.view.View
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import com.github.nullptroma.wallenc.app.MainActivity
import com.github.nullptroma.wallenc.app.R
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
import com.github.nullptroma.wallenc.domain.tasks.TaskForegroundItem
@@ -142,6 +143,7 @@ class TaskPipelineForegroundService : Service() {
.setSmallIcon(android.R.drawable.stat_sys_download)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setContentIntent(openTaskPipelinePendingIntent())
.addAction(
0,
getString(R.string.task_notification_cancel),
@@ -175,6 +177,7 @@ class TaskPipelineForegroundService : Service() {
.setSmallIcon(android.R.drawable.stat_sys_download)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setContentIntent(openTaskPipelinePendingIntent())
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setCustomBigContentView(big)
.addAction(
@@ -185,6 +188,17 @@ class TaskPipelineForegroundService : Service() {
.build()
}
private fun openTaskPipelinePendingIntent(): PendingIntent =
PendingIntent.getActivity(
this,
REQUEST_CODE_OPEN_TASK_PIPELINE,
Intent(this, MainActivity::class.java).apply {
putExtra(MainActivity.EXTRA_OPEN_TASK_PIPELINE, true)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
},
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
private fun cancelAllTasksPendingIntent(): PendingIntent =
PendingIntent.getService(
this,
@@ -323,6 +337,8 @@ class TaskPipelineForegroundService : Service() {
private const val ACTION_CANCEL_ALL_TASKS =
"com.github.nullptroma.wallenc.action.CANCEL_ALL_TASKS"
private const val REQUEST_CODE_OPEN_TASK_PIPELINE = 2
private const val CHANNEL_ID = "wallenc_task_pipeline"
private const val FOREGROUND_NOTIFICATION_ID = 1001