Skip to content

Commit

Permalink
Merge pull request #4493 from nextcloud/avatar_open_conversation
Browse files Browse the repository at this point in the history
display conversation avatar for open conversations
  • Loading branch information
mahibi authored Dec 10, 2024
2 parents 3d16b2e + c32d6a5 commit a268819
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

class OpenConversationsAdapter(val user: User, private val onClick: (OpenConversation) -> Unit) :
ListAdapter<OpenConversation, OpenConversationsAdapter.OpenConversationsViewHolder>(ConversationsCallback) {
private var originalList: List<OpenConversation> = 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<Conversation, OpenConversationsAdapter.OpenConversationsViewHolder>(ConversationsCallback) {
private var originalList: List<Conversation> = 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 {
Expand All @@ -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
Expand All @@ -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
)
}
}

Expand All @@ -79,7 +87,7 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers
}

isFiltering = true
val newList = mutableListOf<OpenConversation>()
val newList = mutableListOf<Conversation>()
for (conversation in originalList) {
if (conversation.displayName.contains(text, true) || conversation.description!!.contains(text, true)) {
newList.add(conversation)
Expand All @@ -91,23 +99,20 @@ class OpenConversationsAdapter(val user: User, private val onClick: (OpenConvers
}
}

override fun onCurrentListChanged(
previousList: MutableList<OpenConversation>,
currentList: MutableList<OpenConversation>
) {
override fun onCurrentListChanged(previousList: MutableList<Conversation>, currentList: MutableList<Conversation>) {
if (!isFiltering) {
originalList = currentList
}
super.onCurrentListChanged(previousList, currentList)
}
}

object ConversationsCallback : DiffUtil.ItemCallback<OpenConversation>() {
override fun areItemsTheSame(oldItem: OpenConversation, newItem: OpenConversation): Boolean {
object ConversationsCallback : DiffUtil.ItemCallback<Conversation>() {
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
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenConversationsModel>
fun fetchConversations(): Observable<List<Conversation>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenConversationsModel> {
return ncApi.getOpenConversations(
override fun fetchConversations(): Observable<List<Conversation>> {
val roomOverall = ncApi.getOpenConversations(
credentials,
ApiUtils.getUrlForOpenConversations(apiVersion, currentUser.baseUrl!!)
).map { mapToOpenConversationsModel(it.ocs?.data!!) }
}

private fun mapToOpenConversationsModel(conversations: List<Conversation>): OpenConversationsModel {
return OpenConversationsModel(
conversations.map { conversation ->
OpenConversation(
// conversation.roomId!!,
conversation.token!!,
conversation.name!!,
conversation.description ?: ""
)
}
)
return roomOverall.map { it.ocs?.data!! }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<OpenConversation>) : ViewState
open class FetchConversationsSuccessState(val conversations: List<Conversation>) : ViewState

private val _viewState: MutableLiveData<ViewState> = MutableLiveData(FetchConversationsStartState)
val viewState: LiveData<ViewState>
Expand All @@ -41,16 +40,16 @@ class OpenConversationsViewModel @Inject constructor(private val repository: Ope
?.subscribe(FetchConversationsObserver())
}

inner class FetchConversationsObserver : Observer<OpenConversationsModel> {
inner class FetchConversationsObserver : Observer<List<Conversation>> {
override fun onSubscribe(d: Disposable) {
// unused atm
}

override fun onNext(model: OpenConversationsModel) {
if (model.conversations.isEmpty()) {
override fun onNext(conversations: List<Conversation>) {
if (conversations.isEmpty()) {
_viewState.value = FetchConversationsEmptyState
} else {
_viewState.value = FetchConversationsSuccessState(model.conversations)
_viewState.value = FetchConversationsSuccessState(conversations)
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 73 errors and 158 warnings</span>
<span class="mdl-layout-title">Lint Report: 72 errors and 158 warnings</span>

0 comments on commit a268819

Please sign in to comment.