mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 04:55:29 +03:00
Merge pull request #3923 from nextcloud/bugfix/noid/openFilesAppFromAnyActivity
open internal links for files app from any screen + open talk links inside the app
This commit is contained in:
commit
2995aa8d29
12 changed files with 64 additions and 80 deletions
|
@ -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
|
||||
|
@ -31,9 +33,14 @@ 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
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
@ -65,6 +72,9 @@ open class BaseActivity : AppCompatActivity() {
|
|||
@Inject
|
||||
lateinit var context: Context
|
||||
|
||||
@Inject
|
||||
lateinit var currentUserProvider: CurrentUserProviderNew
|
||||
|
||||
open val appBarLayoutType: AppBarLayoutType
|
||||
get() = AppBarLayoutType.TOOLBAR
|
||||
|
||||
|
@ -223,6 +233,42 @@ 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 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)
|
||||
}
|
||||
} else {
|
||||
super.startActivity(intent)
|
||||
}
|
||||
} else {
|
||||
super.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = BaseActivity::class.java.simpleName
|
||||
}
|
||||
|
|
|
@ -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, "")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -22,15 +22,27 @@ 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)
|
||||
}
|
||||
|
||||
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 (
|
||||
|
|
Loading…
Reference in a new issue