Skip to content

Commit

Permalink
Export button state bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jemshit committed Sep 9, 2018
1 parent 71c7bfa commit 92fcb02
Showing 1 changed file with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModelProviders
import com.jakewharton.rxbinding2.view.RxView
import com.jemshit.sensorlogger.R
import com.jemshit.sensorlogger.background_work.*
import com.jemshit.sensorlogger.ui.main.exportBusy
import com.jemshit.sensorlogger.ui.statistics.UIWorkStatus
import com.tbruyelle.rxpermissions2.RxPermissions
import io.reactivex.android.schedulers.AndroidSchedulers
Expand Down Expand Up @@ -128,27 +129,6 @@ class ExportFragment : Fragment() {
super.onActivityCreated(savedInstanceState)
exportViewModel = ViewModelProviders.of(activity!!).get(ExportViewModel::class.java)

exportViewModel!!.exportStatus
.observe(this, Observer { status ->
when (status) {
is UIWorkStatus.Idle -> {
enableButtons()
showIdle()
}
is UIWorkStatus.Loading -> {
enableButtons(false)
showLoading()
}
is UIWorkStatus.Error -> {
enableButtons()
showError(status.message)
}
is UIWorkStatus.Success -> {
enableButtons()
showSuccess()
}
}
})

exportViewModel!!.deleteFolderStatus
.observe(this, Observer { status ->
Expand Down Expand Up @@ -203,6 +183,28 @@ class ExportFragment : Fragment() {
}
}
})

exportViewModel!!.exportStatus
.observe(this, Observer { status ->
when (status) {
is UIWorkStatus.Idle -> {
enableButtons()
showIdle()
}
is UIWorkStatus.Loading -> {
enableButtons(false)
showLoading()
}
is UIWorkStatus.Error -> {
enableButtons()
showError(status.message)
}
is UIWorkStatus.Success -> {
enableButtons()
showSuccess()
}
}
})
}

private fun showLoading() {
Expand Down Expand Up @@ -252,8 +254,16 @@ class ExportFragment : Fragment() {
}

private fun enableButtons(enable: Boolean = true) {
button_delete_exported_folder.isEnabled = enable
button_delete_local_data.isEnabled = enable
button_export.isEnabled = enable
if (enable) {
if (!exportBusy) {
button_delete_exported_folder.isEnabled = enable
button_delete_local_data.isEnabled = enable
button_export.isEnabled = enable
}
} else {
button_delete_exported_folder.isEnabled = enable
button_delete_local_data.isEnabled = enable
button_export.isEnabled = enable
}
}
}

0 comments on commit 92fcb02

Please sign in to comment.