From 10b37d43891eaa6d8cacb6657726b478f591fee1 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Wed, 22 Aug 2018 15:16:04 -0400 Subject: [PATCH] Create UI for backup activity --- presentation/src/main/AndroidManifest.xml | 1 + .../java/com/moez/QKSMS/common/Navigator.kt | 6 + .../QKSMS/common/widget/PagerTitleView.kt | 4 +- .../QKSMS/feature/backup/BackupActivity.kt | 101 +++++++++++++++ .../feature/backup/BackupActivityModule.kt | 35 +++++ .../moez/QKSMS/feature/backup/BackupState.kt | 24 ++++ .../moez/QKSMS/feature/backup/BackupView.kt | 33 +++++ .../QKSMS/feature/backup/BackupViewModel.kt | 62 +++++++++ .../moez/QKSMS/feature/main/MainActivity.kt | 11 +- .../com/moez/QKSMS/feature/main/MainView.kt | 2 +- .../moez/QKSMS/feature/main/MainViewModel.kt | 1 + .../android/ActivityBuilderModule.kt | 6 + .../drawable/ic_file_download_black_24dp.xml | 27 ++++ .../drawable/ic_file_upload_black_24dp.xml | 27 ++++ .../res/drawable/ic_history_black_24dp.xml | 27 ++++ .../drawable/ic_import_export_black_24dp.xml | 27 ++++ .../src/main/res/layout/backup_controller.xml | 122 ++++++++++++++++++ .../src/main/res/layout/drawer_view.xml | 29 ++++- presentation/src/main/res/values/strings.xml | 8 ++ 19 files changed, 546 insertions(+), 7 deletions(-) create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivity.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivityModule.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupState.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupView.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupViewModel.kt create mode 100644 presentation/src/main/res/drawable/ic_file_download_black_24dp.xml create mode 100644 presentation/src/main/res/drawable/ic_file_upload_black_24dp.xml create mode 100644 presentation/src/main/res/drawable/ic_history_black_24dp.xml create mode 100644 presentation/src/main/res/drawable/ic_import_export_black_24dp.xml create mode 100644 presentation/src/main/res/layout/backup_controller.xml diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml index 8b5a6619..6f9e74fe 100644 --- a/presentation/src/main/AndroidManifest.xml +++ b/presentation/src/main/AndroidManifest.xml @@ -93,6 +93,7 @@ android:theme="@style/AppThemeLightDialog" /> + diff --git a/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt b/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt index 6c52187e..e51f6663 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt @@ -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) diff --git a/presentation/src/main/java/com/moez/QKSMS/common/widget/PagerTitleView.kt b/presentation/src/main/java/com/moez/QKSMS/common/widget/PagerTitleView.kt index 90343472..870752b4 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/widget/PagerTitleView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/widget/PagerTitleView.kt @@ -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) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivity.kt new file mode 100644 index 00000000..1da75461 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivity.kt @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +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 = 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 = 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) + } + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivityModule.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivityModule.kt new file mode 100644 index 00000000..3b5e6d41 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupActivityModule.kt @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +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 + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupState.kt new file mode 100644 index 00000000..08865f6a --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupState.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.backup + +data class BackupState( + val upgraded: Boolean = false, + val lastBackup: Long = 0 +) \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupView.kt new file mode 100644 index 00000000..6b6809bc --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupView.kt @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.backup + +import android.net.Uri +import com.moez.QKSMS.common.base.QkView +import io.reactivex.Observable + +interface BackupView : QkView { + + fun restoreClicks(): Observable<*> + fun restoreFileSelected(): Observable + fun fabClicks(): Observable<*> + + fun selectFile() + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupViewModel.kt new file mode 100644 index 00000000..4169d834 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupViewModel.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +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(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") + } + } + } + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt index c747d093..1da3a5ed 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt @@ -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) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt index 4bf6bcc7..f14d9f5b 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainView.kt @@ -48,4 +48,4 @@ interface MainView : QkView { } -enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKING, SETTINGS, PLUS, HELP, INVITE } \ No newline at end of file +enum class DrawerItem { INBOX, ARCHIVED, BACKUP, SCHEDULED, BLOCKING, SETTINGS, PLUS, HELP, INVITE } \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt index fbb85cd4..d7b90921 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/main/MainViewModel.kt @@ -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() } diff --git a/presentation/src/main/java/com/moez/QKSMS/injection/android/ActivityBuilderModule.kt b/presentation/src/main/java/com/moez/QKSMS/injection/android/ActivityBuilderModule.kt index 13fbc742..b89740b0 100644 --- a/presentation/src/main/java/com/moez/QKSMS/injection/android/ActivityBuilderModule.kt +++ b/presentation/src/main/java/com/moez/QKSMS/injection/android/ActivityBuilderModule.kt @@ -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 diff --git a/presentation/src/main/res/drawable/ic_file_download_black_24dp.xml b/presentation/src/main/res/drawable/ic_file_download_black_24dp.xml new file mode 100644 index 00000000..7e5961d3 --- /dev/null +++ b/presentation/src/main/res/drawable/ic_file_download_black_24dp.xml @@ -0,0 +1,27 @@ + + + + diff --git a/presentation/src/main/res/drawable/ic_file_upload_black_24dp.xml b/presentation/src/main/res/drawable/ic_file_upload_black_24dp.xml new file mode 100644 index 00000000..cd7e004b --- /dev/null +++ b/presentation/src/main/res/drawable/ic_file_upload_black_24dp.xml @@ -0,0 +1,27 @@ + + + + diff --git a/presentation/src/main/res/drawable/ic_history_black_24dp.xml b/presentation/src/main/res/drawable/ic_history_black_24dp.xml new file mode 100644 index 00000000..b69690ca --- /dev/null +++ b/presentation/src/main/res/drawable/ic_history_black_24dp.xml @@ -0,0 +1,27 @@ + + + + diff --git a/presentation/src/main/res/drawable/ic_import_export_black_24dp.xml b/presentation/src/main/res/drawable/ic_import_export_black_24dp.xml new file mode 100644 index 00000000..881a526b --- /dev/null +++ b/presentation/src/main/res/drawable/ic_import_export_black_24dp.xml @@ -0,0 +1,27 @@ + + + + diff --git a/presentation/src/main/res/layout/backup_controller.xml b/presentation/src/main/res/layout/backup_controller.xml new file mode 100644 index 00000000..de9d8685 --- /dev/null +++ b/presentation/src/main/res/layout/backup_controller.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/layout/drawer_view.xml b/presentation/src/main/res/layout/drawer_view.xml index 8c98f84c..937396b0 100644 --- a/presentation/src/main/res/layout/drawer_view.xml +++ b/presentation/src/main/res/layout/drawer_view.xml @@ -70,6 +70,33 @@ android:layout_marginTop="8dp" android:background="?android:attr/divider" /> + + + + + + + + + + @@ -84,7 +111,7 @@ android:text="@string/drawer_scheduled" /> Saved to gallery + Backup and restore + Last backup + Never + Restore + Select a backup + Currently, only SMS is supported by Backup and Restore. MMS support and scheduled backups will be coming soon! + Backup now + Scheduled Automatically send a message, at the exact moment you\'d like Hey! When was your birthday again?