mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Remove SetupActivity, perform setup in MainActivity
Squashed commit of the following: commit ff6ece72a60917ceec3ea1485901e8929e65bb43 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 9 01:50:33 2018 -0400 Remove default SMS UI from settings commit 1ce79ea756259268c4d2fcd8acbee3101fdbe019 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 9 01:45:33 2018 -0400 Remove SetupActivity, perform setup in MainActivity commit ccad342d2ab8a5346d63dab273ba9cadb2fa62c0 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon May 7 18:02:26 2018 -0400 Don't query ContentProvider without appropriate permission commit 527be2e5331ba0cbfd6f3375c12378105d282b0c Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon May 7 17:12:00 2018 -0400 Show non-blocking UI in MainActivity while syncing
This commit is contained in:
@@ -18,12 +18,14 @@
|
||||
*/
|
||||
package feature.main
|
||||
|
||||
import android.Manifest
|
||||
import android.app.AlertDialog
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.StateListDrawable
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v7.app.ActionBarDrawerToggle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.helper.ItemTouchHelper
|
||||
@@ -53,6 +55,7 @@ import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.drawer_view.*
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import repository.SyncRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
@@ -62,6 +65,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
@Inject lateinit var itemTouchCallback: ConversationItemTouchCallback
|
||||
|
||||
override val viewModelClass = MainViewModel::class
|
||||
override val activityResumedIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
||||
override val composeIntent by lazy { compose.clicks() }
|
||||
override val drawerOpenIntent: Observable<Boolean> by lazy {
|
||||
@@ -86,6 +90,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
override val confirmDeleteIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val swipeConversationIntent by lazy { itemTouchCallback.swipes }
|
||||
override val undoSwipeConversationIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val snackbarButtonIntent by lazy { snackbarButton.clicks() }
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val toggle by lazy { ActionBarDrawerToggle(this, drawerLayout, toolbar, 0, 0) }
|
||||
@@ -205,8 +210,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
toolbar.menu.findItem(R.id.block)?.isVisible = selectedConversations != 0
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = selectedConversations != 0
|
||||
|
||||
syncing.setVisible(state.syncing)
|
||||
synced.setVisible(!state.syncing)
|
||||
rateLayout.setVisible(state.showRating)
|
||||
|
||||
compose.setVisible(state.page is Inbox || state.page is Archived)
|
||||
@@ -255,12 +258,45 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
|
||||
if (drawerLayout.isDrawerOpen(Gravity.START) && !state.drawerOpen) drawerLayout.closeDrawer(Gravity.START)
|
||||
else if (!drawerLayout.isDrawerVisible(Gravity.START) && state.drawerOpen) drawerLayout.openDrawer(Gravity.START)
|
||||
|
||||
syncing.setVisible(state.syncing is SyncRepository.SyncProgress.Running)
|
||||
snackbar.setVisible(state.syncing is SyncRepository.SyncProgress.Idle
|
||||
&& !state.defaultSms || !state.smsPermission || !state.contactPermission)
|
||||
|
||||
when {
|
||||
!state.smsPermission -> {
|
||||
snackbarTitle.setText(R.string.main_permission_required)
|
||||
snackbarMessage.setText(R.string.main_permission_sms)
|
||||
snackbarButton.setText(R.string.main_permission_allow)
|
||||
}
|
||||
|
||||
!state.defaultSms -> {
|
||||
snackbarTitle.setText(R.string.main_default_sms_title)
|
||||
snackbarMessage.setText(R.string.main_default_sms_message)
|
||||
snackbarButton.setText(R.string.main_default_sms_change)
|
||||
}
|
||||
|
||||
!state.contactPermission -> {
|
||||
snackbarTitle.setText(R.string.main_permission_required)
|
||||
snackbarMessage.setText(R.string.main_permission_contacts)
|
||||
snackbarButton.setText(R.string.main_permission_allow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
activityResumedIntent.onNext(Unit)
|
||||
}
|
||||
|
||||
override fun showBackButton(show: Boolean) {
|
||||
toggle.onDrawerSlide(drawer, if (show) 1f else 0f)
|
||||
}
|
||||
|
||||
override fun requestPermissions() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS), 0)
|
||||
}
|
||||
|
||||
override fun clearSearch() {
|
||||
dismissKeyboard()
|
||||
toolbarSearch.text = null
|
||||
|
||||
@@ -20,13 +20,17 @@ package feature.main
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import model.Conversation
|
||||
import repository.SyncRepository
|
||||
|
||||
data class MainState(
|
||||
val hasError: Boolean = false,
|
||||
val page: MainPage = Inbox(),
|
||||
val drawerOpen: Boolean = false,
|
||||
val syncing: Boolean = false,
|
||||
val showRating: Boolean = false
|
||||
val showRating: Boolean = false,
|
||||
val syncing: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle(),
|
||||
val defaultSms: Boolean = false,
|
||||
val smsPermission: Boolean = false,
|
||||
val contactPermission: Boolean = false
|
||||
)
|
||||
|
||||
sealed class MainPage
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.reactivex.Observable
|
||||
|
||||
interface MainView : QkView<MainState> {
|
||||
|
||||
val activityResumedIntent: Observable<*>
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val composeIntent: Observable<Unit>
|
||||
val drawerOpenIntent: Observable<Boolean>
|
||||
@@ -35,8 +36,10 @@ interface MainView : QkView<MainState> {
|
||||
val confirmDeleteIntent: Observable<Unit>
|
||||
val swipeConversationIntent: Observable<Long>
|
||||
val undoSwipeConversationIntent: Observable<Unit>
|
||||
val snackbarButtonIntent: Observable<Unit>
|
||||
val backPressedIntent: Observable<Unit>
|
||||
|
||||
fun requestPermissions()
|
||||
fun clearSearch()
|
||||
fun clearSelection()
|
||||
fun showDeleteDialog()
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
*/
|
||||
package feature.main
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.provider.Telephony
|
||||
import android.support.v4.content.ContextCompat
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
@@ -36,14 +32,15 @@ import interactor.MarkArchived
|
||||
import interactor.MarkBlocked
|
||||
import interactor.MarkUnarchived
|
||||
import interactor.MigratePreferences
|
||||
import interactor.PartialSync
|
||||
import interactor.SyncMessages
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.realm.Realm
|
||||
import manager.PermissionManager
|
||||
import manager.RatingManager
|
||||
import model.SyncLog
|
||||
import repository.MessageRepository
|
||||
import repository.SyncRepository
|
||||
import util.Preferences
|
||||
import util.extensions.removeAccents
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -61,9 +58,11 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
@Inject lateinit var markBlocked: MarkBlocked
|
||||
@Inject lateinit var migratePreferences: MigratePreferences
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var partialSync: PartialSync
|
||||
@Inject lateinit var permissionManager: PermissionManager
|
||||
@Inject lateinit var prefs: Preferences
|
||||
@Inject lateinit var ratingManager: RatingManager
|
||||
@Inject lateinit var syncMessages: SyncMessages
|
||||
@Inject lateinit var syncRepository: SyncRepository
|
||||
|
||||
private val conversations by lazy { messageRepo.getConversations() }
|
||||
|
||||
@@ -78,37 +77,22 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
disposables += markArchived
|
||||
disposables += markUnarchived
|
||||
disposables += migratePreferences
|
||||
disposables += partialSync
|
||||
disposables += syncMessages
|
||||
|
||||
// If it's the first sync, reflect that in the ViewState
|
||||
disposables += Realm.getDefaultInstance()
|
||||
.where(SyncLog::class.java)
|
||||
.findAll()
|
||||
.asFlowable()
|
||||
.filter { it.isLoaded }
|
||||
.map { it.size == 0 }
|
||||
.doOnNext { if (it) partialSync.execute(Unit) }
|
||||
// Show the syncing UI
|
||||
disposables += syncRepository.syncProgress
|
||||
.distinctUntilChanged()
|
||||
.subscribe { syncing -> newState { it.copy(syncing = syncing) } }
|
||||
|
||||
|
||||
// Show the rating UI
|
||||
disposables += ratingManager.shouldShowRating
|
||||
.subscribe { show -> newState { it.copy(showRating = show) } }
|
||||
|
||||
// Migrate the preferences from 2.7.3 if necessary
|
||||
|
||||
// Migrate the preferences from 2.7.3
|
||||
migratePreferences.execute(Unit)
|
||||
|
||||
val isNotDefaultSms = Telephony.Sms.getDefaultSmsPackage(context) != context.packageName
|
||||
val hasSmsPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED
|
||||
val hasContactPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
if (isNotDefaultSms) {
|
||||
partialSync.execute(Unit)
|
||||
}
|
||||
|
||||
if (isNotDefaultSms || !hasSmsPermission || !hasContactPermission) {
|
||||
navigator.showSetupActivity()
|
||||
}
|
||||
|
||||
ratingManager.addSession()
|
||||
markAllSeen.execute(Unit)
|
||||
}
|
||||
@@ -116,14 +100,43 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
override fun bindView(view: MainView) {
|
||||
super.bindView(view)
|
||||
|
||||
if (!permissionManager.hasSmsAndContacts()) {
|
||||
view.requestPermissions()
|
||||
}
|
||||
|
||||
// If the default SMS state or permission states change, update the ViewState
|
||||
Observables.combineLatest(
|
||||
view.activityResumedIntent.map { permissionManager.isDefaultSms() }.distinctUntilChanged(),
|
||||
view.activityResumedIntent.map { permissionManager.hasSms() }.distinctUntilChanged(),
|
||||
view.activityResumedIntent.map { permissionManager.hasContacts() }.distinctUntilChanged(),
|
||||
{ defaultSms, smsPermission, contactPermission ->
|
||||
newState { it.copy(defaultSms = defaultSms, smsPermission = smsPermission, contactPermission = contactPermission) }
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// If the SMS permission state changes from false to true, sync messages
|
||||
view.activityResumedIntent
|
||||
.map { permissionManager.hasSms() }
|
||||
.distinctUntilChanged()
|
||||
.skip(1)
|
||||
.filter { hasSms -> hasSms }
|
||||
.take(1)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
syncMessages.execute(Unit)
|
||||
if (!permissionManager.isDefaultSms()) {
|
||||
navigator.showDefaultSmsDialog()
|
||||
}
|
||||
}
|
||||
|
||||
view.queryChangedIntent
|
||||
.debounce(200, TimeUnit.MILLISECONDS)
|
||||
.map { query -> query.removeAccents() }
|
||||
.withLatestFrom(state, { query, state ->
|
||||
if (state.page is Inbox) {
|
||||
val filteredConversations = if (query.isEmpty()) conversations
|
||||
else conversations
|
||||
.map { conversations -> conversations.filter { conversationFilter.filter(it, query) } }
|
||||
else conversations.map { conversations -> conversations.filter { conversationFilter.filter(it, query) } }
|
||||
|
||||
val page = state.page.copy(showClearButton = query.isNotEmpty(), data = filteredConversations)
|
||||
newState { it.copy(page = page) }
|
||||
@@ -260,6 +273,17 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnarchived.execute(listOf(threadId)) }
|
||||
|
||||
view.snackbarButtonIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
!state.smsPermission -> view.requestPermissions()
|
||||
!state.defaultSms -> navigator.showDefaultSmsDialog()
|
||||
!state.contactPermission -> view.requestPermissions()
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.backPressedIntent
|
||||
.withLatestFrom(state, { _, state ->
|
||||
when {
|
||||
|
||||
@@ -105,11 +105,6 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
||||
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
|
||||
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
||||
|
||||
defaultSms.summary = getString(when (state.isDefaultSmsApp) {
|
||||
true -> R.string.settings_default_sms_summary_true
|
||||
else -> R.string.settings_default_sms_summary_false
|
||||
})
|
||||
|
||||
themePreview.setBackgroundTint(state.theme)
|
||||
night.summary = state.nightModeSummary
|
||||
nightModeDialog.adapter.selectedItem = state.nightModeId
|
||||
|
||||
@@ -22,7 +22,6 @@ import util.Preferences
|
||||
|
||||
data class SettingsState(
|
||||
val syncing: Boolean = false,
|
||||
val isDefaultSmsApp: Boolean = false,
|
||||
val theme: Int = 0,
|
||||
val nightModeSummary: String = "",
|
||||
val nightModeId: Int = Preferences.NIGHT_MODE_OFF,
|
||||
|
||||
@@ -29,7 +29,7 @@ import common.util.Colors
|
||||
import common.util.DateFormatter
|
||||
import common.util.NightModeManager
|
||||
import injection.appComponent
|
||||
import interactor.FullSync
|
||||
import interactor.SyncMessages
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import timber.log.Timber
|
||||
@@ -46,17 +46,11 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var nightModeManager: NightModeManager
|
||||
@Inject lateinit var prefs: Preferences
|
||||
@Inject lateinit var fullSync: FullSync
|
||||
@Inject lateinit var syncMessages: SyncMessages
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
disposables += prefs.defaultSms
|
||||
.asObservable()
|
||||
.subscribe { isDefaultSmsApp ->
|
||||
newState { it.copy(isDefaultSmsApp = isDefaultSmsApp) }
|
||||
}
|
||||
|
||||
disposables += colors.theme
|
||||
.subscribe { color -> newState { it.copy(theme = color) } }
|
||||
|
||||
@@ -108,7 +102,7 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
newState { it.copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
}
|
||||
|
||||
disposables += fullSync
|
||||
disposables += syncMessages
|
||||
}
|
||||
|
||||
override fun bindView(view: SettingsView) {
|
||||
@@ -120,8 +114,6 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
Timber.v("Preference click: ${context.resources.getResourceName(it.id)}")
|
||||
|
||||
when (it.id) {
|
||||
R.id.defaultSms -> navigator.showDefaultSmsDialog()
|
||||
|
||||
R.id.theme -> navigator.showThemePicker()
|
||||
|
||||
R.id.night -> view.showNightModeDialog()
|
||||
@@ -158,7 +150,7 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
|
||||
R.id.sync -> {
|
||||
newState { it.copy(syncing = true) }
|
||||
fullSync.execute(Unit, {
|
||||
syncMessages.execute(Unit, {
|
||||
newState { it.copy(syncing = false) }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package feature.setup
|
||||
|
||||
import android.Manifest
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import injection.appComponent
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.setup_activity.*
|
||||
import common.Navigator
|
||||
import common.base.QkThemedActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class SetupActivity : QkThemedActivity<SetupViewModel>(), SetupView {
|
||||
|
||||
override val viewModelClass = SetupViewModel::class
|
||||
override val activityResumedIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val skipIntent by lazy { skip.clicks() }
|
||||
override val nextIntent by lazy { next.clicks() }
|
||||
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.setup_activity)
|
||||
viewModel.bindView(this)
|
||||
|
||||
colors.background
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
activityResumedIntent.onNext(Unit)
|
||||
}
|
||||
|
||||
override fun render(state: SetupState) {
|
||||
}
|
||||
|
||||
override fun requestDefaultSms() {
|
||||
navigator.showDefaultSmsDialog()
|
||||
}
|
||||
|
||||
override fun requestPermissions() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS), 0)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package feature.setup
|
||||
|
||||
class SetupState
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package feature.setup
|
||||
|
||||
import io.reactivex.Observable
|
||||
import common.base.QkView
|
||||
import feature.setup.SetupState
|
||||
|
||||
interface SetupView : QkView<SetupState> {
|
||||
|
||||
val activityResumedIntent: Observable<*>
|
||||
val skipIntent: Observable<*>
|
||||
val nextIntent: Observable<*>
|
||||
|
||||
fun requestDefaultSms()
|
||||
fun requestPermissions()
|
||||
fun finish()
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package feature.setup
|
||||
|
||||
import android.content.Context
|
||||
import android.provider.Telephony
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import injection.appComponent
|
||||
import manager.PermissionManager
|
||||
import common.base.QkViewModel
|
||||
import feature.setup.SetupState
|
||||
import feature.setup.SetupView
|
||||
import javax.inject.Inject
|
||||
|
||||
class SetupViewModel : QkViewModel<SetupView, SetupState>(SetupState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var permissions: PermissionManager
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun bindView(view: SetupView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.activityResumedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val isDefault = Telephony.Sms.getDefaultSmsPackage(context) == context.packageName
|
||||
|
||||
if (!permissions.hasSmsAndContacts()) view.requestPermissions()
|
||||
else if (isDefault) view.finish()
|
||||
}
|
||||
|
||||
view.skipIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.finish() }
|
||||
|
||||
view.nextIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.requestDefaultSms() }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user