mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 19:18:52 +01:00
Allow toggling of SIA integration, and direct user to play store if not installed
This commit is contained in:
@@ -145,6 +145,15 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the Play Store and display the Should I Answer? listing
|
||||
*/
|
||||
fun showSia() {
|
||||
val url = "https://play.google.com/store/apps/details?id=org.mistergroup.shouldianswerpersonal"
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showSupport() {
|
||||
val intent = Intent(Intent.ACTION_SENDTO)
|
||||
intent.data = Uri.parse("mailto:")
|
||||
|
||||
@@ -20,15 +20,16 @@ package feature.blocked
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.os.Bundle
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.base.QkThemedActivity
|
||||
import injection.appComponent
|
||||
import common.util.extensions.setVisible
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.blocked_activity.*
|
||||
import common.base.QkThemedActivity
|
||||
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedActivity : QkThemedActivity<BlockedViewModel>(), BlockedView {
|
||||
@@ -36,6 +37,7 @@ class BlockedActivity : QkThemedActivity<BlockedViewModel>(), BlockedView {
|
||||
@Inject lateinit var blockedAdapter: BlockedAdapter
|
||||
|
||||
override val viewModelClass = BlockedViewModel::class
|
||||
override val siaClickedIntent by lazy { shouldIAnswer.clicks() }
|
||||
override val unblockIntent by lazy { blockedAdapter.unblock }
|
||||
override val confirmUnblockIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
@@ -54,12 +56,14 @@ class BlockedActivity : QkThemedActivity<BlockedViewModel>(), BlockedView {
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
|
||||
blockedAdapter.emptyView = empty
|
||||
conversations.adapter = blockedAdapter
|
||||
}
|
||||
|
||||
override fun render(state: BlockedState) {
|
||||
blockedAdapter.flowable = state.data
|
||||
empty.setVisible(state.empty)
|
||||
shouldIAnswer.checkbox.isChecked = state.siaEnabled
|
||||
|
||||
blockedAdapter.updateData(state.data)
|
||||
}
|
||||
|
||||
override fun showUnblockDialog() {
|
||||
|
||||
@@ -22,16 +22,16 @@ import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import common.base.QkRealmAdapter
|
||||
import common.base.QkViewHolder
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.blocked_list_item.view.*
|
||||
import model.Contact
|
||||
import model.Conversation
|
||||
import model.PhoneNumber
|
||||
import common.base.FlowableAdapter
|
||||
import common.base.QkViewHolder
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedAdapter @Inject constructor(private val context: Context) : FlowableAdapter<Conversation>() {
|
||||
class BlockedAdapter @Inject constructor(private val context: Context) : QkRealmAdapter<Conversation>() {
|
||||
|
||||
val unblock: PublishSubject<Long> = PublishSubject.create()
|
||||
|
||||
@@ -40,7 +40,7 @@ class BlockedAdapter @Inject constructor(private val context: Context) : Flowabl
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val conversation = getItem(position)
|
||||
val conversation = getItem(position)!!
|
||||
val view = holder.itemView
|
||||
|
||||
view.setOnClickListener { unblock.onNext(conversation.id) }
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
*/
|
||||
package feature.blocked
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
|
||||
data class BlockedState(
|
||||
val data: Flowable<List<Conversation>>? = null,
|
||||
val empty: Boolean = false
|
||||
val siaEnabled: Boolean = false,
|
||||
val data: RealmResults<Conversation>? = null
|
||||
)
|
||||
@@ -18,13 +18,14 @@
|
||||
*/
|
||||
package feature.blocked
|
||||
|
||||
import io.reactivex.Observable
|
||||
import common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface BlockedView : QkView<BlockedState> {
|
||||
|
||||
val siaClickedIntent: Observable<*>
|
||||
val unblockIntent: Observable<Long>
|
||||
val confirmUnblockIntent: Observable<Unit>
|
||||
val confirmUnblockIntent: Observable<*>
|
||||
|
||||
fun showUnblockDialog()
|
||||
|
||||
|
||||
@@ -18,32 +18,51 @@
|
||||
*/
|
||||
package feature.blocked
|
||||
|
||||
import android.content.Context
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.Navigator
|
||||
import common.base.QkViewModel
|
||||
import injection.appComponent
|
||||
import interactor.MarkUnblocked
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import common.base.QkViewModel
|
||||
import repository.MessageRepository
|
||||
import util.Preferences
|
||||
import util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockedViewModel : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var markUnblocked: MarkUnblocked
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
val conversations = messageRepo.getBlockedConversations()
|
||||
.doOnNext { conversations -> newState { it.copy(empty = conversations.isEmpty()) } }
|
||||
newState { it.copy(data = messageRepo.getBlockedConversations()) }
|
||||
|
||||
newState { it.copy(data = conversations) }
|
||||
disposables += prefs.sia.asObservable()
|
||||
.subscribe { enabled -> newState { it.copy(siaEnabled = enabled) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: BlockedView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.siaClickedIntent
|
||||
.map {
|
||||
tryOrNull { context.packageManager.getApplicationInfo("org.mistergroup.shouldianswerpersonal", 0).enabled }
|
||||
?: tryOrNull { context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled }
|
||||
?: false
|
||||
}
|
||||
.doOnNext { installed -> if (!installed) navigator.showSia() }
|
||||
.withLatestFrom(prefs.sia.asObservable(), { installed, enabled -> installed && !enabled })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { shouldEnable -> prefs.sia.set(shouldEnable) }
|
||||
|
||||
// Show confirm unblock conversation dialog
|
||||
view.unblockIntent
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
Reference in New Issue
Block a user