Merged update TLE and Trans buttons into one

This commit is contained in:
Arty Bishop committed 2020-09-09 21:13:24 +01:00
1 parent 53d61e530e
commit e97cc49e22
6 files changed
+13 -80

No files matched your search

@@ -140,12 +140,7 @@ class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmit
})
viewModel.getUpdateStatus().observe(this, Observer { result ->
when (result) {
is Result.Success -> {
when (result.data) {
0 -> getString(R.string.update_tle_success).toast(this)
1 -> getString(R.string.update_trans_success).toast(this)
}
}
is Result.Success -> getString(R.string.update_tle_success).toast(this)
is Result.Error -> getString(R.string.update_failure).toast(this)
}
})
@@ -166,14 +161,13 @@ class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmit
it.lockButton()
}
drawerBinding.drawerBtnTleUrl.setOnClickListener {
showTleSourcesDialog()
TleSourcesDialogFragment(viewModel.getTleSources()).apply {
setSourcesListener(this@MainActivity)
show(supportFragmentManager, "TleSourcesDialog")
}
mainBinding.drawerLayout.closeDrawers()
it.lockButton()
}
drawerBinding.drawerBtnTrans.setOnClickListener {
viewModel.updateTransmitters()
it.lockButton()
}
drawerBinding.drawerBtnGithub.setOnClickListener {
val gitHubUrl = "https://github.com/rt-bishop/LookingSat"
val githubIntent = Intent(Intent.ACTION_VIEW, Uri.parse(gitHubUrl))
@@ -182,16 +176,8 @@ class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmit
drawerBinding.drawerBtnExit.setOnClickListener { finish() }
}
private fun showTleSourcesDialog() {
val sources = viewModel.getTleSources()
TleSourcesDialogFragment(sources).apply {
setSourcesListener(this@MainActivity)
show(supportFragmentManager, "TleSourcesDialog")
}
}
override fun onSourcesSubmit(list: List<TleSource>) {
viewModel.updateEntriesFromWeb(list)
viewModel.updateSatData(list)
}
private fun View.lockButton() {
@@ -91,11 +91,12 @@ class SharedViewModel @Inject constructor(
}
}
fun updateEntriesFromWeb(list: List<TleSource>) {
fun updateSatData(list: List<TleSource>) {
viewModelScope.launch(Dispatchers.IO) {
try {
repository.updateSources(list)
val selected = repository.getSelectedEntries().map { it.catNum }
repository.updateSources(list)
repository.updateTransmitters()
repository.updateEntriesFromUrl(list)
repository.updateEntriesSelection(selected)
_updateStatus.postValue(Result.Success(0))
@@ -112,17 +113,6 @@ class SharedViewModel @Inject constructor(
}
}
fun updateTransmitters() {
viewModelScope.launch(Dispatchers.IO) {
try {
repository.updateTransmitters()
_updateStatus.postValue(Result.Success(1))
} catch (e: Exception) {
_updateStatus.postValue(Result.Error(e))
}
}
}
fun calculatePasses() {
_satPassList.postValue(Result.InProgress)
calculationJob?.cancel()