forked from upstream-mirrors/quik
Show hint for Default SMS preference
This commit is contained in:
@@ -40,6 +40,7 @@ dependencies {
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
compile 'com.android.support:design:26.1.0'
|
||||
compile 'com.bugsnag:bugsnag-android:4.1.1'
|
||||
compile 'com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC3'
|
||||
compile 'com.github.bumptech.glide:glide:4.3.0'
|
||||
compile 'com.google.android:flexbox:0.3.1'
|
||||
compile "com.google.dagger:dagger:2.11"
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.moez.QKSMS.common.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.preference.PreferenceManager
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
@@ -15,4 +17,11 @@ class AppModule(private var application: Application) {
|
||||
return application
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRxPreferences(context: Context) : RxSharedPreferences {
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return RxSharedPreferences.create(preferences)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import kotlinx.android.synthetic.main.settings_activity.*
|
||||
class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
||||
|
||||
override val viewModelClass = SettingsViewModel::class
|
||||
override val preferencesAddedIntent by lazy { fragment.preferencesAdded }
|
||||
override val preferenceClickIntent by lazy { fragment.preferenceClicks }
|
||||
override val preferenceChangeIntent by lazy { fragment.preferenceChanges }
|
||||
|
||||
@@ -39,6 +40,11 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
||||
override fun render(state: SettingsState) {
|
||||
if (progressDialog.isShowing && !state.syncing) progressDialog.hide()
|
||||
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
||||
|
||||
fragment.preferenceManager?.findPreference("defaultSms")?.setSummary(when (state.isDefaultSmsApp) {
|
||||
true -> R.string.settings_default_sms_summary_true
|
||||
else -> R.string.settings_default_sms_summary_false
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,20 @@ import android.preference.Preference
|
||||
import android.preference.PreferenceFragment
|
||||
import com.moez.QKSMS.R
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
class SettingsFragment : PreferenceFragment() {
|
||||
|
||||
val preferenceClicks: PublishSubject<Preference> = PublishSubject.create()
|
||||
val preferenceChanges: PublishSubject<PreferenceChange> = PublishSubject.create()
|
||||
val preferencesAdded: Subject<Unit> = PublishSubject.create()
|
||||
val preferenceClicks: Subject<Preference> = PublishSubject.create()
|
||||
val preferenceChanges: Subject<PreferenceChange> = PublishSubject.create()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
addPreferencesFromResource(R.xml.settings)
|
||||
|
||||
preferencesAdded.onNext(Unit)
|
||||
|
||||
val clickListener = Preference.OnPreferenceClickListener {
|
||||
preferenceClicks.onNext(it)
|
||||
true
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.moez.QKSMS.presentation.settings
|
||||
|
||||
data class SettingsState(
|
||||
val syncing: Boolean = false
|
||||
val syncing: Boolean = false,
|
||||
val isDefaultSmsApp: Boolean = false
|
||||
)
|
||||
@@ -6,6 +6,7 @@ import io.reactivex.Observable
|
||||
|
||||
interface SettingsView : QkView<SettingsState> {
|
||||
|
||||
val preferencesAddedIntent: Observable<Unit>
|
||||
val preferenceClickIntent: Observable<Preference>
|
||||
val preferenceChangeIntent: Observable<PreferenceChange>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.moez.QKSMS.presentation.settings
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.Telephony
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.FullSync
|
||||
import com.moez.QKSMS.presentation.base.QkViewModel
|
||||
@@ -13,17 +14,29 @@ import javax.inject.Inject
|
||||
class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var prefs: RxSharedPreferences
|
||||
@Inject lateinit var fullSync: FullSync
|
||||
|
||||
init {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
|
||||
disposables += fullSync
|
||||
|
||||
disposables += prefs.getBoolean("defaultSms")
|
||||
.asObservable()
|
||||
.subscribe { isDefaultSmsApp ->
|
||||
newState { it.copy(isDefaultSmsApp = isDefaultSmsApp) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun bindView(view: SettingsView) {
|
||||
super.bindView(view)
|
||||
|
||||
// Force update the view once we receive notification that the fragment's preference view has been created
|
||||
intents += view.preferencesAddedIntent.subscribe {
|
||||
newState { it.copy() }
|
||||
}
|
||||
|
||||
intents += view.preferenceClickIntent.subscribe {
|
||||
Timber.v("Preference click: ${it.key}")
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.Telephony
|
||||
import android.support.annotation.RequiresApi
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.domain.interactor.PartialSync
|
||||
import javax.inject.Inject
|
||||
@@ -13,12 +14,15 @@ import javax.inject.Inject
|
||||
class DefaultSmsChangedReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var partialSync: PartialSync
|
||||
@Inject lateinit var prefs: RxSharedPreferences
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
|
||||
val isDefaultSmsApp = intent.getBooleanExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false)
|
||||
prefs.getBoolean("defaultSms").set(isDefaultSmsApp)
|
||||
|
||||
if (isDefaultSmsApp) {
|
||||
val pendingResult = goAsync()
|
||||
partialSync.execute(Unit, { pendingResult.finish() })
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
<string name="drawer_settings">Settings</string>
|
||||
|
||||
<string name="settings_default_sms_title">Default SMS app</string>
|
||||
<string name="settings_default_sms_summary_true">QKSMS is your default SMS app</string>
|
||||
<string name="settings_default_sms_summary_false">Set QKSMS as your 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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user