From e83f40d5c55dfbb42ad7907f81455e29ec32e267 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 13 Jul 2019 13:54:32 +0200 Subject: [PATCH] Added actions for opening files in the file browser No icons are added at this time, so crashes might occur --- .../magisk/model/download/DownloadService.kt | 31 +++++++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt index 82262c1e8..89e3f096b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt @@ -21,6 +21,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Module import com.topjohnwu.magisk.ui.flash.FlashActivity import com.topjohnwu.magisk.utils.Utils +import com.topjohnwu.magisk.utils.chooser import com.topjohnwu.magisk.utils.provide import java.io.File import kotlin.random.Random.Default.nextInt @@ -34,7 +35,7 @@ open class DownloadService : RemoteFileService() { private val File.type get() = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(extension) - .orEmpty() + ?: "resource/folder" override fun onFinished(file: File, subject: DownloadSubject) = when (subject) { is Magisk -> onFinishedInternal(file, subject) @@ -77,7 +78,8 @@ open class DownloadService : RemoteFileService() { file: File, subject: Magisk ) = when (val conf = subject.configuration) { - Download -> setContentIntent(fileIntent(subject.fileName)) + Download -> addAction(0, R.string.download_open_parent, fileParentIntent(subject.fileName)) + .addAction(0, R.string.download_open_self, fileIntent(subject.fileName)) Uninstall -> setContentIntent(FlashActivity.uninstallIntent(context, file)) is Flash -> setContentIntent(FlashActivity.flashIntent(context, file, conf is Secondary)) is Patch -> setContentIntent(FlashActivity.patchIntent(context, file, conf.fileUri)) @@ -88,7 +90,8 @@ open class DownloadService : RemoteFileService() { file: File, subject: Module ) = when (subject.configuration) { - Download -> setContentIntent(fileIntent(subject.fileName)) + Download -> addAction(0, R.string.download_open_parent, fileParentIntent(subject.fileName)) + .addAction(0, R.string.download_open_self, fileIntent(subject.fileName)) is Flash -> setContentIntent(FlashActivity.installIntent(context, file)) else -> this } @@ -98,6 +101,11 @@ open class DownloadService : RemoteFileService() { PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT) .let { setContentIntent(it) } + @Suppress("ReplaceSingleLineLet") + private fun NotificationCompat.Builder.addAction(icon: Int, title: Int, intent: Intent) = + PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT) + .let { addAction(icon, getString(title), it) } + // --- private fun moveToDownloads(file: File) { @@ -131,9 +139,26 @@ open class DownloadService : RemoteFileService() { ) return Intent() } + return fileIntent(file) + } + + private fun fileParentIntent(fileName: String): Intent { + val file = fileName.downloadsFile?.parentFile ?: let { + Utils.toast( + getString(R.string.download_file_folder_error), + Toast.LENGTH_LONG + ) + return Intent() + } + return fileIntent(file) + } + + private fun fileIntent(file: File): Intent { return Intent(Intent.ACTION_VIEW) .setDataAndType(file.provide(this), file.type) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + .chooser() } class Builder { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9842ad7ac..1f188bcfa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,6 +76,8 @@ Injecting installer… Error downloading file Unable to fetch parent folder in order to save the downloaded file, check permissions. + Show in parent folder + Show file Magisk Update Available! Magisk Manager Update Available!