Add ability to change default SMS app in settings

This commit is contained in:
Moez Bhatti
2017-11-01 15:11:00 -07:00
parent 8994c15220
commit 8a313f0269
3 changed files with 17 additions and 0 deletions
@@ -1,5 +1,8 @@
package com.moez.QKSMS.presentation.settings
import android.content.Context
import android.content.Intent
import android.provider.Telephony
import com.moez.QKSMS.common.di.AppComponentManager
import com.moez.QKSMS.domain.interactor.SyncConversations
import com.moez.QKSMS.presentation.base.QkViewModel
@@ -8,6 +11,7 @@ import javax.inject.Inject
class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
@Inject lateinit var context: Context
@Inject lateinit var syncConversations: SyncConversations
init {
@@ -21,6 +25,14 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
Timber.v("Preference click: ${it.key}")
when (it.key) {
"defaultSms" -> {
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
if (Telephony.Sms.getDefaultSmsPackage(context) != context.packageName) {
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, context.packageName)
}
context.startActivity(intent)
}
"sync" -> {
newState { it.copy(syncing = true) }
syncConversations.execute(Unit, {