Create UI for backup activity

This commit is contained in:
Moez Bhatti
2018-08-22 15:16:04 -04:00
parent cbffef5ca0
commit 10b37d4389
19 changed files with 546 additions and 7 deletions
@@ -30,6 +30,7 @@ import android.provider.Settings
import android.provider.Telephony
import android.view.View
import com.moez.QKSMS.BuildConfig
import com.moez.QKSMS.feature.backup.BackupActivity
import com.moez.QKSMS.feature.blocked.BlockedActivity
import com.moez.QKSMS.feature.compose.ComposeActivity
import com.moez.QKSMS.feature.conversationinfo.ConversationInfoActivity
@@ -126,6 +127,11 @@ class Navigator @Inject constructor(
from.startActivity(intent, options.toBundle())
}
fun showBackup() {
analyticsManager.track("Viewed Backup")
startActivity(Intent(context, BackupActivity::class.java))
}
fun showScheduled() {
analyticsManager.track("Viewed Scheduled")
val intent = Intent(context, ScheduledActivity::class.java)
@@ -30,7 +30,7 @@ import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.common.util.extensions.forEach
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.injection.appComponent
import com.uber.autodispose.android.scope
import com.uber.autodispose.android.ViewScopeProvider
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
@@ -97,7 +97,7 @@ class PagerTitleView @JvmOverloads constructor(context: Context, attrs: Attribut
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
}
.autoDisposable(scope())
.autoDisposable(ViewScopeProvider.from(this))
.subscribe { colorStateList ->
childCount.forEach { index ->
(getChildAt(index) as? TextView)?.setTextColor(colorStateList)
@@ -0,0 +1,101 @@
/*
* 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.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.jakewharton.rxbinding2.view.clicks
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
class BackupActivity : QkThemedActivity(), BackupView {
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()
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)
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, "Choose directory"), REQUEST_CODE)
}
}
@@ -0,0 +1,35 @@
/*
* 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,24 @@
/*
* 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
data class BackupState(
val upgraded: Boolean = false,
val lastBackup: Long = 0
)
@@ -0,0 +1,33 @@
/*
* 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.net.Uri
import com.moez.QKSMS.common.base.QkView
import io.reactivex.Observable
interface BackupView : QkView<BackupState> {
fun restoreClicks(): Observable<*>
fun restoreFileSelected(): Observable<Uri>
fun fabClicks(): Observable<*>
fun selectFile()
}
@@ -0,0 +1,62 @@
/*
* 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 com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.androidxcompat.scope
import com.moez.QKSMS.common.base.QkViewModel
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(
private val billingManager: BillingManager,
private val navigator: Navigator
) : QkViewModel<BackupView, BackupState>(BackupState()) {
init {
disposables += billingManager.upgradeStatus
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
}
override fun bindView(view: BackupView) {
super.bindView(view)
view.restoreClicks()
.autoDisposable(view.scope())
.subscribe { view.selectFile() }
view.restoreFileSelected()
.autoDisposable(view.scope())
.subscribe()
view.fabClicks()
.withLatestFrom(billingManager.upgradeStatus) { _, upgraded -> upgraded }
.autoDisposable(view.scope())
.subscribe { upgraded ->
when (upgraded) {
true -> navigator.showQksmsPlusActivity("backup_fab")
false -> navigator.showQksmsPlusActivity("backup_fab")
}
}
}
}
@@ -81,6 +81,7 @@ class MainActivity : QkThemedActivity(), MainView {
Observable.merge(listOf(
inbox.clicks().map { DrawerItem.INBOX },
archived.clicks().map { DrawerItem.ARCHIVED },
backup.clicks().map { DrawerItem.BACKUP },
scheduled.clicks().map { DrawerItem.SCHEDULED },
blocking.clicks().map { DrawerItem.BLOCKING },
settings.clicks().map { DrawerItem.SETTINGS },
@@ -141,8 +142,10 @@ class MainActivity : QkThemedActivity(), MainView {
}
// Miscellaneous views
plusBadge.setBackgroundTint(theme.theme)
plusBadge.setTextColor(theme.textPrimary)
listOf(plusBadge1, plusBadge2).forEach { badge ->
badge.setBackgroundTint(theme.theme)
badge.setTextColor(theme.textPrimary)
}
syncingProgress.indeterminateTintList = ColorStateList.valueOf(theme.theme)
plusIcon.setTint(theme.theme)
rateIcon.setTint(theme.theme)
@@ -193,7 +196,9 @@ class MainActivity : QkThemedActivity(), MainView {
toolbar.menu.findItem(R.id.unread)?.isVisible = !markRead && selectedConversations != 0
toolbar.menu.findItem(R.id.block)?.isVisible = selectedConversations != 0
plusBadge.isVisible = drawerBadgesExperiment.variant && !state.upgraded
listOf(plusBadge1, plusBadge2).forEach { badge ->
badge.isVisible = drawerBadgesExperiment.variant && !state.upgraded
}
plus.isVisible = state.upgraded
plusBanner.isVisible = !state.upgraded
rateLayout.setVisible(state.showRating)
@@ -48,4 +48,4 @@ interface MainView : QkView<MainState> {
}
enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKING, SETTINGS, PLUS, HELP, INVITE }
enum class DrawerItem { INBOX, ARCHIVED, BACKUP, SCHEDULED, BLOCKING, SETTINGS, PLUS, HELP, INVITE }
@@ -192,6 +192,7 @@ class MainViewModel @Inject constructor(
view.drawerItemIntent
.doOnNext { newState { copy(drawerOpen = false) } }
.doOnNext { if (it == DrawerItem.BACKUP) navigator.showBackup() }
.doOnNext { if (it == DrawerItem.SCHEDULED) navigator.showScheduled() }
.doOnNext { if (it == DrawerItem.BLOCKING) navigator.showBlockedConversations() }
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
@@ -18,6 +18,8 @@
*/
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
@@ -51,6 +53,10 @@ abstract class ActivityBuilderModule {
@ContributesAndroidInjector(modules = [PlusActivityModule::class])
abstract fun bindPlusActivity(): PlusActivity
@ActivityScope
@ContributesAndroidInjector(modules = [BackupActivityModule::class])
abstract fun bindBackupActivity(): BackupActivity
@ActivityScope
@ContributesAndroidInjector(modules = [ComposeActivityModule::class])
abstract fun bindComposeActivity(): ComposeActivity