mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Toolbar timer is now being set for the next satellite pass
This commit is contained in:
1 parent
92767bd0a4
commit
cc53847374
2 files changed
+37
-25
No files matched your search
@@ -77,7 +77,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
try {
|
try {
|
||||||
Log.d(tag, "Trying ${tle.name}")
|
Log.d(tag, "Trying ${tle.name}")
|
||||||
val passPredictor = PassPredictor(tle, gsp.value)
|
val passPredictor = PassPredictor(tle, gsp.value)
|
||||||
val passes = passPredictor.getPasses(Date(), 6, true)
|
val passes = passPredictor.getPasses(Date(), 6, false)
|
||||||
for (pass in passes) {
|
for (pass in passes) {
|
||||||
Log.d(tag, "Trying ${pass.maxEl}")
|
Log.d(tag, "Trying ${pass.maxEl}")
|
||||||
satPassList.add(SatPass(tle.name, tle.catnum, pass))
|
satPassList.add(SatPass(tle.name, tle.catnum, pass))
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import com.rtbishop.lookingsat.R
|
|||||||
import com.rtbishop.lookingsat.repo.SatPass
|
import com.rtbishop.lookingsat.repo.SatPass
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class SkyFragment : Fragment() {
|
class SkyFragment : Fragment() {
|
||||||
@@ -37,7 +36,7 @@ class SkyFragment : Fragment() {
|
|||||||
private lateinit var progressBar: ProgressBar
|
private lateinit var progressBar: ProgressBar
|
||||||
private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
|
|
||||||
private var satPassList: List<SatPass> = emptyList()
|
private var aosTimer: CountDownTimer? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
@@ -58,7 +57,7 @@ class SkyFragment : Fragment() {
|
|||||||
|
|
||||||
fab.setOnClickListener { showSelectSatDialog() }
|
fab.setOnClickListener { showSelectSatDialog() }
|
||||||
|
|
||||||
setupTimer()
|
resetTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSelectSatDialog() {
|
private fun showSelectSatDialog() {
|
||||||
@@ -104,6 +103,7 @@ class SkyFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calculatePasses() {
|
private fun calculatePasses() {
|
||||||
|
var satPassList: List<SatPass>
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
recViewFuture.visibility = View.INVISIBLE
|
recViewFuture.visibility = View.INVISIBLE
|
||||||
progressBar.visibility = View.VISIBLE
|
progressBar.visibility = View.VISIBLE
|
||||||
@@ -114,32 +114,44 @@ class SkyFragment : Fragment() {
|
|||||||
progressBar.isIndeterminate = false
|
progressBar.isIndeterminate = false
|
||||||
progressBar.visibility = View.INVISIBLE
|
progressBar.visibility = View.INVISIBLE
|
||||||
recViewFuture.visibility = View.VISIBLE
|
recViewFuture.visibility = View.VISIBLE
|
||||||
|
if (satPassList.isEmpty()) {
|
||||||
|
resetTimer()
|
||||||
|
} else {
|
||||||
|
setTimer(satPassList[0].pass.startTime.time)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTimer() {
|
private fun setTimer(passTime: Long) {
|
||||||
val cal = Calendar.getInstance()
|
if (aosTimer == null) {
|
||||||
cal.add(Calendar.DAY_OF_MONTH, 1)
|
val totalMillis = passTime.minus(System.currentTimeMillis())
|
||||||
cal.set(Calendar.HOUR_OF_DAY, 0)
|
aosTimer = object : CountDownTimer(totalMillis, 1000) {
|
||||||
cal.set(Calendar.MINUTE, 0)
|
override fun onFinish() {
|
||||||
cal.set(Calendar.SECOND, 0)
|
Toast.makeText(activity, "Time is up!", Toast.LENGTH_SHORT).show()
|
||||||
cal.set(Calendar.MILLISECOND, 0)
|
this.cancel()
|
||||||
val totalMillis = cal.timeInMillis - System.currentTimeMillis()
|
resetTimer()
|
||||||
|
}
|
||||||
|
|
||||||
val timer = object : CountDownTimer(totalMillis, 1000) {
|
override fun onTick(millisUntilFinished: Long) {
|
||||||
override fun onFinish() {
|
timeToAos.text = String.format(
|
||||||
Toast.makeText(activity, "Time is up!", Toast.LENGTH_SHORT).show()
|
"AOS -%02d:%02d:%02d",
|
||||||
}
|
TimeUnit.MILLISECONDS.toHours(millisUntilFinished) % 60,
|
||||||
|
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60,
|
||||||
override fun onTick(millisUntilFinished: Long) {
|
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60
|
||||||
timeToAos.text = String.format(
|
)
|
||||||
"AOS -%02d:%02d:%02d",
|
}
|
||||||
TimeUnit.MILLISECONDS.toHours(millisUntilFinished) % 60,
|
|
||||||
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60,
|
|
||||||
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
(aosTimer as CountDownTimer).start()
|
||||||
|
} else {
|
||||||
|
resetTimer()
|
||||||
}
|
}
|
||||||
timer.start()
|
}
|
||||||
|
|
||||||
|
private fun resetTimer() {
|
||||||
|
if (aosTimer != null) {
|
||||||
|
(aosTimer as CountDownTimer).cancel()
|
||||||
|
aosTimer = null
|
||||||
|
}
|
||||||
|
timeToAos.text = String.format("AOS -%02d:%02d:%02d", 0, 0, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user