Skip to content

Commit 337ee20

Browse files
feat: click download notification navigate to download screen
1 parent 1bf5bb6 commit 337ee20

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

android/src/main/kotlin/project/pipepipe/app/MainActivity.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import project.pipepipe.app.platform.AndroidActions
4141
import project.pipepipe.app.platform.AndroidMediaController
4242
import project.pipepipe.app.platform.AndroidMenuItems
4343
import project.pipepipe.app.platform.AndroidRouteHandler
44+
import project.pipepipe.app.service.DownloadService
4445
import project.pipepipe.app.service.FeedUpdateManager
4546
import project.pipepipe.app.ui.component.*
4647
import project.pipepipe.app.ui.navigation.NavGraph
@@ -72,6 +73,7 @@ class MainActivity : ComponentActivity() {
7273
checkIntentForFeedFailures(intent)
7374
checkIntentForStreamsFailures(intent)
7475
checkIntentForChannelNavigation(intent)
76+
checkIntentForDownload(intent)
7577
handleDeepLink(intent)
7678

7779
setContentView(R.layout.activity_main)
@@ -325,6 +327,7 @@ class MainActivity : ComponentActivity() {
325327
checkIntentForFeedFailures(intent)
326328
checkIntentForStreamsFailures(intent)
327329
checkIntentForChannelNavigation(intent)
330+
checkIntentForDownload(intent)
328331
handleDeepLink(intent)
329332
}
330333

@@ -341,6 +344,18 @@ class MainActivity : ComponentActivity() {
341344
}
342345
}
343346

347+
private fun checkIntentForDownload(intent: Intent) {
348+
if (intent.action == DownloadService.ACTION_OPEN_DOWNLOADS_FINISHED) {
349+
if (SharedContext.sharedVideoDetailViewModel.uiState.value.pageState == VideoDetailPageState.DETAIL_PAGE) {
350+
SharedContext.sharedVideoDetailViewModel.showAsBottomPlayer()
351+
}
352+
if (SharedContext.playQueueVisibility.value) {
353+
SharedContext.toggleShowPlayQueueVisibility()
354+
}
355+
navController.navigate(Screen.Download.route)
356+
}
357+
}
358+
344359

345360
private fun checkIntentForPlayQueue(intent: Intent) {
346361
openPlayQueueFromIntent = intent.getBooleanExtra("open_play_queue", false)
@@ -494,6 +509,7 @@ class MainActivity : ComponentActivity() {
494509

495510

496511
override fun onUserLeaveHint() {
512+
println(777)
497513
super.onUserLeaveHint()
498514

499515
val uiState = SharedContext.sharedVideoDetailViewModel.uiState.value

android/src/main/kotlin/project/pipepipe/app/service/DownloadService.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import kotlinx.coroutines.runBlocking
1515
import project.pipepipe.app.MR
1616
import project.pipepipe.app.database.DatabaseOperations
1717
import dev.icerock.moko.resources.desc.desc
18+
import project.pipepipe.app.MainActivity
1819

1920
/**
2021
* Foreground service for managing downloads
@@ -36,6 +37,7 @@ class DownloadService : Service() {
3637
.setSmallIcon(android.R.drawable.stat_sys_download)
3738
.setPriority(NotificationCompat.PRIORITY_LOW)
3839
.setOngoing(true)
40+
.setContentIntent(makePendingIntent(this, ACTION_OPEN_DOWNLOADS_FINISHED))
3941
.build()
4042
startForeground(FOREGROUND_NOTIFICATION_ID, notification)
4143
isForeground = true
@@ -100,6 +102,7 @@ class DownloadService : Service() {
100102
.setSmallIcon(android.R.drawable.stat_sys_download)
101103
.setPriority(NotificationCompat.PRIORITY_LOW)
102104
.setOngoing(true)
105+
.setContentIntent(makePendingIntent(this, ACTION_OPEN_DOWNLOADS_FINISHED))
103106
.build()
104107
startForeground(FOREGROUND_NOTIFICATION_ID, notification)
105108
isForeground = true
@@ -124,8 +127,8 @@ class DownloadService : Service() {
124127
private const val COMPLETION_NOTIFICATION_ID = 3002
125128
private const val ERROR_NOTIFICATION_BASE_ID = 3100
126129

127-
private const val ACTION_RESET_DOWNLOAD_FINISHED = "project.pipepipe.reset_download_finished"
128-
private const val ACTION_OPEN_DOWNLOADS_FINISHED = "project.pipepipe.open_downloads_finished"
130+
const val ACTION_RESET_DOWNLOAD_FINISHED = "project.pipepipe.reset_download_finished"
131+
const val ACTION_OPEN_DOWNLOADS_FINISHED = "project.pipepipe.open_downloads_finished"
129132

130133
private var instance: DownloadService? = null
131134

@@ -177,13 +180,13 @@ class DownloadService : Service() {
177180
}
178181

179182
private fun makePendingIntent(context: Context, action: String): PendingIntent {
180-
val intent = Intent(context, DownloadService::class.java).setAction(action)
183+
val intent = Intent(context, MainActivity::class.java).setAction(action)
181184
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
182185
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
183186
} else {
184187
PendingIntent.FLAG_UPDATE_CURRENT
185188
}
186-
return PendingIntent.getService(context, action.hashCode(), intent, flags)
189+
return PendingIntent.getActivity(context, action.hashCode(), intent, flags)
187190
}
188191
}
189192
}

0 commit comments

Comments
 (0)