Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Minor fixes

Arty Bishop8eb551fde6fb
diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/PassesAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/PassesAdapter.kt
index ed7dc344..b2fb0c95 100644
--- a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/PassesAdapter.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/PassesAdapter.kt
@@ -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)
+ }
}
}
}
diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/PolarFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/PolarFragment.kt
index 0135db6f..eee9994f 100644
--- a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/PolarFragment.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/PolarFragment.kt
@@ -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) {
diff --git a/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt b/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt
index a5fc2280..da313fdd 100644
--- a/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt
@@ -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 {
diff --git a/app/src/main/res/drawable/ic_trans.xml b/app/src/main/res/drawable/ic_trans.xml
deleted file mode 100644
index 6a33bba8..00000000
--- a/app/src/main/res/drawable/ic_trans.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24"
- android:viewportHeight="24">
- <path
- android:fillColor="@color/themeLight"
- android:pathData="M12,11c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,13c0,-3.31 -2.69,-6 -6,-6s-6,2.69 -6,6c0,2.22 1.21,4.15 3,5.19l1,-1.74c-1.19,-0.7 -2,-1.97 -2,-3.45 0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,1.48 -0.81,2.75 -2,3.45l1,1.74c1.79,-1.04 3,-2.97 3,-5.19zM12,3C6.48,3 2,7.48 2,13c0,3.7 2.01,6.92 4.99,8.65l1,-1.73C5.61,18.53 4,15.96 4,13c0,-4.42 3.58,-8 8,-8s8,3.58 8,8c0,2.96 -1.61,5.53 -4,6.92l1,1.73c2.99,-1.73 5,-4.95 5,-8.65 0,-5.52 -4.48,-10 -10,-10z" />
-</vector>
diff --git a/app/src/main/res/layout/fragment_passes.xml b/app/src/main/res/layout/fragment_passes.xml
index c31ca871..3aebb7ea 100644
--- a/app/src/main/res/layout/fragment_passes.xml
+++ b/app/src/main/res/layout/fragment_passes.xml
@@ -48,7 +48,7 @@
app:layout_constraintStart_toStartOf="@id/passes_bar"
app:layout_constraintTop_toTopOf="parent" />
- <TextView
+ <com.google.android.material.textview.MaterialTextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -62,7 +62,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/passes_timer" />
- <TextView
+ <com.google.android.material.textview.MaterialTextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/app/src/main/res/layout/item_trans.xml b/app/src/main/res/layout/item_trans.xml
index 10d8b6f6..04c1fc4b 100644
--- a/app/src/main/res/layout/item_trans.xml
+++ b/app/src/main/res/layout/item_trans.xml
@@ -31,15 +31,16 @@
android:id="@+id/description"
android:layout_width="0dp"
android:layout_height="wrap_content"
- android:layout_marginStart="4dp"
+ android:layout_marginStart="2dp"
android:layout_marginTop="4dp"
- android:layout_marginEnd="6dp"
+ android:layout_marginEnd="2dp"
android:ellipsize="end"
+ android:gravity="center"
android:maxLines="1"
android:text="@string/trans_description"
- app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintEnd_toStartOf="@+id/img_uplink"
app:layout_constraintHorizontal_chainStyle="spread_inside"
- app:layout_constraintStart_toEndOf="@+id/img_trans"
+ app:layout_constraintStart_toEndOf="@+id/img_downlink"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
@@ -51,7 +52,7 @@
android:text="@string/trans_down_low_doppler"
android:textColor="@color/themeLight"
android:textSize="30sp"
- app:layout_constraintEnd_toStartOf="@+id/img_downlink"
+ app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description" />
@@ -65,7 +66,7 @@
android:textSize="30sp"
app:layout_constraintBaseline_toBaselineOf="@+id/downlink"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toEndOf="@+id/img_uplink" />
+ app:layout_constraintStart_toStartOf="@+id/guideline" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/mode"
@@ -92,39 +93,29 @@
app:layout_constraintStart_toEndOf="@+id/mode" />
<ImageView
- android:id="@+id/img_trans"
+ android:id="@+id/img_downlink"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="4dp"
+ android:layout_marginTop="4dp"
android:contentDescription="@string/placeholder"
+ android:rotation="90"
app:layout_constraintBottom_toBottomOf="@+id/description"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="@+id/description"
- app:srcCompat="@drawable/ic_trans" />
-
- <ImageView
- android:id="@+id/img_downlink"
- android:layout_width="18dp"
- android:layout_height="18dp"
- android:layout_marginEnd="4dp"
- android:contentDescription="@string/placeholder"
- android:rotation="90"
- app:layout_constraintBottom_toBottomOf="@+id/downlink"
- app:layout_constraintEnd_toStartOf="@+id/guideline"
- app:layout_constraintTop_toTopOf="@+id/downlink"
+ app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow" />
<ImageView
android:id="@+id/img_uplink"
android:layout_width="18dp"
android:layout_height="18dp"
- android:layout_marginStart="4dp"
+ android:layout_marginTop="4dp"
+ android:layout_marginEnd="4dp"
android:contentDescription="@string/placeholder"
android:rotation="270"
- app:layout_constraintBottom_toBottomOf="@+id/uplink"
- app:layout_constraintHorizontal_chainStyle="packed"
- app:layout_constraintStart_toStartOf="@+id/guideline"
- app:layout_constraintTop_toTopOf="@+id/uplink"
+ app:layout_constraintBottom_toBottomOf="@+id/description"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow" />
<androidx.constraintlayout.widget.Guideline