Open Nextcloud files in Nextcloud app if installed
This commit is contained in:
parent
7ba13a8ba7
commit
7ad36684ae
@ -2,20 +2,18 @@ package de.mm20.launcher2.search.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import de.mm20.launcher2.files.R
|
||||
import de.mm20.launcher2.helper.NetworkUtils
|
||||
import de.mm20.launcher2.nextcloud.NextcloudApiHelper
|
||||
|
||||
class NextcloudFile(
|
||||
fileId: Long,
|
||||
override val label: String,
|
||||
path: String,
|
||||
mimeType: String,
|
||||
size: Long,
|
||||
isDirectory: Boolean,
|
||||
val server: String,
|
||||
metaData: List<Pair<Int, String>>
|
||||
fileId: Long,
|
||||
override val label: String,
|
||||
path: String,
|
||||
mimeType: String,
|
||||
size: Long,
|
||||
isDirectory: Boolean,
|
||||
val server: String,
|
||||
metaData: List<Pair<Int, String>>
|
||||
) : File(fileId, path, mimeType, size, isDirectory, metaData) {
|
||||
override val badgeKey: String = "nextcloud://"
|
||||
|
||||
@ -25,9 +23,26 @@ class NextcloudFile(
|
||||
get() = true
|
||||
|
||||
override fun getLaunchIntent(context: Context): Intent? {
|
||||
var nextcloudApp: String? = null
|
||||
return Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse("$server/f/$id")
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
`package` = getNextcloudAppPackage(context)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun getNextcloudAppPackage(context: Context): String? {
|
||||
val candidates = listOf("com.nextcloud.client", "com.nextcloud.android.beta")
|
||||
|
||||
for (c in candidates) {
|
||||
try {
|
||||
context.packageManager.getPackageInfo(c, 0)
|
||||
return c
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user