simplify complex conditions for readability

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-03-11 15:18:12 +01:00
parent 454dbc5db2
commit 6206e4910d
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
5 changed files with 44 additions and 22 deletions

View File

@ -113,10 +113,10 @@ class AccountVerificationController(args: Bundle? = null) :
actionBar?.hide() actionBar?.hide()
if (isAccountImport && if (
isAccountImport &&
!UriUtils.hasHttpProtocollPrefixed(baseUrl!!) || !UriUtils.hasHttpProtocollPrefixed(baseUrl!!) ||
!TextUtils.isEmpty(originalProtocol!!) && isSameProtocol(baseUrl!!, originalProtocol!!)
!baseUrl!!.startsWith(originalProtocol!!)
) { ) {
determineBaseUrlProtocol(true) determineBaseUrlProtocol(true)
} else { } else {
@ -124,6 +124,10 @@ class AccountVerificationController(args: Bundle? = null) :
} }
} }
private fun isSameProtocol(baseUrl: String, originalProtocol: String ) : Boolean {
return !TextUtils.isEmpty(originalProtocol) && !baseUrl.startsWith(originalProtocol)
}
private fun checkEverything() { private fun checkEverything() {
val credentials = ApiUtils.getCredentials(username, token) val credentials = ApiUtils.getCredentials(username, token)
cookieManager.cookieStore.removeAll() cookieManager.cookieStore.removeAll()

View File

@ -1605,12 +1605,7 @@ class ChatController(args: Bundle) :
activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener(null) activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener(null)
} }
if (conversationUser != null && if (conversationUser != null && isActivityNotChangingConfigurations() && isNotInCall()) {
activity != null &&
!activity?.isChangingConfigurations!! &&
!ApplicationWideCurrentRoomHolder.getInstance().isInCall &&
!ApplicationWideCurrentRoomHolder.getInstance().isDialing
) {
ApplicationWideCurrentRoomHolder.getInstance().clear() ApplicationWideCurrentRoomHolder.getInstance().clear()
if (inConversation && validSessionId()) { if (inConversation && validSessionId()) {
leaveRoom() leaveRoom()
@ -1622,6 +1617,15 @@ class ChatController(args: Bundle) :
} }
} }
private fun isActivityNotChangingConfigurations(): Boolean {
return activity != null && !activity?.isChangingConfigurations!!
}
private fun isNotInCall(): Boolean {
return !ApplicationWideCurrentRoomHolder.getInstance().isInCall &&
!ApplicationWideCurrentRoomHolder.getInstance().isDialing
}
override val title: String override val title: String
get() = get() =
if (currentConversation?.displayName != null) { if (currentConversation?.displayName != null) {
@ -2118,11 +2122,9 @@ class ChatController(args: Bundle) :
for (i in chatMessageList.indices) { for (i in chatMessageList.indices) {
if (chatMessageList.size > i + 1) { if (chatMessageList.size > i + 1) {
if (TextUtils.isEmpty(chatMessageList[i].systemMessage) && if (isSameDayNonSystemMessages(chatMessageList[i], chatMessageList[i + 1]) &&
TextUtils.isEmpty(chatMessageList[i + 1].systemMessage) &&
chatMessageList[i + 1].actorId == chatMessageList[i].actorId && chatMessageList[i + 1].actorId == chatMessageList[i].actorId &&
countGroupedMessages < 4 && countGroupedMessages < 4
DateFormatter.isSameDay(chatMessageList[i].createdAt, chatMessageList[i + 1].createdAt)
) { ) {
chatMessageList[i].isGrouped = true chatMessageList[i].isGrouped = true
countGroupedMessages++ countGroupedMessages++
@ -2254,6 +2256,12 @@ class ChatController(args: Bundle) :
} }
} }
private fun isSameDayNonSystemMessages(messageLeft: ChatMessage, messageRight: ChatMessage): Boolean {
return TextUtils.isEmpty(messageLeft.systemMessage) &&
TextUtils.isEmpty(messageRight.systemMessage) &&
DateFormatter.isSameDay(messageLeft.createdAt,messageRight.createdAt)
}
override fun onLoadMore(page: Int, totalItemsCount: Int) { override fun onLoadMore(page: Int, totalItemsCount: Int) {
if (!historyRead && inConversation) { if (!historyRead && inConversation) {
pullChatMessages(0) pullChatMessages(0)

View File

@ -213,9 +213,7 @@ class ServerSelectionController : NewBaseController(R.layout.controller_server_s
val productName = resources!!.getString(R.string.nc_server_product_name) val productName = resources!!.getString(R.string.nc_server_product_name)
val versionString: String = status.getVersion().substring(0, status.getVersion().indexOf(".")) val versionString: String = status.getVersion().substring(0, status.getVersion().indexOf("."))
val version: Int = versionString.toInt() val version: Int = versionString.toInt()
if (status.isInstalled && !status.isMaintenance && if (isServerStatusQueryable(status) && version >= 13) {
!status.isNeedsUpgrade && version >= 13
) {
router.pushController( router.pushController(
RouterTransaction.with( RouterTransaction.with(
WebViewLoginController( WebViewLoginController(
@ -285,6 +283,10 @@ class ServerSelectionController : NewBaseController(R.layout.controller_server_s
} }
} }
private fun isServerStatusQueryable(status: Status): Boolean {
return status.isInstalled && !status.isMaintenance && !status.isNeedsUpgrade
}
private fun setErrorText(text: String) { private fun setErrorText(text: String) {
binding.errorText.text = text binding.errorText.text = text
binding.errorText.visibility = View.VISIBLE binding.errorText.visibility = View.VISIBLE

View File

@ -51,6 +51,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.database.user.UserUtils import com.nextcloud.talk.utils.database.user.UserUtils
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder
import com.vanniktech.emoji.EmojiPopup import com.vanniktech.emoji.EmojiPopup
import okhttp3.internal.immutableListOf
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.parceler.Parcels import org.parceler.Parcels
import org.parceler.Parcels.unwrap import org.parceler.Parcels.unwrap
@ -215,15 +216,12 @@ class EntryMenuController(args: Bundle) :
else -> { else -> {
} }
} }
if (operation === ConversationOperationEnum.OPS_CODE_JOIN_ROOM || if (PASSWORD_ENTRY_OPERATIONS.contains(operation)) {
operation === ConversationOperationEnum.OPS_CODE_CHANGE_PASSWORD ||
operation === ConversationOperationEnum.OPS_CODE_SET_PASSWORD ||
operation === ConversationOperationEnum.OPS_CODE_SHARE_LINK
) {
binding.textInputLayout.endIconMode = TextInputLayout.END_ICON_PASSWORD_TOGGLE binding.textInputLayout.endIconMode = TextInputLayout.END_ICON_PASSWORD_TOGGLE
} else { } else {
binding.textInputLayout.endIconMode = TextInputLayout.END_ICON_NONE binding.textInputLayout.endIconMode = TextInputLayout.END_ICON_NONE
} }
binding.textInputLayout.hint = labelText binding.textInputLayout.hint = labelText
binding.textInputLayout.requestFocus() binding.textInputLayout.requestFocus()
@ -327,4 +325,14 @@ class EntryMenuController(args: Bundle) :
packageName = args.getString(BundleKeys.KEY_APP_ITEM_PACKAGE_NAME, "") packageName = args.getString(BundleKeys.KEY_APP_ITEM_PACKAGE_NAME, "")
callUrl = args.getString(BundleKeys.KEY_CALL_URL, "") callUrl = args.getString(BundleKeys.KEY_CALL_URL, "")
} }
companion object {
private val PASSWORD_ENTRY_OPERATIONS: List<ConversationOperationEnum> =
immutableListOf(
ConversationOperationEnum.OPS_CODE_JOIN_ROOM,
ConversationOperationEnum.OPS_CODE_CHANGE_PASSWORD,
ConversationOperationEnum.OPS_CODE_SET_PASSWORD,
ConversationOperationEnum.OPS_CODE_SHARE_LINK
)
}
} }

View File

@ -1,5 +1,5 @@
build: build:
maxIssues: 157 maxIssues: 151
weights: weights:
# complexity: 2 # complexity: 2
# LongParameterList: 1 # LongParameterList: 1