mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
fixes
This commit is contained in:
@@ -1,21 +1,3 @@
|
||||
/*
|
||||
* 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 dev.octoshrimpy.quik.feature.scheduled
|
||||
|
||||
import android.content.Context
|
||||
@@ -29,8 +11,11 @@ import dev.octoshrimpy.quik.manager.BillingManager
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
class ScheduledViewModel @Inject constructor(
|
||||
@@ -40,43 +25,55 @@ class ScheduledViewModel @Inject constructor(
|
||||
private val scheduledMessageRepo: ScheduledMessageRepository,
|
||||
private val sendScheduledMessage: SendScheduledMessage
|
||||
) : QkViewModel<ScheduledView, ScheduledState>(ScheduledState(
|
||||
scheduledMessages = scheduledMessageRepo.getScheduledMessages()
|
||||
scheduledMessages = scheduledMessageRepo.getScheduledMessages()
|
||||
)) {
|
||||
|
||||
init {
|
||||
disposables += billingManager.upgradeStatus
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: ScheduledView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.messageClickIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showMessageOptions() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showMessageOptions() }
|
||||
|
||||
view.messageMenuIntent
|
||||
.withLatestFrom(view.messageClickIntent) { itemId, messageId ->
|
||||
when (itemId) {
|
||||
0 -> sendScheduledMessage.execute(messageId)
|
||||
1 -> scheduledMessageRepo.getScheduledMessage(messageId)?.let { message ->
|
||||
ClipboardUtils.copy(context, message.body)
|
||||
context.makeToast(R.string.toast_copied)
|
||||
}
|
||||
2 -> scheduledMessageRepo.deleteScheduledMessage(messageId)
|
||||
.withLatestFrom(view.messageClickIntent) { itemId, messageId ->
|
||||
when (itemId) {
|
||||
0 -> sendScheduledMessage.execute(messageId)
|
||||
1 -> scheduledMessageRepo.getScheduledMessage(messageId)?.let { message ->
|
||||
ClipboardUtils.copy(context, message.body)
|
||||
context.makeToast(R.string.toast_copied)
|
||||
}
|
||||
2 -> {
|
||||
val deleteSubscription = Observable.fromCallable {
|
||||
scheduledMessageRepo.deleteScheduledMessage(messageId)
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
// Handle completion, e.g., log success or update UI
|
||||
}, {
|
||||
// Handle error, e.g., log or show error message
|
||||
})
|
||||
|
||||
disposables += deleteSubscription
|
||||
}
|
||||
Unit
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
Unit
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.composeIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showCompose() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showCompose() }
|
||||
|
||||
view.upgradeIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showQksmsPlusActivity("schedule_fab") }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showQksmsPlusActivity("schedule_fab") }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user