forked from upstream-mirrors/quik
Merge pull request #498 from Inhishonor/scheduled
Rework Scheduled Messages
This commit is contained in:
@@ -36,7 +36,7 @@ class QkRealmMigration @Inject constructor(
|
||||
) : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SchemaVersion: Long = 11
|
||||
const val SchemaVersion: Long = 12
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@@ -233,6 +233,14 @@ class QkRealmMigration @Inject constructor(
|
||||
|
||||
version++
|
||||
}
|
||||
if (version == 11L) {
|
||||
realm.schema.get("ScheduledMessage")
|
||||
?.addField("conversationId", Long::class.java, FieldAttribute.REQUIRED)
|
||||
// Because there was never any property associated with which conversation/recipients a scheduled message was for,
|
||||
// we can't update this field on a realm migration. It will be set to a default of 0
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
check(version >= newVersion) { "Migration missing from v$oldVersion to v$newVersion" }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.reactivex.schedulers.Schedulers
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmResults
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRepository {
|
||||
@@ -20,7 +21,8 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
recipients: List<String>,
|
||||
sendAsGroup: Boolean,
|
||||
body: String,
|
||||
attachments: List<String>
|
||||
attachments: List<String>,
|
||||
conversationId: Long
|
||||
): ScheduledMessage {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val id = (realm
|
||||
@@ -33,7 +35,7 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
val attachmentsRealmList = RealmList(*attachments.toTypedArray())
|
||||
|
||||
val message = ScheduledMessage(id, date, subId, recipientsRealmList, sendAsGroup, body,
|
||||
attachmentsRealmList)
|
||||
attachmentsRealmList, conversationId)
|
||||
|
||||
realm.executeTransaction { realm.insertOrUpdate(message) }
|
||||
|
||||
@@ -62,6 +64,13 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
override fun getScheduledMessagesForConversation(conversationId: Long): RealmResults<ScheduledMessage> {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(ScheduledMessage::class.java)
|
||||
.equalTo("conversationId", conversationId)
|
||||
.findAllAsync()
|
||||
}
|
||||
|
||||
override fun deleteScheduledMessage(id: Long) {
|
||||
val subscription = Completable.fromAction {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
@@ -71,12 +80,12 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
|
||||
realm.executeTransaction { message?.deleteFromRealm() }
|
||||
}
|
||||
}.subscribeOn(Schedulers.io()) // Perform the operation in a background thread
|
||||
.observeOn(AndroidSchedulers.mainThread()) // Switch back to the main thread if needed
|
||||
}.subscribeOn(Schedulers.io()) // Run on a background thread and switch to main if needed
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
// Handle completion, e.g., log success or update UI
|
||||
Timber.v("Successfully deleted scheduled messages.")
|
||||
}, {
|
||||
// Handle error, e.g., log or show error message
|
||||
Timber.e("Deleting scheduled messages failed.")
|
||||
})
|
||||
|
||||
disposables.add(subscription)
|
||||
@@ -96,9 +105,4 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
.map { it.id }
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure to clear disposables when the repository is no longer needed
|
||||
fun clearDisposables() {
|
||||
disposables.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package dev.octoshrimpy.quik.interactor
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toUri
|
||||
import dev.octoshrimpy.quik.extensions.getName
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
@@ -42,7 +41,8 @@ class AddScheduledMessage @Inject constructor(
|
||||
val recipients: List<String>,
|
||||
val sendAsGroup: Boolean,
|
||||
val body: String,
|
||||
val attachments: List<String>
|
||||
val attachments: List<String>,
|
||||
val conversationId: Long
|
||||
)
|
||||
|
||||
@SuppressLint("Range")
|
||||
@@ -51,14 +51,20 @@ class AddScheduledMessage @Inject constructor(
|
||||
return Flowable.just(params)
|
||||
.map { // step 1 - save, as-is, to db to get primary key id
|
||||
scheduledMessageRepo.saveScheduledMessage(
|
||||
it.date, it.subId, it.recipients, it.sendAsGroup, it.body, it.attachments
|
||||
it.date,
|
||||
it.subId,
|
||||
it.recipients,
|
||||
it.sendAsGroup,
|
||||
it.body,
|
||||
it.attachments,
|
||||
it.conversationId
|
||||
)
|
||||
}
|
||||
.map { scheduledMessageDb ->
|
||||
// step 2 - copy attachments to app local storage
|
||||
scheduledMessageDb.attachments = RealmList(
|
||||
*scheduledMessageDb.attachments.mapNotNull {
|
||||
val inUri = Uri.parse(it)
|
||||
val inUri = it.toUri()
|
||||
try {
|
||||
// get filename of input uri or use random uuid on fail to get
|
||||
val filename = inUri.getName(context) ?: UUID.randomUUID()
|
||||
@@ -93,5 +99,4 @@ class AddScheduledMessage @Inject constructor(
|
||||
}
|
||||
.flatMap { updateScheduledMessageAlarms.buildObservable(Unit) }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -41,11 +42,12 @@ class DeleteScheduledMessages @Inject constructor(
|
||||
val topDir = File(context.filesDir, "scheduled-${it}")
|
||||
topDir.exists() && topDir.deleteRecursively()
|
||||
}
|
||||
} catch (e: Exception) { /* nothing */ }
|
||||
} catch (e: Exception) {
|
||||
Timber.e("Unable to delete scheduled messages.")
|
||||
}
|
||||
|
||||
// delete the db entries
|
||||
scheduledMessageRepo.deleteScheduledMessages(it)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ open class ScheduledMessage(
|
||||
var recipients: RealmList<String> = RealmList(),
|
||||
var sendAsGroup: Boolean = true,
|
||||
var body: String = "",
|
||||
var attachments: RealmList<String> = RealmList()
|
||||
var attachments: RealmList<String> = RealmList(),
|
||||
var conversationId: Long = 0
|
||||
) : RealmObject() {
|
||||
|
||||
fun copy(
|
||||
@@ -39,10 +40,11 @@ open class ScheduledMessage(
|
||||
recipients: RealmList<String> = this.recipients,
|
||||
sendAsGroup: Boolean = this.sendAsGroup,
|
||||
body: String = this.body,
|
||||
attachments: RealmList<String> = this.attachments
|
||||
attachments: RealmList<String> = this.attachments,
|
||||
conversationId: Long = this.conversationId
|
||||
): ScheduledMessage {
|
||||
|
||||
return ScheduledMessage(id, date, subId, recipients, sendAsGroup, body, attachments)
|
||||
return ScheduledMessage(id, date, subId, recipients, sendAsGroup, body, attachments, conversationId)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,9 @@
|
||||
*/
|
||||
package dev.octoshrimpy.quik.repository
|
||||
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
import dev.octoshrimpy.quik.model.ScheduledMessage
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmResults
|
||||
|
||||
interface ScheduledMessageRepository {
|
||||
@@ -32,9 +34,13 @@ interface ScheduledMessageRepository {
|
||||
recipients: List<String>,
|
||||
sendAsGroup: Boolean,
|
||||
body: String,
|
||||
attachments: List<String>
|
||||
attachments: List<String>,
|
||||
conversationId: Long
|
||||
): ScheduledMessage
|
||||
|
||||
/**
|
||||
* Updates scheduled messages with new uris
|
||||
*/
|
||||
fun updateScheduledMessage(scheduledMessage: ScheduledMessage)
|
||||
|
||||
/**
|
||||
@@ -47,15 +53,24 @@ interface ScheduledMessageRepository {
|
||||
*/
|
||||
fun getScheduledMessage(id: Long): ScheduledMessage?
|
||||
|
||||
/**
|
||||
* Returns all scheduled messages with the given [conversationId]
|
||||
*/
|
||||
fun getScheduledMessagesForConversation(conversationId: Long): RealmResults<ScheduledMessage>
|
||||
|
||||
/**
|
||||
* Deletes the scheduled message with the given [id]
|
||||
*/
|
||||
fun deleteScheduledMessage(id: Long)
|
||||
|
||||
// delete multiple scheduled messages by id list
|
||||
/**
|
||||
* Delete multiple scheduled messages by id list
|
||||
*/
|
||||
fun deleteScheduledMessages(ids: List<Long>)
|
||||
|
||||
// get a list of all scheduled message ids (in scheduled date order)
|
||||
/**
|
||||
* Get a list of all scheduled message ids (in scheduled date order)
|
||||
*/
|
||||
fun getAllScheduledMessageIdsSnapshot(): List<Long>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +160,9 @@ class Navigator @Inject constructor(
|
||||
startActivity(Intent(context, BackupActivity::class.java))
|
||||
}
|
||||
|
||||
fun showScheduled() {
|
||||
fun showScheduled(conversationId: Long?) {
|
||||
val intent = Intent(context, ScheduledActivity::class.java)
|
||||
conversationId?.let { intent.putExtra("conversationId", it) }
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@ import kotlinx.android.synthetic.main.compose_activity.scheduleLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledCancel
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledGroup
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledTime
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledSend
|
||||
import kotlinx.android.synthetic.main.compose_activity.send
|
||||
import kotlinx.android.synthetic.main.compose_activity.sendAsGroup
|
||||
import kotlinx.android.synthetic.main.compose_activity.sendAsGroupBackground
|
||||
@@ -182,7 +183,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val scheduleSelectedIntent: Subject<Long> = PublishSubject.create()
|
||||
override val changeSimIntent by lazy { sim.clicks() }
|
||||
override val scheduleCancelIntent by lazy { scheduledCancel.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
override val sendIntent by lazy { Observable.merge(send.clicks(), scheduledSend.clicks()) }
|
||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()
|
||||
@@ -468,6 +469,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
// Don't set the adapters unless needed
|
||||
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
|
||||
|
||||
toolbar.menu.findItem(R.id.viewScheduledMessages)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
&& state.query.isEmpty() && state.hasScheduledMessages
|
||||
toolbar.menu.findItem(R.id.select_all)?.isVisible = !state.editingMode && (messageAdapter.itemCount > 1) && state.selectedMessages != 0
|
||||
toolbar.menu.findItem(R.id.add)?.isVisible = state.editingMode
|
||||
toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
@@ -532,9 +535,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
|
||||
simIndex.text = state.subscription?.simSlotIndex?.plus(1)?.toString()
|
||||
|
||||
// show either send or audio msg record button
|
||||
send.visibility = if (state.canSend && !state.loading) View.VISIBLE else View.INVISIBLE
|
||||
// show either send, audio msg record, or sendScheduled button
|
||||
send.visibility = if (state.canSend && !state.loading && state.scheduled == 0L) View.VISIBLE else View.INVISIBLE
|
||||
recordAudioMsg.visibility = if (state.canSend && !state.loading) View.INVISIBLE else View.VISIBLE
|
||||
scheduledSend.visibility = if (state.canSend && (state.scheduled != 0L) && !state.loading) View.VISIBLE else View.INVISIBLE
|
||||
|
||||
// if not in editing mode, and there are no non-me participants that can be sent to,
|
||||
// hide controls that allow constructing a reply and inform user no valid recipients
|
||||
|
||||
@@ -47,6 +47,7 @@ data class ComposeState(
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfoCompat? = null,
|
||||
val canSend: Boolean = false,
|
||||
val hasScheduledMessages: Boolean = false,
|
||||
val validRecipientNumbers: Int = 1,
|
||||
val audioMsgRecording: Boolean = false,
|
||||
val saveDraft: Boolean = true,
|
||||
|
||||
@@ -72,6 +72,7 @@ import dev.octoshrimpy.quik.model.getText
|
||||
import dev.octoshrimpy.quik.repository.ContactRepository
|
||||
import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
import dev.octoshrimpy.quik.util.ActiveSubscriptionObservable
|
||||
import dev.octoshrimpy.quik.util.FileUtils
|
||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||
@@ -114,6 +115,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val markRead: MarkRead,
|
||||
private val messageDetailsFormatter: MessageDetailsFormatter,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val scheduledMessageRepo: ScheduledMessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val permissionManager: PermissionManager,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
@@ -265,6 +267,22 @@ class ComposeViewModel @Inject constructor(
|
||||
newState { copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
|
||||
// checks if there are any scheduled messages in convo
|
||||
disposables += conversation
|
||||
.distinctUntilChanged { conversation -> conversation.id }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.switchMap { conversation ->
|
||||
scheduledMessageRepo
|
||||
.getScheduledMessagesForConversation(conversation.id)
|
||||
.asFlowable()
|
||||
.toObservable()
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { liveResults ->
|
||||
val hasAny = liveResults.isNotEmpty()
|
||||
newState { copy(hasScheduledMessages = hasAny) }
|
||||
}
|
||||
|
||||
// actions
|
||||
if (mode == "scheduling")
|
||||
newState { copy(scheduling = true) }
|
||||
@@ -338,6 +356,15 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy() } }
|
||||
|
||||
// Show scheduled messages
|
||||
view.optionsItemIntent
|
||||
.filter {it == R.id.viewScheduledMessages}
|
||||
.withLatestFrom(state, conversation)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { (_, _, conversation) ->
|
||||
navigator.showScheduled(conversation.id)
|
||||
}
|
||||
|
||||
// toggle select all / select none
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.select_all }
|
||||
@@ -834,7 +861,8 @@ class ComposeViewModel @Inject constructor(
|
||||
.subscribe {
|
||||
newState {
|
||||
copy(
|
||||
canSend = (it.first.isNotBlank() || (it.second > 0)) || (it.third > 0)
|
||||
canSend = (it.first.isNotBlank() || (it.second > 0)),
|
||||
scheduled = it.third
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1098,6 +1126,7 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val conversationId = (conversation.id)
|
||||
val addresses = when (conversation.recipients.isNotEmpty()) {
|
||||
true -> conversation.recipients.map { it.address }
|
||||
false -> chips.map { chip -> chip.address }
|
||||
@@ -1115,10 +1144,11 @@ class ComposeViewModel @Inject constructor(
|
||||
addresses,
|
||||
sendAsGroup,
|
||||
body.toString(),
|
||||
state.attachments.map { it.uri.toString() }
|
||||
state.attachments.map { it.uri.toString() },
|
||||
conversationId
|
||||
)
|
||||
).also {
|
||||
newState { copy(scheduled = 0) }
|
||||
newState { copy(scheduled = 0, hasScheduledMessages = true ) }
|
||||
showScheduledToast = true
|
||||
}
|
||||
|
||||
|
||||
+21
@@ -24,6 +24,7 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.Navigator
|
||||
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
|
||||
@@ -33,7 +34,9 @@ import dev.octoshrimpy.quik.common.util.DateFormatter
|
||||
import dev.octoshrimpy.quik.common.util.extensions.resolveThemeColor
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setTint
|
||||
import dev.octoshrimpy.quik.model.Conversation
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.conversation_list_item.*
|
||||
import kotlinx.android.synthetic.main.conversation_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
@@ -42,9 +45,11 @@ class ConversationsAdapter @Inject constructor(
|
||||
private val colors: Colors,
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val scheduledMessageRepo: ScheduledMessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : QkRealmAdapter<Conversation>() {
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
init {
|
||||
// This is how we access the threadId for the swipe actions
|
||||
@@ -117,6 +122,16 @@ class ConversationsAdapter @Inject constructor(
|
||||
// Make the preview in italics if draft
|
||||
if (conversation.draft.isNotEmpty()) holder.snippet.setTypeface(null, Typeface.ITALIC)
|
||||
|
||||
// Get Scheduled Messages
|
||||
val disposable = scheduledMessageRepo
|
||||
.getScheduledMessagesForConversation(conversation.id)
|
||||
.asFlowable()
|
||||
.toObservable()
|
||||
.subscribe { messages ->
|
||||
holder.scheduled.isVisible = messages.isNotEmpty()
|
||||
}
|
||||
disposables.add(disposable)
|
||||
|
||||
holder.pinned.isVisible = conversation.pinned
|
||||
holder.unread.setTint(theme)
|
||||
}
|
||||
@@ -129,4 +144,10 @@ class ConversationsAdapter @Inject constructor(
|
||||
return if (getItem(position)?.unread == false) 0 else 1
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView)
|
||||
disposables.clear()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ class MainViewModel @Inject constructor(
|
||||
else -> newState { copy(hasError = true) }
|
||||
}
|
||||
NavItem.BACKUP -> navigator.showBackup()
|
||||
NavItem.SCHEDULED -> navigator.showScheduled()
|
||||
NavItem.SCHEDULED -> navigator.showScheduled(null)
|
||||
NavItem.BLOCKING -> navigator.showBlockedConversations()
|
||||
NavItem.SETTINGS -> navigator.showSettings()
|
||||
// NavItem.PLUS -> navigator.showQksmsPlusActivity("main_menu")
|
||||
|
||||
@@ -66,7 +66,7 @@ class PlusViewModel @Inject constructor(
|
||||
|
||||
view.scheduleClicks
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showScheduled() }
|
||||
.subscribe { navigator.showScheduled(null) }
|
||||
|
||||
view.backupClicks
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -51,7 +51,9 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
override val editScheduledMessage: Subject<Long> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ScheduledViewModel::class.java] }
|
||||
private val viewModel by lazy {
|
||||
ViewModelProviders.of(this, viewModelFactory)[ScheduledViewModel::class.java]
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
@@ -97,7 +99,7 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
((scheduledMessageAdapter.itemCount != 0) && (state.selectedMessages == 1))
|
||||
|
||||
// show compose button
|
||||
compose.isVisible = state.upgraded
|
||||
compose.isVisible = state.upgraded && (state.conversationId == null)
|
||||
upgrade.isVisible = !state.upgraded
|
||||
}
|
||||
|
||||
@@ -152,4 +154,4 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -23,6 +23,7 @@ import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
import dev.octoshrimpy.quik.injection.ViewModelKey
|
||||
import javax.inject.Named
|
||||
|
||||
@Module
|
||||
class ScheduledActivityModule {
|
||||
@@ -32,4 +33,9 @@ class ScheduledActivityModule {
|
||||
@ViewModelKey(ScheduledViewModel::class)
|
||||
fun provideScheduledViewModel(viewModel: ScheduledViewModel): ViewModel = viewModel
|
||||
|
||||
}
|
||||
@Provides
|
||||
@Named("conversationId")
|
||||
fun getConversationId(activity: ScheduledActivity):
|
||||
Long? = activity.intent.extras?.getLong("conversationId")
|
||||
|
||||
}
|
||||
|
||||
+4
-5
@@ -53,7 +53,8 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.scheduled_message_list_item, parent, false)
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.scheduled_message_list_item, parent, false)
|
||||
|
||||
view.attachments.adapter = ScheduledMessageAttachmentAdapter(context)
|
||||
view.attachments.setRecycledViewPool(imagesViewPool)
|
||||
@@ -76,7 +77,8 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
val message = getItem(position) ?: return
|
||||
|
||||
// GroupAvatarView only accepts recipients, so map the phone numbers to recipients
|
||||
holder.avatars.recipients = message.recipients.map { address -> Recipient(address = address) }
|
||||
holder.avatars.recipients =
|
||||
message.recipients.map { address -> Recipient(address = address) }
|
||||
|
||||
holder.recipients.text = message.recipients.joinToString(",") { address ->
|
||||
contactCache[address]?.name?.takeIf { it.isNotBlank() } ?: address
|
||||
@@ -111,10 +113,7 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return super.get(key)?.takeIf { it.isValid }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -65,5 +65,4 @@ class ScheduledMessageAttachmentAdapter @Inject constructor(
|
||||
else -> holder.fileName.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,5 @@ data class ScheduledState(
|
||||
val scheduledMessages: RealmResults<ScheduledMessage>? = null,
|
||||
val upgraded: Boolean = true,
|
||||
val selectedMessages: Int = 0,
|
||||
val conversationId: Long? = null,
|
||||
)
|
||||
|
||||
@@ -15,8 +15,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class ScheduledViewModel @Inject constructor(
|
||||
@Named("conversationId") private val conversationId: Long?,
|
||||
billingManager: BillingManager,
|
||||
private val context: Context,
|
||||
private val navigator: Navigator,
|
||||
@@ -24,10 +26,12 @@ class ScheduledViewModel @Inject constructor(
|
||||
private val sendScheduledMessageInteractor: SendScheduledMessage,
|
||||
private val deleteScheduledMessagesInteractor: DeleteScheduledMessages,
|
||||
) : QkViewModel<ScheduledView, ScheduledState>(ScheduledState(
|
||||
scheduledMessages = scheduledMessageRepo.getScheduledMessages()
|
||||
scheduledMessages = scheduledMessageRepo.getScheduledMessages(),
|
||||
conversationId = conversationId
|
||||
)) {
|
||||
|
||||
init {
|
||||
loadMessages(conversationId)
|
||||
disposables += billingManager.upgradeStatus
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
}
|
||||
@@ -50,14 +54,21 @@ class ScheduledViewModel @Inject constructor(
|
||||
// show the delete message dialog if one or more messages selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.delete }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages ->
|
||||
selectedMessages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showDeleteDialog(it) }
|
||||
.subscribe {
|
||||
val ids = it.mapNotNull(scheduledMessageRepo::getScheduledMessage)
|
||||
.map { it.id }
|
||||
view.showDeleteDialog(ids)
|
||||
}
|
||||
|
||||
|
||||
// copy the selected message text to the clipboard
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.copy }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages ->
|
||||
selectedMessages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val messages = it
|
||||
@@ -78,14 +89,16 @@ class ScheduledViewModel @Inject constructor(
|
||||
// send the messages now menu item selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.send_now }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages ->
|
||||
selectedMessages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showSendNowDialog(it) }
|
||||
|
||||
// edit message menu item selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.edit_message }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessage -> selectedMessage.first() }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessage ->
|
||||
selectedMessage.first() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showEditMessageDialog(it) }
|
||||
|
||||
@@ -126,7 +139,7 @@ class ScheduledViewModel @Inject constructor(
|
||||
// navigate back or unselect
|
||||
view.optionsItemIntent
|
||||
.filter { it == android.R.id.home }
|
||||
.map { Unit }
|
||||
.map { }
|
||||
.mergeWith(view.backPressedIntent)
|
||||
.withLatestFrom(state) { _, state -> state }
|
||||
.autoDisposable(view.scope())
|
||||
@@ -148,4 +161,12 @@ class ScheduledViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showQksmsPlusActivity("schedule_fab") }
|
||||
}
|
||||
|
||||
private fun loadMessages(conversationId: Long?) {
|
||||
val results = if (conversationId != null)
|
||||
scheduledMessageRepo.getScheduledMessagesForConversation(conversationId)
|
||||
else
|
||||
scheduledMessageRepo.getScheduledMessages()
|
||||
newState { copy(scheduledMessages = results) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +207,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:text="@string/compose_scheduled_for"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
@@ -347,6 +348,21 @@
|
||||
app:tint="?android:textColorSecondary"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/scheduledSend"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/scheduled_send_cd"
|
||||
android:src="@drawable/ic_schedule_send_black_24dp"
|
||||
android:padding="10dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@id/messageBackground"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:tint="?android:textColorSecondary"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/Toolbar"
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/pinned"
|
||||
app:layout_constraintEnd_toStartOf="@id/scheduled"
|
||||
app:layout_constraintStart_toStartOf="@id/title"
|
||||
app:layout_constraintTop_toBottomOf="@id/title"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
@@ -80,9 +80,23 @@
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingTop="2dp"
|
||||
android:src="@drawable/ic_baseline_push_pin_24"
|
||||
android:tint="?android:attr/textColorTertiary"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toStartOf="@id/scheduled"
|
||||
app:layout_constraintTop_toTopOf="@id/snippet"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/scheduled"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:paddingStart="4dp"
|
||||
android:src="@drawable/ic_event_black_24dp"
|
||||
android:tint="?android:attr/textColorTertiary"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toStartOf="@id/unread"
|
||||
app:layout_constraintTop_toTopOf="@id/snippet"
|
||||
tools:visibility="visible" />
|
||||
|
||||
@@ -34,6 +34,13 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/viewScheduledMessages"
|
||||
android:icon="@drawable/ic_event_black_24dp"
|
||||
android:title="@string/compose_scheduled_view"
|
||||
android:visible="false"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/select_all"
|
||||
android:icon="?attr/actionModeSelectAllDrawable"
|
||||
|
||||
@@ -135,10 +135,11 @@
|
||||
<string name="compose_send_group_summary">Recipients and replies will be visible to everyone</string>
|
||||
<string name="compose_messages_empty">This is the start of your conversation. Say something nice!</string>
|
||||
<string name="compose_vcard_label">Contact card</string>
|
||||
<string name="compose_scheduled_for">Scheduled for</string>
|
||||
<string name="compose_scheduled_for">Scheduled time:</string>
|
||||
<string name="compose_scheduled_future">Selected time must be in the future!</string>
|
||||
<string name="compose_scheduled_plus">You must unlock QUIK+ to use scheduled messaging</string>
|
||||
<string name="compose_scheduled_toast">Added to scheduled messages</string>
|
||||
<string name="compose_scheduled_view">Scheduled messages for this conversation</string>
|
||||
<string name="compose_hint">Write a message…</string>
|
||||
<string name="compose_no_valid_recipients">Can\'t send to other participants</string>
|
||||
<string name="compose_menu_copy">Copy text</string>
|
||||
@@ -250,6 +251,7 @@
|
||||
<!--  is a special character required at the end of this string to fix it's formatting in the app -->
|
||||
<string name="scheduled_empty_message_3_timestamp">Sending on December 23rd </string>
|
||||
<string name="scheduled_compose_cd">Schedule a message</string>
|
||||
<string name="scheduled_send_cd">Schedule this message</string>
|
||||
<string name="scheduled_options_title">Scheduled message</string>
|
||||
<string name="attachment_missing">Missing</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user