forked from upstream-mirrors/quik
#965 - Add ability to pin conversations
This commit is contained in:
@@ -26,7 +26,7 @@ import io.realm.RealmMigration
|
||||
class QkRealmMigration : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SCHEMA_VERSION: Long = 4
|
||||
const val SCHEMA_VERSION: Long = 5
|
||||
}
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
@@ -66,6 +66,13 @@ class QkRealmMigration : RealmMigration {
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 4L) {
|
||||
realm.schema.get("Conversation")
|
||||
?.addField("pinned", Boolean::class.java, FieldAttribute.REQUIRED, FieldAttribute.INDEXED)
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
if (version < newVersion) {
|
||||
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.equalTo("archived", archived)
|
||||
.equalTo("blocked", false)
|
||||
.isNotEmpty("recipients")
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.sort("pinned", Sort.DESCENDING, "date", Sort.DESCENDING)
|
||||
.findAllAsync()
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.equalTo("archived", false)
|
||||
.equalTo("blocked", false)
|
||||
.isNotEmpty("recipients")
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.sort("pinned", Sort.DESCENDING, "date", Sort.DESCENDING)
|
||||
.findAll())
|
||||
}
|
||||
|
||||
@@ -206,6 +206,30 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun markPinned(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.pinned = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markUnpinned(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.pinned = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markBlocked(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.interactor
|
||||
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkPinned @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> conversationRepo.markPinned(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.interactor
|
||||
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkUnpinned @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
|
||||
|
||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
||||
return Flowable.just(params.toLongArray())
|
||||
.doOnNext { threadIds -> conversationRepo.markUnpinned(*threadIds) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ open class Conversation(
|
||||
@PrimaryKey var id: Long = 0,
|
||||
@Index var archived: Boolean = false,
|
||||
@Index var blocked: Boolean = false,
|
||||
@Index var pinned: Boolean = false,
|
||||
var recipients: RealmList<Recipient> = RealmList(),
|
||||
var count: Int = 0,
|
||||
var date: Long = 0,
|
||||
|
||||
@@ -41,6 +41,10 @@ interface ConversationRepository {
|
||||
|
||||
fun markUnarchived(vararg threadIds: Long)
|
||||
|
||||
fun markPinned(vararg threadIds: Long)
|
||||
|
||||
fun markUnpinned(vararg threadIds: Long)
|
||||
|
||||
fun markBlocked(vararg threadIds: Long)
|
||||
|
||||
fun markUnblocked(vararg threadIds: Long)
|
||||
|
||||
+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) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
~
|
||||
~ This file is part of QKSMS.
|
||||
~
|
||||
~ QKSMS is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ QKSMS is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19.083 1c0 1.018-1.424 1.907-3.541 2.382V11c2.926.652 4.958 2.086 4.958 3.751h-7.792V23h-1.416v-8.25H3.5c0-1.665 2.032-3.1 4.958-3.751V3.382C6.341 2.907 4.917 2.018 4.917 1h14.166z"/>
|
||||
</vector>
|
||||
@@ -63,11 +63,23 @@
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/pinned"
|
||||
app:layout_constraintStart_toStartOf="@id/title"
|
||||
app:layout_constraintTop_toBottomOf="@id/title"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pinned"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:src="@drawable/ic_pin_black_24dp"
|
||||
android:tint="?android:attr/textColorSecondary"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/snippet"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/date"
|
||||
style="@style/TextTertiary"
|
||||
|
||||
@@ -40,6 +40,20 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/pin"
|
||||
android:icon="@drawable/ic_pin_black_24dp"
|
||||
android:title="@string/main_menu_pin"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/unpin"
|
||||
android:icon="@drawable/ic_pin_black_24dp"
|
||||
android:title="@string/main_menu_unpin"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/read"
|
||||
android:icon="@drawable/ic_drafts_black_24dp"
|
||||
|
||||
@@ -38,12 +38,14 @@
|
||||
<string name="main_drawer_open_cd">Open navigation drawer</string>
|
||||
<string name="main_title_selected">%d selected</string>
|
||||
<string name="main_menu_clear">Clear</string>
|
||||
<string name="main_menu_read">Mark read</string>
|
||||
<string name="main_menu_unread">Mark unread</string>
|
||||
<string name="main_menu_archive">Archive</string>
|
||||
<string name="main_menu_unarchive">Unarchive</string>
|
||||
<string name="main_menu_block">Block</string>
|
||||
<string name="main_menu_delete">Delete</string>
|
||||
<string name="main_menu_pin">Pin to top</string>
|
||||
<string name="main_menu_unpin">Unpin</string>
|
||||
<string name="main_menu_read">Mark read</string>
|
||||
<string name="main_menu_unread">Mark unread</string>
|
||||
<string name="main_menu_block">Block</string>
|
||||
<string name="main_syncing">Syncing messages…</string>
|
||||
<string name="main_sender_you">You: %s</string>
|
||||
<string name="main_message_results_title">Results in messages</string>
|
||||
|
||||
Reference in New Issue
Block a user