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, {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<string name="drawer_blocked">Blocked</string>
|
||||
<string name="drawer_settings">Settings</string>
|
||||
|
||||
<string name="settings_default_sms_title">Default SMS app</string>
|
||||
<string name="settings_sync_title">Sync messages</string>
|
||||
<string name="settings_sync_summary">Re-sync your messages with the native Android SMS database</string>
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<Preference
|
||||
android:key="defaultSms"
|
||||
android:title="@string/settings_default_sms_title" />
|
||||
|
||||
<Preference
|
||||
android:key="sync"
|
||||
android:summary="@string/settings_sync_summary"
|
||||
|
||||
Reference in New Issue
Block a user