From 5fd8541ddc6a9ac145911f9930030e60c9253291 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 27 Nov 2024 18:18:18 +0100 Subject: [PATCH 1/8] Use correct model Signed-off-by: sowjanyakch --- .../data/OpenConversationsRepository.kt | 3 ++- .../data/OpenConversationsRepositoryImpl.kt | 18 +++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt index f096ea46c0..4e9fb7a157 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepository.kt @@ -6,9 +6,10 @@ */ package com.nextcloud.talk.openconversations.data +import com.nextcloud.talk.models.json.conversations.Conversation import io.reactivex.Observable interface OpenConversationsRepository { - fun fetchConversations(): Observable + fun fetchConversations(): Observable> } diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt index 5edbf922d6..3dbaf4dbb2 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsRepositoryImpl.kt @@ -21,23 +21,11 @@ class OpenConversationsRepositoryImpl(private val ncApi: NcApi, currentUserProvi val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)) - override fun fetchConversations(): Observable { - return ncApi.getOpenConversations( + override fun fetchConversations(): Observable> { + val roomOverall = ncApi.getOpenConversations( credentials, ApiUtils.getUrlForOpenConversations(apiVersion, currentUser.baseUrl!!) - ).map { mapToOpenConversationsModel(it.ocs?.data!!) } - } - - private fun mapToOpenConversationsModel(conversations: List): OpenConversationsModel { - return OpenConversationsModel( - conversations.map { conversation -> - OpenConversation( - // conversation.roomId!!, - conversation.token!!, - conversation.name!!, - conversation.description ?: "" - ) - } ) + return roomOverall.map { it.ocs?.data!! } } } From b769a024c4a9ec47345605d931878af21716ee7c Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 27 Nov 2024 18:23:14 +0100 Subject: [PATCH 2/8] Modify ViewModel Signed-off-by: sowjanyakch --- .../viewmodels/OpenConversationsViewModel.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt b/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt index cf75dafb2e..cfe387a261 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/viewmodels/OpenConversationsViewModel.kt @@ -10,8 +10,7 @@ import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.nextcloud.talk.openconversations.data.OpenConversation -import com.nextcloud.talk.openconversations.data.OpenConversationsModel +import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.openconversations.data.OpenConversationsRepository import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers @@ -27,7 +26,7 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope object FetchConversationsStartState : ViewState object FetchConversationsEmptyState : ViewState object FetchConversationsErrorState : ViewState - open class FetchConversationsSuccessState(val conversations: List) : ViewState + open class FetchConversationsSuccessState(val conversations: List) : ViewState private val _viewState: MutableLiveData = MutableLiveData(FetchConversationsStartState) val viewState: LiveData @@ -41,16 +40,16 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope ?.subscribe(FetchConversationsObserver()) } - inner class FetchConversationsObserver : Observer { + inner class FetchConversationsObserver : Observer> { override fun onSubscribe(d: Disposable) { // unused atm } - override fun onNext(model: OpenConversationsModel) { - if (model.conversations.isEmpty()) { + override fun onNext(conversations: List) { + if (conversations.isEmpty()) { _viewState.value = FetchConversationsEmptyState } else { - _viewState.value = FetchConversationsSuccessState(model.conversations) + _viewState.value = FetchConversationsSuccessState(conversations) } } From 5b8b3bb0277c89a54310d1cb1cc449b2518a5d70 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 27 Nov 2024 18:31:14 +0100 Subject: [PATCH 3/8] Modify Adapter and ListOpenConversationsActivity Signed-off-by: sowjanyakch --- .../ListOpenConversationsActivity.kt | 13 +++-- .../adapters/OpenConversationsAdapter.kt | 47 +++++++++++-------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt index 9918fc1539..c074032056 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -21,15 +21,15 @@ import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.chat.ChatActivity import com.nextcloud.talk.databinding.ActivityOpenConversationsBinding +import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.openconversations.adapters.OpenConversationsAdapter -import com.nextcloud.talk.openconversations.data.OpenConversation import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel import com.nextcloud.talk.utils.bundle.BundleKeys import com.vanniktech.ui.showKeyboardAndFocus import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class ListOpenConversationsActivity : BaseActivity() { +class ListOpenConversationsActivity : BaseActivity() { private lateinit var binding: ActivityOpenConversationsBinding @@ -62,7 +62,7 @@ class ListOpenConversationsActivity : BaseActivity() { val user = currentUserProvider.currentUser.blockingGet() - adapter = OpenConversationsAdapter(user) { conversation -> adapterOnClick(conversation) } + adapter = OpenConversationsAdapter(user, viewThemeUtils) { conversation -> adapterOnClick(conversation) } binding.openConversationsRecyclerView.adapter = adapter binding.searchOpenConversations.setOnClickListener { searching = !searching @@ -86,9 +86,9 @@ class ListOpenConversationsActivity : BaseActivity() { } } - private fun adapterOnClick(conversation: OpenConversation) { + private fun adapterOnClick(conversation: Conversation) { val bundle = Bundle() - bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.roomToken) + bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.token) val chatIntent = Intent(context, ChatActivity::class.java) chatIntent.putExtras(bundle) @@ -143,3 +143,6 @@ class ListOpenConversationsActivity : BaseActivity() { viewThemeUtils.material.themeToolbar(binding.openConversationsToolbar) } } + + + diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt index b8a9e2d0f3..8268349d2e 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt @@ -13,21 +13,24 @@ import android.widget.RelativeLayout import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import com.nextcloud.talk.R import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.RvItemOpenConversationBinding -import com.nextcloud.talk.extensions.loadUserAvatar -import com.nextcloud.talk.openconversations.data.OpenConversation - -class OpenConversationsAdapter(val user: User, private val onClick: (OpenConversation) -> Unit) : - ListAdapter(ConversationsCallback) { - private var originalList: List = emptyList() +import com.nextcloud.talk.extensions.loadConversationAvatar +import com.nextcloud.talk.models.domain.ConversationModel +import com.nextcloud.talk.models.json.conversations.Conversation +import com.nextcloud.talk.ui.theme.ViewThemeUtils + +class OpenConversationsAdapter(val user: User, + val viewThemeUtils: ViewThemeUtils, + private val onClick: (Conversation) -> Unit) : + ListAdapter(ConversationsCallback) { + private var originalList: List = emptyList() private var isFiltering = false inner class OpenConversationsViewHolder(val itemBinding: RvItemOpenConversationBinding) : RecyclerView.ViewHolder(itemBinding.root) { - var currentConversation: OpenConversation? = null + var currentConversation: Conversation? = null init { itemBinding.root.setOnClickListener { @@ -37,11 +40,11 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers } } - fun bindItem(conversation: OpenConversation) { + fun bindItem(conversation: Conversation) { val nameTextLayoutParams: RelativeLayout.LayoutParams = itemBinding.nameText.layoutParams as RelativeLayout.LayoutParams - currentConversation = conversation + val currentConversationModel = ConversationModel.mapToConversationModel(conversation, user) itemBinding.nameText.text = conversation.displayName if (conversation.description == "") { itemBinding.descriptionText.visibility = View.GONE @@ -50,9 +53,15 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers itemBinding.descriptionText.text = conversation.description } + // load avatar from server when https://github.com/nextcloud/spreed/issues/9600 is solved - // itemBinding.avatarView.loadUserAvatar(user, conversation.displayName, true, false) - itemBinding.avatarView.loadUserAvatar(R.drawable.ic_circular_group) + itemBinding.avatarView.loadConversationAvatar( + user, + currentConversationModel, + false, + viewThemeUtils + ) + //itemBinding.avatarView.loadUserAvatar(R.drawable.ic_circular_group) } } @@ -79,7 +88,7 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers } isFiltering = true - val newList = mutableListOf() + val newList = mutableListOf() for (conversation in originalList) { if (conversation.displayName.contains(text, true) || conversation.description!!.contains(text, true)) { newList.add(conversation) @@ -92,8 +101,8 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers } override fun onCurrentListChanged( - previousList: MutableList, - currentList: MutableList + previousList: MutableList, + currentList: MutableList ) { if (!isFiltering) { originalList = currentList @@ -102,12 +111,12 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers } } -object ConversationsCallback : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: OpenConversation, newItem: OpenConversation): Boolean { +object ConversationsCallback : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Conversation, newItem: Conversation): Boolean { return oldItem == newItem } - override fun areContentsTheSame(oldItem: OpenConversation, newItem: OpenConversation): Boolean { - return oldItem.roomToken == newItem.roomToken + override fun areContentsTheSame(oldItem: Conversation, newItem: Conversation): Boolean { + return oldItem.token == newItem.token } } From 0111e0f7119b5620552717c1dfb4888b44556196 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 27 Nov 2024 18:34:25 +0100 Subject: [PATCH 4/8] ktlintFormat Signed-off-by: sowjanyakch --- .../ListOpenConversationsActivity.kt | 5 +---- .../adapters/OpenConversationsAdapter.kt | 14 ++++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt index c074032056..949c5ee980 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -29,7 +29,7 @@ import com.vanniktech.ui.showKeyboardAndFocus import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class ListOpenConversationsActivity : BaseActivity() { +class ListOpenConversationsActivity : BaseActivity() { private lateinit var binding: ActivityOpenConversationsBinding @@ -143,6 +143,3 @@ class ListOpenConversationsActivity : BaseActivity() { viewThemeUtils.material.themeToolbar(binding.openConversationsToolbar) } } - - - diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt index 8268349d2e..4489838f82 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt @@ -20,9 +20,11 @@ import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.ui.theme.ViewThemeUtils -class OpenConversationsAdapter(val user: User, +class OpenConversationsAdapter( + val user: User, val viewThemeUtils: ViewThemeUtils, - private val onClick: (Conversation) -> Unit) : + private val onClick: (Conversation) -> Unit +) : ListAdapter(ConversationsCallback) { private var originalList: List = emptyList() private var isFiltering = false @@ -53,7 +55,6 @@ class OpenConversationsAdapter(val user: User, itemBinding.descriptionText.text = conversation.description } - // load avatar from server when https://github.com/nextcloud/spreed/issues/9600 is solved itemBinding.avatarView.loadConversationAvatar( user, @@ -61,7 +62,7 @@ class OpenConversationsAdapter(val user: User, false, viewThemeUtils ) - //itemBinding.avatarView.loadUserAvatar(R.drawable.ic_circular_group) + // itemBinding.avatarView.loadUserAvatar(R.drawable.ic_circular_group) } } @@ -100,10 +101,7 @@ class OpenConversationsAdapter(val user: User, } } - override fun onCurrentListChanged( - previousList: MutableList, - currentList: MutableList - ) { + override fun onCurrentListChanged(previousList: MutableList, currentList: MutableList) { if (!isFiltering) { originalList = currentList } From 3216318ccd22129967bf3ed78639cd9f7a95fde8 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 27 Nov 2024 18:38:57 +0100 Subject: [PATCH 5/8] suppress lint warning for invalid string format Signed-off-by: sowjanyakch --- .../talk/adapters/messages/IncomingDeckCardViewHolder.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt index b16eb217a5..dbadc85d42 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingDeckCardViewHolder.kt @@ -118,6 +118,7 @@ class IncomingDeckCardViewHolder(incomingView: View, payload: Any) : MessageHold ) } + @SuppressLint("StringFormatInvalid") private fun showDeckCard(message: ChatMessage) { if (message.messageParameters != null && message.messageParameters!!.size > 0) { for (key in message.messageParameters!!.keys) { From 1d9f6e0e4143f6ed4fc39ae96fab3a8997f1228a Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Wed, 27 Nov 2024 18:48:01 +0100 Subject: [PATCH 6/8] refactor code - remove comments Signed-off-by: sowjanyakch --- .../talk/openconversations/adapters/OpenConversationsAdapter.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt index 4489838f82..89da0c0027 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/adapters/OpenConversationsAdapter.kt @@ -55,14 +55,12 @@ class OpenConversationsAdapter( itemBinding.descriptionText.text = conversation.description } - // load avatar from server when https://github.com/nextcloud/spreed/issues/9600 is solved itemBinding.avatarView.loadConversationAvatar( user, currentConversationModel, false, viewThemeUtils ) - // itemBinding.avatarView.loadUserAvatar(R.drawable.ic_circular_group) } } From 32713ed2657a5b9c7012e5d21badacdab8607bc1 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 3 Dec 2024 12:17:28 +0000 Subject: [PATCH 7/8] Analysis: update lint results to reflect reduced error/warning count Signed-off-by: github-actions --- scripts/analysis/lint-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index 8ceecf7610..46887447d6 100644 --- a/scripts/analysis/lint-results.txt +++ b/scripts/analysis/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 73 errors and 158 warnings + Lint Report: 72 errors and 158 warnings From c32d6a5bdf5bd4f68b02f33080f23727885d8740 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Tue, 3 Dec 2024 15:32:59 +0100 Subject: [PATCH 8/8] remove unused models Signed-off-by: sowjanyakch --- .../data/JoinConversationModel.kt | 11 ----------- .../openconversations/data/OpenConversation.kt | 14 -------------- .../data/OpenConversationsModel.kt | 11 ----------- 3 files changed, 36 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/openconversations/data/JoinConversationModel.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversation.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsModel.kt diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/JoinConversationModel.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/JoinConversationModel.kt deleted file mode 100644 index 3178fb706e..0000000000 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/JoinConversationModel.kt +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Nextcloud Talk - Android Client - * - * SPDX-FileCopyrightText: 2023 Marcel Hibbe - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package com.nextcloud.talk.openconversations.data - -data class JoinConversationModel( - var success: Boolean -) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversation.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversation.kt deleted file mode 100644 index 65d272e512..0000000000 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversation.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Nextcloud Talk - Android Client - * - * SPDX-FileCopyrightText: 2023 Marcel Hibbe - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package com.nextcloud.talk.openconversations.data - -data class OpenConversation( - // var roomId: String, - var roomToken: String, - var displayName: String, - var description: String? -) diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsModel.kt b/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsModel.kt deleted file mode 100644 index 5b63e58860..0000000000 --- a/app/src/main/java/com/nextcloud/talk/openconversations/data/OpenConversationsModel.kt +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Nextcloud Talk - Android Client - * - * SPDX-FileCopyrightText: 2023 Marcel Hibbe - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package com.nextcloud.talk.openconversations.data - -data class OpenConversationsModel( - var conversations: List -)