Added framework DataSources, DataMapper and Models

This commit is contained in:
Arty Bishop committed 2021-04-23 10:19:51 +01:00
1 parent 865ecfb5bf
commit 53fcf4790a
46 files changed
+566 -58

No files matched your search

+2 -2
View File
@@ -6,12 +6,12 @@
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".ui.Look4SatApplication"
android:name=".presentation.Look4SatApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".ui.Look4SatActivity"
android:name=".presentation.Look4SatActivity"
android:theme="@style/AppTheme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -0,0 +1,21 @@
package com.rtbishop.look4sat.framework.api
import com.rtbishop.look4sat.data.RemoteDataSource
import com.rtbishop.look4sat.domain.model.SatTrans
import java.io.InputStream
class RetrofitDataSource(private val satelliteService: SatelliteService) : RemoteDataSource {
override suspend fun fetchFileStream(url: String): InputStream? {
return satelliteService.fetchFileByUrl(url).body()?.byteStream()
}
override suspend fun fetchTransmitters(): List<SatTrans> {
return satelliteService.fetchTransmitters().map { trans ->
SatTrans(
trans.uuid, trans.info, trans.isAlive, trans.downlink,
trans.uplink, trans.mode, trans.isInverted, trans.catNum
)
}
}
}
@@ -0,0 +1,35 @@
/*
* 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.framework.api
import com.rtbishop.look4sat.framework.model.SatTrans
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Streaming
import retrofit2.http.Url
interface SatelliteService {
@Streaming
@GET
suspend fun fetchFileByUrl(@Url url: String): Response<ResponseBody>
@GET("transmitters/")
suspend fun fetchTransmitters(): List<SatTrans>
}
@@ -0,0 +1,51 @@
/*
* 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.framework.db
import androidx.room.TypeConverter
import com.rtbishop.look4sat.predict4kotlin.Satellite
import com.rtbishop.look4sat.predict4kotlin.TLE
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
object RoomConverters {
private lateinit var tleAdapter: JsonAdapter<TLE>
fun initialize(moshi: Moshi) {
tleAdapter = moshi.adapter(TLE::class.java)
}
@JvmStatic
@TypeConverter
fun tleToString(tle: TLE): String {
return tleAdapter.toJson(tle)
}
@JvmStatic
@TypeConverter
fun tleFromString(string: String): TLE? {
return tleAdapter.fromJson(string)
}
@JvmStatic
@TypeConverter
fun satFromString(string: String): Satellite? {
return Satellite.createSat(tleAdapter.fromJson(string))
}
}
@@ -0,0 +1,41 @@
package com.rtbishop.look4sat.framework.db
import com.rtbishop.look4sat.data.LocalDataSource
import com.rtbishop.look4sat.domain.model.SatEntry
import com.rtbishop.look4sat.domain.model.SatItem
import com.rtbishop.look4sat.domain.model.SatTrans
import com.rtbishop.look4sat.predict4kotlin.Satellite
import com.rtbishop.look4sat.utility.DataMapper
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class RoomDataSource(private val satelliteDao: SatelliteDao) : LocalDataSource {
override fun getSatItems(): Flow<List<SatItem>> {
return satelliteDao.getSatItems()
.map { satItems -> DataMapper.satItemsToDomainItems(satItems) }
}
override suspend fun getSelectedSatellites(): List<Satellite> {
return satelliteDao.getSelectedSatellites()
}
override suspend fun updateEntries(entries: List<SatEntry>) {
val satEntries = entries.map { entry -> DataMapper.domainEntryToSatEntry(entry) }
satelliteDao.updateEntries(satEntries)
}
override suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
satelliteDao.updateEntriesSelection(catNums, isSelected)
}
override fun getTransmittersForSat(catNum: Int): Flow<List<SatTrans>> {
return satelliteDao.getSatTransmitters(catNum)
.map { satTransList -> DataMapper.satTransListToDomainTransList(satTransList) }
}
override suspend fun updateTransmitters(satelliteTrans: List<SatTrans>) {
val satTransList = DataMapper.domainTransListToSatTransList(satelliteTrans)
satelliteDao.updateTransmitters(satTransList)
}
}
@@ -0,0 +1,81 @@
/*
* 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.framework.db
import androidx.room.*
import com.rtbishop.look4sat.framework.model.SatEntry
import com.rtbishop.look4sat.framework.model.SatItem
import com.rtbishop.look4sat.framework.model.SatTrans
import com.rtbishop.look4sat.predict4kotlin.Satellite
import kotlinx.coroutines.flow.Flow
@Dao
interface SatelliteDao {
@Transaction
@Query("SELECT catNum, name, isSelected FROM entries ORDER BY name ASC")
fun getSatItems(): Flow<List<SatItem>>
@Query("SELECT * FROM transmitters WHERE catNum = :catNum")
fun getSatTransmitters(catNum: Int): Flow<List<SatTrans>>
@Query("SELECT tle FROM entries WHERE isSelected = 1")
suspend fun getSelectedSatellites(): List<Satellite>
@Query("SELECT catNum FROM entries WHERE isSelected = 1")
suspend fun getSelectedCatNums(): List<Int>
@Transaction
suspend fun updateEntries(entries: List<SatEntry>) {
val selectedCatNums = getSelectedCatNums()
insertEntries(entries)
restoreEntriesSelection(selectedCatNums, true)
}
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertEntries(entries: List<SatEntry>)
@Transaction
suspend fun restoreEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
clearEntriesSelection()
catNums.forEach { catNum -> updateEntrySelection(catNum, isSelected) }
}
@Query("UPDATE entries SET isSelected = 0")
suspend fun clearEntriesSelection()
@Query("UPDATE entries SET isSelected = :isSelected WHERE catNum = :catNum")
suspend fun updateEntrySelection(catNum: Int, isSelected: Boolean)
@Transaction
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean) {
catNums.forEach { catNum -> updateEntrySelection(catNum, isSelected) }
}
@Transaction
suspend fun updateTransmitters(transmitters: List<SatTrans>) {
deleteTransmitters()
insertTransmitters(transmitters)
}
@Query("DELETE from transmitters")
suspend fun deleteTransmitters()
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertTransmitters(transmitters: List<SatTrans>)
}
@@ -0,0 +1,31 @@
/*
* 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.framework.db
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.rtbishop.look4sat.framework.model.SatEntry
import com.rtbishop.look4sat.framework.model.SatTrans
@Database(entities = [SatEntry::class, SatTrans::class], version = 1)
@TypeConverters(RoomConverters::class)
abstract class SatelliteDb : RoomDatabase() {
abstract fun satelliteDao(): SatelliteDao
}
@@ -0,0 +1,24 @@
/*
* 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.framework.model
sealed class Result<out T : Any> {
data class Success<out T : Any>(val data: T) : Result<T>()
data class Error(val exception: Throwable) : Result<Nothing>()
object InProgress : Result<Nothing>()
}
@@ -0,0 +1,30 @@
/*
* 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.framework.model
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.rtbishop.look4sat.predict4kotlin.TLE
@Entity(tableName = "entries")
data class SatEntry(
val tle: TLE,
@PrimaryKey val catNum: Int = tle.catnum,
val name: String = tle.name,
var isSelected: Boolean = false
)
@@ -0,0 +1,33 @@
/*
* 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.framework.model
import androidx.room.Relation
data class SatItem(
val catNum: Int,
val name: String,
var isSelected: Boolean,
@Relation(
parentColumn = "catNum",
entity = SatTrans::class,
entityColumn = "catNum",
projection = ["mode"]
)
val modes: List<String>
)
@@ -15,9 +15,9 @@
* 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.domain.model
package com.rtbishop.look4sat.framework.model
import com.rtbishop.look4sat.predict4kotlin.PassPredictor
import com.rtbishop.look4sat.utility.PassPredictor
import java.util.*
data class SatPass(
@@ -0,0 +1,34 @@
/*
* 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.framework.model
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.squareup.moshi.Json
@Entity(tableName = "transmitters")
data class SatTrans(
@PrimaryKey @field:Json(name = "uuid") val uuid: String,
@field:Json(name = "description") val info: String,
@field:Json(name = "alive") val isAlive: Boolean,
@field:Json(name = "downlink_low") var downlink: Long?,
@field:Json(name = "uplink_low") var uplink: Long?,
@field:Json(name = "mode") val mode: String?,
@field:Json(name = "invert") val isInverted: Boolean,
@field:Json(name = "norad_cat_id") val catNum: Int
)
@@ -0,0 +1,35 @@
/*
* 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.framework.model
import com.github.amsacode.predict4java.Position
import com.github.amsacode.predict4java.Satellite
import org.osmdroid.views.overlay.Overlay
data class SelectedSat(
val pass: Satellite,
val catNum: Int,
val name: String,
val range: Double,
val altitude: Double,
val velocity: Double,
val qthLoc: String,
val osmPos: Position,
val footprint: Overlay,
val groundTrack: Overlay
)
@@ -0,0 +1,20 @@
/*
* 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.framework.model
class TleSource(var url: String = String())
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.presentation
import android.content.pm.ActivityInfo
import android.os.Bundle
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.presentation
import android.app.Application
import com.rtbishop.look4sat.BuildConfig
@@ -15,7 +15,7 @@
* 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.entriesScreen
package com.rtbishop.look4sat.presentation.entriesScreen
import android.view.LayoutInflater
import android.view.ViewGroup
@@ -15,7 +15,7 @@
* 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.entriesScreen
package com.rtbishop.look4sat.presentation.entriesScreen
import android.os.Bundle
import android.view.View
@@ -15,7 +15,7 @@
* 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.entriesScreen
package com.rtbishop.look4sat.presentation.entriesScreen
import android.content.Context
import android.net.Uri
@@ -15,7 +15,7 @@
* 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.infoScreen
package com.rtbishop.look4sat.presentation.infoScreen
import android.content.Intent
import android.net.Uri
@@ -15,7 +15,7 @@
* 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.mapScreen
package com.rtbishop.look4sat.presentation.mapScreen
import android.graphics.Color
import android.graphics.ColorMatrix
@@ -15,7 +15,7 @@
* 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.mapScreen
package com.rtbishop.look4sat.presentation.mapScreen
import android.graphics.Color
import android.graphics.Paint
@@ -15,7 +15,7 @@
* 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.passesScreen
package com.rtbishop.look4sat.presentation.passesScreen
import android.view.LayoutInflater
import android.view.ViewGroup
@@ -15,7 +15,7 @@
* 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.passesScreen
package com.rtbishop.look4sat.presentation.passesScreen
import android.os.Bundle
import android.view.View
@@ -15,7 +15,7 @@
* 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.passesScreen
package com.rtbishop.look4sat.presentation.passesScreen
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
@@ -23,7 +23,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.rtbishop.look4sat.data.model.Result
import com.rtbishop.look4sat.data.model.SatPass
import com.rtbishop.look4sat.data.repository.PassesRepo
import com.rtbishop.look4sat.utility.PassesRepo
import com.rtbishop.look4sat.data.repository.SatelliteRepo
import com.rtbishop.look4sat.utility.PrefsManager
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.presentation.polarScreen
import android.os.Bundle
import android.view.View
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.presentation.polarScreen
import android.content.Context
import android.graphics.Canvas
@@ -15,14 +15,15 @@
* 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
package com.rtbishop.look4sat.presentation.polarScreen
import androidx.lifecycle.*
import com.rtbishop.look4sat.data.model.SatPass
import com.rtbishop.look4sat.data.model.SatTrans
import com.rtbishop.look4sat.data.repository.PassesRepo
import com.rtbishop.look4sat.utility.PassesRepo
import com.rtbishop.look4sat.data.repository.SatelliteRepo
import com.rtbishop.look4sat.di.IoDispatcher
import com.rtbishop.look4sat.utility.OrientationProvider
import com.rtbishop.look4sat.utility.PrefsManager
import com.rtbishop.look4sat.utility.round
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.presentation.polarScreen
import android.view.LayoutInflater
import android.view.ViewGroup
@@ -15,7 +15,7 @@
* 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.prefsScreen
package com.rtbishop.look4sat.presentation.prefsScreen
import android.Manifest
import android.content.pm.PackageManager
@@ -15,7 +15,7 @@
* 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.sourcesDialog
package com.rtbishop.look4sat.presentation.sourcesDialog
import android.view.LayoutInflater
import android.view.ViewGroup
@@ -15,7 +15,7 @@
* 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.sourcesDialog
package com.rtbishop.look4sat.presentation.sourcesDialog
import android.os.Bundle
import android.view.LayoutInflater
@@ -15,7 +15,7 @@
* 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.splashDialog
package com.rtbishop.look4sat.presentation.splashDialog
import android.os.Bundle
import android.view.LayoutInflater
@@ -0,0 +1,69 @@
package com.rtbishop.look4sat.utility
import com.rtbishop.look4sat.framework.model.SatEntry
import com.rtbishop.look4sat.framework.model.SatItem
import com.rtbishop.look4sat.framework.model.SatTrans
import com.rtbishop.look4sat.domain.model.SatEntry as DomainEntry
import com.rtbishop.look4sat.domain.model.SatItem as DomainItem
import com.rtbishop.look4sat.domain.model.SatTrans as DomainTrans
object DataMapper {
// Framework to Domain
fun satEntryToDomainEntry(entry: SatEntry): DomainEntry {
return DomainEntry(entry.tle, entry.catNum, entry.name, entry.isSelected)
}
fun satEntriesToDomainEntries(entries: List<SatEntry>): List<DomainEntry> {
return entries.map { entry -> satEntryToDomainEntry(entry) }
}
fun satItemToDomainItem(item: SatItem): DomainItem {
return DomainItem(item.catNum, item.name, item.isSelected, item.modes)
}
fun satItemsToDomainItems(items: List<SatItem>): List<DomainItem> {
return items.map { item -> satItemToDomainItem(item) }
}
fun satTransToDomainTrans(transmitter: SatTrans): DomainTrans {
return DomainTrans(
transmitter.uuid, transmitter.info, transmitter.isAlive, transmitter.downlink,
transmitter.uplink, transmitter.mode, transmitter.isInverted, transmitter.catNum
)
}
fun satTransListToDomainTransList(transmitters: List<SatTrans>): List<DomainTrans> {
return transmitters.map { transmitter -> satTransToDomainTrans(transmitter) }
}
// Domain to Framework
fun domainEntryToSatEntry(entry: DomainEntry): SatEntry {
return SatEntry(entry.tle, entry.catNum, entry.name, entry.isSelected)
}
fun domainEntriesToSatEntries(entries: List<DomainEntry>): List<SatEntry> {
return entries.map { entry -> domainEntryToSatEntry(entry) }
}
fun domainItemToSatItem(item: DomainItem): SatItem {
return SatItem(item.catNum, item.name, item.isSelected, item.modes)
}
fun domainItemsToSatItems(items: List<DomainItem>): List<SatItem> {
return items.map { item -> domainItemToSatItem(item) }
}
fun domainTransToSatTrans(transmitter: DomainTrans): SatTrans {
return SatTrans(
transmitter.uuid, transmitter.info, transmitter.isAlive, transmitter.downlink,
transmitter.uplink, transmitter.mode, transmitter.isInverted, transmitter.catNum
)
}
fun domainTransListToSatTransList(transmitters: List<DomainTrans>): List<SatTrans> {
return transmitters.map { transmitter -> domainTransToSatTrans(transmitter) }
}
}
@@ -15,7 +15,7 @@
* 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
package com.rtbishop.look4sat.utility
import android.hardware.Sensor
import android.hardware.SensorEvent
@@ -15,13 +15,11 @@
* 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.data.repository
package com.rtbishop.look4sat.utility
import com.github.amsacode.predict4java.Satellite
import com.rtbishop.look4sat.data.model.SatPass
import com.rtbishop.look4sat.di.DefaultDispatcher
import com.rtbishop.look4sat.utility.PrefsManager
import com.rtbishop.look4sat.utility.getPredictor
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
+1 -1
View File
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.infoScreen.InfoFragment">
tools:context=".presentation.infoScreen.InfoFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
+8 -8
View File
@@ -7,7 +7,7 @@
<fragment
android:id="@+id/nav_entries"
android:name="com.rtbishop.look4sat.ui.entriesScreen.EntriesFragment"
android:name="com.rtbishop.look4sat.presentation.entriesScreen.EntriesFragment"
tools:layout="@layout/fragment_entries">
<action
android:id="@+id/action_entries_to_passes"
@@ -27,7 +27,7 @@
<fragment
android:id="@+id/nav_passes"
android:name="com.rtbishop.look4sat.ui.passesScreen.PassesFragment"
android:name="com.rtbishop.look4sat.presentation.passesScreen.PassesFragment"
tools:layout="@layout/fragment_passes">
<action
android:id="@+id/action_passes_to_polar"
@@ -40,7 +40,7 @@
<fragment
android:id="@+id/nav_polar"
android:name="com.rtbishop.look4sat.ui.polarScreen.PolarFragment"
android:name="com.rtbishop.look4sat.presentation.polarScreen.PolarFragment"
tools:layout="@layout/fragment_polar">
<action
android:id="@+id/action_polar_to_passes"
@@ -55,24 +55,24 @@
<fragment
android:id="@+id/nav_map"
android:name="com.rtbishop.look4sat.ui.mapScreen.MapFragment"
android:name="com.rtbishop.look4sat.presentation.mapScreen.MapFragment"
tools:layout="@layout/fragment_map" />
<fragment
android:id="@+id/nav_prefs"
android:name="com.rtbishop.look4sat.ui.prefsScreen.PrefsFragment" />
android:name="com.rtbishop.look4sat.presentation.prefsScreen.PrefsFragment" />
<fragment
android:id="@+id/nav_info"
android:name="com.rtbishop.look4sat.ui.infoScreen.InfoFragment"
android:name="com.rtbishop.look4sat.presentation.infoScreen.InfoFragment"
tools:layout="@layout/fragment_info" />
<dialog
android:id="@+id/nav_dialog_sources"
android:name="com.rtbishop.look4sat.ui.sourcesDialog.SourcesDialog"
android:name="com.rtbishop.look4sat.presentation.sourcesDialog.SourcesDialog"
tools:layout="@layout/dialog_sources" />
<dialog
android:id="@+id/nav_dialog_splash"
android:name="com.rtbishop.look4sat.ui.splashDialog.SplashDialog"
android:name="com.rtbishop.look4sat.presentation.splashDialog.SplashDialog"
tools:layout="@layout/dialog_splash" />
</navigation>
@@ -1,9 +1,9 @@
package com.rtbishop.look4sat.data
import com.rtbishop.look4sat.domain.SatelliteRepo
import com.rtbishop.look4sat.domain.model.SatEntry
import com.rtbishop.look4sat.domain.model.SatItem
import com.rtbishop.look4sat.domain.SatelliteRepo
import com.rtbishop.look4sat.domain.model.Transmitter
import com.rtbishop.look4sat.domain.model.SatTrans
import com.rtbishop.look4sat.predict4kotlin.Satellite
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.coroutineScope
@@ -23,7 +23,7 @@ class DefaultSatelliteRepo(
return localSource.getSatItems()
}
override fun getTransmittersForSat(catNum: Int): Flow<List<Transmitter>> {
override fun getTransmittersForSat(catNum: Int): Flow<List<SatTrans>> {
return localSource.getTransmittersForSat(catNum)
}
@@ -44,7 +44,7 @@ class DefaultSatelliteRepo(
val entries = mutableListOf<SatEntry>()
val streams = mutableListOf<InputStream>()
sources.forEach { source ->
val stream = remoteSource.fetchFileStream(source)
remoteSource.fetchFileStream(source)?.let { stream ->
if (source.contains(".zip", true)) {
val zipStream = ZipInputStream(stream).apply { nextEntry }
streams.add(zipStream)
@@ -52,6 +52,7 @@ class DefaultSatelliteRepo(
streams.add(stream)
}
}
}
streams.forEach { stream ->
val importedEntries = Satellite.importTLE(stream).map { tle -> SatEntry(tle) }
entries.addAll(importedEntries)
@@ -2,7 +2,7 @@ package com.rtbishop.look4sat.data
import com.rtbishop.look4sat.domain.model.SatEntry
import com.rtbishop.look4sat.domain.model.SatItem
import com.rtbishop.look4sat.domain.model.Transmitter
import com.rtbishop.look4sat.domain.model.SatTrans
import com.rtbishop.look4sat.predict4kotlin.Satellite
import kotlinx.coroutines.flow.Flow
@@ -16,7 +16,7 @@ interface LocalDataSource {
suspend fun updateEntriesSelection(catNums: List<Int>, isSelected: Boolean)
fun getTransmittersForSat(catNum: Int): Flow<List<Transmitter>>
fun getTransmittersForSat(catNum: Int): Flow<List<SatTrans>>
suspend fun updateTransmitters(transmitters: List<Transmitter>)
suspend fun updateTransmitters(satelliteTrans: List<SatTrans>)
}
@@ -1,11 +1,11 @@
package com.rtbishop.look4sat.data
import com.rtbishop.look4sat.domain.model.Transmitter
import com.rtbishop.look4sat.domain.model.SatTrans
import java.io.InputStream
interface RemoteDataSource {
fun fetchFileStream(url: String): InputStream
suspend fun fetchFileStream(url: String): InputStream?
fun fetchTransmitters(): List<Transmitter>
suspend fun fetchTransmitters(): List<SatTrans>
}
@@ -1,7 +1,7 @@
package com.rtbishop.look4sat.domain
import com.rtbishop.look4sat.domain.model.SatItem
import com.rtbishop.look4sat.domain.model.Transmitter
import com.rtbishop.look4sat.domain.model.SatTrans
import com.rtbishop.look4sat.predict4kotlin.Satellite
import kotlinx.coroutines.flow.Flow
import java.io.InputStream
@@ -10,7 +10,7 @@ interface SatelliteRepo {
fun getSatItems(): Flow<List<SatItem>>
fun getTransmittersForSat(catNum: Int): Flow<List<Transmitter>>
fun getTransmittersForSat(catNum: Int): Flow<List<SatTrans>>
suspend fun getSelectedSatellites(): List<Satellite>
@@ -4,7 +4,7 @@ import com.rtbishop.look4sat.predict4kotlin.TLE
data class SatEntry(
val tle: TLE,
var isSelected: Boolean = false,
val catNum: Int = tle.catnum,
val name: String = tle.name
val name: String = tle.name,
var isSelected: Boolean = false
)
@@ -1,6 +1,6 @@
package com.rtbishop.look4sat.domain.model
data class Transmitter(
data class SatTrans(
val uuid: String,
val info: String,
val isAlive: Boolean,
@@ -1,12 +1,12 @@
package com.rtbishop.look4sat.interactors
import com.rtbishop.look4sat.domain.SatelliteRepo
import com.rtbishop.look4sat.domain.model.Transmitter
import com.rtbishop.look4sat.domain.model.SatTrans
import kotlinx.coroutines.flow.Flow
class GetTransmittersForSat(private val satelliteRepo: SatelliteRepo) {
operator fun invoke(catNum: Int): Flow<List<Transmitter>> {
operator fun invoke(catNum: Int): Flow<List<SatTrans>> {
return satelliteRepo.getTransmittersForSat(catNum)
}
}
@@ -349,9 +349,12 @@ abstract class Satellite(val tle: TLE) {
companion object {
fun createSat(tle: TLE): Satellite {
return if (tle.isDeepspace) DeepSpaceSat(tle)
else NearEarthSat(tle)
fun createSat(tle: TLE?): Satellite? {
return when {
tle == null -> null
tle.isDeepspace -> DeepSpaceSat(tle)
else -> NearEarthSat(tle)
}
}
fun importTLE(tleStream: InputStream): List<TLE> {