remove try-catch for NPEs for bindings

since null checks are done for the nullable bindings by PR #2694, the try-catch blocks arent necessary anymore.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-01-17 08:37:42 +01:00
parent 30879dfd49
commit 1d9868daa6
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
6 changed files with 179 additions and 271 deletions

View File

@ -367,7 +367,6 @@ class ChatController(args: Bundle) :
setTitle()
participantPermissions = ParticipantPermissions(conversationUser, currentConversation!!)
try {
setupSwipeToReply()
setupMentionAutocomplete()
checkShowCallButtons()
@ -379,11 +378,6 @@ class ChatController(args: Bundle) :
} else {
Log.d(TAG, "already inConversation. joinRoomWithPassword is skipped")
}
} 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")
}
}
override fun onError(e: Throwable) {
@ -714,7 +708,6 @@ class ChatController(args: Bundle) :
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
try {
if (s.length >= lengthFilter) {
binding?.messageInputView?.inputEditText?.error = String.format(
Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit),
@ -747,11 +740,6 @@ class ChatController(args: Bundle) :
}
}
}
} 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")
}
}
override fun afterTextChanged(s: Editable) {
@ -768,17 +756,11 @@ class ChatController(args: Bundle) :
showMicrophoneButton(true)
binding?.messageInputView?.messageInput?.doAfterTextChanged {
try {
if (binding?.messageInputView?.messageInput?.text?.isEmpty() == true) {
showMicrophoneButton(true)
} else {
showMicrophoneButton(false)
}
} 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")
}
}
var sliderInitX = 0F
@ -1771,13 +1753,7 @@ class ChatController(args: Bundle) :
)
},
onEmojiClickListener = {
try {
binding?.messageInputView?.inputEditText?.editableText?.append(" ")
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchronously and UI might have been destroyed in the meantime
Log.i(WebViewLoginController.TAG, "UI destroyed - view binding already gone")
}
}
)
}
@ -1937,13 +1913,7 @@ class ChatController(args: Bundle) :
setupWebsocket()
try {
checkLobbyState()
} 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")
}
if (isFirstMessagesProcessing) {
pullChatMessages(0)
@ -2123,17 +2093,10 @@ class ChatController(args: Bundle) :
override fun onNext(genericOverall: GenericOverall) {
myFirstMessage = message
try {
if (binding?.popupBubbleView?.isShown == true) {
binding?.popupBubbleView?.hide()
}
binding?.messagesListView?.smoothScrollToPosition(0)
} 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")
}
}
override fun onError(e: Throwable) {
@ -2246,7 +2209,6 @@ class ChatController(args: Bundle) :
override fun onNext(response: Response<*>) {
Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - got response")
pullChatMessagesPending = false
try {
if (response.code() == HTTP_CODE_NOT_MODIFIED) {
Log.d(TAG, "pullChatMessages - quasi recursive call to pullChatMessages")
pullChatMessages(1, setReadMarker, xChatLastCommonRead)
@ -2255,11 +2217,6 @@ class ChatController(args: Bundle) :
} else {
processMessagesResponse(response, 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")
}
processExpiredMessages()
}
@ -2291,17 +2248,11 @@ class ChatController(args: Bundle) :
override fun onNext(response: Response<*>) {
Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - got response")
pullChatMessagesPending = false
try {
if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
pastPreconditionFailed = true
} else {
processMessagesResponse(response, false)
}
} catch (e: 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", e)
}
processExpiredMessages()
}

View File

@ -493,13 +493,7 @@ class ConversationInfoController(args: Bundle) :
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(participantsOverall: ParticipantsOverall) {
try {
handleParticipants(participantsOverall.ocs!!.data!!)
} 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")
}
}
override fun onError(e: Throwable) {
@ -646,7 +640,6 @@ class ConversationInfoController(args: Bundle) :
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(roomOverall: RoomOverall) {
try {
conversation = roomOverall.ocs!!.data
val conversationCopy = conversation
@ -719,11 +712,6 @@ class ConversationInfoController(args: Bundle) :
binding?.notificationSettingsView?.notificationSettings?.visibility = VISIBLE
}
} 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")
}
}
override fun onError(e: Throwable) {

View File

@ -355,7 +355,6 @@ class ProfileController : BaseController(R.layout.controller_profile) {
return
}
try {
binding?.emptyList?.emptyListViewHeadline?.text = headline
binding?.emptyList?.emptyListViewText?.text = message
binding?.emptyList?.emptyListIcon?.setImageResource(errorResource)
@ -363,11 +362,6 @@ class ProfileController : BaseController(R.layout.controller_profile) {
binding?.emptyList?.emptyListViewText?.visibility = View.VISIBLE
binding?.userinfoList?.visibility = View.GONE
binding?.loadingContent?.visibility = View.GONE
} 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")
}
}
@Suppress("Detekt.LongMethod")

View File

@ -29,7 +29,6 @@ import android.net.Uri
import android.os.Bundle
import android.security.KeyChain
import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
@ -199,7 +198,6 @@ class ServerSelectionController :
@Suppress("Detekt.TooGenericExceptionCaught")
private fun checkServerAndProceed() {
dispose()
try {
var url: String = binding?.serverEntryTextInputEditText?.text.toString().trim { it <= ' ' }
binding?.serverEntryTextInputEditText?.isEnabled = false
showserverEntryProgressBar()
@ -216,11 +214,6 @@ class ServerSelectionController :
} 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")
}
}
private fun checkServer(queryUrl: String, checkForcedHttps: Boolean) {
@ -357,18 +350,12 @@ class ServerSelectionController :
private fun setCertTextView() {
if (activity != null) {
activity!!.runOnUiThread {
try {
if (!TextUtils.isEmpty(appPreferences!!.temporaryClientCertAlias)) {
binding?.certTextView?.setText(R.string.nc_change_cert_auth)
} else {
binding?.certTextView?.setText(R.string.nc_configure_cert_auth)
}
hideserverEntryProgressBar()
} catch (npe: java.lang.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")
}
}
}
}

View File

@ -848,7 +848,6 @@ class SettingsController : BaseController(R.layout.controller_settings) {
private inner class ProxyTypeChangeListener : OnPreferenceValueChangedListener<String> {
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onChanged(newValue: String) {
try {
if (("No proxy" == newValue)) {
hideProxySettings()
} else {
@ -864,11 +863,6 @@ class SettingsController : BaseController(R.layout.controller_settings) {
}
showProxySettings()
}
} 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")
}
}
}

View File

@ -178,7 +178,6 @@ class WebViewLoginController(args: Bundle? = null) : BaseController(
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onPageFinished(view: WebView, url: String) {
try {
loginStep++
if (!basePageLoaded) {
binding?.progressBar?.visibility = View.GONE
@ -207,11 +206,6 @@ class WebViewLoginController(args: Bundle? = null) : BaseController(
}
}
}
} 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")
}
super.onPageFinished(view, url)
}