forked from upstream-mirrors/quik
Remove link between messages and conversations
This commit is contained in:
@@ -154,7 +154,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
return
|
||||
}
|
||||
|
||||
val conversation = message.conversation ?: return
|
||||
val conversation = messageRepo.getConversation(message.threadId) ?: return
|
||||
val threadId = conversation.id
|
||||
|
||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
*/
|
||||
package common.util.filter
|
||||
|
||||
import model.Message
|
||||
import model.Conversation
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationFilter @Inject constructor(private val recipientFilter: RecipientFilter) : Filter<Message>() {
|
||||
class ConversationFilter @Inject constructor(private val recipientFilter: RecipientFilter) : Filter<Conversation>() {
|
||||
|
||||
override fun filter(item: Message, query: CharSequence): Boolean {
|
||||
return item.conversation?.recipients?.any { recipient -> recipientFilter.filter(recipient, query) } ?: false
|
||||
override fun filter(item: Conversation, query: CharSequence): Boolean {
|
||||
return item.recipients.any { recipient -> recipientFilter.filter(recipient, query) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
package feature.conversations
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
@@ -35,7 +34,7 @@ import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_list_item.view.*
|
||||
import model.Contact
|
||||
import model.Message
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -43,13 +42,12 @@ class ConversationsAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val colors: Colors
|
||||
) : QkRealmAdapter<Message>() {
|
||||
) : QkRealmAdapter<Conversation>() {
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
val longClicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
private var attachedRecyclerViews = 0
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
@@ -72,22 +70,8 @@ class ConversationsAdapter @Inject constructor(
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
fun isAttachedToRecyclerView() = attachedRecyclerViews > 0
|
||||
|
||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView)
|
||||
attachedRecyclerViews++
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView)
|
||||
attachedRecyclerViews--
|
||||
disposables.clear()
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||
val message = getItem(position)!!
|
||||
val conversation = message.conversation!!
|
||||
val conversation = getItem(position)!!
|
||||
val view = viewHolder.itemView
|
||||
|
||||
view.clicks().subscribe { clicks.onNext(conversation.id) }
|
||||
@@ -97,12 +81,12 @@ class ConversationsAdapter @Inject constructor(
|
||||
recipient.contact ?: Contact().apply { numbers.add(PhoneNumber().apply { address = recipient.address }) }
|
||||
}
|
||||
view.title.text = conversation.getTitle()
|
||||
view.date.text = dateFormatter.getConversationTimestamp(message.date)
|
||||
view.snippet.text = if (message.isMe()) "You: ${message.getSummary()}" else message.getSummary()
|
||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||
view.snippet.text = if (conversation.me) "You: ${conversation.snippet}" else conversation.snippet
|
||||
}
|
||||
|
||||
override fun getItemId(index: Int): Long {
|
||||
return getItem(index)!!.conversation!!.id
|
||||
return getItem(index)!!.id
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
|
||||
@@ -54,7 +54,7 @@ class GalleryViewModel(intent: Intent) : QkViewModel<GalleryView, GalleryState>(
|
||||
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
||||
.mapNotNull { message -> message.conversation }
|
||||
.mapNotNull { message -> messageRepo.getConversation(message.threadId) }
|
||||
.subscribe { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package feature.main
|
||||
|
||||
import common.MenuItem
|
||||
import io.realm.RealmResults
|
||||
import model.Message
|
||||
import model.Conversation
|
||||
|
||||
data class MainState(
|
||||
val page: MainPage = Inbox(),
|
||||
@@ -32,12 +32,12 @@ sealed class MainPage
|
||||
|
||||
data class Inbox(
|
||||
val showClearButton: Boolean = false,
|
||||
val data: RealmResults<Message>? = null,
|
||||
val data: RealmResults<Conversation>? = null,
|
||||
val menu: List<MenuItem> = ArrayList(),
|
||||
val showArchivedSnackbar: Boolean = false) : MainPage()
|
||||
|
||||
data class Archived(
|
||||
val data: RealmResults<Message>? = null,
|
||||
val data: RealmResults<Conversation>? = null,
|
||||
val menu: List<MenuItem> = ArrayList()) : MainPage()
|
||||
|
||||
data class Scheduled(
|
||||
|
||||
@@ -38,7 +38,7 @@ import common.util.extensions.dpToPx
|
||||
import feature.main.MainActivity
|
||||
import injection.appComponent
|
||||
import model.Contact
|
||||
import model.Message
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import repository.MessageRepository
|
||||
import javax.inject.Inject
|
||||
@@ -56,7 +56,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
private val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
private val smallWidget = intent.getBooleanExtra("small_widget", false)
|
||||
private var conversations: List<Message> = listOf()
|
||||
private var conversations: List<Conversation> = listOf()
|
||||
private val appWidgetManager by lazy { AppWidgetManager.getInstance(context) }
|
||||
|
||||
// Cache colors, load lazily. This entire class is recreated when the widget is recreated,
|
||||
@@ -97,8 +97,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
}
|
||||
|
||||
private fun getConversationView(position: Int): RemoteViews {
|
||||
val message = conversations[position]
|
||||
val conversation = message.conversation!!
|
||||
val conversation = conversations[position]
|
||||
|
||||
val remoteViews = RemoteViews(context.packageName, R.layout.widget_list_item)
|
||||
|
||||
@@ -138,15 +137,15 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
// Name
|
||||
remoteViews.setTextColor(R.id.name, textPrimary)
|
||||
remoteViews.setTextViewText(R.id.name, boldText(conversation.getTitle(), !message.read))
|
||||
remoteViews.setTextViewText(R.id.name, boldText(conversation.getTitle(), !conversation.read))
|
||||
|
||||
// Date
|
||||
remoteViews.setTextColor(R.id.date, if (message.read) textTertiary else textPrimary)
|
||||
remoteViews.setTextViewText(R.id.date, boldText(dateFormatter.getConversationTimestamp(message.date), !message.read))
|
||||
remoteViews.setTextColor(R.id.date, if (conversation.read) textTertiary else textPrimary)
|
||||
remoteViews.setTextViewText(R.id.date, boldText(dateFormatter.getConversationTimestamp(conversation.date), !conversation.read))
|
||||
|
||||
// Snippet
|
||||
remoteViews.setTextColor(R.id.snippet, if (message.read) textTertiary else textPrimary)
|
||||
remoteViews.setTextViewText(R.id.snippet, boldText(message.getSummary(), !message.read))
|
||||
remoteViews.setTextColor(R.id.snippet, if (conversation.read) textTertiary else textPrimary)
|
||||
remoteViews.setTextViewText(R.id.snippet, boldText(conversation.snippet, !conversation.read))
|
||||
|
||||
// Launch conversation on click
|
||||
val clickIntent = Intent().putExtra("threadId", conversation.id)
|
||||
|
||||
@@ -49,6 +49,7 @@ class SendMessage @Inject constructor(
|
||||
sendMms(params.threadId, params.addresses, params.body, params.attachments)
|
||||
}
|
||||
}
|
||||
.doOnNext { messageRepo.updateConversation(params.threadId) }
|
||||
.doOnNext { messageRepo.markUnarchived(params.threadId) }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user