mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 04:29:45 +01:00
Fix updates to items + various improvements
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
2681e6ef24
commit
9d2a5d4f2c
@ -50,6 +50,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.flexibleadapter.utils.FlexibleUtils;
|
||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConversationItem
|
||||
@ -71,7 +72,23 @@ public class ConversationItem
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof ConversationItem) {
|
||||
ConversationItem inItem = (ConversationItem) o;
|
||||
return conversation.getConversationId().equals(inItem.getModel().getConversationId());
|
||||
Conversation comparedConversation = inItem.conversation;
|
||||
return (conversation.getConversationId().equals(comparedConversation.getConversationId())
|
||||
&& Objects.equals(conversation.getToken(), comparedConversation.getToken())
|
||||
&& Objects.equals(conversation.getName(), comparedConversation.getName())
|
||||
&& Objects.equals(conversation.getDisplayName(), comparedConversation.getDisplayName())
|
||||
&& Objects.equals(conversation.getType(), comparedConversation.getType())
|
||||
&& Objects.equals(conversation.getLastMessage(), comparedConversation.getLastMessage())
|
||||
&& Objects.equals(conversation.getFavorite(), comparedConversation.getFavorite())
|
||||
&& Objects.equals(conversation.getHasPassword(), comparedConversation.getHasPassword())
|
||||
&& Objects.equals(conversation.getUnreadMessages(),
|
||||
comparedConversation.getUnreadMessages())
|
||||
&& Objects.equals(conversation.getUnreadMention(),
|
||||
comparedConversation.getUnreadMention())
|
||||
&& Objects.equals(conversation.getObjectType(), comparedConversation.getObjectType())
|
||||
&& Objects.equals(conversation.getChanging(), comparedConversation.getChanging())
|
||||
&& Objects.equals(userEntity.getId(), inItem.userEntity.getId())
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -82,7 +99,8 @@ public class ConversationItem
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return conversation.hashCode();
|
||||
return Objects.hash(conversation.getConversationId(), conversation.getToken(),
|
||||
userEntity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,7 +86,7 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
lateinit var viewModel: ConversationsListViewModel
|
||||
val factory: ConversationListViewModelFactory by inject()
|
||||
|
||||
private val recyclerViewAdapter = FlexibleAdapter(mutableListOf())
|
||||
private val recyclerViewAdapter = FlexibleAdapter(mutableListOf(), null, true)
|
||||
|
||||
private var searchItem: MenuItem? = null
|
||||
private var settingsItem: MenuItem? = null
|
||||
@ -246,7 +246,7 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
})
|
||||
|
||||
conversationsLiveData.observe(this@ConversationsListView, Observer {
|
||||
if (it.size == 0) {
|
||||
if (it.isEmpty()) {
|
||||
viewState.value = LOADED_EMPTY
|
||||
} else {
|
||||
viewState.value = LOADED
|
||||
@ -270,7 +270,7 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
)
|
||||
}
|
||||
|
||||
recyclerViewAdapter.updateDataSet(newConversations as List<IFlexible<ViewHolder>>?)
|
||||
recyclerViewAdapter.updateDataSet(newConversations as List<IFlexible<ViewHolder>>?, false)
|
||||
})
|
||||
|
||||
searchQuery.observe(this@ConversationsListView, Observer {
|
||||
@ -320,16 +320,17 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
override fun onAttach(view: View) {
|
||||
super.onAttach(view)
|
||||
view.recyclerView.initRecyclerView(
|
||||
SmoothScrollLinearLayoutManager(view.context), recyclerViewAdapter
|
||||
SmoothScrollLinearLayoutManager(view.context), recyclerViewAdapter, false
|
||||
)
|
||||
|
||||
view.swipeRefreshLayoutView.setOnRefreshListener { viewModel.loadConversations() }
|
||||
view.swipeRefreshLayoutView.setColorSchemeResources(R.color.colorPrimary)
|
||||
|
||||
recyclerViewAdapter.fastScroller = view.fast_scroller
|
||||
recyclerViewAdapter.mItemClickListener = this
|
||||
recyclerViewAdapter.mItemLongClickListener = this
|
||||
|
||||
view.swipeRefreshLayoutView.setOnRefreshListener { viewModel.loadConversations() }
|
||||
view.swipeRefreshLayoutView.setColorSchemeResources(R.color.colorPrimary)
|
||||
|
||||
|
||||
view.fast_scroller.setBubbleTextCreator { position ->
|
||||
var displayName =
|
||||
(recyclerViewAdapter.getItem(position) as ConversationItem).model.displayName
|
||||
|
@ -103,6 +103,9 @@ class ConversationsListViewModel constructor(
|
||||
|
||||
override fun onError(errorModel: ErrorModel?) {
|
||||
messageData = errorModel?.getErrorMessage()
|
||||
if (errorModel?.code == 400) {
|
||||
// couldn't leave because we're last moderator
|
||||
}
|
||||
viewModelScope.launch {
|
||||
setConversationUpdateStatus(conversation, false)
|
||||
}
|
||||
|
@ -50,8 +50,7 @@ abstract class ConversationsDao {
|
||||
abstract suspend fun saveConversations(vararg conversations: ConversationEntity)
|
||||
|
||||
@Query(
|
||||
"UPDATE conversations SET changing = :changing WHERE user = :userId AND " +
|
||||
"'conversation_id' = :conversationId"
|
||||
"UPDATE conversations SET changing = :changing WHERE user = :userId AND conversation_id = :conversationId"
|
||||
)
|
||||
abstract suspend fun updateChangingValueForConversation(
|
||||
userId: Long,
|
||||
@ -60,7 +59,7 @@ abstract class ConversationsDao {
|
||||
)
|
||||
|
||||
@Query(
|
||||
"UPDATE conversations SET favorite = :favorite, changing = 0 WHERE user = :userId AND 'conversation_id' = :conversationId"
|
||||
"UPDATE conversations SET favorite = :favorite, changing = 0 WHERE user = :userId AND conversation_id = :conversationId"
|
||||
)
|
||||
abstract suspend fun updateFavoriteValueForConversation(
|
||||
userId: Long,
|
||||
@ -68,7 +67,7 @@ abstract class ConversationsDao {
|
||||
favorite: Boolean
|
||||
)
|
||||
|
||||
@Query("DELETE FROM conversations WHERE user = :userId AND 'conversation_id' = :conversationId")
|
||||
@Query("DELETE FROM conversations WHERE user = :userId AND conversation_id = :conversationId")
|
||||
abstract suspend fun deleteConversation(
|
||||
userId: Long,
|
||||
conversationId: String
|
||||
@ -77,7 +76,7 @@ abstract class ConversationsDao {
|
||||
@Delete
|
||||
abstract suspend fun deleteConversations(vararg conversation: ConversationEntity)
|
||||
|
||||
@Query("DELETE FROM conversations WHERE user = :userId AND 'modified_at' < :timestamp")
|
||||
@Query("DELETE FROM conversations WHERE user = :userId AND modified_at < :timestamp")
|
||||
abstract suspend fun deleteConversationsForUserWithTimestamp(
|
||||
userId: Long,
|
||||
timestamp: Long
|
||||
|
@ -317,5 +317,7 @@
|
||||
|
||||
<string name="nc_general_settings">General</string>
|
||||
<string name="nc_allow_guests">Allow guests</string>
|
||||
<string name="nc_last_moderator_title">Could not leave conversation</string>
|
||||
<string name="nc_last_moderator">You need to promote a new moderator before you can leave %1$s.</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user