Drawer buttons are now disabled till their commands are fully executed

This commit is contained in:
Arty Bishop committed 2020-01-03 18:17:20 +00:00
1 parent ba7f3f432e
commit 3f96fb0933
3 files changed
+42 -11

No files matched your search

@@ -120,7 +120,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
apply()
}
_gsp.postValue(GroundStationPosition(lat, lon, alt))
_debugMessage.postValue("Location was updated")
_debugMessage.postValue(app.getString(R.string.updateLocSuccess))
}
}
@@ -145,9 +145,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
}
tleMainList = tleList
tleSelection = mutableListOf()
_debugMessage.postValue("TLE file was updated")
_debugMessage.postValue(app.getString(R.string.updateTleSuccess))
} catch (exception: IOException) {
_debugMessage.postValue("Couldn't update TLE file")
_debugMessage.postValue(app.getString(R.string.updateTleFailure))
}
}
}
@@ -156,9 +156,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
viewModelScope.launch(Dispatchers.IO) {
try {
repository.updateTransmittersDatabase()
_debugMessage.postValue("Transmitters were updated")
_debugMessage.postValue(app.getString(R.string.updateTransSuccess))
} catch (exception: IOException) {
_debugMessage.postValue("Couldn't update transmitters")
_debugMessage.postValue(app.getString(R.string.updateTransFailure))
}
}
}
@@ -121,8 +121,13 @@ class MainActivity : AppCompatActivity() {
}
private fun setupObservers() {
viewModel.debugMessage.observe(this, Observer { debug_message ->
Toast.makeText(this, debug_message, Toast.LENGTH_SHORT).show()
viewModel.debugMessage.observe(this, Observer { message ->
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
when (message) {
getString(R.string.updateLocSuccess) -> drawerBtnLoc.enable()
getString(R.string.updateTleSuccess), getString(R.string.updateTleFailure) -> drawerBtnTle.enable()
getString(R.string.updateTransSuccess), getString(R.string.updateTransFailure) -> drawerBtnTrans.enable()
}
})
viewModel.gsp.observe(this, Observer { gsp ->
@@ -132,11 +137,21 @@ class MainActivity : AppCompatActivity() {
}
private fun setupDrawer() {
drawerBtnLoc.setOnClickListener { requestLocationUpdate() }
drawerBtnTle.setOnClickListener { viewModel.updateAndSaveTleFile() }
drawerBtnTrans.setOnClickListener { viewModel.updateTransmittersDatabase() }
drawerBtnLoc.setOnClickListener {
drawerBtnLoc.disable()
requestLocationUpdate()
}
drawerBtnTle.setOnClickListener {
drawerBtnTle.disable()
viewModel.updateAndSaveTleFile()
}
drawerBtnTrans.setOnClickListener {
drawerBtnTrans.disable()
viewModel.updateTransmittersDatabase()
}
drawerBtnGithub.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl)))
val githubIntent = Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl))
startActivity(githubIntent)
}
drawerBtnExit.setOnClickListener { finish() }
}
@@ -167,4 +182,14 @@ class MainActivity : AppCompatActivity() {
val navController = findNavController(R.id.nav_host)
return navController.navigateUp(appBarConfig) || super.onSupportNavigateUp()
}
}
fun ImageButton.enable() {
this.isEnabled = true
this.alpha = 1.0f
}
fun ImageButton.disable() {
this.isEnabled = false
this.alpha = 0.25f
}
+6
View File
@@ -100,4 +100,10 @@
<string name="map_gsp">GSP</string>
<string name="map_content">Nasa Map</string>
<string name="placeholder">Placeholder</string>
<string name="updateLocSuccess">Location was updated</string>
<string name="updateTleSuccess">TLE file was updated</string>
<string name="updateTleFailure">Could not update TLE file</string>
<string name="updateTransSuccess">Transmitters database was updated</string>
<string name="updateTransFailure">Could not update transmitters</string>
</resources>