Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Removed sat track tail from the map, minor refactoring
Arty Bishop18820b79f4fc
diff --git a/app/src/main/java/com/rtbishop/look4sat/di/ApplicationModule.kt b/app/src/main/java/com/rtbishop/look4sat/di/ApplicationModule.ktindex 6da7115a..30307255 100644--- a/app/src/main/java/com/rtbishop/look4sat/di/ApplicationModule.kt+++ b/app/src/main/java/com/rtbishop/look4sat/di/ApplicationModule.kt@@ -22,7 +22,6 @@ import android.content.Contextimport android.content.SharedPreferencesimport android.hardware.SensorManagerimport android.location.LocationManager-import android.view.WindowManagerimport androidx.preference.PreferenceManagerimport dagger.Moduleimport dagger.Provides@@ -49,11 +48,6 @@ object ApplicationModule {return context.getSystemService(Context.SENSOR_SERVICE) as SensorManager}- @Provides- fun provideWindowManager(@ApplicationContext context: Context): WindowManager {- return context.getSystemService(Context.WINDOW_SERVICE) as WindowManager- }-@Providesfun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {return PreferenceManager.getDefaultSharedPreferences(context)diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/entriesScreen/EntriesFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/entriesScreen/EntriesFragment.ktindex f4754b24..0afa24ae 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/entriesScreen/EntriesFragment.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/entriesScreen/EntriesFragment.kt@@ -33,6 +33,7 @@ import com.rtbishop.look4sat.data.model.TleSourceimport com.rtbishop.look4sat.databinding.FragmentEntriesBindingimport com.rtbishop.look4sat.utility.RecyclerDividerimport com.rtbishop.look4sat.utility.getNavResult+import com.rtbishop.look4sat.utility.navigateSafeimport dagger.hilt.android.AndroidEntryPoint@AndroidEntryPoint@@ -61,7 +62,9 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = falseaddItemDecoration(RecyclerDivider(R.drawable.rec_divider_light))}- importWeb.setOnClickListener { findNavController().navigate(R.id.nav_dialog_sources) }+ importWeb.setOnClickListener {+ findNavController().navigateSafe(R.id.action_entries_to_sources)+ }importFile.setOnClickListener { filePicker.launch("*/*") }selectMode.setOnClickListener { viewModel.createModesDialog(requireContext()).show() }selectAll.setOnClickListener { viewModel.selectCurrentItems() }diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/mapScreen/MapViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/ui/mapScreen/MapViewModel.ktindex f9878e43..ff585913 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/mapScreen/MapViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/mapScreen/MapViewModel.kt@@ -24,7 +24,6 @@ import com.github.amsacode.predict4java.Positionimport com.github.amsacode.predict4java.SatPosimport com.github.amsacode.predict4java.Satelliteimport com.rtbishop.look4sat.data.model.SelectedSat-import com.rtbishop.look4sat.utility.PrefsManagerimport com.rtbishop.look4sat.data.repository.SatelliteRepoimport com.rtbishop.look4sat.utility.*import dagger.hilt.android.lifecycle.HiltViewModel@@ -35,7 +34,6 @@ import org.osmdroid.views.overlay.Overlayimport org.osmdroid.views.overlay.Polygonimport org.osmdroid.views.overlay.Polylineimport timber.log.Timber-import java.lang.IllegalArgumentExceptionimport java.util.*import javax.inject.Inject@@ -142,7 +140,7 @@ class MapViewModel @Inject constructor(}private fun getSatTrack(satellite: Satellite): Overlay {- val positions = satellite.getPredictor(gsp).getPositions(dateNow, 15, 3, 3.2)+ val positions = satellite.getPredictor(gsp).getPositions(dateNow, 15, 0, 3.2)val trackOverlay = FolderOverlay()val trackPoints = mutableListOf<GeoPoint>()var oldLon = 0.0diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/Orientation.kt b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/Orientation.ktdeleted file mode 100644index 9d647663..00000000--- a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/Orientation.kt+++ /dev/null@@ -1,85 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2021 Arty Bishop ([email protected])- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with this program. If not, see <https://www.gnu.org/licenses/>.- */-package com.rtbishop.look4sat.ui.polarScreen--import android.hardware.Sensor-import android.hardware.SensorEvent-import android.hardware.SensorEventListener-import android.hardware.SensorManager-import android.view.Surface-import android.view.WindowManager-import javax.inject.Inject-import kotlin.math.atan2-import kotlin.math.round--class Orientation @Inject constructor(- private val mSensorManager: SensorManager,- private val mWindowManager: WindowManager-) : SensorEventListener {-- interface OrientationListener {- fun onOrientationChanged(azimuth: Float, pitch: Float, roll: Float)- }-- private val mRotationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)- private val mRotationMatrix = FloatArray(9)- private val mOrientationValues = FloatArray(3)- private val mOneRadDegrees = 57.295779513f- private var mListener: OrientationListener? = null-- fun startListening(listener: OrientationListener) {- if (mListener !== listener) {- mListener = listener- mSensorManager.registerListener(this, mRotationSensor, 16000)- } else return- }-- fun stopListening() {- mSensorManager.unregisterListener(this)- mListener = null- }-- override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {}-- override fun onSensorChanged(event: SensorEvent) {- if (mListener == null) return- else if (event.sensor == mRotationSensor) updateOrientation(event.values)- }-- @Suppress("DEPRECATION")- private fun updateOrientation(rotationVector: FloatArray) {- SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector)- val (matrixColumn, sense) = when (mWindowManager.defaultDisplay.rotation) {- Surface.ROTATION_0 -> Pair(0, 1)- Surface.ROTATION_90 -> Pair(1, -1)- Surface.ROTATION_180 -> Pair(0, -1)- Surface.ROTATION_270 -> Pair(1, 1)- else -> error("Invalid screen rotation value")- }- val x = sense * mRotationMatrix[matrixColumn]- val y = sense * mRotationMatrix[matrixColumn + 3]- val azimuth = -atan2(y, x) * mOneRadDegrees-// SensorManager.getOrientation(mRotationMatrix, mOrientationValues)-// val azimuth = mOrientationValues[0] * mOneRadDegrees- val pitch = mOrientationValues[1] * mOneRadDegrees- val roll = mOrientationValues[2] * mOneRadDegrees- val magneticAzimuth = (azimuth + 360f) % 360f- val roundedAzimuth = round(magneticAzimuth * 10) / 10- mListener?.onOrientationChanged(roundedAzimuth, pitch, roll)- }-}\ No newline at end of filediff --git a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/OrientationProvider.kt b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/OrientationProvider.ktnew file mode 100644index 00000000..4c1adf42--- /dev/null+++ b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/OrientationProvider.kt@@ -0,0 +1,77 @@+/*+ * Look4Sat. Amateur radio satellite tracker and pass predictor.+ * Copyright (C) 2019-2021 Arty Bishop ([email protected])+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */+package com.rtbishop.look4sat.ui.polarScreen++import android.hardware.Sensor+import android.hardware.SensorEvent+import android.hardware.SensorEventListener+import android.hardware.SensorManager+import javax.inject.Inject+import kotlin.math.round++class OrientationProvider @Inject constructor(private val sensorManager: SensorManager) :+ SensorEventListener {++ interface OrientationListener {+ fun onOrientationChanged(azimuth: Float, pitch: Float, roll: Float)+ }++ private val sensor: Sensor? = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)+ private val rotationMatrix = FloatArray(9)+ private val orientationValues = FloatArray(3)+ private val oneRadDegrees = 57.295779513f+ private var sensorAccuracy: Int = SensorManager.SENSOR_STATUS_UNRELIABLE+ private var orientationListener: OrientationListener? = null++ fun startListening(listener: OrientationListener) {+ if (sensor != null && orientationListener !== listener) {+ orientationListener = listener+ sensorManager.registerListener(this, sensor, 16000)+ } else return+ }++ fun stopListening() {+ sensorManager.unregisterListener(this)+ orientationListener = null+ }++ override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {+ sensorAccuracy = accuracy+ }++ override fun onSensorChanged(event: SensorEvent) {+ when {+ orientationListener == null -> return+ sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE -> return+ event.sensor == sensor -> updateOrientation(event.values)+ }+ }++ private fun updateOrientation(rotationVector: FloatArray) {+ SensorManager.getRotationMatrixFromVector(rotationMatrix, rotationVector)+ SensorManager.getOrientation(rotationMatrix, orientationValues)+ val azimuth = orientationValues[0] * oneRadDegrees+ val pitch = orientationValues[1] * oneRadDegrees+ val roll = orientationValues[2] * oneRadDegrees+ val magneticAzimuth = (azimuth + 360f) % 360f+ val roundedAzimuth = round(magneticAzimuth * 10) / 10+ val roundedPitch = round(pitch * 10) / 10+ val roundedRoll = round(roll * 10) / 10+ orientationListener?.onOrientationChanged(roundedAzimuth, roundedPitch, roundedRoll)+ }+}diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.ktindex b1b2c51a..08703a86 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarFragment.kt@@ -29,6 +29,7 @@ import com.rtbishop.look4sat.data.model.SatPassimport com.rtbishop.look4sat.databinding.FragmentPolarBindingimport com.rtbishop.look4sat.utility.RecyclerDividerimport com.rtbishop.look4sat.utility.formatForTimer+import com.rtbishop.look4sat.utility.navigateSafeimport dagger.hilt.android.AndroidEntryPointimport java.util.*@@ -119,7 +120,7 @@ class PolarFragment : Fragment(R.layout.fragment_polar) {binding.polarTimer.text = millisBeforeEnd.formatForTimer()if (dateNow.after(satPass.losDate)) {binding.polarTimer.text = 0L.formatForTimer()- findNavController().popBackStack()+ findNavController().navigateSafe(R.id.action_polar_to_passes)}}} else {diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarViewModel.ktindex 9b192fdd..8d05495d 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/polarScreen/PolarViewModel.kt@@ -34,12 +34,12 @@ import javax.inject.Inject@HiltViewModelclass PolarViewModel @Inject constructor(- private val orientation: Orientation,+ private val orientationProvider: OrientationProvider,private val prefsManager: PrefsManager,private val passesRepo: PassesRepo,private val satelliteRepo: SatelliteRepo,@IoDispatcher private val ioDispatcher: CoroutineDispatcher-) : ViewModel(), Orientation.OrientationListener {+) : ViewModel(), OrientationProvider.OrientationListener {private val magDeclination = prefsManager.getMagDeclination()private val _transmitters = MutableLiveData<List<SatTrans>>()@@ -59,11 +59,11 @@ class PolarViewModel @Inject constructor(}fun enableSensor() {- if (prefsManager.shouldUseCompass()) orientation.startListening(this)+ if (prefsManager.shouldUseCompass()) orientationProvider.startListening(this)}fun disableSensor() {- if (prefsManager.shouldUseCompass()) orientation.stopListening()+ if (prefsManager.shouldUseCompass()) orientationProvider.stopListening()}override fun onOrientationChanged(azimuth: Float, pitch: Float, roll: Float) {diff --git a/app/src/main/res/layout/fragment_polar.xml b/app/src/main/res/layout/fragment_polar.xmlindex 27b6af97..68cd0afe 100644--- a/app/src/main/res/layout/fragment_polar.xml+++ b/app/src/main/res/layout/fragment_polar.xml@@ -78,25 +78,23 @@android:id="@+id/recycler"android:layout_width="0dp"android:layout_height="0dp"- android:layout_marginTop="23dp"android:padding="2dp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"- app:layout_constraintTop_toBottomOf="@+id/frame" />+ app:layout_constraintTop_toBottomOf="@+id/sat_name" /><com.google.android.material.textview.MaterialTextViewandroid:id="@+id/no_trans_msg"android:layout_width="0dp"android:layout_height="wrap_content"- android:layout_marginTop="23dp"android:gravity="center"android:text="@string/trans_no_data"android:textSize="15sp"android:visibility="invisible"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"- app:layout_constraintTop_toBottomOf="@+id/frame" />+ app:layout_constraintTop_toTopOf="@+id/recycler" /><com.google.android.material.textview.MaterialTextViewandroid:id="@+id/sat_name"@@ -104,7 +102,7 @@android:layout_height="wrap_content"android:layout_marginTop="0dp"android:gravity="center"- android:text="Sat Name"+ android:text="@string/placeholder"android:textSize="15sp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.0"diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xmlindex a914bf65..936d9f8a 100644--- a/app/src/main/res/navigation/nav_graph.xml+++ b/app/src/main/res/navigation/nav_graph.xml@@ -16,6 +16,13 @@app:exitAnim="@anim/nav_default_exit_anim"app:popEnterAnim="@anim/nav_default_pop_enter_anim"app:popExitAnim="@anim/nav_default_pop_exit_anim" />+ <action+ android:id="@+id/action_entries_to_sources"+ app:destination="@id/nav_dialog_sources"+ app:enterAnim="@anim/nav_default_enter_anim"+ app:exitAnim="@anim/nav_default_exit_anim"+ app:popEnterAnim="@anim/nav_default_pop_enter_anim"+ app:popExitAnim="@anim/nav_default_pop_exit_anim" /></fragment><fragment@@ -35,6 +42,15 @@android:id="@+id/nav_polar"android:name="com.rtbishop.look4sat.ui.polarScreen.PolarFragment"tools:layout="@layout/fragment_polar">+ <action+ android:id="@+id/action_polar_to_passes"+ app:destination="@id/nav_passes"+ app:enterAnim="@anim/nav_default_enter_anim"+ app:exitAnim="@anim/nav_default_exit_anim"+ app:popEnterAnim="@anim/nav_default_pop_enter_anim"+ app:popExitAnim="@anim/nav_default_pop_exit_anim"+ app:popUpTo="@id/nav_passes"+ app:popUpToInclusive="true" /></fragment><fragmentdiff --git a/app/src/test/java/com/rtbishop/look4sat/CoroutineTestRule.kt b/app/src/test/java/com/rtbishop/look4sat/CoroutineTestRule.ktdeleted file mode 100644index 7f6cd069..00000000--- a/app/src/test/java/com/rtbishop/look4sat/CoroutineTestRule.kt+++ /dev/null@@ -1,42 +0,0 @@-/*- * Look4Sat. Amateur radio satellite tracker and pass predictor.- * Copyright (C) 2019-2021 Arty Bishop ([email protected])- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with this program. If not, see <https://www.gnu.org/licenses/>.- */-package com.rtbishop.look4sat--import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.ExperimentalCoroutinesApi-import kotlinx.coroutines.test.TestCoroutineDispatcher-import kotlinx.coroutines.test.resetMain-import kotlinx.coroutines.test.setMain-import org.junit.rules.TestWatcher-import org.junit.runner.Description--@ExperimentalCoroutinesApi-class CoroutineTestRule(private val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) :- TestWatcher() {-- override fun starting(description: Description?) {- super.starting(description)- Dispatchers.setMain(dispatcher)- }-- override fun finished(description: Description?) {- super.finished(description)- Dispatchers.resetMain()- dispatcher.cleanupTestCoroutines()- }-}