mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Move option to edit blocking manager settings to selection screen
This commit is contained in:
@@ -183,7 +183,7 @@ class Navigator @Inject constructor(
|
||||
/**
|
||||
* Launch the Play Store and display the Call Control listing
|
||||
*/
|
||||
fun showCallControl() {
|
||||
fun installCallControl() {
|
||||
val url = "https://play.google.com/store/apps/details?id=com.flexaspect.android.everycallcontrol"
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(intent)
|
||||
@@ -192,7 +192,7 @@ class Navigator @Inject constructor(
|
||||
/**
|
||||
* Launch the Play Store and display the Should I Answer? listing
|
||||
*/
|
||||
fun showSia() {
|
||||
fun installSia() {
|
||||
val url = "https://play.google.com/store/apps/details?id=org.mistergroup.shouldianswer"
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(intent)
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
|
||||
fun Activity.dismissKeyboard() {
|
||||
window.currentFocus?.let { focus ->
|
||||
val imm = getSystemService(
|
||||
Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(focus.windowToken, 0)
|
||||
|
||||
focus.clearFocus()
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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 com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.TypedValue
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
|
||||
fun Context.getColorCompat(colorRes: Int): Int {
|
||||
//return black as a default color, in case an invalid color ID was passed in
|
||||
return tryOrNull { ContextCompat.getColor(this, colorRes) } ?: Color.BLACK
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to resolve a resource id from the current theme, based on the [attributeId]
|
||||
*/
|
||||
fun Context.resolveThemeAttribute(attributeId: Int, default: Int = 0): Int {
|
||||
val outValue = TypedValue()
|
||||
val wasResolved = theme.resolveAttribute(attributeId, outValue, true)
|
||||
|
||||
return if (wasResolved) outValue.resourceId else default
|
||||
}
|
||||
|
||||
fun Context.resolveThemeBoolean(attributeId: Int, default: Boolean = false): Boolean {
|
||||
val outValue = TypedValue()
|
||||
val wasResolved = theme.resolveAttribute(attributeId, outValue, true)
|
||||
|
||||
return if (wasResolved) outValue.data != 0 else default
|
||||
}
|
||||
|
||||
fun Context.resolveThemeColor(attributeId: Int, default: Int = 0): Int {
|
||||
val outValue = TypedValue()
|
||||
val wasResolved = theme.resolveAttribute(attributeId, outValue, true)
|
||||
|
||||
return if (wasResolved) getColorCompat(outValue.resourceId) else default
|
||||
}
|
||||
|
||||
fun Context.makeToast(@StringRes res: Int, duration: Int = Toast.LENGTH_SHORT) {
|
||||
Toast.makeText(this, res, duration).show()
|
||||
}
|
||||
|
||||
fun Context.makeToast(text: String, duration: Int = Toast.LENGTH_SHORT) {
|
||||
Toast.makeText(this, text, duration).show()
|
||||
}
|
||||
|
||||
fun Activity.dismissKeyboard() {
|
||||
window.currentFocus?.let { focus ->
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(focus.windowToken, 0)
|
||||
|
||||
focus.clearFocus()
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isInstalled(packageName: String): Boolean {
|
||||
return tryOrNull(false) { packageManager.getApplicationInfo(packageName, 0).enabled } ?: false
|
||||
}
|
||||
@@ -88,6 +88,12 @@ class RadioPreferenceView @JvmOverloads constructor(
|
||||
context.obtainStyledAttributes(attrs, R.styleable.RadioPreferenceView)?.run {
|
||||
title = getString(R.styleable.RadioPreferenceView_title)
|
||||
summary = getString(R.styleable.RadioPreferenceView_summary)
|
||||
|
||||
// If there's a custom view used for the preference's widget, inflate it
|
||||
getResourceId(R.styleable.RadioPreferenceView_widget, -1).takeIf { it != -1 }?.let { id ->
|
||||
View.inflate(context, id, widgetFrame)
|
||||
}
|
||||
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import com.moez.QKSMS.common.QkChangeHandler
|
||||
import com.moez.QKSMS.common.base.QkController
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.feature.blocking.manager.BlockingManagerController
|
||||
import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import kotlinx.android.synthetic.main.blocking_controller.*
|
||||
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
|
||||
@@ -38,7 +36,6 @@ import javax.inject.Inject
|
||||
class BlockingController : QkController<BlockingView, BlockingState, BlockingPresenter>(), BlockingView {
|
||||
|
||||
override val blockingManagerIntent by lazy { blockingManager.clicks() }
|
||||
override val settingsClicks by lazy { settings.clicks() }
|
||||
override val dropClickedIntent by lazy { drop.clicks() }
|
||||
override val conversationClicks by lazy { blockingAdapter.clicks }
|
||||
|
||||
@@ -55,7 +52,6 @@ class BlockingController : QkController<BlockingView, BlockingState, BlockingPre
|
||||
override fun onViewCreated() {
|
||||
super.onViewCreated()
|
||||
|
||||
settings.setTint(colors.theme().theme)
|
||||
blockingAdapter.emptyView = empty
|
||||
conversations.adapter = blockingAdapter
|
||||
|
||||
@@ -82,10 +78,4 @@ class BlockingController : QkController<BlockingView, BlockingState, BlockingPre
|
||||
.popChangeHandler(QkChangeHandler()))
|
||||
}
|
||||
|
||||
override fun openBlockedNumbers() {
|
||||
router.pushController(RouterTransaction.with(BlockedNumbersController())
|
||||
.pushChangeHandler(QkChangeHandler())
|
||||
.popChangeHandler(QkChangeHandler()))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
package com.moez.QKSMS.feature.blocking
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.blocking.BlockingManager
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkPresenter
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
@@ -32,7 +30,6 @@ import javax.inject.Inject
|
||||
|
||||
class BlockingPresenter @Inject constructor(
|
||||
context: Context,
|
||||
private val blockingManager: BlockingManager,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
@@ -63,18 +60,6 @@ class BlockingPresenter @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.openBlockingManager() }
|
||||
|
||||
view.settingsClicks
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
// TODO: This is a hack, get rid of it once we implement AndroidX navigation
|
||||
val client = prefs.blockingManager.get()
|
||||
if (client == Preferences.BLOCKING_MANAGER_QKSMS && Build.VERSION.SDK_INT < 24) {
|
||||
view.openBlockedNumbers()
|
||||
} else {
|
||||
blockingManager.openSettings()
|
||||
}
|
||||
}
|
||||
|
||||
view.dropClickedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { prefs.drop.set(!prefs.drop.get()) }
|
||||
|
||||
@@ -24,10 +24,8 @@ import io.reactivex.Observable
|
||||
interface BlockingView : QkViewContract<BlockingState> {
|
||||
|
||||
val blockingManagerIntent: Observable<*>
|
||||
val settingsClicks: Observable<*>
|
||||
val dropClickedIntent: Observable<*>
|
||||
val conversationClicks: Observable<Long>
|
||||
|
||||
fun openBlockingManager()
|
||||
fun openBlockedNumbers()
|
||||
}
|
||||
|
||||
+36
-4
@@ -1,13 +1,19 @@
|
||||
package com.moez.QKSMS.feature.blocking.manager
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.QkChangeHandler
|
||||
import com.moez.QKSMS.common.base.QkController
|
||||
import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.blocking_manager_controller.*
|
||||
import kotlinx.android.synthetic.main.blocking_manager_list_option.view.*
|
||||
import kotlinx.android.synthetic.main.radio_preference_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -16,6 +22,8 @@ class BlockingManagerController : QkController<BlockingManagerView, BlockingMana
|
||||
|
||||
@Inject override lateinit var presenter: BlockingManagerPresenter
|
||||
|
||||
private val activityResumedSubject: PublishSubject<Unit> = PublishSubject.create()
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
retainViewMode = RetainViewMode.RETAIN_DETACH
|
||||
@@ -29,14 +37,38 @@ class BlockingManagerController : QkController<BlockingManagerView, BlockingMana
|
||||
showBackButton(true)
|
||||
}
|
||||
|
||||
override fun render(state: BlockingManagerState) {
|
||||
qksms.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_QKSMS
|
||||
callControl.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_CC
|
||||
shouldIAnswer.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_SIA
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
activityResumedSubject.onNext(Unit)
|
||||
}
|
||||
|
||||
override fun render(state: BlockingManagerState) {
|
||||
qksms.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_QKSMS
|
||||
|
||||
callControl.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_CC
|
||||
callControl.launch.setImageResource(when (state.callControlInstalled) {
|
||||
true -> R.drawable.ic_chevron_right_black_24dp
|
||||
false -> R.drawable.ic_info_black_24dp
|
||||
})
|
||||
|
||||
shouldIAnswer.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_SIA
|
||||
shouldIAnswer.launch.setImageResource(when (state.siaInstalled) {
|
||||
true -> R.drawable.ic_chevron_right_black_24dp
|
||||
false -> R.drawable.ic_info_black_24dp
|
||||
})
|
||||
}
|
||||
|
||||
override fun activityResumed(): Observable<*> = activityResumedSubject
|
||||
override fun qksmsClicked(): Observable<*> = qksms.clicks()
|
||||
override fun launchQksmsClicked(): Observable<*> = qksms.launch.clicks()
|
||||
override fun callControlClicked(): Observable<*> = callControl.clicks()
|
||||
override fun launchCallControlClicked(): Observable<*> = callControl.launch.clicks()
|
||||
override fun siaClicked(): Observable<*> = shouldIAnswer.clicks()
|
||||
override fun launchSiaClicked(): Observable<*> = shouldIAnswer.launch.clicks()
|
||||
|
||||
override fun openBlockedNumbers() {
|
||||
router.pushController(RouterTransaction.with(BlockedNumbersController())
|
||||
.pushChangeHandler(QkChangeHandler())
|
||||
.popChangeHandler(QkChangeHandler()))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+56
-13
@@ -1,10 +1,11 @@
|
||||
package com.moez.QKSMS.feature.blocking.manager
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import com.moez.QKSMS.blocking.CallControlBlockingClient
|
||||
import com.moez.QKSMS.blocking.QkBlockingClient
|
||||
import com.moez.QKSMS.blocking.ShouldIAnswerBlockingClient
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkPresenter
|
||||
import com.moez.QKSMS.common.util.extensions.isInstalled
|
||||
import com.moez.QKSMS.manager.AnalyticsManager
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
@@ -14,10 +15,15 @@ import javax.inject.Inject
|
||||
class BlockingManagerPresenter @Inject constructor(
|
||||
private val analytics: AnalyticsManager,
|
||||
private val callControl: CallControlBlockingClient,
|
||||
private val context: Context,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
) : QkPresenter<BlockingManagerView, BlockingManagerState>(BlockingManagerState()) {
|
||||
private val prefs: Preferences,
|
||||
private val qksms: QkBlockingClient,
|
||||
private val shouldIAnswer: ShouldIAnswerBlockingClient
|
||||
) : QkPresenter<BlockingManagerView, BlockingManagerState>(BlockingManagerState(
|
||||
blockingManager = prefs.blockingManager.get(),
|
||||
callControlInstalled = callControl.isAvailable(),
|
||||
siaInstalled = shouldIAnswer.isAvailable()
|
||||
)) {
|
||||
|
||||
init {
|
||||
disposables += prefs.blockingManager.asObservable()
|
||||
@@ -27,6 +33,18 @@ class BlockingManagerPresenter @Inject constructor(
|
||||
override fun bindIntents(view: BlockingManagerView) {
|
||||
super.bindIntents(view)
|
||||
|
||||
view.activityResumed()
|
||||
.map { callControl.isAvailable() }
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { available -> newState { copy(callControlInstalled = available) } }
|
||||
|
||||
view.activityResumed()
|
||||
.map { shouldIAnswer.isAvailable() }
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { available -> newState { copy(siaInstalled = available) } }
|
||||
|
||||
view.qksmsClicked()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
@@ -34,12 +52,23 @@ class BlockingManagerPresenter @Inject constructor(
|
||||
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_QKSMS)
|
||||
}
|
||||
|
||||
view.launchQksmsClicked()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
// TODO: This is a hack, get rid of it once we implement AndroidX navigation
|
||||
if (Build.VERSION.SDK_INT < 24) {
|
||||
view.openBlockedNumbers()
|
||||
} else {
|
||||
qksms.openSettings()
|
||||
}
|
||||
}
|
||||
|
||||
view.callControlClicked()
|
||||
.filter {
|
||||
val installed = context.isInstalled("com.flexaspect.android.everycallcontrol")
|
||||
val installed = callControl.isAvailable()
|
||||
if (!installed) {
|
||||
analytics.track("Install Call Control")
|
||||
navigator.showCallControl()
|
||||
navigator.installCallControl()
|
||||
}
|
||||
|
||||
val enabled = prefs.blockingManager.get() == Preferences.BLOCKING_MANAGER_CC
|
||||
@@ -52,16 +81,21 @@ class BlockingManagerPresenter @Inject constructor(
|
||||
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_CC)
|
||||
}
|
||||
|
||||
view.launchCallControlClicked()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
when (callControl.isAvailable()) {
|
||||
true -> callControl.openSettings()
|
||||
false -> navigator.installCallControl()
|
||||
}
|
||||
}
|
||||
|
||||
view.siaClicked()
|
||||
.filter {
|
||||
val installed = listOf("org.mistergroup.shouldianswer",
|
||||
"org.mistergroup.shouldianswerpersonal",
|
||||
"org.mistergroup.muzutozvednout")
|
||||
.any(context::isInstalled)
|
||||
|
||||
val installed = shouldIAnswer.isAvailable()
|
||||
if (!installed) {
|
||||
analytics.track("Install SIA")
|
||||
navigator.showSia()
|
||||
navigator.installSia()
|
||||
}
|
||||
|
||||
val enabled = prefs.blockingManager.get() == Preferences.BLOCKING_MANAGER_SIA
|
||||
@@ -72,6 +106,15 @@ class BlockingManagerPresenter @Inject constructor(
|
||||
analytics.setUserProperty("Blocking Manager", "SIA")
|
||||
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_SIA)
|
||||
}
|
||||
|
||||
view.launchSiaClicked()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
when (shouldIAnswer.isAvailable()) {
|
||||
true -> shouldIAnswer.openSettings()
|
||||
false -> navigator.installSia()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package com.moez.QKSMS.feature.blocking.manager
|
||||
|
||||
data class BlockingManagerState(
|
||||
val blockingManager: Int = 0
|
||||
val blockingManager: Int = 0,
|
||||
val callControlInstalled: Boolean = false,
|
||||
val siaInstalled: Boolean = false
|
||||
)
|
||||
|
||||
+6
@@ -5,8 +5,14 @@ import io.reactivex.Observable
|
||||
|
||||
interface BlockingManagerView : QkViewContract<BlockingManagerState> {
|
||||
|
||||
fun activityResumed(): Observable<*>
|
||||
fun qksmsClicked(): Observable<*>
|
||||
fun launchQksmsClicked(): Observable<*>
|
||||
fun callControlClicked(): Observable<*>
|
||||
fun launchCallControlClicked(): Observable<*>
|
||||
fun siaClicked(): Observable<*>
|
||||
fun launchSiaClicked(): Observable<*>
|
||||
|
||||
fun openBlockedNumbers()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user