mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 19:17:21 +00:00
Added mockito dependency, fixed radar view update bug #51
This commit is contained in:
1 parent
4cfab17413
commit
1806e0d147
13 files changed
+31
-31
No files matched your search
@@ -67,6 +67,8 @@ dependencies {
|
||||
implementation "com.jakewharton.timber:timber:$timber_version"
|
||||
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
testImplementation "org.mockito:mockito-core:$mockito_version"
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_test_version"
|
||||
androidTestImplementation "org.mockito:mockito-android:$mockito_version"
|
||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leak_canary_version"
|
||||
}
|
||||
@@ -44,8 +44,8 @@ object InteractorsModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideImportDataFromFileUseCase(satelliteRepo: SatelliteRepo): ImportDataFromFile {
|
||||
return ImportDataFromFile(satelliteRepo)
|
||||
fun provideImportDataFromStreamUseCase(satelliteRepo: SatelliteRepo): ImportDataFromStream {
|
||||
return ImportDataFromStream(satelliteRepo)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.io.InputStream
|
||||
|
||||
class NetworkDataSource(private val api: SatelliteService) : RemoteDataSource {
|
||||
|
||||
override suspend fun fetchFileStream(url: String): InputStream? {
|
||||
override suspend fun fetchDataStream(url: String): InputStream? {
|
||||
return api.fetchFileByUrl(url).body()?.byteStream()
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ import com.rtbishop.look4sat.domain.model.SatItem
|
||||
import com.rtbishop.look4sat.framework.model.Result
|
||||
import com.rtbishop.look4sat.framework.model.TleSource
|
||||
import com.rtbishop.look4sat.interactors.GetSatItems
|
||||
import com.rtbishop.look4sat.interactors.ImportDataFromFile
|
||||
import com.rtbishop.look4sat.interactors.ImportDataFromStream
|
||||
import com.rtbishop.look4sat.interactors.ImportDataFromWeb
|
||||
import com.rtbishop.look4sat.interactors.UpdateEntriesSelection
|
||||
import com.rtbishop.look4sat.utility.PrefsManager
|
||||
@@ -46,7 +46,7 @@ class EntriesViewModel @Inject constructor(
|
||||
private val prefsManager: PrefsManager,
|
||||
private val resolver: ContentResolver,
|
||||
private val getSatItems: GetSatItems,
|
||||
private val importDataFromFile: ImportDataFromFile,
|
||||
private val importDataFromStream: ImportDataFromStream,
|
||||
private val importDataFromWeb: ImportDataFromWeb,
|
||||
private val updateEntriesSelection: UpdateEntriesSelection,
|
||||
) : ViewModel(), EntriesAdapter.EntriesClickListener, SearchView.OnQueryTextListener {
|
||||
@@ -70,7 +70,7 @@ class EntriesViewModel @Inject constructor(
|
||||
_satData.value = Result.InProgress
|
||||
runCatching {
|
||||
resolver.openInputStream(uri)?.use { stream ->
|
||||
importDataFromFile(stream)
|
||||
importDataFromStream(stream)
|
||||
}
|
||||
}.onFailure { _satData.value = Result.Error(it) }
|
||||
}
|
||||
|
||||
@@ -50,7 +50,9 @@ class MapViewModel @Inject constructor(
|
||||
private lateinit var selectedSat: Satellite
|
||||
|
||||
val stationPos = liveData {
|
||||
emit(Position(gsp.latitude.toOsmLat(), gsp.longitude.toOsmLon()))
|
||||
val osmLat = getOsmLat(gsp.latitude)
|
||||
val osmLon = getOsmLon(gsp.longitude)
|
||||
emit(Position(osmLat, osmLon))
|
||||
}
|
||||
|
||||
private val _satTrack = MutableLiveData<List<List<Position>>>()
|
||||
@@ -120,8 +122,8 @@ class MapViewModel @Inject constructor(
|
||||
val satPositions = mutableMapOf<Satellite, Position>()
|
||||
list.forEach { satellite ->
|
||||
val satPos = satellite.getPredictor(gsp).getSatPos(date)
|
||||
val osmLat = Math.toDegrees(satPos.latitude).toOsmLat()
|
||||
val osmLon = Math.toDegrees(satPos.longitude).toOsmLon()
|
||||
val osmLat = getOsmLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = getOsmLon(Math.toDegrees(satPos.longitude))
|
||||
satPositions[satellite] = Position(osmLat, osmLon)
|
||||
}
|
||||
_allSatPositions.postValue(satPositions)
|
||||
@@ -133,9 +135,9 @@ class MapViewModel @Inject constructor(
|
||||
val satTracks = mutableListOf<List<Position>>()
|
||||
val currentTrack = mutableListOf<Position>()
|
||||
var oldLongitude = 0.0
|
||||
sat.getPredictor(gsp).getPositions(date, 15, 0, 2.4).forEach { pos ->
|
||||
val osmLat = Math.toDegrees(pos.latitude).toOsmLat()
|
||||
val osmLon = Math.toDegrees(pos.longitude).toOsmLon()
|
||||
sat.getPredictor(gsp).getPositions(date, 15, 0, 2.4).forEach { satPos ->
|
||||
val osmLat = getOsmLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = getOsmLon(Math.toDegrees(satPos.longitude))
|
||||
val currentPosition = Position(osmLat, osmLon)
|
||||
if (oldLongitude < -170.0 && currentPosition.longitude > 170.0) {
|
||||
// adding left terminal position
|
||||
@@ -161,7 +163,9 @@ class MapViewModel @Inject constructor(
|
||||
private suspend fun setSelectedSatFootprint(sat: Satellite, gsp: StationPosition, date: Date) {
|
||||
withContext(defaultDispatcher) {
|
||||
val satFootprint = sat.getPosition(gsp, date).getRangeCircle().map { rangePos ->
|
||||
Position(rangePos.latitude.toOsmLat(), rangePos.longitude.toOsmLon())
|
||||
val osmLat = getOsmLat(rangePos.latitude)
|
||||
val osmLon = getOsmLon(rangePos.longitude)
|
||||
Position(osmLat, osmLon)
|
||||
}
|
||||
_satFootprint.postValue(satFootprint)
|
||||
}
|
||||
@@ -170,8 +174,8 @@ class MapViewModel @Inject constructor(
|
||||
private suspend fun setSelectedSatData(sat: Satellite, gsp: StationPosition, date: Date) {
|
||||
withContext(defaultDispatcher) {
|
||||
val satPos = sat.getPredictor(gsp).getSatPos(date)
|
||||
val osmLat = Math.toDegrees(satPos.latitude).toOsmLat()
|
||||
val osmLon = Math.toDegrees(satPos.longitude).toOsmLon()
|
||||
val osmLat = getOsmLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = getOsmLon(Math.toDegrees(satPos.longitude))
|
||||
val osmPos = Position(osmLat, osmLon)
|
||||
val qthLoc = qthConverter.positionToQTH(osmPos.latitude, osmPos.longitude) ?: "-- --"
|
||||
val velocity = getOrbitalVelocity(satPos.altitude)
|
||||
@@ -183,19 +187,10 @@ class MapViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun Double.toOsmLat(): Double {
|
||||
return min(max(this, -85.0), 85.0)
|
||||
}
|
||||
|
||||
private fun getOsmLat(latitude: Double): Double {
|
||||
return min(max(latitude, -85.0), 85.0)
|
||||
}
|
||||
|
||||
private fun Double.toOsmLon(): Double {
|
||||
val newLon = if (this < -180.0) this + 360.0 else if (this > 180.0) this - 360.0 else this
|
||||
return min(max(newLon, -180.0), 180.0)
|
||||
}
|
||||
|
||||
private fun getOsmLon(longitude: Double): Double {
|
||||
val newLongitude = when {
|
||||
longitude < -180.0 -> longitude + 360.0
|
||||
|
||||
@@ -92,6 +92,7 @@ class PolarView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
canvas.drawColor(ContextCompat.getColor(context, R.color.greyDark))
|
||||
canvas.translate(polarCenter, polarCenter)
|
||||
drawRadarView(canvas)
|
||||
drawRadarText(canvas)
|
||||
|
||||
@@ -14,6 +14,7 @@ buildscript {
|
||||
osmdroid_version = '6.1.10'
|
||||
timber_version = '4.7.1'
|
||||
junit_version = '4.13.2'
|
||||
mockito_version = '3.9.0'
|
||||
coroutines_test_version = '1.3.2'
|
||||
leak_canary_version = '2.5'
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
|
||||
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
testImplementation "org.mockito:mockito-core:$mockito_version"
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_test_version"
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class DefaultSatelliteRepo(
|
||||
return localSource.getSelectedSatellites()
|
||||
}
|
||||
|
||||
override suspend fun importDataFromFile(stream: InputStream) = withContext(ioDispatcher) {
|
||||
override suspend fun importDataFromStream(stream: InputStream) = withContext(ioDispatcher) {
|
||||
val importedEntries = Satellite.importElements(stream).map { tle -> SatEntry(tle) }
|
||||
localSource.updateEntries(importedEntries)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class DefaultSatelliteRepo(
|
||||
val importedEntries = mutableListOf<SatEntry>()
|
||||
val streams = mutableListOf<InputStream>()
|
||||
sources.forEach { source ->
|
||||
remoteSource.fetchFileStream(source)?.let { stream ->
|
||||
remoteSource.fetchDataStream(source)?.let { stream ->
|
||||
if (source.contains(".zip", true)) {
|
||||
val zipStream = ZipInputStream(stream).apply { nextEntry }
|
||||
streams.add(zipStream)
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.InputStream
|
||||
|
||||
interface RemoteDataSource {
|
||||
|
||||
suspend fun fetchFileStream(url: String): InputStream?
|
||||
suspend fun fetchDataStream(url: String): InputStream?
|
||||
|
||||
suspend fun fetchTransmitters(): List<SatTrans>
|
||||
}
|
||||
@@ -14,7 +14,7 @@ interface SatelliteRepo {
|
||||
|
||||
suspend fun getSelectedSatellites(): List<Satellite>
|
||||
|
||||
suspend fun importDataFromFile(stream: InputStream)
|
||||
suspend fun importDataFromStream(stream: InputStream)
|
||||
|
||||
suspend fun importDataFromWeb(sources: List<String>)
|
||||
|
||||
|
||||
@@ -21,5 +21,5 @@ data class StationPosition(
|
||||
val latitude: Double,
|
||||
val longitude: Double,
|
||||
val altitude: Double,
|
||||
val name: String = "base"
|
||||
val name: String = "default"
|
||||
)
|
||||
+2
-2
@@ -3,9 +3,9 @@ package com.rtbishop.look4sat.interactors
|
||||
import com.rtbishop.look4sat.domain.SatelliteRepo
|
||||
import java.io.InputStream
|
||||
|
||||
class ImportDataFromFile(private val satelliteRepo: SatelliteRepo) {
|
||||
class ImportDataFromStream(private val satelliteRepo: SatelliteRepo) {
|
||||
|
||||
suspend operator fun invoke(stream: InputStream) {
|
||||
satelliteRepo.importDataFromFile(stream)
|
||||
satelliteRepo.importDataFromStream(stream)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user