mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-07 21:17:23 +00:00
Fixed the drawer buttons' enable/disable behaviour
This commit is contained in:
1 parent
cd30ff5343
commit
1c1845a29d
1 file changed
+14
-15
@@ -33,6 +33,7 @@ import androidx.core.app.ActivityCompat
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.navigateUp
|
import androidx.navigation.ui.navigateUp
|
||||||
@@ -42,6 +43,8 @@ import com.rtbishop.look4sat.MainViewModel
|
|||||||
import com.rtbishop.look4sat.R
|
import com.rtbishop.look4sat.R
|
||||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||||
import com.rtbishop.look4sat.databinding.DrawerHeaderBinding
|
import com.rtbishop.look4sat.databinding.DrawerHeaderBinding
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@@ -105,18 +108,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun setupObservers() {
|
private fun setupObservers() {
|
||||||
viewModel.getDebugMessage().observe(this, Observer { message ->
|
viewModel.getDebugMessage().observe(this, Observer { message ->
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||||
when (message) {
|
|
||||||
getString(R.string.update_loc_success) -> drawerBinding.drawerBtnLoc.isEnabled =
|
|
||||||
true
|
|
||||||
getString(R.string.update_tle_success) -> drawerBinding.drawerBtnTle.isEnabled =
|
|
||||||
true
|
|
||||||
getString(R.string.update_trans_success) -> drawerBinding.drawerBtnTrans.isEnabled =
|
|
||||||
true
|
|
||||||
getString(R.string.update_failure) -> {
|
|
||||||
drawerBinding.drawerBtnTle.isEnabled = true
|
|
||||||
drawerBinding.drawerBtnTrans.isEnabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.getGSP().observe(this, Observer { gsp ->
|
viewModel.getGSP().observe(this, Observer { gsp ->
|
||||||
@@ -129,16 +120,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun setupDrawer() {
|
private fun setupDrawer() {
|
||||||
drawerBinding.drawerBtnLoc.setOnClickListener {
|
drawerBinding.drawerBtnLoc.setOnClickListener {
|
||||||
it.isEnabled = false
|
|
||||||
requestLocationUpdate()
|
requestLocationUpdate()
|
||||||
|
it.lockButton()
|
||||||
}
|
}
|
||||||
drawerBinding.drawerBtnTle.setOnClickListener {
|
drawerBinding.drawerBtnTle.setOnClickListener {
|
||||||
it.isEnabled = false
|
|
||||||
viewModel.updateAndSaveTleFile()
|
viewModel.updateAndSaveTleFile()
|
||||||
|
it.lockButton()
|
||||||
}
|
}
|
||||||
drawerBinding.drawerBtnTrans.setOnClickListener {
|
drawerBinding.drawerBtnTrans.setOnClickListener {
|
||||||
it.isEnabled = false
|
|
||||||
viewModel.updateTransmittersDatabase()
|
viewModel.updateTransmittersDatabase()
|
||||||
|
it.lockButton()
|
||||||
}
|
}
|
||||||
drawerBinding.drawerBtnGithub.setOnClickListener {
|
drawerBinding.drawerBtnGithub.setOnClickListener {
|
||||||
val githubIntent = Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl))
|
val githubIntent = Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl))
|
||||||
@@ -147,6 +138,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
drawerBinding.drawerBtnExit.setOnClickListener { finish() }
|
drawerBinding.drawerBtnExit.setOnClickListener { finish() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun View.lockButton() {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
this@lockButton.isEnabled = false
|
||||||
|
delay(3000)
|
||||||
|
this@lockButton.isEnabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun requestLocationUpdate() {
|
private fun requestLocationUpdate() {
|
||||||
if (ContextCompat.checkSelfPermission(this, permLocation) != permGranted) {
|
if (ContextCompat.checkSelfPermission(this, permLocation) != permGranted) {
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permLocation)) {
|
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permLocation)) {
|
||||||
|
|||||||
Reference in new issue
Block a user