Renamed and moved several classes and interfaces
This commit is contained in:
1 parent
84240c94c6
commit
b6d019ace7
24 files changed
+155
-153
No files matched your search
+1
-1
@@ -24,7 +24,7 @@ import android.hardware.SensorManager
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.round
|
||||
|
||||
class OrientationProvider @Inject constructor(private val sensorManager: SensorManager) :
|
||||
class OrientationSource @Inject constructor(private val sensorManager: SensorManager) :
|
||||
SensorEventListener {
|
||||
|
||||
interface OrientationListener {
|
||||
+3
-3
@@ -21,7 +21,7 @@ import android.content.SharedPreferences
|
||||
import android.hardware.GeomagneticField
|
||||
import android.location.LocationManager
|
||||
import androidx.core.content.edit
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.domain.GeoPos
|
||||
import com.rtbishop.look4sat.domain.QthConverter
|
||||
import com.rtbishop.look4sat.utility.round
|
||||
@@ -29,11 +29,11 @@ import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import javax.inject.Inject
|
||||
|
||||
class PreferencesProvider @Inject constructor(
|
||||
class PreferencesSource @Inject constructor(
|
||||
moshi: Moshi,
|
||||
private val locationManager: LocationManager,
|
||||
private val preferences: SharedPreferences
|
||||
) : PreferencesSource {
|
||||
) : Preferences {
|
||||
|
||||
private val sourcesType = Types.newParameterizedType(List::class.java, String::class.java)
|
||||
private val sourcesAdapter = moshi.adapter<List<String>>(sourcesType)
|
||||
+5
-5
@@ -17,18 +17,18 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework.api
|
||||
|
||||
import com.rtbishop.look4sat.data.RemoteDataSource
|
||||
import com.rtbishop.look4sat.data.RemoteSource
|
||||
import com.rtbishop.look4sat.domain.Transmitter
|
||||
import com.rtbishop.look4sat.utility.DataMapper
|
||||
import java.io.InputStream
|
||||
|
||||
class RemoteSource(private val api: SatelliteService) : RemoteDataSource {
|
||||
class RemoteDataSource(private val satelliteApi: SatelliteApi) : RemoteSource {
|
||||
|
||||
override suspend fun fetchDataStream(url: String): InputStream? {
|
||||
return api.fetchFileByUrl(url).body()?.byteStream()
|
||||
override suspend fun fetchFileStream(url: String): InputStream? {
|
||||
return satelliteApi.fetchFileStream(url).body()?.byteStream()
|
||||
}
|
||||
|
||||
override suspend fun fetchTransmitters(): List<Transmitter> {
|
||||
return DataMapper.satTransListToDomainTransList(api.fetchTransmitters())
|
||||
return DataMapper.satTransListToDomainTransList(satelliteApi.fetchTransmitters())
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -24,11 +24,11 @@ import retrofit2.http.GET
|
||||
import retrofit2.http.Streaming
|
||||
import retrofit2.http.Url
|
||||
|
||||
interface SatelliteService {
|
||||
interface SatelliteApi {
|
||||
|
||||
@Streaming
|
||||
@GET
|
||||
suspend fun fetchFileByUrl(@Url url: String): Response<ResponseBody>
|
||||
suspend fun fetchFileStream(@Url url: String): Response<ResponseBody>
|
||||
|
||||
@GET("transmitters/")
|
||||
suspend fun fetchTransmitters(): List<Transmitter>
|
||||
+7
-7
@@ -17,18 +17,18 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.framework.db
|
||||
|
||||
import com.rtbishop.look4sat.data.LocalDataSource
|
||||
import com.rtbishop.look4sat.data.LocalSource
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
import com.rtbishop.look4sat.data.SatItem
|
||||
import com.rtbishop.look4sat.domain.Transmitter
|
||||
import com.rtbishop.look4sat.domain.Satellite
|
||||
import com.rtbishop.look4sat.domain.Transmitter
|
||||
import com.rtbishop.look4sat.utility.DataMapper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class LocalSource(private val satelliteDao: SatelliteDao) : LocalDataSource {
|
||||
class LocalDataSource(private val satelliteDao: SatelliteDao) : LocalSource {
|
||||
|
||||
override fun getSatItems(): Flow<List<SatItem>> {
|
||||
override fun getEntriesWithModes(): Flow<List<SatItem>> {
|
||||
return satelliteDao.getSatItems()
|
||||
.map { satItems -> DataMapper.satItemsToDomainItems(satItems) }
|
||||
}
|
||||
@@ -46,13 +46,13 @@ class LocalSource(private val satelliteDao: SatelliteDao) : LocalDataSource {
|
||||
satelliteDao.updateEntriesSelection(catNums, isSelected)
|
||||
}
|
||||
|
||||
override fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>> {
|
||||
override fun getTransmitters(catNum: Int): Flow<List<Transmitter>> {
|
||||
return satelliteDao.getSatTransmitters(catNum)
|
||||
.map { satTransList -> DataMapper.satTransListToDomainTransList(satTransList) }
|
||||
}
|
||||
|
||||
override suspend fun updateTransmitters(satelliteTrans: List<Transmitter>) {
|
||||
val satTransList = DataMapper.domainTransListToSatTransList(satelliteTrans)
|
||||
override suspend fun updateTransmitters(transmitters: List<Transmitter>) {
|
||||
val satTransList = DataMapper.domainTransListToSatTransList(transmitters)
|
||||
satelliteDao.updateTransmitters(satTransList)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import com.rtbishop.look4sat.domain.TLE
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
object Converters {
|
||||
object RoomConverters {
|
||||
|
||||
private lateinit var paramsAdapter: JsonAdapter<TLE>
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.rtbishop.look4sat.framework.model.SatEntry
|
||||
import com.rtbishop.look4sat.framework.model.Transmitter
|
||||
|
||||
@Database(entities = [SatEntry::class, Transmitter::class], version = 2, exportSchema = true)
|
||||
@TypeConverters(Converters::class)
|
||||
@TypeConverters(RoomConverters::class)
|
||||
abstract class SatelliteDb : RoomDatabase() {
|
||||
|
||||
abstract fun satelliteDao(): SatelliteDao
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import dagger.hilt.components.SingletonComponent
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object ApplicationModule {
|
||||
object AndroidModule {
|
||||
|
||||
@Provides
|
||||
fun provideContentResolver(@ApplicationContext context: Context): ContentResolver {
|
||||
+21
-18
@@ -21,12 +21,15 @@ import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.location.LocationManager
|
||||
import androidx.room.Room
|
||||
import com.rtbishop.look4sat.data.*
|
||||
import com.rtbishop.look4sat.data.LocalSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.data.RemoteSource
|
||||
import com.rtbishop.look4sat.data.SatelliteRepo
|
||||
import com.rtbishop.look4sat.domain.PassReporter
|
||||
import com.rtbishop.look4sat.domain.Predictor
|
||||
import com.rtbishop.look4sat.framework.PreferencesProvider
|
||||
import com.rtbishop.look4sat.framework.api.RemoteSource
|
||||
import com.rtbishop.look4sat.framework.api.SatelliteService
|
||||
import com.rtbishop.look4sat.framework.PreferencesSource
|
||||
import com.rtbishop.look4sat.framework.api.RemoteDataSource
|
||||
import com.rtbishop.look4sat.framework.api.SatelliteApi
|
||||
import com.rtbishop.look4sat.framework.db.*
|
||||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
@@ -41,7 +44,7 @@ import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object SatelliteDataModule {
|
||||
object DataModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@@ -55,8 +58,8 @@ object SatelliteDataModule {
|
||||
moshi: Moshi,
|
||||
locationManager: LocationManager,
|
||||
preferences: SharedPreferences
|
||||
): PreferencesSource {
|
||||
return PreferencesProvider(moshi, locationManager, preferences)
|
||||
): Preferences {
|
||||
return PreferencesSource(moshi, locationManager, preferences)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -68,17 +71,17 @@ object SatelliteDataModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSatelliteRepo(
|
||||
preferencesSource: PreferencesSource,
|
||||
localDataSource: LocalDataSource,
|
||||
remoteDataSource: RemoteDataSource,
|
||||
preferences: Preferences,
|
||||
localSource: LocalSource,
|
||||
remoteSource: RemoteSource,
|
||||
@IoDispatcher dispatcher: CoroutineDispatcher
|
||||
): SatelliteRepo {
|
||||
return SatelliteRepo(preferencesSource, localDataSource, remoteDataSource, dispatcher)
|
||||
return SatelliteRepo(preferences, localSource, remoteSource, dispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideLocalDataSource(satelliteDao: SatelliteDao): LocalDataSource {
|
||||
return LocalSource(satelliteDao)
|
||||
fun provideLocalDataSource(satelliteDao: SatelliteDao): LocalSource {
|
||||
return LocalDataSource(satelliteDao)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -90,24 +93,24 @@ object SatelliteDataModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||
Converters.initialize(moshi)
|
||||
RoomConverters.initialize(moshi)
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "SatelliteDb")
|
||||
.addMigrations(MIGRATION_1_2).build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRemoteDataSource(satelliteService: SatelliteService): RemoteDataSource {
|
||||
return RemoteSource(satelliteService)
|
||||
fun provideRemoteDataSource(satelliteApi: SatelliteApi): RemoteSource {
|
||||
return RemoteDataSource(satelliteApi)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSatelliteService(): SatelliteService {
|
||||
fun provideSatelliteService(): SatelliteApi {
|
||||
return Retrofit.Builder()
|
||||
.baseUrl("https://db.satnogs.org/api/")
|
||||
.addConverterFactory(MoshiConverterFactory.create())
|
||||
.build().create(SatelliteService::class.java)
|
||||
.build().create(SatelliteApi::class.java)
|
||||
}
|
||||
|
||||
@Provides
|
||||
File renamed without changes.
+3
-3
@@ -21,7 +21,7 @@ import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import android.widget.SearchView
|
||||
import androidx.lifecycle.*
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.data.SatelliteRepo
|
||||
import com.rtbishop.look4sat.data.SatItem
|
||||
import com.rtbishop.look4sat.framework.model.Result
|
||||
@@ -33,7 +33,7 @@ import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class EntriesViewModel @Inject constructor(
|
||||
private val preferencesSource: PreferencesSource,
|
||||
private val preferences: Preferences,
|
||||
private val resolver: ContentResolver,
|
||||
private val satelliteRepo: SatelliteRepo,
|
||||
) : ViewModel(), EntriesAdapter.EntriesClickListener, SearchView.OnQueryTextListener {
|
||||
@@ -67,7 +67,7 @@ class EntriesViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
_satData.value = Result.InProgress
|
||||
try {
|
||||
preferencesSource.saveTleSources(sources)
|
||||
preferences.saveTleSources(sources)
|
||||
satelliteRepo.updateEntriesFromWeb(sources)
|
||||
} catch (exception: Exception) {
|
||||
_satData.value = Result.Error(exception)
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.rtbishop.look4sat.presentation.mapScreen
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import com.rtbishop.look4sat.domain.Predictor
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.data.SatelliteRepo
|
||||
import com.rtbishop.look4sat.domain.*
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -33,7 +33,7 @@ import kotlin.math.min
|
||||
class MapViewModel @Inject constructor(
|
||||
private val satelliteRepo: SatelliteRepo,
|
||||
private val predictor: Predictor,
|
||||
private val preferences: PreferencesSource,
|
||||
private val preferences: Preferences,
|
||||
) : ViewModel() {
|
||||
|
||||
private val stationPos = preferences.loadStationPosition()
|
||||
|
||||
+16
-16
@@ -21,7 +21,7 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.data.SatelliteRepo
|
||||
import com.rtbishop.look4sat.domain.Predictor
|
||||
import com.rtbishop.look4sat.domain.SatPass
|
||||
@@ -36,7 +36,7 @@ import javax.inject.Inject
|
||||
class PassesViewModel @Inject constructor(
|
||||
private val satelliteRepo: SatelliteRepo,
|
||||
private val predictor: Predictor,
|
||||
private val preferencesSource: PreferencesSource
|
||||
private val preferences: Preferences
|
||||
) : ViewModel() {
|
||||
|
||||
private val _passes = MutableLiveData<Result<List<SatPass>>>(Result.InProgress)
|
||||
@@ -46,14 +46,14 @@ class PassesViewModel @Inject constructor(
|
||||
val isFirstLaunchDone: LiveData<Boolean> = _isFirstLaunchDone
|
||||
|
||||
init {
|
||||
if (preferencesSource.isSetupDone()) {
|
||||
if (preferences.isSetupDone()) {
|
||||
viewModelScope.launch {
|
||||
_passes.postValue(Result.InProgress)
|
||||
val dateNow = Date()
|
||||
val satellites = satelliteRepo.getSelectedSatellites()
|
||||
val stationPos = preferencesSource.loadStationPosition()
|
||||
val hoursAhead = preferencesSource.getHoursAhead()
|
||||
val minElev = preferencesSource.getMinElevation()
|
||||
val stationPos = preferences.loadStationPosition()
|
||||
val hoursAhead = preferences.getHoursAhead()
|
||||
val minElev = preferences.getMinElevation()
|
||||
predictor.triggerCalculation(satellites, stationPos, dateNow, hoursAhead, minElev)
|
||||
}
|
||||
} else {
|
||||
@@ -68,19 +68,19 @@ class PassesViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun triggerInitialSetup() {
|
||||
preferencesSource.updatePositionFromGPS()
|
||||
preferences.updatePositionFromGPS()
|
||||
viewModelScope.launch {
|
||||
_passes.postValue(Result.InProgress)
|
||||
val defaultCatNums = listOf(43700, 25544, 25338, 28654, 33591, 40069, 27607, 24278)
|
||||
val dateNow = Date()
|
||||
val satellites = satelliteRepo.getSelectedSatellites()
|
||||
val stationPos = preferencesSource.loadStationPosition()
|
||||
val hoursAhead = preferencesSource.getHoursAhead()
|
||||
val minElev = preferencesSource.getMinElevation()
|
||||
satelliteRepo.updateEntriesFromWeb(preferencesSource.loadDefaultSources())
|
||||
val stationPos = preferences.loadStationPosition()
|
||||
val hoursAhead = preferences.getHoursAhead()
|
||||
val minElev = preferences.getMinElevation()
|
||||
satelliteRepo.updateEntriesFromWeb(preferences.loadDefaultSources())
|
||||
satelliteRepo.updateEntriesSelection(defaultCatNums, true)
|
||||
predictor.forceCalculation(satellites, stationPos, dateNow, hoursAhead, minElev)
|
||||
preferencesSource.setSetupDone()
|
||||
preferences.setSetupDone()
|
||||
_isFirstLaunchDone.value = true
|
||||
}
|
||||
}
|
||||
@@ -91,15 +91,15 @@ class PassesViewModel @Inject constructor(
|
||||
passesProcessing?.cancelAndJoin()
|
||||
val dateNow = Date()
|
||||
val satellites = satelliteRepo.getSelectedSatellites()
|
||||
val stationPos = preferencesSource.loadStationPosition()
|
||||
val hoursAhead = preferencesSource.getHoursAhead()
|
||||
val minElev = preferencesSource.getMinElevation()
|
||||
val stationPos = preferences.loadStationPosition()
|
||||
val hoursAhead = preferences.getHoursAhead()
|
||||
val minElev = preferences.getMinElevation()
|
||||
predictor.forceCalculation(satellites, stationPos, dateNow, hoursAhead, minElev)
|
||||
}
|
||||
}
|
||||
|
||||
fun shouldUseUTC(): Boolean {
|
||||
return preferencesSource.shouldUseUTC()
|
||||
return preferences.shouldUseUTC()
|
||||
}
|
||||
|
||||
private suspend fun tickPasses(passes: List<SatPass>) = withContext(Dispatchers.Default) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.databinding.FragmentRadarBinding
|
||||
import com.rtbishop.look4sat.domain.SatPass
|
||||
import com.rtbishop.look4sat.domain.SatPos
|
||||
@@ -39,7 +39,7 @@ import javax.inject.Inject
|
||||
class RadarFragment : Fragment(R.layout.fragment_radar) {
|
||||
|
||||
@Inject
|
||||
lateinit var preferences: PreferencesSource
|
||||
lateinit var preferences: Preferences
|
||||
private val viewModel: RadarViewModel by viewModels()
|
||||
private var radarView: RadarView? = null
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ package com.rtbishop.look4sat.presentation.radarScreen
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import com.rtbishop.look4sat.domain.PassReporter
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.data.SatelliteRepo
|
||||
import com.rtbishop.look4sat.domain.Predictor
|
||||
import com.rtbishop.look4sat.domain.SatPass
|
||||
import com.rtbishop.look4sat.domain.SatPos
|
||||
import com.rtbishop.look4sat.domain.Transmitter
|
||||
import com.rtbishop.look4sat.framework.OrientationProvider
|
||||
import com.rtbishop.look4sat.framework.OrientationSource
|
||||
import com.rtbishop.look4sat.utility.round
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -37,12 +37,12 @@ import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class RadarViewModel @Inject constructor(
|
||||
private val orientationProvider: OrientationProvider,
|
||||
private val preferences: PreferencesSource,
|
||||
private val orientationSource: OrientationSource,
|
||||
private val preferences: Preferences,
|
||||
private val predictor: Predictor,
|
||||
private val satelliteRepo: SatelliteRepo,
|
||||
private val passReporter: PassReporter
|
||||
) : ViewModel(), OrientationProvider.OrientationListener {
|
||||
) : ViewModel(), OrientationSource.OrientationListener {
|
||||
|
||||
private val stationPos = preferences.loadStationPosition()
|
||||
private val _passData = MutableLiveData<RadarData>()
|
||||
@@ -64,11 +64,11 @@ class RadarViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun enableSensor() {
|
||||
if (preferences.shouldUseCompass()) orientationProvider.startListening(this)
|
||||
if (preferences.shouldUseCompass()) orientationSource.startListening(this)
|
||||
}
|
||||
|
||||
fun disableSensor() {
|
||||
if (preferences.shouldUseCompass()) orientationProvider.stopListening()
|
||||
if (preferences.shouldUseCompass()) orientationSource.stopListening()
|
||||
}
|
||||
|
||||
override fun onOrientationChanged(azimuth: Float, pitch: Float, roll: Float) {
|
||||
|
||||
+9
-9
@@ -29,8 +29,8 @@ import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.framework.PreferencesProvider
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.framework.PreferencesSource
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -38,7 +38,7 @@ import javax.inject.Inject
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
@Inject
|
||||
lateinit var preferencesSource: PreferencesSource
|
||||
lateinit var preferences: Preferences
|
||||
|
||||
private val requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
|
||||
@@ -56,20 +56,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
findPreference<Preference>(PreferencesProvider.keyPositionGPS)?.apply {
|
||||
findPreference<Preference>(PreferencesSource.keyPositionGPS)?.apply {
|
||||
setOnPreferenceClickListener {
|
||||
updatePositionFromGPS()
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<Preference>(PreferencesProvider.keyPositionQTH)?.apply {
|
||||
findPreference<Preference>(PreferencesSource.keyPositionQTH)?.apply {
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
updatePositionFromQth(newValue.toString())
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<EditTextPreference>(PreferencesProvider.keyRotatorAddress)?.apply {
|
||||
findPreference<EditTextPreference>(PreferencesSource.keyRotatorAddress)?.apply {
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val ip4 = "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!\$)|\$)){4}\$"
|
||||
if (newValue.toString().matches(ip4.toRegex())) {
|
||||
@@ -81,7 +81,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<EditTextPreference>(PreferencesProvider.keyRotatorPort)?.apply {
|
||||
findPreference<EditTextPreference>(PreferencesSource.keyRotatorPort)?.apply {
|
||||
setOnBindEditTextListener { it.inputType = InputType.TYPE_CLASS_NUMBER }
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val portValue = newValue.toString()
|
||||
@@ -96,7 +96,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
|
||||
private fun updatePositionFromQth(qthString: String): Boolean {
|
||||
return if (preferencesSource.updatePositionFromQTH(qthString)) {
|
||||
return if (preferences.updatePositionFromQTH(qthString)) {
|
||||
showSnack(getString(R.string.pref_pos_success))
|
||||
true
|
||||
} else {
|
||||
@@ -109,7 +109,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
val locPermString = Manifest.permission.ACCESS_FINE_LOCATION
|
||||
val locPermResult = ContextCompat.checkSelfPermission(requireContext(), locPermString)
|
||||
if (locPermResult == PackageManager.PERMISSION_GRANTED) {
|
||||
if (preferencesSource.updatePositionFromGPS()) {
|
||||
if (preferences.updatePositionFromGPS()) {
|
||||
showSnack(getString(R.string.pref_pos_success))
|
||||
} else {
|
||||
showSnack(getString(R.string.pref_pos_gps_null))
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatDialogFragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.data.Preferences
|
||||
import com.rtbishop.look4sat.databinding.DialogSourcesBinding
|
||||
import com.rtbishop.look4sat.utility.setNavResult
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -35,7 +35,7 @@ import javax.inject.Inject
|
||||
class SourcesDialog : AppCompatDialogFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var prefsManager: PreferencesSource
|
||||
lateinit var prefsManager: Preferences
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.dialog_sources, group, false)
|
||||
|
||||
+4
-4
@@ -21,11 +21,11 @@ import com.rtbishop.look4sat.domain.Transmitter
|
||||
import com.rtbishop.look4sat.domain.Satellite
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface LocalDataSource {
|
||||
interface LocalSource {
|
||||
|
||||
fun getSatItems(): Flow<List<SatItem>>
|
||||
fun getEntriesWithModes(): Flow<List<SatItem>>
|
||||
|
||||
fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>>
|
||||
fun getTransmitters(catNum: Int): Flow<List<Transmitter>>
|
||||
|
||||
suspend fun getSelectedSatellites(): List<Satellite>
|
||||
|
||||
@@ -33,5 +33,5 @@ interface LocalDataSource {
|
||||
|
||||
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean)
|
||||
|
||||
suspend fun updateTransmitters(satelliteTrans: List<Transmitter>)
|
||||
suspend fun updateTransmitters(transmitters: List<Transmitter>)
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ package com.rtbishop.look4sat.data
|
||||
|
||||
import com.rtbishop.look4sat.domain.GeoPos
|
||||
|
||||
interface PreferencesSource {
|
||||
interface Preferences {
|
||||
|
||||
fun positionToQTH(lat: Double, lon: Double): String?
|
||||
|
||||
+2
-2
@@ -20,9 +20,9 @@ package com.rtbishop.look4sat.data
|
||||
import com.rtbishop.look4sat.domain.Transmitter
|
||||
import java.io.InputStream
|
||||
|
||||
interface RemoteDataSource {
|
||||
interface RemoteSource {
|
||||
|
||||
suspend fun fetchDataStream(url: String): InputStream?
|
||||
suspend fun fetchFileStream(url: String): InputStream?
|
||||
|
||||
suspend fun fetchTransmitters(): List<Transmitter>
|
||||
}
|
||||
@@ -29,43 +29,43 @@ import java.io.InputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class SatelliteRepo(
|
||||
private val preferencesSource: PreferencesSource,
|
||||
private val localDataSource: LocalDataSource,
|
||||
private val remoteDataSource: RemoteDataSource,
|
||||
private val ioDispatcher: CoroutineDispatcher
|
||||
private val preferences: Preferences,
|
||||
private val localSource: LocalSource,
|
||||
private val remoteSource: RemoteSource,
|
||||
private val repoDispatcher: CoroutineDispatcher
|
||||
) {
|
||||
|
||||
fun saveSelectedModes(modes: List<String>) {
|
||||
preferencesSource.saveModesSelection(modes)
|
||||
preferences.saveModesSelection(modes)
|
||||
}
|
||||
|
||||
fun loadSelectedModes(): List<String> {
|
||||
return preferencesSource.loadModesSelection()
|
||||
return preferences.loadModesSelection()
|
||||
}
|
||||
|
||||
fun getSatItems(): Flow<List<SatItem>> {
|
||||
return localDataSource.getSatItems()
|
||||
return localSource.getEntriesWithModes()
|
||||
}
|
||||
|
||||
fun getSatTransmitters(catNum: Int): Flow<List<Transmitter>> {
|
||||
return localDataSource.getSatTransmitters(catNum)
|
||||
return localSource.getTransmitters(catNum)
|
||||
}
|
||||
|
||||
suspend fun getSelectedSatellites(): List<Satellite> {
|
||||
return localDataSource.getSelectedSatellites()
|
||||
return localSource.getSelectedSatellites()
|
||||
}
|
||||
|
||||
suspend fun updateEntriesFromFile(stream: InputStream) = withContext(ioDispatcher) {
|
||||
localDataSource.updateEntries(importSatEntries(stream))
|
||||
suspend fun updateEntriesFromFile(stream: InputStream) = withContext(repoDispatcher) {
|
||||
localSource.updateEntries(importSatEntries(stream))
|
||||
}
|
||||
|
||||
suspend fun updateEntriesFromWeb(sources: List<String>) {
|
||||
coroutineScope {
|
||||
launch(ioDispatcher) {
|
||||
launch(repoDispatcher) {
|
||||
val streams = mutableListOf<InputStream>()
|
||||
val entries = mutableListOf<SatEntry>()
|
||||
sources.forEach { source ->
|
||||
remoteDataSource.fetchDataStream(source)?.let { stream ->
|
||||
remoteSource.fetchFileStream(source)?.let { stream ->
|
||||
if (source.contains(".zip", true)) {
|
||||
val zipStream = ZipInputStream(stream).apply { nextEntry }
|
||||
streams.add(zipStream)
|
||||
@@ -75,20 +75,20 @@ class SatelliteRepo(
|
||||
}
|
||||
}
|
||||
streams.forEach { stream -> entries.addAll(importSatEntries(stream)) }
|
||||
localDataSource.updateEntries(entries)
|
||||
localSource.updateEntries(entries)
|
||||
}
|
||||
launch(ioDispatcher) {
|
||||
val transmitters = remoteDataSource.fetchTransmitters().filter { it.isAlive }
|
||||
localDataSource.updateTransmitters(transmitters)
|
||||
launch(repoDispatcher) {
|
||||
val transmitters = remoteSource.fetchTransmitters().filter { it.isAlive }
|
||||
localSource.updateTransmitters(transmitters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
|
||||
localDataSource.updateEntriesSelection(catNums, isSelected)
|
||||
localSource.updateEntriesSelection(catNums, isSelected)
|
||||
}
|
||||
|
||||
private fun importSatEntries(stream: InputStream): List<SatEntry> {
|
||||
return TLE.parseStream(stream).map { tle -> SatEntry(tle) }
|
||||
return TLE.parseTleStream(stream).map { tle -> SatEntry(tle) }
|
||||
}
|
||||
}
|
||||
@@ -50,35 +50,32 @@ data class SatPos(
|
||||
|
||||
fun getRangeCircle(): List<GeoPos> {
|
||||
val positions = mutableListOf<GeoPos>()
|
||||
val lat = this.latitude
|
||||
val lon = this.longitude
|
||||
// rangeCircleRadiusKm
|
||||
// earthRadiusKm * acos(earthRadiusKm / (earthRadiusKm + satPos.altitude))
|
||||
val beta = acos(earthRadiusKm / (earthRadiusKm + this.altitude))
|
||||
// val radiusKm = earthRadiusKm * acos(earthRadiusKm / (earthRadiusKm + altitude))
|
||||
var tempAzimuth = 0
|
||||
while (tempAzimuth < 360) {
|
||||
val azimuth = tempAzimuth / 360.0 * 2.0 * Math.PI
|
||||
var rangelat = asin(sin(lat) * cos(beta) + cos(azimuth) * sin(beta) * cos(lat))
|
||||
val num = (cos(beta) - (sin(lat) * sin(rangelat)))
|
||||
val den = cos(lat) * cos(rangelat)
|
||||
var rangelon = if (tempAzimuth == 0 && (beta > ((Math.PI / 2.0) - lat))) {
|
||||
lon + Math.PI
|
||||
} else if (tempAzimuth == 180 && (beta > ((Math.PI / 2.0) - lat))) {
|
||||
lon + Math.PI
|
||||
var lat = asin(sin(latitude) * cos(beta) + cos(azimuth) * sin(beta) * cos(latitude))
|
||||
val num = (cos(beta) - (sin(latitude) * sin(lat)))
|
||||
val den = cos(latitude) * cos(lat)
|
||||
var lon = if (tempAzimuth == 0 && (beta > ((Math.PI / 2.0) - latitude))) {
|
||||
longitude + Math.PI
|
||||
} else if (tempAzimuth == 180 && (beta > ((Math.PI / 2.0) - latitude))) {
|
||||
longitude + Math.PI
|
||||
} else if (abs(num / den) > 1.0) {
|
||||
lon
|
||||
longitude
|
||||
} else {
|
||||
if ((180 - tempAzimuth) >= 0) {
|
||||
lon - acos(num / den)
|
||||
longitude - acos(num / den)
|
||||
} else {
|
||||
lon + acos(num / den)
|
||||
longitude + acos(num / den)
|
||||
}
|
||||
}
|
||||
while (rangelon < 0.0) rangelon += Math.PI * 2.0
|
||||
while (rangelon > Math.PI * 2.0) rangelon -= Math.PI * 2.0
|
||||
rangelat = Math.toDegrees(rangelat)
|
||||
rangelon = Math.toDegrees(rangelon)
|
||||
positions.add(GeoPos(rangelat, rangelon))
|
||||
while (lon < 0.0) lon += Math.PI * 2.0
|
||||
while (lon > Math.PI * 2.0) lon -= Math.PI * 2.0
|
||||
lat = Math.toDegrees(lat)
|
||||
lon = Math.toDegrees(lon)
|
||||
positions.add(GeoPos(lat, lon))
|
||||
tempAzimuth += 1
|
||||
}
|
||||
return positions
|
||||
|
||||
@@ -48,39 +48,41 @@ data class TLE(
|
||||
|
||||
companion object {
|
||||
|
||||
fun parseStream(stream: InputStream): List<TLE> {
|
||||
val itemParams = mutableListOf(String(), String(), String())
|
||||
val importedItems = mutableListOf<TLE>()
|
||||
fun parseTleStream(stream: InputStream): List<TLE> {
|
||||
val tleStrings = mutableListOf(String(), String(), String())
|
||||
val parsedItems = mutableListOf<TLE>()
|
||||
var lineIndex = 0
|
||||
stream.bufferedReader().forEachLine { line ->
|
||||
itemParams[lineIndex] = line
|
||||
tleStrings[lineIndex] = line
|
||||
if (lineIndex < 2) {
|
||||
lineIndex++
|
||||
} else {
|
||||
val isLineOneValid = itemParams[1].substring(0, 1) == "1"
|
||||
val isLineTwoValid = itemParams[2].substring(0, 1) == "2"
|
||||
val isLineOneValid = tleStrings[1].substring(0, 1) == "1"
|
||||
val isLineTwoValid = tleStrings[2].substring(0, 1) == "2"
|
||||
if (!isLineOneValid && !isLineTwoValid) return@forEachLine
|
||||
parseParams(itemParams)?.let { tle -> importedItems.add(tle) }
|
||||
parseTleStrings(tleStrings)?.let { tle -> parsedItems.add(tle) }
|
||||
lineIndex = 0
|
||||
}
|
||||
}
|
||||
return importedItems
|
||||
return parsedItems
|
||||
}
|
||||
|
||||
private fun parseParams(params: List<String>): TLE? {
|
||||
if (params[1].substring(0, 1) != "1" && params[2].substring(0, 1) != "2") return null
|
||||
private fun parseTleStrings(tleStrings: List<String>): TLE? {
|
||||
if (tleStrings[1].substring(0, 1) != "1" && tleStrings[2].substring(0, 1) != "2") {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
val name: String = params[0].trim()
|
||||
val epoch: Double = params[1].substring(18, 32).toDouble()
|
||||
val meanmo: Double = params[2].substring(52, 63).toDouble()
|
||||
val eccn: Double = 1.0e-07 * params[2].substring(26, 33).toDouble()
|
||||
val incl: Double = params[2].substring(8, 16).toDouble()
|
||||
val raan: Double = params[2].substring(17, 25).toDouble()
|
||||
val argper: Double = params[2].substring(34, 42).toDouble()
|
||||
val meanan: Double = params[2].substring(43, 51).toDouble()
|
||||
val catnum: Int = params[1].substring(2, 7).trim().toInt()
|
||||
val bstar: Double = 1.0e-5 * params[1].substring(53, 59).toDouble() /
|
||||
10.0.pow(params[1].substring(60, 61).toDouble())
|
||||
val name: String = tleStrings[0].trim()
|
||||
val epoch: Double = tleStrings[1].substring(18, 32).toDouble()
|
||||
val meanmo: Double = tleStrings[2].substring(52, 63).toDouble()
|
||||
val eccn: Double = 1.0e-07 * tleStrings[2].substring(26, 33).toDouble()
|
||||
val incl: Double = tleStrings[2].substring(8, 16).toDouble()
|
||||
val raan: Double = tleStrings[2].substring(17, 25).toDouble()
|
||||
val argper: Double = tleStrings[2].substring(34, 42).toDouble()
|
||||
val meanan: Double = tleStrings[2].substring(43, 51).toDouble()
|
||||
val catnum: Int = tleStrings[1].substring(2, 7).trim().toInt()
|
||||
val bstar: Double = 1.0e-5 * tleStrings[1].substring(53, 59).toDouble() /
|
||||
10.0.pow(tleStrings[1].substring(60, 61).toDouble())
|
||||
return TLE(name, epoch, meanmo, eccn, incl, raan, argper, meanan, catnum, bstar)
|
||||
} catch (exception: Exception) {
|
||||
return null
|
||||
|
||||
+7
-7
@@ -3,9 +3,9 @@ package com.rtbishop.look4sat
|
||||
import com.rtbishop.look4sat.domain.TLE
|
||||
import org.junit.Test
|
||||
|
||||
class Look4SatTest {
|
||||
class TleParserTest {
|
||||
|
||||
private val validParamsStream = """
|
||||
private val validTleStream = """
|
||||
ISS (ZARYA)
|
||||
1 25544U 98067A 21255.21005818 -.00120443 00000-0 -22592-2 0 9998
|
||||
2 25544 51.6451 272.4173 0002526 27.1693 64.4213 15.48396490302085
|
||||
@@ -16,7 +16,7 @@ class Look4SatTest {
|
||||
1 48869U 21057A 21254.57379002 .00002620 00000-0 56399-4 0 9993
|
||||
2 48869 51.6436 275.5624 0003404 23.4371 118.9508 15.48629868301984
|
||||
""".trimIndent().byteInputStream()
|
||||
private val invalidParamsStream = """
|
||||
private val invalidTleStream = """
|
||||
1 25544U 98067A 21255.21005818 -.00120443 00000-0 -22592-2 0 9998
|
||||
2 25544 51.6451 272.4173 0002526 27.1693 64.4213 15.48396490302085
|
||||
1 48852U 21053A 21254.65783594 .00009779 00000-0 11349-3 0 9992
|
||||
@@ -26,14 +26,14 @@ class Look4SatTest {
|
||||
""".trimIndent().byteInputStream()
|
||||
|
||||
@Test
|
||||
fun `Given valid params stream returns valid data`() {
|
||||
val parsedList = TLE.parseStream(validParamsStream)
|
||||
fun `Given valid TLE stream returns valid data`() {
|
||||
val parsedList = TLE.parseTleStream(validTleStream)
|
||||
assert(parsedList[2].catnum == 48869)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given invalid params stream returns empty list`() {
|
||||
val parsedList = TLE.parseStream(invalidParamsStream)
|
||||
fun `Given invalid TLE stream returns empty list`() {
|
||||
val parsedList = TLE.parseTleStream(invalidTleStream)
|
||||
assert(parsedList.isEmpty())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user