diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt index b55017140..3c1d70d53 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt @@ -53,6 +53,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.preferences.AppPreferences import com.stfalcon.chatkit.messages.MessageHolders import java.net.URLEncoder @@ -218,7 +219,7 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) : Mess binding.webview.webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { - return if (url != null && (url.startsWith("http://") || url.startsWith("https://")) + return if (url != null && UriUtils.hasHttpProtocollPrefixed(url) ) { view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) true diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt index 6ef0c283b..3a0fe3a6a 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt @@ -47,6 +47,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.models.json.chat.ReadStatus import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.UriUtils import com.stfalcon.chatkit.messages.MessageHolders import java.net.URLEncoder import javax.inject.Inject @@ -131,7 +132,7 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders binding.webview.webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { - return if (url != null && (url.startsWith("http://") || url.startsWith("https://")) + return if (url != null && UriUtils.hasHttpProtocollPrefixed(url) ) { view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) true diff --git a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt index 2f5b050f9..97241d178 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt @@ -48,6 +48,7 @@ import com.nextcloud.talk.models.json.generic.Status import com.nextcloud.talk.models.json.userprofile.UserProfileOverall import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ClosedInterfaceImpl +import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BASE_URL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_ACCOUNT_IMPORT @@ -113,8 +114,7 @@ class AccountVerificationController(args: Bundle? = null) : actionBar?.hide() if (isAccountImport && - !baseUrl!!.startsWith("http://") && - !baseUrl!!.startsWith("https://") || + !UriUtils.hasHttpProtocollPrefixed(baseUrl!!) || !TextUtils.isEmpty(originalProtocol!!) && !baseUrl!!.startsWith(originalProtocol!!) ) { diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt index bd5d228a1..7b5fa77c4 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.kt @@ -48,6 +48,7 @@ import com.nextcloud.talk.utils.AccountUtils.findAccounts import com.nextcloud.talk.utils.AccountUtils.getAppNameBasedOnPackage import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils +import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_ACCOUNT_IMPORT import com.nextcloud.talk.utils.database.user.UserUtils import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder @@ -197,7 +198,7 @@ class ServerSelectionController : NewBaseController(R.layout.controller_server_s url = url.substring(0, url.length - 1) } val queryUrl = url + ApiUtils.getUrlPostfixForStatus() - if (url.startsWith("http://") || url.startsWith("https://")) { + if (UriUtils.hasHttpProtocollPrefixed(url)) { checkServer(queryUrl, false) } else { checkServer("https://$queryUrl", true) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.kt b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.kt index e37718594..319033fa1 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.kt @@ -46,6 +46,7 @@ import com.nextcloud.talk.controllers.util.viewBinding import com.nextcloud.talk.databinding.ControllerEntryMenuBinding import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.utils.ShareUtils +import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.database.user.UserUtils import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder @@ -117,9 +118,11 @@ class EntryMenuController(args: Bundle) : override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { // unused atm } + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { // unused atm } + override fun afterTextChanged(s: Editable) { if (!TextUtils.isEmpty(s)) { if (operation === ConversationOperationEnum.OPS_CODE_RENAME_ROOM) { @@ -143,10 +146,7 @@ class EntryMenuController(args: Bundle) : } binding.textInputLayout.isErrorEnabled = false } else if ( - ( - binding.textEdit.text.toString().startsWith("http://") || - binding.textEdit.text.toString().startsWith("https://") - ) && + UriUtils.hasHttpProtocollPrefixed(binding.textEdit.text.toString()) && binding.textEdit.text.toString().contains("/call/") ) { if (!binding.okButton.isEnabled) { diff --git a/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt index 947844e90..34c66d86c 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/AccountUtils.kt @@ -55,10 +55,7 @@ object AccountUtils { internalUserEntity = userEntitiesList[i] importAccount = getInformationFromAccount(account) if (importAccount.token != null) { - if ( - importAccount.baseUrl.startsWith("http://") || - importAccount.baseUrl.startsWith("https://") - ) { + if (UriUtils.hasHttpProtocollPrefixed(importAccount.baseUrl)) { if ( internalUserEntity.username == importAccount.username && internalUserEntity.baseUrl == importAccount.baseUrl 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 1397e7714..d668c8521 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/UriUtils.kt @@ -24,6 +24,7 @@ import android.content.Context import android.database.Cursor import android.net.Uri import android.provider.OpenableColumns +import android.text.TextUtils import android.util.Log class UriUtils { @@ -50,5 +51,9 @@ class UriUtils { } return filename } + + fun hasHttpProtocollPrefixed(uri: String): Boolean { + return uri.startsWith("http://") || uri.startsWith("https://") + } } }