forked from upstream-mirrors/quik
Create UI for backup activity
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user