Commit e83f40d5 authored by Viktor De Pasquale's avatar Viktor De Pasquale Committed by John Wu

Added actions for opening files in the file browser

No icons are added at this time, so crashes might occur
parent e5118418
...@@ -21,6 +21,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.Magisk ...@@ -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.model.entity.internal.DownloadSubject.Module
import com.topjohnwu.magisk.ui.flash.FlashActivity import com.topjohnwu.magisk.ui.flash.FlashActivity
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.utils.chooser
import com.topjohnwu.magisk.utils.provide import com.topjohnwu.magisk.utils.provide
import java.io.File import java.io.File
import kotlin.random.Random.Default.nextInt import kotlin.random.Random.Default.nextInt
...@@ -34,7 +35,7 @@ open class DownloadService : RemoteFileService() { ...@@ -34,7 +35,7 @@ open class DownloadService : RemoteFileService() {
private val File.type private val File.type
get() = MimeTypeMap.getSingleton() get() = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension) .getMimeTypeFromExtension(extension)
.orEmpty() ?: "resource/folder"
override fun onFinished(file: File, subject: DownloadSubject) = when (subject) { override fun onFinished(file: File, subject: DownloadSubject) = when (subject) {
is Magisk -> onFinishedInternal(file, subject) is Magisk -> onFinishedInternal(file, subject)
...@@ -77,7 +78,8 @@ open class DownloadService : RemoteFileService() { ...@@ -77,7 +78,8 @@ open class DownloadService : RemoteFileService() {
file: File, file: File,
subject: Magisk subject: Magisk
) = when (val conf = subject.configuration) { ) = 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)) Uninstall -> setContentIntent(FlashActivity.uninstallIntent(context, file))
is Flash -> setContentIntent(FlashActivity.flashIntent(context, file, conf is Secondary)) is Flash -> setContentIntent(FlashActivity.flashIntent(context, file, conf is Secondary))
is Patch -> setContentIntent(FlashActivity.patchIntent(context, file, conf.fileUri)) is Patch -> setContentIntent(FlashActivity.patchIntent(context, file, conf.fileUri))
...@@ -88,7 +90,8 @@ open class DownloadService : RemoteFileService() { ...@@ -88,7 +90,8 @@ open class DownloadService : RemoteFileService() {
file: File, file: File,
subject: Module subject: Module
) = when (subject.configuration) { ) = 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)) is Flash -> setContentIntent(FlashActivity.installIntent(context, file))
else -> this else -> this
} }
...@@ -98,6 +101,11 @@ open class DownloadService : RemoteFileService() { ...@@ -98,6 +101,11 @@ open class DownloadService : RemoteFileService() {
PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT) PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT)
.let { setContentIntent(it) } .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) { private fun moveToDownloads(file: File) {
...@@ -131,9 +139,26 @@ open class DownloadService : RemoteFileService() { ...@@ -131,9 +139,26 @@ open class DownloadService : RemoteFileService() {
) )
return Intent() 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) return Intent(Intent.ACTION_VIEW)
.setDataAndType(file.provide(this), file.type) .setDataAndType(file.provide(this), file.type)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.chooser()
} }
class Builder { class Builder {
......
...@@ -76,6 +76,8 @@ ...@@ -76,6 +76,8 @@
<string name="download_module">Injecting installer…</string> <string name="download_module">Injecting installer…</string>
<string name="download_file_error">Error downloading file</string> <string name="download_file_error">Error downloading file</string>
<string name="download_file_folder_error">Unable to fetch parent folder in order to save the downloaded file, check permissions.</string> <string name="download_file_folder_error">Unable to fetch parent folder in order to save the downloaded file, check permissions.</string>
<string name="download_open_parent">Show in parent folder</string>
<string name="download_open_self">Show file</string>
<string name="magisk_update_title">Magisk Update Available!</string> <string name="magisk_update_title">Magisk Update Available!</string>
<string name="manager_update_title">Magisk Manager Update Available!</string> <string name="manager_update_title">Magisk Manager Update Available!</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment