From 42e6d9b52fa0862d2f1c35646c3235cd0dd0bc80 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 13 Oct 2022 13:26:31 +0200 Subject: [PATCH] extract methods from fetchRooms method reduce complexity for codacy score.. Signed-off-by: Marcel Hibbe --- .../ConversationsListController.kt | 96 ++++++++++--------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt index 8e6a0e464..680ca6f93 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt @@ -523,51 +523,9 @@ class ConversationsListController(bundle: Bundle) : adapterWasNull = false binding.loadingContent.visibility = View.GONE } - if (ocs!!.data!!.isNotEmpty()) { - if (binding.emptyLayout.visibility != View.GONE) { - binding.emptyLayout.visibility = View.GONE - } - if (binding.swipeRefreshLayoutView.visibility != View.VISIBLE) { - binding.swipeRefreshLayoutView.visibility = View.VISIBLE - } - } else { - if (binding.emptyLayout.visibility != View.VISIBLE) { - binding.emptyLayout.visibility = View.VISIBLE - } - if (binding.swipeRefreshLayoutView.visibility != View.GONE) { - binding.swipeRefreshLayoutView.visibility = View.GONE - } - } + initOverallLayout(ocs!!.data!!.isNotEmpty()) for (conversation in ocs.data!!) { - if (bundle.containsKey(KEY_FORWARD_HIDE_SOURCE_ROOM) && conversation.roomId == bundle.getString( - KEY_FORWARD_HIDE_SOURCE_ROOM - ) - ) { - continue - } - val headerTitle: String = resources!!.getString(R.string.conversations) - var genericTextHeaderItem: GenericTextHeaderItem - if (!callHeaderItems.containsKey(headerTitle)) { - genericTextHeaderItem = GenericTextHeaderItem(headerTitle, viewThemeUtils) - callHeaderItems[headerTitle] = genericTextHeaderItem - } - if (activity != null) { - val conversationItem = ConversationItem( - conversation, - currentUser, - activity, - viewThemeUtils - ) - conversationItems.add(conversationItem) - val conversationItemWithHeader = ConversationItem( - conversation, - currentUser, - activity, - callHeaderItems[headerTitle], - viewThemeUtils - ) - conversationItemsWithHeader.add(conversationItemWithHeader) - } + addToConversationItems(conversation) } sortConversations(conversationItems) sortConversations(conversationItemsWithHeader) @@ -593,6 +551,56 @@ class ConversationsListController(bundle: Bundle) : } } + private fun initOverallLayout(isConversationListNotEmpty: Boolean) { + if (isConversationListNotEmpty) { + if (binding.emptyLayout.visibility != View.GONE) { + binding.emptyLayout.visibility = View.GONE + } + if (binding.swipeRefreshLayoutView.visibility != View.VISIBLE) { + binding.swipeRefreshLayoutView.visibility = View.VISIBLE + } + } else { + if (binding.emptyLayout.visibility != View.VISIBLE) { + binding.emptyLayout.visibility = View.VISIBLE + } + if (binding.swipeRefreshLayoutView.visibility != View.GONE) { + binding.swipeRefreshLayoutView.visibility = View.GONE + } + } + } + + private fun addToConversationItems(conversation: Conversation) { + if (bundle.containsKey(KEY_FORWARD_HIDE_SOURCE_ROOM) && conversation.roomId == bundle.getString( + KEY_FORWARD_HIDE_SOURCE_ROOM + ) + ) { + return + } + val headerTitle: String = resources!!.getString(R.string.conversations) + val genericTextHeaderItem: GenericTextHeaderItem + if (!callHeaderItems.containsKey(headerTitle)) { + genericTextHeaderItem = GenericTextHeaderItem(headerTitle, viewThemeUtils) + callHeaderItems[headerTitle] = genericTextHeaderItem + } + if (activity != null) { + val conversationItem = ConversationItem( + conversation, + currentUser, + activity, + viewThemeUtils + ) + conversationItems.add(conversationItem) + val conversationItemWithHeader = ConversationItem( + conversation, + currentUser, + activity, + callHeaderItems[headerTitle], + viewThemeUtils + ) + conversationItemsWithHeader.add(conversationItemWithHeader) + } + } + private fun showErrorDialog() { val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton.context) .setIcon(