forked from upstream-mirrors/quik
Show activity to prompt setting default sms app on launch
This commit is contained in:
@@ -6,6 +6,7 @@ import com.moez.QKSMS.presentation.common.widget.*
|
||||
import com.moez.QKSMS.presentation.compose.ComposeActivity
|
||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
||||
import com.moez.QKSMS.presentation.compose.DetailedChipView
|
||||
import com.moez.QKSMS.presentation.defaultsms.DefaultSmsActivity
|
||||
import com.moez.QKSMS.presentation.main.MainActivity
|
||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||
import com.moez.QKSMS.presentation.settings.SettingsActivity
|
||||
@@ -21,6 +22,7 @@ interface AppComponent {
|
||||
fun inject(application: QKApplication)
|
||||
|
||||
fun inject(activity: MainActivity)
|
||||
fun inject(activity: DefaultSmsActivity)
|
||||
fun inject(activity: ComposeActivity)
|
||||
fun inject(activity: SettingsActivity)
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import android.provider.Settings
|
||||
import com.moez.QKSMS.common.util.NotificationManager
|
||||
import com.moez.QKSMS.presentation.compose.ComposeActivity
|
||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
||||
import com.moez.QKSMS.presentation.defaultsms.DefaultSmsActivity
|
||||
import com.moez.QKSMS.presentation.defaultsms.DefaultSmsViewModel
|
||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||
import com.moez.QKSMS.presentation.settings.SettingsActivity
|
||||
import com.moez.QKSMS.presentation.settings.SettingsViewModel
|
||||
@@ -26,6 +28,11 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
fun showDefaultSmsActivity() {
|
||||
val intent = Intent(context, DefaultSmsActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showCompose(body: String? = null) {
|
||||
val intent = Intent(context, ComposeActivity::class.java)
|
||||
intent.putExtra("body", body)
|
||||
@@ -66,6 +73,10 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
MainViewModel()
|
||||
}
|
||||
|
||||
DefaultSmsViewModel::class.java -> {
|
||||
DefaultSmsViewModel()
|
||||
}
|
||||
|
||||
ComposeViewModel::class.java -> {
|
||||
val threadId = intent.getLongExtra("threadId", 0)
|
||||
val body = intent.getStringExtra("body") ?: ""
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.moez.QKSMS.presentation.defaultsms
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.provider.Telephony
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.di.appComponent
|
||||
import com.moez.QKSMS.presentation.common.base.QkActivity
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.default_sms_activity.*
|
||||
|
||||
class DefaultSmsActivity : QkActivity<DefaultSmsViewModel>(), DefaultSmsView {
|
||||
|
||||
override val viewModelClass = DefaultSmsViewModel::class
|
||||
override val skipIntent by lazy { skip.clicks() }
|
||||
override val nextIntent by lazy { next.clicks() }
|
||||
override val defaultSmsSetIntent: Subject<Boolean> = PublishSubject.create()
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.default_sms_activity)
|
||||
viewModel.bindView(this)
|
||||
|
||||
disposables += colors.background
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
defaultSmsSetIntent.onNext(Telephony.Sms.getDefaultSmsPackage(this) == packageName)
|
||||
}
|
||||
|
||||
override fun render(state: DefaultSmsState) {
|
||||
if (state.requestPermission) {
|
||||
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
|
||||
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
if (state.finished) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.moez.QKSMS.presentation.defaultsms
|
||||
|
||||
data class DefaultSmsState(
|
||||
val requestPermission: Boolean = false,
|
||||
val finished: Boolean = false
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.moez.QKSMS.presentation.defaultsms
|
||||
|
||||
import com.moez.QKSMS.presentation.common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface DefaultSmsView : QkView<DefaultSmsState> {
|
||||
|
||||
val skipIntent: Observable<*>
|
||||
val nextIntent: Observable<*>
|
||||
val defaultSmsSetIntent: Observable<Boolean>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.moez.QKSMS.presentation.defaultsms
|
||||
|
||||
import com.moez.QKSMS.presentation.common.base.QkViewModel
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
|
||||
class DefaultSmsViewModel : QkViewModel<DefaultSmsView, DefaultSmsState>(DefaultSmsState()) {
|
||||
|
||||
override fun bindView(view: DefaultSmsView) {
|
||||
super.bindView(view)
|
||||
|
||||
intents += view.skipIntent
|
||||
.subscribe { newState { it.copy(finished = true) } }
|
||||
|
||||
intents += view.nextIntent
|
||||
.subscribe { newState { it.copy(requestPermission = true) } }
|
||||
|
||||
intents += view.defaultSmsSetIntent
|
||||
.subscribe { isDefault -> newState { it.copy(requestPermission = false, finished = isDefault) } }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
||||
|
||||
if (Telephony.Sms.getDefaultSmsPackage(context) != context.packageName) {
|
||||
navigator.showDefaultSmsActivity()
|
||||
partialSync.execute(Unit)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user