mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
#965 - Add ability to pin conversations
This commit is contained in:
+4
-4
@@ -40,14 +40,14 @@ import javax.inject.Named
|
||||
|
||||
class ConversationInfoViewModel @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
messageRepo: MessageRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
private val markBlocked: MarkBlocked,
|
||||
private val markUnblocked: MarkUnblocked,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val deleteConversations: DeleteConversations
|
||||
private val navigator: Navigator
|
||||
) : QkViewModel<ConversationInfoView, ConversationInfoState>(
|
||||
ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId))
|
||||
) {
|
||||
@@ -56,7 +56,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
disposables += conversationRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.asObservable()
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
if (!conversation.isValid) {
|
||||
|
||||
+2
@@ -22,6 +22,7 @@ import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkRealmAdapter
|
||||
@@ -87,6 +88,7 @@ class ConversationsAdapter @Inject constructor(
|
||||
true -> context.getString(R.string.main_sender_you, conversation.snippet)
|
||||
false -> conversation.snippet
|
||||
}
|
||||
view.pinned.isVisible = conversation.pinned
|
||||
}
|
||||
|
||||
override fun getItemId(index: Int): Long {
|
||||
|
||||
@@ -166,6 +166,12 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
return
|
||||
}
|
||||
|
||||
val markPinned = when (state.page) {
|
||||
is Inbox -> state.page.markPinned
|
||||
is Archived -> state.page.markPinned
|
||||
else -> true
|
||||
}
|
||||
|
||||
val markRead = when (state.page) {
|
||||
is Inbox -> state.page.markRead
|
||||
is Archived -> state.page.markRead
|
||||
@@ -181,12 +187,14 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
toolbarSearch.setVisible(state.page is Inbox && state.page.selected == 0 || state.page is Searching)
|
||||
toolbarTitle.setVisible(toolbarSearch.visibility != View.VISIBLE)
|
||||
|
||||
toolbar.menu.findItem(R.id.read)?.isVisible = markRead && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.unread)?.isVisible = !markRead && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.archive)?.isVisible = state.page is Inbox && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.unarchive)?.isVisible = state.page is Archived && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.block)?.isVisible = selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.pin)?.isVisible = markPinned && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.unpin)?.isVisible = !markPinned && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.read)?.isVisible = markRead && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.unread)?.isVisible = !markRead && selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.block)?.isVisible = selectedConversations != 0
|
||||
|
||||
plus.isVisible = state.upgraded
|
||||
plusBanner.isVisible = !state.upgraded
|
||||
|
||||
@@ -39,6 +39,7 @@ sealed class MainPage
|
||||
|
||||
data class Inbox(
|
||||
val showClearButton: Boolean = false,
|
||||
val markPinned: Boolean = true,
|
||||
val markRead: Boolean = false,
|
||||
val data: RealmResults<Conversation>? = null,
|
||||
val selected: Int = 0,
|
||||
@@ -51,6 +52,7 @@ data class Searching(
|
||||
|
||||
data class Archived(
|
||||
val showClearButton: Boolean = false,
|
||||
val markPinned: Boolean = true,
|
||||
val markRead: Boolean = false,
|
||||
val data: RealmResults<Conversation>? = null,
|
||||
val selected: Int = 0) : MainPage()
|
||||
@@ -28,8 +28,10 @@ import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkAllSeen
|
||||
import com.moez.QKSMS.interactor.MarkArchived
|
||||
import com.moez.QKSMS.interactor.MarkBlocked
|
||||
import com.moez.QKSMS.interactor.MarkPinned
|
||||
import com.moez.QKSMS.interactor.MarkRead
|
||||
import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
import com.moez.QKSMS.interactor.MarkUnpinned
|
||||
import com.moez.QKSMS.interactor.MarkUnread
|
||||
import com.moez.QKSMS.interactor.MigratePreferences
|
||||
import com.moez.QKSMS.interactor.SyncMessages
|
||||
@@ -56,11 +58,13 @@ class MainViewModel @Inject constructor(
|
||||
syncRepository: SyncRepository,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markRead: MarkRead,
|
||||
private val markUnread: MarkUnread,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
private val markBlocked: MarkBlocked,
|
||||
private val markPinned: MarkPinned,
|
||||
private val markRead: MarkRead,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
private val markUnpinned: MarkUnpinned,
|
||||
private val markUnread: MarkUnread,
|
||||
private val navigator: Navigator,
|
||||
private val permissionManager: PermissionManager,
|
||||
private val ratingManager: RatingManager,
|
||||
@@ -205,16 +209,6 @@ class MainViewModel @Inject constructor(
|
||||
view.optionsItemIntent
|
||||
.withLatestFrom(view.conversationsSelectedIntent) { itemId, conversations ->
|
||||
when (itemId) {
|
||||
R.id.read -> {
|
||||
markRead.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.unread -> {
|
||||
markUnread.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.archive -> {
|
||||
markArchived.execute(conversations)
|
||||
view.clearSelection()
|
||||
@@ -225,12 +219,32 @@ class MainViewModel @Inject constructor(
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.delete -> view.showDeleteDialog()
|
||||
|
||||
R.id.pin -> {
|
||||
markPinned.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.unpin -> {
|
||||
markUnpinned.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.read -> {
|
||||
markRead.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.unread -> {
|
||||
markUnread.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.block -> {
|
||||
markBlocked.execute(conversations)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
R.id.delete -> view.showDeleteDialog()
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
@@ -256,6 +270,9 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
view.conversationsSelectedIntent
|
||||
.withLatestFrom(state) { selection, state ->
|
||||
val pin = selection
|
||||
.mapNotNull(conversationRepo::getConversation)
|
||||
.sumBy { if (it.pinned) -1 else 1 } >= 0
|
||||
val read = selection
|
||||
.mapNotNull(conversationRepo::getConversation)
|
||||
.sumBy { if (it.read) -1 else 1 } >= 0
|
||||
@@ -263,12 +280,12 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
val page = state.page.copy(markRead = read, selected = selected, showClearButton = selected > 0)
|
||||
val page = state.page.copy(markPinned = pin, markRead = read, selected = selected, showClearButton = selected > 0)
|
||||
newState { copy(page = page.copy(markRead = read, selected = selected, showClearButton = selected > 0)) }
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
val page = state.page.copy(markRead = read, selected = selected, showClearButton = selected > 0)
|
||||
val page = state.page.copy(markPinned = pin, markRead = read, selected = selected, showClearButton = selected > 0)
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user