Catch NPE on ServerSelection view binding

Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
Tim Krüger 2022-05-03 12:16:34 +02:00 committed by Marcel Hibbe
parent b60de3858b
commit 8e981f04b0
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -21,12 +21,14 @@
*/ */
package com.nextcloud.talk.controllers package com.nextcloud.talk.controllers
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.security.KeyChain import android.security.KeyChain
import android.text.TextUtils import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
@ -188,23 +190,30 @@ class ServerSelectionController :
binding.certTextView.setOnClickListener { onCertClick() } binding.certTextView.setOnClickListener { onCertClick() }
} }
@SuppressLint("LongLogTag")
private fun checkServerAndProceed() { private fun checkServerAndProceed() {
dispose() dispose()
var url: String = binding.serverEntryTextInputEditText.text.toString().trim { it <= ' ' } try {
binding.serverEntryTextInputEditText.isEnabled = false var url: String = binding.serverEntryTextInputEditText.text.toString().trim { it <= ' ' }
showserverEntryProgressBar() binding.serverEntryTextInputEditText.isEnabled = false
if (binding.helperTextView.visibility != View.INVISIBLE) { showserverEntryProgressBar()
binding.helperTextView.visibility = View.INVISIBLE if (binding.helperTextView.visibility != View.INVISIBLE) {
binding.certTextView.visibility = View.INVISIBLE binding.helperTextView.visibility = View.INVISIBLE
} binding.certTextView.visibility = View.INVISIBLE
if (url.endsWith("/")) { }
url = url.substring(0, url.length - 1) if (url.endsWith("/")) {
} url = url.substring(0, url.length - 1)
val queryUrl = url + ApiUtils.getUrlPostfixForStatus() }
if (UriUtils.hasHttpProtocollPrefixed(url)) { val queryUrl = url + ApiUtils.getUrlPostfixForStatus()
checkServer(queryUrl, false) if (UriUtils.hasHttpProtocollPrefixed(url)) {
} else { checkServer(queryUrl, false)
checkServer("https://$queryUrl", true) } else {
checkServer("https://$queryUrl", true)
}
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchronously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
} }
} }