forked from upstream-mirrors/quik
Add ability to change default SMS app in settings
This commit is contained in:
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user