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 b16eb217a..dbadc85d4 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) { 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 9918fc153..949c5ee98 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -21,8 +21,8 @@ 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 @@ -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) 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 b8a9e2d0f..89da0c002 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,26 @@ 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 +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, private val onClick: (OpenConversation) -> Unit) : - ListAdapter(ConversationsCallback) { - private var originalList: List = emptyList() +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 +42,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 +55,12 @@ 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 + ) } } @@ -79,7 +87,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) @@ -91,10 +99,7 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers } } - override fun onCurrentListChanged( - previousList: MutableList, - currentList: MutableList - ) { + override fun onCurrentListChanged(previousList: MutableList, currentList: MutableList) { if (!isFiltering) { originalList = currentList } @@ -102,12 +107,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 } } 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 3178fb706..000000000 --- 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 65d272e51..000000000 --- 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 5b63e5886..000000000 --- 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 -) 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 f096ea46c..4e9fb7a15 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 5edbf922d..3dbaf4dbb 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!! } } } 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 cf75dafb2..cfe387a26 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) } } diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index 8ceecf761..46887447d 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