Removed sat track tail from the map, minor refactoring

This commit is contained in:
Arty Bishop committed 2021-04-17 12:46:51 +01:00
1 parent a205ebfa2b
commit 18820b79f4
10 files changed
+107 -147

No files matched your search

@@ -22,7 +22,6 @@ import android.content.Context
import android.content.SharedPreferences
import android.hardware.SensorManager
import android.location.LocationManager
import android.view.WindowManager
import androidx.preference.PreferenceManager
import dagger.Module
import 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
}
@Provides
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(context)
@@ -33,6 +33,7 @@ import com.rtbishop.look4sat.data.model.TleSource
import com.rtbishop.look4sat.databinding.FragmentEntriesBinding
import com.rtbishop.look4sat.utility.RecyclerDivider
import com.rtbishop.look4sat.utility.getNavResult
import com.rtbishop.look4sat.utility.navigateSafe
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
@@ -61,7 +62,9 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
addItemDecoration(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() }
@@ -24,7 +24,6 @@ import com.github.amsacode.predict4java.Position
import com.github.amsacode.predict4java.SatPos
import com.github.amsacode.predict4java.Satellite
import com.rtbishop.look4sat.data.model.SelectedSat
import com.rtbishop.look4sat.utility.PrefsManager
import com.rtbishop.look4sat.data.repository.SatelliteRepo
import com.rtbishop.look4sat.utility.*
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -35,7 +34,6 @@ import org.osmdroid.views.overlay.Overlay
import org.osmdroid.views.overlay.Polygon
import org.osmdroid.views.overlay.Polyline
import timber.log.Timber
import java.lang.IllegalArgumentException
import 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.0
@@ -1,85 +0,0 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
*
* 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)
}
}
@@ -0,0 +1,77 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
*
* 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)
}
}
@@ -29,6 +29,7 @@ import com.rtbishop.look4sat.data.model.SatPass
import com.rtbishop.look4sat.databinding.FragmentPolarBinding
import com.rtbishop.look4sat.utility.RecyclerDivider
import com.rtbishop.look4sat.utility.formatForTimer
import com.rtbishop.look4sat.utility.navigateSafe
import dagger.hilt.android.AndroidEntryPoint
import 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 {
@@ -34,12 +34,12 @@ import javax.inject.Inject
@HiltViewModel
class 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) {
+3 -5
View File
@@ -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.MaterialTextView
android: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.MaterialTextView
android: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"
+16
View File
@@ -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>
<fragment
@@ -1,42 +0,0 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2021 Arty Bishop (bishop.arty@gmail.com)
*
* 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()
}
}