From 8876718677eff034837771ebf2ecac1d26b27ba1 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 21 May 2024 11:57:55 +0200 Subject: [PATCH 1/2] open links for files app from any screen. With this change, all links that target files in the same nextcloud instance will be opened in the files app, no matter on which screen the link was. Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/activities/BaseActivity.kt | 36 +++++++++++++++++++ .../nextcloud/talk/activities/CallActivity.kt | 7 +--- .../com/nextcloud/talk/chat/ChatActivity.kt | 33 ----------------- .../ConversationInfoActivity.kt | 4 --- .../ConversationInfoEditActivity.kt | 4 --- .../talk/diagnose/DiagnoseActivity.kt | 4 --- .../talk/invitation/InvitationsActivity.kt | 6 +--- .../messagesearch/MessageSearchActivity.kt | 6 +--- .../ListOpenConversationsActivity.kt | 6 +--- .../talk/settings/SettingsActivity.kt | 4 --- .../activities/SharedItemsActivity.kt | 12 ++----- .../java/com/nextcloud/talk/utils/UriUtils.kt | 1 + 12 files changed, 43 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt index 7c76ddc57..df7235fbd 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt @@ -10,8 +10,10 @@ package com.nextcloud.talk.activities import android.annotation.SuppressLint import android.content.Context +import android.content.Intent import android.os.Build import android.os.Bundle +import android.text.TextUtils import android.util.Log import android.view.View import android.view.ViewGroup @@ -34,6 +36,9 @@ import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.events.CertificateEvent import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.FileViewerUtils +import com.nextcloud.talk.utils.UriUtils +import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.preferences.AppPreferences import com.nextcloud.talk.utils.ssl.TrustManager import org.greenrobot.eventbus.EventBus @@ -65,6 +70,9 @@ open class BaseActivity : AppCompatActivity() { @Inject lateinit var context: Context + @Inject + lateinit var currentUserProvider: CurrentUserProviderNew + open val appBarLayoutType: AppBarLayoutType get() = AppBarLayoutType.TOOLBAR @@ -223,6 +231,34 @@ open class BaseActivity : AppCompatActivity() { showCertificateDialog(event.x509Certificate, event.trustManager, event.sslErrorHandler) } + 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 (UriUtils.isInstanceInternalFileShareUrl(user.baseUrl!!, uri)) { + // https://cloud.nextcloud.com/f/41 + val fileViewerUtils = FileViewerUtils(applicationContext, user) + fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileShareFileId(uri)) + } else if (UriUtils.isInstanceInternalFileUrl(user.baseUrl!!, uri)) { + // https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41 + val fileViewerUtils = FileViewerUtils(applicationContext, user) + fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileFileId(uri)) + } else if (UriUtils.isInstanceInternalFileUrlNew(user.baseUrl!!, uri)) { + // https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41 + val fileViewerUtils = FileViewerUtils(applicationContext, user) + fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileFileIdNew(uri)) + } else { + super.startActivity(intent) + } + } else { + super.startActivity(intent) + } + } else { + super.startActivity(intent) + } + } + companion object { private val TAG = BaseActivity::class.java.simpleName } diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt index 99fd461a8..d14f3c4d7 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt @@ -120,7 +120,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM import com.nextcloud.talk.utils.CapabilitiesUtil import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability import com.nextcloud.talk.utils.CapabilitiesUtil.isCallRecordingAvailable -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil import com.nextcloud.talk.utils.power.PowerManagerUtils import com.nextcloud.talk.utils.registerPermissionHandlerBroadcastReceiver @@ -183,10 +182,6 @@ class CallActivity : CallBaseActivity() { @Inject var ncApi: NcApi? = null - @JvmField - @Inject - var currentUserProvider: CurrentUserProviderNew? = null - @JvmField @Inject var userManager: UserManager? = null @@ -375,7 +370,7 @@ class CallActivity : CallBaseActivity() { binding = CallActivityBinding.inflate(layoutInflater) setContentView(binding!!.root) hideNavigationIfNoPipAvailable() - conversationUser = currentUserProvider!!.currentUser.blockingGet() + conversationUser = currentUserProvider.currentUser.blockingGet() val extras = intent.extras roomId = extras!!.getString(KEY_ROOM_ID, "") roomToken = extras.getString(KEY_ROOM_TOKEN, "") diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 596387c13..b2c3affea 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -195,7 +195,6 @@ import com.nextcloud.talk.utils.Mimetype import com.nextcloud.talk.utils.NotificationUtils import com.nextcloud.talk.utils.ParticipantPermissions import com.nextcloud.talk.utils.SpreedFeatures -import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.VibrationUtils import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CALL_VOICE_ONLY @@ -209,7 +208,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil import com.nextcloud.talk.utils.rx.DisposableSet import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder @@ -267,9 +265,6 @@ class ChatActivity : @Inject lateinit var ncApi: NcApi - @Inject - lateinit var currentUserProvider: CurrentUserProviderNew - @Inject lateinit var permissionUtil: PlatformPermissionUtil @@ -3300,34 +3295,6 @@ class ChatActivity : ) } - 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 (UriUtils.isInstanceInternalFileShareUrl(user.baseUrl!!, uri)) { - // https://cloud.nextcloud.com/f/41 - val fileViewerUtils = FileViewerUtils(applicationContext, user) - fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileShareFileId(uri)) - } else if (UriUtils.isInstanceInternalFileUrl(user.baseUrl!!, uri)) { - // https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41 - val fileViewerUtils = FileViewerUtils(applicationContext, user) - fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileFileId(uri)) - } else if (UriUtils.isInstanceInternalFileUrlNew(user.baseUrl!!, uri)) { - // https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41 - val fileViewerUtils = FileViewerUtils(applicationContext, user) - fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileFileIdNew(uri)) - } else { - super.startActivity(intent) - } - } else { - super.startActivity(intent) - } - } else { - super.startActivity(intent) - } - } - fun sendSelectLocalFileIntent() { if (!permissionUtil.isFilesPermissionGranted()) { requestReadFilesPermissions() diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index dc285c211..ac5ba9d58 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -76,7 +76,6 @@ import com.nextcloud.talk.utils.DateUtils import com.nextcloud.talk.utils.ShareUtils import com.nextcloud.talk.utils.SpreedFeatures import com.nextcloud.talk.utils.bundle.BundleKeys -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.preferences.preferencestorage.DatabaseStorageModule import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager @@ -103,9 +102,6 @@ class ConversationInfoActivity : @Inject lateinit var ncApi: NcApi - @Inject - lateinit var currentUserProvider: CurrentUserProviderNew - @Inject lateinit var conversationsRepository: ConversationsRepository diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index 6464c9be6..c030ea7e2 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -41,7 +41,6 @@ import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.CapabilitiesUtil import com.nextcloud.talk.utils.PickImage import com.nextcloud.talk.utils.bundle.BundleKeys -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -57,9 +56,6 @@ class ConversationInfoEditActivity : BaseActivity() { @Inject lateinit var ncApi: NcApi - @Inject - lateinit var currentUserProvider: CurrentUserProviderNew - @Inject lateinit var viewModelFactory: ViewModelProvider.Factory diff --git a/app/src/main/java/com/nextcloud/talk/diagnose/DiagnoseActivity.kt b/app/src/main/java/com/nextcloud/talk/diagnose/DiagnoseActivity.kt index 8599146c6..68e69dc65 100644 --- a/app/src/main/java/com/nextcloud/talk/diagnose/DiagnoseActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/diagnose/DiagnoseActivity.kt @@ -43,7 +43,6 @@ import com.nextcloud.talk.utils.NotificationUtils import com.nextcloud.talk.utils.PushUtils.Companion.LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY import com.nextcloud.talk.utils.PushUtils.Companion.LATEST_PUSH_REGISTRATION_AT_SERVER import com.nextcloud.talk.utils.UserIdUtils -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil import com.nextcloud.talk.utils.power.PowerManagerUtils import javax.inject.Inject @@ -62,9 +61,6 @@ class DiagnoseActivity : BaseActivity() { @Inject lateinit var userManager: UserManager - @Inject - lateinit var currentUserProvider: CurrentUserProviderNew - @Inject lateinit var platformPermissionUtil: PlatformPermissionUtil diff --git a/app/src/main/java/com/nextcloud/talk/invitation/InvitationsActivity.kt b/app/src/main/java/com/nextcloud/talk/invitation/InvitationsActivity.kt index 9fbb23786..b0ec75f28 100644 --- a/app/src/main/java/com/nextcloud/talk/invitation/InvitationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/invitation/InvitationsActivity.kt @@ -27,7 +27,6 @@ import com.nextcloud.talk.invitation.data.ActionEnum import com.nextcloud.talk.invitation.data.Invitation import com.nextcloud.talk.invitation.viewmodels.InvitationsViewModel import com.nextcloud.talk.utils.bundle.BundleKeys -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) @@ -41,9 +40,6 @@ class InvitationsActivity : BaseActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - @Inject - lateinit var userProvider: CurrentUserProviderNew - lateinit var invitationsViewModel: InvitationsViewModel lateinit var adapter: InvitationsAdapter @@ -63,7 +59,7 @@ class InvitationsActivity : BaseActivity() { invitationsViewModel = ViewModelProvider(this, viewModelFactory)[InvitationsViewModel::class.java] - currentUser = userProvider.currentUser.blockingGet() + currentUser = currentUserProvider.currentUser.blockingGet() invitationsViewModel.fetchInvitations(currentUser) binding = ActivityInvitationsBinding.inflate(layoutInflater) diff --git a/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt b/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt index 0f7e38566..f32e54193 100644 --- a/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt @@ -29,7 +29,6 @@ import com.nextcloud.talk.conversationlist.ConversationsListActivity import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ActivityMessageSearchBinding import com.nextcloud.talk.utils.bundle.BundleKeys -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.rx.SearchViewObservable.Companion.observeSearchView import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractFlexibleItem @@ -47,9 +46,6 @@ class MessageSearchActivity : BaseActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - @Inject - lateinit var userProvider: CurrentUserProviderNew - private lateinit var binding: ActivityMessageSearchBinding private lateinit var searchView: SearchView @@ -77,7 +73,7 @@ class MessageSearchActivity : BaseActivity() { setupSystemColors() viewModel = ViewModelProvider(this, viewModelFactory)[MessageSearchViewModel::class.java] - user = userProvider.currentUser.blockingGet() + user = currentUserProvider.currentUser.blockingGet() val roomToken = intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!! viewModel.initialize(roomToken) setupStateObserver() diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt index 8b1dcd432..ac57ffe55 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -23,7 +23,6 @@ import com.nextcloud.talk.openconversations.adapters.OpenConversationsAdapter import com.nextcloud.talk.openconversations.data.OpenConversation import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel import com.nextcloud.talk.utils.bundle.BundleKeys -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) @@ -37,9 +36,6 @@ class ListOpenConversationsActivity : BaseActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - @Inject - lateinit var userProvider: CurrentUserProviderNew - lateinit var openConversationsViewModel: OpenConversationsViewModel lateinit var adapter: OpenConversationsAdapter @@ -57,7 +53,7 @@ class ListOpenConversationsActivity : BaseActivity() { setContentView(binding.root) setupSystemColors() - val user = userProvider.currentUser.blockingGet() + val user = currentUserProvider.currentUser.blockingGet() adapter = OpenConversationsAdapter(user) { conversation -> adapterOnClick(conversation) } binding.openConversationsRecyclerView.adapter = adapter diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index ef65255af..e86439a59 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -75,7 +75,6 @@ import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri import com.nextcloud.talk.utils.NotificationUtils.getMessageRingtoneUri import com.nextcloud.talk.utils.SecurityUtils import com.nextcloud.talk.utils.SpreedFeatures -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil import com.nextcloud.talk.utils.power.PowerManagerUtils import com.nextcloud.talk.utils.preferences.AppPreferencesImpl @@ -107,9 +106,6 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu @Inject lateinit var userManager: UserManager - @Inject - lateinit var currentUserProvider: CurrentUserProviderNew - @Inject lateinit var platformPermissionUtil: PlatformPermissionUtil diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt b/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt index fbdb3c68f..021cb9faa 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt @@ -13,7 +13,6 @@ import android.os.Bundle import android.util.Log import android.view.MenuItem import android.view.View -import androidx.appcompat.app.AppCompatActivity import androidx.core.content.res.ResourcesCompat import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager @@ -22,31 +21,24 @@ import androidx.recyclerview.widget.RecyclerView import autodagger.AutoInjector import com.google.android.material.tabs.TabLayout import com.nextcloud.talk.R +import com.nextcloud.talk.activities.BaseActivity import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ActivitySharedItemsBinding import com.nextcloud.talk.shareditems.adapters.SharedItemsAdapter import com.nextcloud.talk.shareditems.model.SharedItemType import com.nextcloud.talk.shareditems.viewmodels.SharedItemsViewModel -import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN -import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class SharedItemsActivity : AppCompatActivity() { - - @Inject - lateinit var currentUserProvider: CurrentUserProviderNew +class SharedItemsActivity : BaseActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - @Inject - lateinit var viewThemeUtils: ViewThemeUtils - private lateinit var binding: ActivitySharedItemsBinding private lateinit var viewModel: SharedItemsViewModel diff --git a/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt index 1529ed258..afc93e995 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt @@ -22,6 +22,7 @@ class UriUtils { fun isInstanceInternalFileShareUrl(baseUrl: String, url: String): Boolean { // https://cloud.nextcloud.com/f/41 + // https://cloud.nextcloud.com/index.php/f/41 return (url.startsWith("$baseUrl/f/") || url.startsWith("$baseUrl/index.php/f/")) && Regex(".*/f/\\d*").matches(url) } From 932352b78549a5669e953993ac88edfcedd70a23 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 23 May 2024 16:01:43 +0200 Subject: [PATCH 2/2] open talk links of same baseurl inside the app Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/activities/BaseActivity.kt | 10 ++++++++++ .../main/java/com/nextcloud/talk/utils/UriUtils.kt | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt index df7235fbd..0f16bd502 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/BaseActivity.kt @@ -33,11 +33,13 @@ import com.nextcloud.talk.account.ServerSelectionActivity import com.nextcloud.talk.account.SwitchAccountActivity import com.nextcloud.talk.account.WebViewLoginActivity import com.nextcloud.talk.application.NextcloudTalkApplication +import com.nextcloud.talk.chat.ChatActivity import com.nextcloud.talk.events.CertificateEvent import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.FileViewerUtils import com.nextcloud.talk.utils.UriUtils +import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew import com.nextcloud.talk.utils.preferences.AppPreferences import com.nextcloud.talk.utils.ssl.TrustManager @@ -248,6 +250,14 @@ open class BaseActivity : AppCompatActivity() { // https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41 val fileViewerUtils = FileViewerUtils(applicationContext, user) fileViewerUtils.openFileInFilesApp(uri, UriUtils.extractInstanceInternalFileFileIdNew(uri)) + } else if (UriUtils.isInstanceInternalTalkUrl(user.baseUrl!!, uri)) { + // https://cloud.nextcloud.com/call/123456789 + val bundle = Bundle() + bundle.putString(BundleKeys.KEY_ROOM_TOKEN, UriUtils.extractRoomTokenFromTalkUrl(uri)) + val chatIntent = Intent(context, ChatActivity::class.java) + chatIntent.putExtras(bundle) + chatIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(chatIntent) } else { super.startActivity(intent) } diff --git a/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt index afc93e995..a6e57b099 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt @@ -27,11 +27,22 @@ class UriUtils { Regex(".*/f/\\d*").matches(url) } + fun isInstanceInternalTalkUrl(baseUrl: String, url: String): Boolean { + // https://cloud.nextcloud.com/call/123456789 + return (url.startsWith("$baseUrl/call/") || url.startsWith("$baseUrl/index.php/call/")) && + Regex(".*/call/\\d*").matches(url) + } + fun extractInstanceInternalFileShareFileId(url: String): String { // https://cloud.nextcloud.com/f/41 return Uri.parse(url).lastPathSegment ?: "" } + fun extractRoomTokenFromTalkUrl(url: String): String { + // https://cloud.nextcloud.com/call/123456789 + return Uri.parse(url).lastPathSegment ?: "" + } + fun isInstanceInternalFileUrl(baseUrl: String, url: String): Boolean { // https://cloud.nextcloud.com/apps/files/?dir=/Engineering&fileid=41 return (