mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-19 18:55:05 +01:00
Preparations for filtering conversations
This commit is contained in:
parent
53e4f70c69
commit
51568aa00e
@ -57,10 +57,18 @@ class ConversationsRepositoryImpl(val conversationsDao: ConversationsDao) :
|
|||||||
.deleteConversation(userId, conversationId)
|
.deleteConversation(userId, conversationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversationsForUser(userId: Long): LiveData<List<Conversation>> {
|
override fun getConversationsForUser(userId: Long, filter: String?): LiveData<List<Conversation>> {
|
||||||
return conversationsDao.getConversationsForUser(userId).distinctUntilChanged().map { data ->
|
filter?.let {
|
||||||
data.map {
|
return conversationsDao.getConversationsForUserWithFilter(userId, it).distinctUntilChanged().map { data ->
|
||||||
it.toConversation()
|
data.map {conversationEntity ->
|
||||||
|
conversationEntity.toConversation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: run {
|
||||||
|
return conversationsDao.getConversationsForUser(userId).distinctUntilChanged().map { data ->
|
||||||
|
data.map {
|
||||||
|
it.toConversation()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import androidx.lifecycle.LiveData
|
|||||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
|
|
||||||
interface ConversationsRepository {
|
interface ConversationsRepository {
|
||||||
fun getConversationsForUser(userId: Long): LiveData<List<Conversation>>
|
fun getConversationsForUser(userId: Long, filter: String?): LiveData<List<Conversation>>
|
||||||
fun getShortcutTargetConversations(userId: Long): LiveData<List<Conversation>>
|
fun getShortcutTargetConversations(userId: Long): LiveData<List<Conversation>>
|
||||||
|
|
||||||
suspend fun getConversationForUserWithToken(userId: Long, token: String): Conversation?
|
suspend fun getConversationForUserWithToken(userId: Long, token: String): Conversation?
|
||||||
|
@ -22,8 +22,11 @@ package com.nextcloud.talk.newarch.features.conversationsList
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.os.Handler
|
||||||
|
import android.util.Log
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.Transformations
|
import androidx.lifecycle.Transformations
|
||||||
|
import androidx.lifecycle.distinctUntilChanged
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import coil.Coil
|
import coil.Coil
|
||||||
import coil.api.get
|
import coil.api.get
|
||||||
@ -47,6 +50,7 @@ import kotlinx.coroutines.launch
|
|||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
|
|
||||||
|
|
||||||
class ConversationsListViewModel constructor(
|
class ConversationsListViewModel constructor(
|
||||||
application: Application,
|
application: Application,
|
||||||
private val getConversationsUseCase: GetConversationsUseCase,
|
private val getConversationsUseCase: GetConversationsUseCase,
|
||||||
@ -62,13 +66,18 @@ class ConversationsListViewModel constructor(
|
|||||||
var messageData: String? = null
|
var messageData: String? = null
|
||||||
val networkStateLiveData: MutableLiveData<ConversationsListViewNetworkState> = MutableLiveData(ConversationsListViewNetworkState.LOADING)
|
val networkStateLiveData: MutableLiveData<ConversationsListViewNetworkState> = MutableLiveData(ConversationsListViewNetworkState.LOADING)
|
||||||
val avatar: MutableLiveData<Drawable> = MutableLiveData(DisplayUtils.getRoundedDrawable(context.getDrawable(R.drawable.ic_settings_white_24dp)))
|
val avatar: MutableLiveData<Drawable> = MutableLiveData(DisplayUtils.getRoundedDrawable(context.getDrawable(R.drawable.ic_settings_white_24dp)))
|
||||||
val conversationsLiveData = Transformations.switchMap(globalService.currentUserLiveData) {
|
val filterLiveData: MutableLiveData<String?> = MutableLiveData(null)
|
||||||
|
val conversationsLiveData = Transformations.switchMap(globalService.currentUserLiveData) { user ->
|
||||||
if (networkStateLiveData.value != ConversationsListViewNetworkState.LOADING) {
|
if (networkStateLiveData.value != ConversationsListViewNetworkState.LOADING) {
|
||||||
networkStateLiveData.postValue(ConversationsListViewNetworkState.LOADING)
|
networkStateLiveData.postValue(ConversationsListViewNetworkState.LOADING)
|
||||||
}
|
}
|
||||||
loadConversations()
|
loadConversations()
|
||||||
loadAvatar()
|
loadAvatar()
|
||||||
conversationsRepository.getConversationsForUser(it.id!!)
|
|
||||||
|
filterLiveData.value = null
|
||||||
|
Transformations.switchMap(filterLiveData.distinctUntilChanged()) { filter ->
|
||||||
|
conversationsRepository.getConversationsForUser(user.id!!, filter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun leaveConversation(conversation: Conversation) {
|
fun leaveConversation(conversation: Conversation) {
|
||||||
|
@ -33,7 +33,7 @@ class DebouncingQueryTextListener(
|
|||||||
lifecycle: Lifecycle,
|
lifecycle: Lifecycle,
|
||||||
private val onDebouncingQueryTextChange: (String?) -> Unit
|
private val onDebouncingQueryTextChange: (String?) -> Unit
|
||||||
) : OnQueryTextListener {
|
) : OnQueryTextListener {
|
||||||
var debouncePeriod: Long = 500
|
private var debouncePeriod: Long = 500
|
||||||
|
|
||||||
private val coroutineScope = lifecycle.coroutineScope
|
private val coroutineScope = lifecycle.coroutineScope
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ abstract class ConversationsDao {
|
|||||||
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY favorite DESC, last_activity DESC")
|
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY favorite DESC, last_activity DESC")
|
||||||
abstract fun getConversationsForUser(userId: Long): LiveData<List<ConversationEntity>>
|
abstract fun getConversationsForUser(userId: Long): LiveData<List<ConversationEntity>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM conversations WHERE user_id = :userId AND display_name LIKE '%' || :filter || '%' ORDER BY favorite DESC, last_activity DESC")
|
||||||
|
abstract fun getConversationsForUserWithFilter(userId: Long, filter: String): LiveData<List<ConversationEntity>>
|
||||||
|
|
||||||
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY favorite DESC, last_activity DESC LIMIT 4")
|
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY favorite DESC, last_activity DESC LIMIT 4")
|
||||||
abstract fun getShortcutTargetConversations(userId: Long): LiveData<List<ConversationEntity>>
|
abstract fun getShortcutTargetConversations(userId: Long): LiveData<List<ConversationEntity>>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user