mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-04 11:37:22 +00:00
Minor fixes
This commit is contained in:
1 parent
ad073724cb
commit
8eb551fde6
6 files changed
+62
-74
No files matched your search
@@ -33,7 +33,7 @@ import com.rtbishop.look4sat.ui.fragments.PassesFragmentDirections
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class PassesAdapter(context: Context, private var shouldUseUTC: Boolean = false) :
|
||||
class PassesAdapter(context: Context, private val shouldUseUTC: Boolean = false) :
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
private val satIdFormat = context.getString(R.string.pass_satId)
|
||||
@@ -55,21 +55,23 @@ class PassesAdapter(context: Context, private var shouldUseUTC: Boolean = false)
|
||||
val iterator = satPassList.listIterator()
|
||||
while (iterator.hasNext()) {
|
||||
val satPass = iterator.next()
|
||||
if (satPass.progress < 100) {
|
||||
val timeStart = satPass.pass.startTime.time
|
||||
val timeEnd = satPass.pass.endTime.time
|
||||
if (timeNow.minus(timeStart) > 0) {
|
||||
satPass.active = true
|
||||
if (!satPass.tle.isDeepspace) {
|
||||
if (satPass.progress < 100) {
|
||||
val timeStart = satPass.pass.startTime.time
|
||||
if (timeNow > timeStart) {
|
||||
satPass.active = true
|
||||
val timeEnd = satPass.pass.endTime.time
|
||||
val index = satPassList.indexOf(satPass)
|
||||
val deltaNow = timeNow.minus(timeStart).toFloat()
|
||||
val deltaTotal = timeEnd.minus(timeStart).toFloat()
|
||||
satPass.progress = ((deltaNow / deltaTotal) * 100).toInt()
|
||||
notifyItemChanged(index)
|
||||
}
|
||||
} else {
|
||||
val index = satPassList.indexOf(satPass)
|
||||
val deltaTotal = timeEnd.minus(timeStart)
|
||||
val deltaNow = timeNow.minus(timeStart)
|
||||
satPass.progress = ((deltaNow.toFloat() / deltaTotal.toFloat()) * 100).toInt()
|
||||
notifyItemChanged(index)
|
||||
iterator.remove()
|
||||
notifyItemRemoved(index)
|
||||
}
|
||||
} else {
|
||||
val index = satPassList.indexOf(satPass)
|
||||
iterator.remove()
|
||||
notifyItemRemoved(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,9 +122,11 @@ class PassesAdapter(context: Context, private var shouldUseUTC: Boolean = false)
|
||||
}
|
||||
|
||||
itemView.setOnClickListener {
|
||||
val passIndex = satPassList.indexOf(satPass)
|
||||
val action = PassesFragmentDirections.actionPassToPolar(passIndex)
|
||||
itemView.findNavController().navigate(action)
|
||||
if (satPass.progress < 100) {
|
||||
val passIndex = satPassList.indexOf(satPass)
|
||||
val action = PassesFragmentDirections.actionPassToPolar(passIndex)
|
||||
itemView.findNavController().navigate(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
package com.rtbishop.look4sat.ui.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.*
|
||||
import android.hardware.Sensor
|
||||
import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -68,7 +71,7 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
addItemDecoration(RecyclerDivider(R.drawable.rec_divider_dark))
|
||||
}
|
||||
calculateMagneticDeclination()
|
||||
magneticDeclination = prefsManager.getMagDeclination()
|
||||
observePasses()
|
||||
}
|
||||
|
||||
@@ -76,7 +79,7 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||
super.onResume()
|
||||
if (prefsManager.shouldUseCompass()) {
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR).also { sensor ->
|
||||
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL)
|
||||
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,19 +113,12 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||
satPass = result.data[args.satPassIndex]
|
||||
polarView = PolarView(requireContext(), satPass)
|
||||
binding.frame.addView(polarView)
|
||||
observeTimer()
|
||||
observeTransmitters()
|
||||
observeTimer()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun observeTimer() {
|
||||
viewModel.getCurrentTimeMillis().observe(viewLifecycleOwner, {
|
||||
transmitterAdapter.notifyDataSetChanged()
|
||||
setPassText(Date(it))
|
||||
})
|
||||
}
|
||||
|
||||
private fun observeTransmitters() {
|
||||
viewModel.getTransmittersForSat(satPass.tle.catnum).observe(viewLifecycleOwner, {
|
||||
if (it.isNotEmpty()) {
|
||||
@@ -137,15 +133,12 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||
})
|
||||
}
|
||||
|
||||
private fun calculateMagneticDeclination() {
|
||||
prefsManager.getStationPosition().let {
|
||||
magneticDeclination = GeomagneticField(
|
||||
it.latitude.toFloat(),
|
||||
it.longitude.toFloat(),
|
||||
it.heightAMSL.toFloat(),
|
||||
System.currentTimeMillis()
|
||||
).declination
|
||||
}
|
||||
private fun observeTimer() {
|
||||
viewModel.getCurrentTimeMillis().observe(viewLifecycleOwner, {
|
||||
setPassText(Date(it))
|
||||
polarView?.invalidate()
|
||||
transmitterAdapter.notifyDataSetChanged()
|
||||
})
|
||||
}
|
||||
|
||||
private fun setPassText(date: Date) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.rtbishop.look4sat.utility
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.hardware.GeomagneticField
|
||||
import android.location.LocationManager
|
||||
import androidx.core.content.edit
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
@@ -56,6 +57,14 @@ class PrefsManager @Inject constructor(
|
||||
return GroundStationPosition(lat, lon, alt)
|
||||
}
|
||||
|
||||
fun getMagDeclination(): Float {
|
||||
val stationPosition = getStationPosition()
|
||||
val lat = stationPosition.latitude.toFloat()
|
||||
val lon = stationPosition.longitude.toFloat()
|
||||
val alt = stationPosition.heightAMSL.toFloat()
|
||||
return GeomagneticField(lat, lon, alt, System.currentTimeMillis()).declination
|
||||
}
|
||||
|
||||
fun setStationPositionFromGPS() {
|
||||
try {
|
||||
locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)?.let {
|
||||
|
||||
Reference in new issue
Block a user