Migrate Backup screen to Conductor

This commit is contained in:
Moez Bhatti
2018-08-22 17:09:43 -04:00
parent 10b37d4389
commit b7605cd362
8 changed files with 192 additions and 193 deletions
@@ -18,84 +18,35 @@
*/
package com.moez.QKSMS.feature.backup
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.jakewharton.rxbinding2.view.clicks
import com.bluelinelabs.conductor.Conductor
import com.bluelinelabs.conductor.Router
import com.bluelinelabs.conductor.RouterTransaction
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkThemedActivity
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import dagger.android.AndroidInjection
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.backup_controller.*
import javax.inject.Inject
import kotlinx.android.synthetic.main.container_activity.*
class BackupActivity : QkThemedActivity(), BackupView {
class BackupActivity : QkThemedActivity() {
companion object {
private const val REQUEST_CODE = 427
}
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[BackupViewModel::class.java] }
private val restoreFileSubject: Subject<Uri> = PublishSubject.create()
private lateinit var router: Router
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.backup_controller)
setTitle(R.string.backup_title)
showBackButton(true)
viewModel.bindView(this)
setContentView(R.layout.container_activity)
colors.theme().let { theme ->
fab.setBackgroundTint(theme.theme)
fabIcon.setTint(theme.textPrimary)
fabLabel.setTextColor(theme.textPrimary)
router = Conductor.attachRouter(this, container, savedInstanceState)
if (!router.hasRootController()) {
router.setRoot(RouterTransaction.with(BackupController()))
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
data?.data?.run(restoreFileSubject::onNext)
override fun onBackPressed() {
if (!router.handleBack()) {
super.onBackPressed()
}
}
override fun render(state: BackupState) {
restore.isEnabled = state.upgraded
fabIcon.setImageResource(when (state.upgraded) {
true -> R.drawable.ic_file_upload_black_24dp
false -> R.drawable.ic_star_black_24dp
})
fabLabel.setText(when (state.upgraded) {
true -> R.string.backup_now
false -> R.string.title_qksms_plus
})
}
override fun restoreClicks(): Observable<*> = restore.clicks()
override fun restoreFileSelected(): Observable<Uri> = restoreFileSubject
override fun fabClicks(): Observable<*> = fab.clicks()
override fun selectFile() {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "*/*"
startActivityForResult(Intent.createChooser(intent, "Choose directory"), REQUEST_CODE)
}
}
@@ -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 com.moez.QKSMS.feature.backup
import androidx.lifecycle.ViewModel
import com.moez.QKSMS.injection.ViewModelKey
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
@Module
class BackupActivityModule {
@Provides
@IntoMap
@ViewModelKey(BackupViewModel::class)
fun providePlusViewModel(viewModel: BackupViewModel): ViewModel = viewModel
}
@@ -0,0 +1,103 @@
/*
* 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 com.moez.QKSMS.feature.backup
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.view.View
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkController
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.injection.appComponent
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.backup_controller.*
import javax.inject.Inject
class BackupController : QkController<BackupView, BackupState, BackupPresenter>(), BackupView {
companion object {
private const val REQUEST_CODE = 427
}
@Inject override lateinit var presenter: BackupPresenter
private val restoreFileSubject: Subject<Uri> = PublishSubject.create()
init {
appComponent.inject(this)
layoutRes = R.layout.backup_controller
}
override fun onAttach(view: View) {
super.onAttach(view)
presenter.bindIntents(this)
setTitle(R.string.backup_title)
showBackButton(true)
}
override fun onViewCreated() {
super.onViewCreated()
themedActivity?.colors?.theme()?.let { theme ->
fab.setBackgroundTint(theme.theme)
fabIcon.setTint(theme.textPrimary)
fabLabel.setTextColor(theme.textPrimary)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
data?.data?.run(restoreFileSubject::onNext)
}
}
override fun render(state: BackupState) {
restore.isEnabled = state.upgraded
fabIcon.setImageResource(when (state.upgraded) {
true -> R.drawable.ic_file_upload_black_24dp
false -> R.drawable.ic_star_black_24dp
})
fabLabel.setText(when (state.upgraded) {
true -> R.string.backup_now
false -> R.string.title_qksms_plus
})
}
override fun restoreClicks(): Observable<*> = restore.clicks()
override fun restoreFileSelected(): Observable<Uri> = restoreFileSubject
override fun fabClicks(): Observable<*> = fab.clicks()
override fun selectFile() {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "*/*"
startActivityForResult(Intent.createChooser(intent, null), REQUEST_CODE)
}
}
@@ -19,26 +19,25 @@
package com.moez.QKSMS.feature.backup
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.androidxcompat.scope
import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.common.base.QkPresenter
import com.moez.QKSMS.common.util.BillingManager
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import javax.inject.Inject
class BackupViewModel @Inject constructor(
class BackupPresenter @Inject constructor(
private val billingManager: BillingManager,
private val navigator: Navigator
) : QkViewModel<BackupView, BackupState>(BackupState()) {
) : QkPresenter<BackupView, BackupState>(BackupState()) {
init {
disposables += billingManager.upgradeStatus
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
}
override fun bindView(view: BackupView) {
super.bindView(view)
override fun bindIntents(view: BackupView) {
super.bindIntents(view)
view.restoreClicks()
.autoDisposable(view.scope())
@@ -19,10 +19,10 @@
package com.moez.QKSMS.feature.backup
import android.net.Uri
import com.moez.QKSMS.common.base.QkView
import com.moez.QKSMS.common.base.QkViewContract
import io.reactivex.Observable
interface BackupView : QkView<BackupState> {
interface BackupView : QkViewContract<BackupState> {
fun restoreClicks(): Observable<*>
fun restoreFileSelected(): Observable<Uri>
@@ -26,6 +26,7 @@ import com.moez.QKSMS.common.widget.PreferenceView
import com.moez.QKSMS.common.widget.QkEditText
import com.moez.QKSMS.common.widget.QkSwitch
import com.moez.QKSMS.common.widget.QkTextView
import com.moez.QKSMS.feature.backup.BackupController
import com.moez.QKSMS.feature.compose.DetailedChipView
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent
import com.moez.QKSMS.feature.settings.SettingsController
@@ -56,6 +57,7 @@ interface AppComponent {
fun inject(application: QKApplication)
fun inject(controller: AboutController)
fun inject(controller: BackupController)
fun inject(controller: SettingsController)
fun inject(controller: SwipeActionsController)
@@ -19,7 +19,6 @@
package com.moez.QKSMS.injection.android
import com.moez.QKSMS.feature.backup.BackupActivity
import com.moez.QKSMS.feature.backup.BackupActivityModule
import com.moez.QKSMS.feature.blocked.BlockedActivity
import com.moez.QKSMS.feature.blocked.BlockedActivityModule
import com.moez.QKSMS.feature.compose.ComposeActivity
@@ -54,7 +53,7 @@ abstract class ActivityBuilderModule {
abstract fun bindPlusActivity(): PlusActivity
@ActivityScope
@ContributesAndroidInjector(modules = [BackupActivityModule::class])
@ContributesAndroidInjector(modules = [])
abstract fun bindBackupActivity(): BackupActivity
@ActivityScope
@@ -17,106 +17,86 @@
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<include layout="@layout/toolbar" />
<FrameLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/backup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_history_black_24dp"
app:title="@string/backup_last"
tools:summary="@string/backup_never" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/restore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_file_download_black_24dp"
app:summary="@string/backup_restore_summary"
app:title="@string/backup_restore_title" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/divider" />
<com.moez.QKSMS.common.widget.QkTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:text="@string/backup_disclaimer"
android:textColor="?android:attr/textColorTertiary"
app:textSize="secondary" />
</LinearLayout>
</ScrollView>
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingTop="8dp">
<LinearLayout
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:background="@drawable/rounded_rectangle_24dp"
android:elevation="4dp"
android:gravity="center"
tools:backgroundTint="@color/tools_theme">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/fabIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_star_black_24dp"
tools:tint="@color/textPrimaryDark" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/backup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_history_black_24dp"
app:title="@string/backup_last"
tools:summary="@string/backup_never" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/restore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_file_download_black_24dp"
app:summary="@string/backup_restore_summary"
app:title="@string/backup_restore_title" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/divider" />
<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/fabLabel"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="@string/title_qksms_plus"
android:textColor="@color/textPrimaryDark"
android:textStyle="bold"
app:textSize="primary" />
android:layout_margin="24dp"
android:text="@string/backup_disclaimer"
android:textColor="?android:attr/textColorTertiary"
app:textSize="secondary" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="@drawable/ab_shadow" />
</ScrollView>
</FrameLayout>
<LinearLayout
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:background="@drawable/rounded_rectangle_24dp"
android:elevation="4dp"
android:gravity="center"
tools:backgroundTint="@color/tools_theme">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/divider" />
<ImageView
android:id="@+id/fabIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_star_black_24dp"
tools:tint="@color/textPrimaryDark" />
</LinearLayout>
<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/fabLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="@string/title_qksms_plus"
android:textColor="@color/textPrimaryDark"
android:textStyle="bold"
app:textSize="primary" />
</LinearLayout>
</FrameLayout>