forked from upstream-mirrors/quik
#45 - Rename group chats
This commit is contained in:
@@ -166,8 +166,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.filter { conversation -> conversation.id != 0L }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { conversation.onNext(it) }
|
||||
.subscribe(conversation::onNext)
|
||||
|
||||
// When the conversation changes, update the threadId and the messages for the adapter
|
||||
disposables += conversation
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.text.InputFilter
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
@@ -29,10 +30,14 @@ import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.Navigator
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.animateLayoutChanges
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.resolveThemeColor
|
||||
import common.util.extensions.scrapViews
|
||||
import common.util.extensions.setVisible
|
||||
import common.widget.QkEditText
|
||||
import dagger.android.AndroidInjection
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_info_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -44,6 +49,8 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
@Inject lateinit var itemDecoration: GridSpacingItemDecoration
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
override val nameIntent by lazy { name.clicks() }
|
||||
override val nameChangedIntent: Subject<String> = PublishSubject.create()
|
||||
override val notificationsIntent by lazy { notifications.clicks() }
|
||||
override val themeIntent by lazy { themePrefs.clicks() }
|
||||
override val archiveIntent by lazy { archive.clicks() }
|
||||
@@ -87,6 +94,9 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
recipientAdapter.threadId = state.threadId
|
||||
recipientAdapter.updateData(state.recipients)
|
||||
|
||||
name.setVisible(state.recipients?.size ?: 0 >= 2)
|
||||
name.summary = state.name
|
||||
|
||||
notifications.setVisible(!state.blocked)
|
||||
|
||||
archive.setVisible(!state.blocked)
|
||||
@@ -103,6 +113,27 @@ class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
|
||||
mediaAdapter.updateData(state.media)
|
||||
}
|
||||
|
||||
override fun showNameDialog(name: String) {
|
||||
val editText = QkEditText(this).apply {
|
||||
val padding = 8.dpToPx(this@ConversationInfoActivity)
|
||||
setPadding(padding * 3, padding, padding * 3, padding)
|
||||
setSingleLine(true)
|
||||
setHint(R.string.info_name_hint)
|
||||
setText(name)
|
||||
setHintTextColor(context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
setTextColor(context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
filters = arrayOf(InputFilter.LengthFilter(30))
|
||||
background = null
|
||||
}
|
||||
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.info_name)
|
||||
.setView(editText)
|
||||
.setPositiveButton(R.string.button_save, { _, _ -> nameChangedIntent.onNext(editText.text.toString()) })
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun showDeleteDialog() {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
|
||||
@@ -24,6 +24,7 @@ import model.MmsPart
|
||||
import model.Recipient
|
||||
|
||||
data class ConversationInfoState(
|
||||
val name: String = "",
|
||||
val recipients: RealmList<Recipient>? = null,
|
||||
val threadId: Long = 0,
|
||||
val archived: Boolean = false,
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
*/
|
||||
package feature.conversationinfo
|
||||
|
||||
import io.reactivex.Observable
|
||||
import common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface ConversationInfoView : QkView<ConversationInfoState> {
|
||||
|
||||
val nameIntent: Observable<*>
|
||||
val nameChangedIntent: Observable<String>
|
||||
val notificationsIntent: Observable<Unit>
|
||||
val themeIntent: Observable<Unit>
|
||||
val archiveIntent: Observable<Unit>
|
||||
@@ -30,6 +32,7 @@ interface ConversationInfoView : QkView<ConversationInfoState> {
|
||||
val deleteIntent: Observable<Unit>
|
||||
val confirmDeleteIntent: Observable<Unit>
|
||||
|
||||
fun showNameDialog(name: String)
|
||||
fun showDeleteDialog()
|
||||
|
||||
}
|
||||
@@ -27,9 +27,10 @@ import interactor.MarkArchived
|
||||
import interactor.MarkBlocked
|
||||
import interactor.MarkUnarchived
|
||||
import interactor.MarkUnblocked
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import model.Conversation
|
||||
import repository.MessageRepository
|
||||
import util.extensions.asObservable
|
||||
@@ -38,21 +39,21 @@ import javax.inject.Named
|
||||
|
||||
class ConversationInfoViewModel @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
messageRepo: MessageRepository,
|
||||
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
|
||||
) : QkViewModel<ConversationInfoView, ConversationInfoState>(
|
||||
ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId))
|
||||
) {
|
||||
|
||||
private val conversation: Observable<Conversation>
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
|
||||
init {
|
||||
conversation = messageRepo.getConversationAsync(threadId)
|
||||
disposables += messageRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.filter { conversation -> conversation.isLoaded }
|
||||
.doOnNext { conversation ->
|
||||
@@ -62,6 +63,7 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.filter { conversation -> conversation.id != 0L }
|
||||
.subscribe(conversation::onNext)
|
||||
|
||||
disposables += markArchived
|
||||
disposables += markUnarchived
|
||||
@@ -75,6 +77,12 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.subscribe { recipients -> newState { copy(recipients = recipients) } }
|
||||
|
||||
// Update conversation title whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.name }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { name -> newState { copy(name = name) } }
|
||||
|
||||
// Update the view's archived state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.archived }
|
||||
@@ -91,6 +99,21 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
override fun bindView(view: ConversationInfoView) {
|
||||
super.bindView(view)
|
||||
|
||||
// Show the conversation title dialog
|
||||
view.nameIntent
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.map { conversation -> conversation.name }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::showNameDialog)
|
||||
|
||||
// Set the conversation title
|
||||
view.nameChangedIntent
|
||||
.withLatestFrom(conversation) { name, conversation ->
|
||||
messageRepo.setConversationName(conversation.id, name)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Show the notifications settings for the conversation
|
||||
view.notificationsIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
|
||||
Reference in New Issue
Block a user