forked from upstream-mirrors/quik
Allow adding to contacts from inbox
This commit is contained in:
+1
-2
@@ -35,7 +35,6 @@ import javax.inject.Inject
|
||||
class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipient>() {
|
||||
|
||||
var threadId: Long = 0L
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
@@ -71,4 +70,4 @@ class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipi
|
||||
disposables.clear()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +197,12 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
return
|
||||
}
|
||||
|
||||
val addContact = when (state.page) {
|
||||
is Inbox -> state.page.addContact
|
||||
is Archived -> state.page.addContact
|
||||
else -> false
|
||||
}
|
||||
|
||||
val markPinned = when (state.page) {
|
||||
is Inbox -> state.page.markPinned
|
||||
is Archived -> state.page.markPinned
|
||||
@@ -221,6 +227,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
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.delete)?.isVisible = selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.add)?.isVisible = addContact && 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
|
||||
|
||||
@@ -38,6 +38,7 @@ data class MainState(
|
||||
sealed class MainPage
|
||||
|
||||
data class Inbox(
|
||||
val addContact: Boolean = false,
|
||||
val markPinned: Boolean = true,
|
||||
val markRead: Boolean = false,
|
||||
val data: RealmResults<Conversation>? = null,
|
||||
@@ -50,6 +51,7 @@ data class Searching(
|
||||
) : MainPage()
|
||||
|
||||
data class Archived(
|
||||
val addContact: Boolean = false,
|
||||
val markPinned: Boolean = true,
|
||||
val markRead: Boolean = false,
|
||||
val data: RealmResults<Conversation>? = null,
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkViewModel
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.extensions.removeAccents
|
||||
import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkAllSeen
|
||||
@@ -34,6 +35,7 @@ import com.moez.QKSMS.interactor.MarkUnpinned
|
||||
import com.moez.QKSMS.interactor.MarkUnread
|
||||
import com.moez.QKSMS.interactor.MigratePreferences
|
||||
import com.moez.QKSMS.interactor.SyncMessages
|
||||
import com.moez.QKSMS.listener.ContactAddedListener
|
||||
import com.moez.QKSMS.manager.ChangelogManager
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.manager.RatingManager
|
||||
@@ -58,6 +60,7 @@ class MainViewModel @Inject constructor(
|
||||
markAllSeen: MarkAllSeen,
|
||||
migratePreferences: MigratePreferences,
|
||||
syncRepository: SyncRepository,
|
||||
private val contactAddedListener: ContactAddedListener,
|
||||
private val changelogManager: ChangelogManager,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
@@ -275,6 +278,20 @@ class MainViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.optionsItemIntent
|
||||
.filter { itemId -> itemId == R.id.add }
|
||||
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations -> conversations }
|
||||
.doOnNext { view.clearSelection() }
|
||||
.filter { conversations -> conversations.size == 1 }
|
||||
.map { conversations -> conversations.first() }
|
||||
.mapNotNull(conversationRepo::getConversation)
|
||||
.map { conversation -> conversation.recipients }
|
||||
.mapNotNull { recipients -> recipients[0]?.address?.takeIf { recipients.size == 1 } }
|
||||
.doOnNext(navigator::addContact)
|
||||
.flatMap(contactAddedListener::listen)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.optionsItemIntent
|
||||
.filter { itemId -> itemId == R.id.pin }
|
||||
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations ->
|
||||
@@ -342,22 +359,24 @@ 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
|
||||
val conversations = selection.mapNotNull(conversationRepo::getConversation)
|
||||
val add = conversations.firstOrNull()
|
||||
?.takeIf { conversations.size == 1 }
|
||||
?.takeIf { conversation -> conversation.recipients.size == 1 }
|
||||
?.recipients?.first()
|
||||
?.takeIf { recipient -> recipient.contact == null } != null
|
||||
val pin = conversations.sumBy { if (it.pinned) -1 else 1 } >= 0
|
||||
val read = conversations.sumBy { if (it.read) -1 else 1 } >= 0
|
||||
val selected = selection.size
|
||||
|
||||
when (state.page) {
|
||||
is Inbox -> {
|
||||
val page = state.page.copy(markPinned = pin, markRead = read, selected = selected)
|
||||
newState { copy(page = page.copy(markRead = read, selected = selected)) }
|
||||
val page = state.page.copy(addContact = add, markPinned = pin, markRead = read, selected = selected)
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
|
||||
is Archived -> {
|
||||
val page = state.page.copy(markPinned = pin, markRead = read, selected = selected)
|
||||
val page = state.page.copy(addContact = add, markPinned = pin, markRead = read, selected = selected)
|
||||
newState { copy(page = page) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,13 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/add"
|
||||
android:icon="@drawable/ic_person_add_black_24dp"
|
||||
android:title="@string/main_menu_add_contact"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/pin"
|
||||
android:icon="@drawable/ic_pin_black_24dp"
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
<string name="main_menu_archive">Archive</string>
|
||||
<string name="main_menu_unarchive">Unarchive</string>
|
||||
<string name="main_menu_delete">Delete</string>
|
||||
<string name="main_menu_add_contact">Add to contacts</string>
|
||||
<string name="main_menu_pin">Pin to top</string>
|
||||
<string name="main_menu_unpin">Unpin</string>
|
||||
<string name="main_menu_read">Mark as read</string>
|
||||
|
||||
Reference in New Issue
Block a user