Skip to content

Commit

Permalink
Implement first steps for sending file share links to files client
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
  • Loading branch information
AndyScherzinger committed Sep 20, 2023
1 parent 4192040 commit 2e67825
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,69 @@ class ChatActivity :
)
}

fun isInstanceFileUrl(user: User, url: String): Boolean {
return url.startsWith(user.baseUrl!!) &&
(isInstanceInternalFileShareUrl(user.baseUrl!!, url) || isInstanceInternalFileUrl(user.baseUrl!!, url))
}

fun isInstanceInternalFileShareUrl(baseUrl: String, url: String): Boolean {
// https://cloud.nextcloud.com/f/41
return url.startsWith("$baseUrl/f/") || url.startsWith("$baseUrl/index.php/f/")
}

fun extractInstanceInternalFileShareFileId(url: String): String {
// https://cloud.nextcloud.com/f/41
return "41"
}

fun isInstanceInternalFileUrl(baseUrl: String, url: String): Boolean {
//https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41
return url.startsWith("$baseUrl/apps/files/") || url.startsWith("$baseUrl/index.php/apps/files/")
}

fun extractInstanceInternalFileFileId(url: String): String {
// https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41
return "41"
}

fun isInstanceInternalFileUrlNew(baseUrl: String, url: String): Boolean {
//https://cloud.nextcloud.com/apps/files/files/41?dir=/
return url.startsWith("$baseUrl/apps/files/files/") || url.startsWith("$baseUrl/index.php/apps/files/files/")
}

fun extractInstanceInternalFileFileIdNew(url: String): String {
// https://cloud.nextcloud.com/apps/files/files/41?dir=/
return "41"
}

override fun startActivity(intent: Intent) {
val user = currentUserProvider.currentUser.blockingGet()
if (intent.data != null && TextUtils.equals(intent.action, Intent.ACTION_VIEW)) {
val uri = intent.data.toString()
if (uri.startsWith(user.baseUrl!!)) {
if (isInstanceInternalFileShareUrl(user.baseUrl!!, uri)) {
// https://cloud.nextcloud.com/f/41
val fileViewerUtils = FileViewerUtils(this, user)
fileViewerUtils.openFileInFilesApp(uri, extractInstanceInternalFileShareFileId(uri))
} else if (isInstanceInternalFileUrl(user.baseUrl!!, uri)) {
// https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41
val fileViewerUtils = FileViewerUtils(this, user)
fileViewerUtils.openFileInFilesApp(uri, extractInstanceInternalFileFileId(uri))
} else if (isInstanceInternalFileUrlNew(user.baseUrl!!, uri)) {
// https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41
val fileViewerUtils = FileViewerUtils(this, user)
fileViewerUtils.openFileInFilesApp(uri, extractInstanceInternalFileFileIdNew(uri))
} else {
super.startActivity(intent)
}
} else {
super.startActivity(intent)
}
} else {
super.startActivity(intent)
}
}

fun sendSelectLocalFileIntent() {
if (!permissionUtil.isFilesPermissionGranted()) {
requestReadFilesPermissions()
Expand Down

0 comments on commit 2e67825

Please sign in to comment.