Restored passes calculation functionality
This commit is contained in:
1 parent
e38ee6384e
commit
1d753ba81f
18 files changed
+175
-193
No files matched your search
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.rtbishop.look4sat.dagger.modules
|
||||
|
||||
import com.rtbishop.look4sat.repo.remote.TransApi
|
||||
import com.rtbishop.look4sat.repo.remote.TransmittersApi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -38,11 +38,11 @@ class NetworkModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideTransApi(): TransApi {
|
||||
fun provideTransApi(): TransmittersApi {
|
||||
return Retrofit.Builder()
|
||||
.baseUrl("https://db.satnogs.org/api/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
.create(TransApi::class.java)
|
||||
.create(TransmittersApi::class.java)
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import androidx.room.Room
|
||||
import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||
import com.rtbishop.look4sat.repo.local.SatDb
|
||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||
import com.rtbishop.look4sat.repo.local.TransDao
|
||||
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
@@ -40,8 +40,8 @@ class PersistenceModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideTransDao(db: SatDb): TransDao {
|
||||
return db.transDao()
|
||||
fun provideTransDao(db: SatDb): TransmittersDao {
|
||||
return db.transmittersDao()
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.rtbishop.look4sat.repo.DefaultRepository
|
||||
import com.rtbishop.look4sat.repo.Repository
|
||||
import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||
import com.rtbishop.look4sat.repo.local.TransDao
|
||||
import com.rtbishop.look4sat.repo.remote.TransApi
|
||||
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
||||
import com.rtbishop.look4sat.repo.remote.TransmittersApi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -27,18 +27,18 @@ class RepoModule {
|
||||
fun provideDefaultRepository(
|
||||
resolver: ContentResolver,
|
||||
client: OkHttpClient,
|
||||
transApi: TransApi,
|
||||
transmittersApi: TransmittersApi,
|
||||
entriesDao: EntriesDao,
|
||||
transDao: TransDao,
|
||||
transmittersDao: TransmittersDao,
|
||||
sourcesDao: SourcesDao
|
||||
): Repository {
|
||||
return DefaultRepository(
|
||||
resolver,
|
||||
client,
|
||||
transApi,
|
||||
transmittersApi,
|
||||
entriesDao,
|
||||
sourcesDao,
|
||||
transDao
|
||||
transmittersDao
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ import com.rtbishop.look4sat.data.SatTrans
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||
import com.rtbishop.look4sat.repo.local.TransDao
|
||||
import com.rtbishop.look4sat.repo.remote.TransApi
|
||||
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
||||
import com.rtbishop.look4sat.repo.remote.TransmittersApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -40,10 +40,10 @@ import javax.inject.Inject
|
||||
class DefaultRepository @Inject constructor(
|
||||
private val resolver: ContentResolver,
|
||||
private val client: OkHttpClient,
|
||||
private val api: TransApi,
|
||||
private val api: TransmittersApi,
|
||||
private val entriesDao: EntriesDao,
|
||||
private val sourcesDao: SourcesDao,
|
||||
private val transDao: TransDao
|
||||
private val transmittersDao: TransmittersDao
|
||||
) : Repository {
|
||||
|
||||
override fun getSources(): LiveData<List<TleSource>> {
|
||||
@@ -51,72 +51,48 @@ class DefaultRepository @Inject constructor(
|
||||
}
|
||||
|
||||
override suspend fun updateSources(sources: List<TleSource>) {
|
||||
sourcesDao.clearSources()
|
||||
sourcesDao.insertSources(sources)
|
||||
sourcesDao.updateSources(sources)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
override fun getAllEntries(): LiveData<List<SatEntry>> {
|
||||
return entriesDao.getAllEntries()
|
||||
override fun getEntries(): LiveData<List<SatEntry>> {
|
||||
return entriesDao.getEntries()
|
||||
}
|
||||
|
||||
override fun getSelectedEntries(): LiveData<List<SatEntry>> {
|
||||
return entriesDao.getSelectedEntries()
|
||||
}
|
||||
|
||||
override suspend fun updateEntriesFromFile(tleUri: Uri) {
|
||||
override suspend fun updateEntriesFromFile(fileUri: Uri) {
|
||||
withContext(Dispatchers.IO) {
|
||||
resolver.openInputStream(tleUri)?.use { stream ->
|
||||
val tleList = TLE.importSat(stream)
|
||||
val entries = tleList.map { SatEntry(it) }
|
||||
entriesDao.clearEntries()
|
||||
entriesDao.insertEntries(entries)
|
||||
resolver.openInputStream(fileUri)?.use { stream ->
|
||||
val importedEntries = TLE.importSat(stream).map { SatEntry(it) }
|
||||
entriesDao.updateEntries(importedEntries)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateEntriesFromUrl(urlList: List<TleSource>) {
|
||||
override suspend fun updateEntriesFromSources(sources: List<TleSource>) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val streams = getStreamsForSources(urlList)
|
||||
val entries = getEntriesForStreams(streams)
|
||||
entriesDao.clearEntries()
|
||||
entriesDao.insertEntries(entries)
|
||||
val streams = mutableListOf<InputStream>()
|
||||
sources.forEach { source ->
|
||||
val request = Request.Builder().url(source.url).build()
|
||||
val stream = client.newCall(request).execute().body?.byteStream()
|
||||
stream?.let { inputStream -> streams.add(inputStream) }
|
||||
}
|
||||
val importedEntries = mutableListOf<SatEntry>()
|
||||
streams.forEach { stream ->
|
||||
val entries = TLE.importSat(stream).map { tle -> SatEntry(tle) }
|
||||
importedEntries.addAll(entries)
|
||||
}
|
||||
entriesDao.updateEntries(importedEntries)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateEntriesSelection(catNumList: List<Int>) {
|
||||
entriesDao.clearEntriesSelection()
|
||||
catNumList.forEach { entriesDao.updateEntrySelection(it) }
|
||||
override suspend fun updateEntriesSelection(satIds: List<Int>) {
|
||||
entriesDao.updateEntriesSelection(satIds)
|
||||
}
|
||||
|
||||
private fun getStreamsForSources(urlList: List<TleSource>): MutableList<InputStream> {
|
||||
val streams = mutableListOf<InputStream>()
|
||||
urlList.withIndex().forEach {
|
||||
val request = Request.Builder().url(it.value.url).build()
|
||||
val stream = client.newCall(request).execute().body?.byteStream()
|
||||
stream?.let { inputStream -> streams.add(inputStream) }
|
||||
}
|
||||
return streams
|
||||
override suspend fun getTransmittersForSatId(satId: Int): List<SatTrans> {
|
||||
return transmittersDao.getTransmittersForSatId(satId)
|
||||
}
|
||||
|
||||
private fun getEntriesForStreams(streams: MutableList<InputStream>): MutableList<SatEntry> {
|
||||
val entries = mutableListOf<SatEntry>()
|
||||
streams.forEach {
|
||||
val list = TLE.importSat(it).map { tle -> SatEntry(tle) }
|
||||
entries.addAll(list)
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
override suspend fun updateTransmitters() {
|
||||
transDao.clearTransmitters()
|
||||
transDao.insertTransmitters(api.fetchTransList())
|
||||
}
|
||||
|
||||
override suspend fun getTransmittersByCatNum(catNum: Int): List<SatTrans> {
|
||||
return transDao.getTransmittersForCatNum(catNum)
|
||||
transmittersDao.updateTransmitters(api.getTransmitters())
|
||||
}
|
||||
}
|
||||
@@ -14,19 +14,17 @@ interface Repository {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fun getAllEntries(): LiveData<List<SatEntry>>
|
||||
fun getEntries(): LiveData<List<SatEntry>>
|
||||
|
||||
fun getSelectedEntries(): LiveData<List<SatEntry>>
|
||||
suspend fun updateEntriesFromFile(fileUri: Uri)
|
||||
|
||||
suspend fun updateEntriesFromFile(tleUri: Uri)
|
||||
suspend fun updateEntriesFromSources(sources: List<TleSource>)
|
||||
|
||||
suspend fun updateEntriesFromUrl(urlList: List<TleSource>)
|
||||
|
||||
suspend fun updateEntriesSelection(catNumList: List<Int>)
|
||||
suspend fun updateEntriesSelection(satIds: List<Int>)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
suspend fun updateTransmitters()
|
||||
|
||||
suspend fun getTransmittersByCatNum(catNum: Int): List<SatTrans>
|
||||
suspend fun getTransmittersForSatId(satId: Int): List<SatTrans>
|
||||
}
|
||||
@@ -20,30 +20,36 @@
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.*
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
|
||||
@Dao
|
||||
interface EntriesDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertEntries(entries: List<SatEntry>)
|
||||
|
||||
@Query("SELECT * FROM entries ORDER BY name ASC")
|
||||
fun getAllEntries(): LiveData<List<SatEntry>>
|
||||
fun getEntries(): LiveData<List<SatEntry>>
|
||||
|
||||
@Query("SELECT * FROM entries WHERE isSelected = 1 ORDER BY name ASC")
|
||||
fun getSelectedEntries(): LiveData<List<SatEntry>>
|
||||
|
||||
@Query("UPDATE entries SET isSelected = 1 WHERE catNum == :catNum")
|
||||
suspend fun updateEntrySelection(catNum: Int)
|
||||
|
||||
@Query("UPDATE entries SET isSelected = 0")
|
||||
suspend fun clearEntriesSelection()
|
||||
@Transaction
|
||||
suspend fun updateEntries(entries: List<SatEntry>) {
|
||||
clearEntries()
|
||||
insertEntries(entries)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM entries")
|
||||
suspend fun clearEntries()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertEntries(entries: List<SatEntry>)
|
||||
|
||||
@Transaction
|
||||
suspend fun updateEntriesSelection(satIds: List<Int>) {
|
||||
clearSelection()
|
||||
updateSelection(satIds)
|
||||
}
|
||||
|
||||
@Query("UPDATE entries SET isSelected = 0")
|
||||
suspend fun clearSelection()
|
||||
|
||||
@Query("UPDATE entries SET isSelected = 1 WHERE catNum IN (:satIds)")
|
||||
suspend fun updateSelection(satIds: List<Int>)
|
||||
}
|
||||
@@ -28,16 +28,16 @@ import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.utility.Converters
|
||||
|
||||
@Database(
|
||||
entities = [SatTrans::class, SatEntry::class, TleSource::class],
|
||||
entities = [TleSource::class, SatEntry::class, SatTrans::class],
|
||||
version = 1,
|
||||
exportSchema = false
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SatDb : RoomDatabase() {
|
||||
|
||||
abstract fun sourcesDao(): SourcesDao
|
||||
|
||||
abstract fun entriesDao(): EntriesDao
|
||||
|
||||
abstract fun transDao(): TransDao
|
||||
|
||||
abstract fun sourcesDao(): SourcesDao
|
||||
abstract fun transmittersDao(): TransmittersDao
|
||||
}
|
||||
@@ -1,21 +1,24 @@
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.*
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
|
||||
@Dao
|
||||
interface SourcesDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSources(sources: List<TleSource>)
|
||||
|
||||
@Query("SELECT * FROM sources")
|
||||
fun getSources(): LiveData<List<TleSource>>
|
||||
|
||||
@Transaction
|
||||
suspend fun updateSources(sources: List<TleSource>) {
|
||||
clearSources()
|
||||
insertSources(sources)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM sources")
|
||||
suspend fun clearSources()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSources(sources: List<TleSource>)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.rtbishop.look4sat.data.SatTrans
|
||||
|
||||
@Dao
|
||||
interface TransDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertTransmitters(satTrans: List<SatTrans>)
|
||||
|
||||
@Query("SELECT * FROM transmitters WHERE isAlive = 1 and catNum = :catNum")
|
||||
suspend fun getTransmittersForCatNum(catNum: Int): List<SatTrans>
|
||||
|
||||
@Query("DELETE FROM transmitters")
|
||||
suspend fun clearTransmitters()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.room.*
|
||||
import com.rtbishop.look4sat.data.SatTrans
|
||||
|
||||
@Dao
|
||||
interface TransmittersDao {
|
||||
|
||||
@Query("SELECT * FROM transmitters WHERE isAlive = 1 and catNum = :satId")
|
||||
suspend fun getTransmittersForSatId(satId: Int): List<SatTrans>
|
||||
|
||||
@Transaction
|
||||
suspend fun updateTransmitters(transmitters: List<SatTrans>) {
|
||||
clearTransmitters()
|
||||
insertTransmitters(transmitters)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM transmitters")
|
||||
suspend fun clearTransmitters()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertTransmitters(transmitters: List<SatTrans>)
|
||||
}
|
||||
+2
-2
@@ -22,8 +22,8 @@ package com.rtbishop.look4sat.repo.remote
|
||||
import com.rtbishop.look4sat.data.SatTrans
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface TransApi {
|
||||
interface TransmittersApi {
|
||||
|
||||
@GET("transmitters/")
|
||||
suspend fun fetchTransList(): List<SatTrans>
|
||||
suspend fun getTransmitters(): List<SatTrans>
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import com.rtbishop.look4sat.repo.Repository
|
||||
import com.rtbishop.look4sat.utility.PassPredictor
|
||||
import com.rtbishop.look4sat.utility.PrefsManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -39,20 +38,18 @@ class SharedViewModel @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : ViewModel() {
|
||||
|
||||
private val _passes = MutableLiveData<Result<MutableList<SatPass>>>()
|
||||
|
||||
init {
|
||||
if (prefsManager.isFirstLaunch()) {
|
||||
setDefaultTleSources()
|
||||
}
|
||||
}
|
||||
|
||||
val tleSources = repository.getSources()
|
||||
val allEntries = repository.getAllEntries()
|
||||
val selectedEntries = repository.getSelectedEntries()
|
||||
|
||||
private var calculationJob: Job? = null
|
||||
private val _satPassList = MutableLiveData<Result<MutableList<SatPass>>>()
|
||||
fun getPassList(): LiveData<Result<MutableList<SatPass>>> = _satPassList
|
||||
fun getTransmittersForSat(id: Int) = liveData { emit(repository.getTransmittersByCatNum(id)) }
|
||||
fun getSources() = repository.getSources()
|
||||
fun getEntries() = repository.getEntries()
|
||||
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
||||
fun getTransmittersForSat(id: Int) = liveData { emit(repository.getTransmittersForSatId(id)) }
|
||||
|
||||
fun getPassPrefs(): PassPrefs {
|
||||
return prefsManager.getPassPrefs()
|
||||
@@ -66,8 +63,8 @@ class SharedViewModel @Inject constructor(
|
||||
return prefsManager.getStationPosition()
|
||||
}
|
||||
|
||||
fun updateStationPosition() {
|
||||
prefsManager.updateStationPosition()
|
||||
fun setStationPositionFromGPS() {
|
||||
prefsManager.setStationPositionFromGPS()
|
||||
}
|
||||
|
||||
fun shouldUseUTC(): Boolean {
|
||||
@@ -79,43 +76,35 @@ class SharedViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun updateEntriesFromFile(uri: Uri) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val selected = selectedEntries.value!!.map { it.catNum }
|
||||
viewModelScope.launch {
|
||||
repository.updateEntriesFromFile(uri)
|
||||
repository.updateEntriesSelection(selected)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSatelliteData(list: List<TleSource>) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val selected = selectedEntries.value!!.map { it.catNum }
|
||||
repository.updateSources(list)
|
||||
repository.updateEntriesFromUrl(list)
|
||||
fun updateEntriesFromSources(sources: List<TleSource>) {
|
||||
viewModelScope.launch {
|
||||
repository.updateSources(sources)
|
||||
repository.updateEntriesFromSources(sources)
|
||||
repository.updateTransmitters()
|
||||
repository.updateEntriesSelection(selected)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateEntriesSelection(catNumList: MutableList<Int>) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.updateEntriesSelection(catNumList)
|
||||
calculatePasses()
|
||||
fun updateEntriesSelection(satIds: MutableList<Int>) {
|
||||
viewModelScope.launch {
|
||||
repository.updateEntriesSelection(satIds)
|
||||
}
|
||||
}
|
||||
|
||||
fun calculatePasses() {
|
||||
_satPassList.postValue(Result.InProgress)
|
||||
calculationJob?.cancel()
|
||||
var passList = mutableListOf<SatPass>()
|
||||
val dateNow = Date()
|
||||
val gsp = prefsManager.getStationPosition()
|
||||
calculationJob = viewModelScope.launch(Dispatchers.Default) {
|
||||
repository.getSelectedEntries().value?.forEach {
|
||||
passList.addAll(getPassesForEntries(it, dateNow, gsp))
|
||||
fun calculatePassesForEntries(entries: List<SatEntry>) {
|
||||
_passes.value = Result.InProgress
|
||||
val dateNow = Date(System.currentTimeMillis())
|
||||
val passes = mutableListOf<SatPass>()
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
entries.forEach {
|
||||
passes.addAll(getPassesForEntries(it, dateNow, getStationPosition()))
|
||||
}
|
||||
val hoursAhead = prefsManager.getPassPrefs().hoursAhead
|
||||
passList = filterAndSortPasses(passList, dateNow, hoursAhead)
|
||||
_satPassList.postValue(Result.Success(passList))
|
||||
val filteredPasses = filterAndSortPasses(passes, dateNow, getPassPrefs().hoursAhead)
|
||||
_passes.postValue(Result.Success(filteredPasses))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,26 +54,20 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
||||
}
|
||||
importWeb.setOnClickListener { showImportFromWebDialog() }
|
||||
importFile.setOnClickListener { showImportFromFileDialog() }
|
||||
searchBar.setOnQueryTextListener(entriesAdapter)
|
||||
selectAll.setOnClickListener { entriesAdapter.selectAll() }
|
||||
entriesFab.setOnClickListener { goToPassesAndCalculateForSelection() }
|
||||
entriesFab.setOnClickListener { navigateToPasses() }
|
||||
searchBar.setOnQueryTextListener(entriesAdapter)
|
||||
searchBar.clearFocus()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupObservers() {
|
||||
viewModel.tleSources.observe(viewLifecycleOwner, { tleSources = it })
|
||||
viewModel.allEntries.observe(viewLifecycleOwner, {
|
||||
viewModel.getSources().observe(viewLifecycleOwner, { tleSources = it })
|
||||
viewModel.getEntries().observe(viewLifecycleOwner, {
|
||||
entriesAdapter.setEntries(it as MutableList<SatEntry>)
|
||||
})
|
||||
}
|
||||
|
||||
private fun goToPassesAndCalculateForSelection() {
|
||||
val catNumList = mutableListOf<Int>()
|
||||
entriesAdapter.getEntries().forEach { if (it.isSelected) catNumList.add(it.catNum) }
|
||||
viewModel.updateEntriesSelection(catNumList)
|
||||
requireView().findNavController().navigate(R.id.action_entries_to_passes)
|
||||
}
|
||||
|
||||
private fun showImportFromWebDialog() {
|
||||
SourcesDialog(tleSources, viewModel).show(childFragmentManager, "SourcesDialog")
|
||||
}
|
||||
@@ -86,6 +80,13 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateToPasses() {
|
||||
val catNumList = mutableListOf<Int>()
|
||||
entriesAdapter.getEntries().forEach { if (it.isSelected) catNumList.add(it.catNum) }
|
||||
viewModel.updateEntriesSelection(catNumList)
|
||||
requireView().findNavController().navigate(R.id.action_entries_to_passes)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == pickFileReqCode && resultCode == AppCompatActivity.RESULT_OK) {
|
||||
data?.data?.also { uri -> viewModel.updateEntriesFromFile(uri) }
|
||||
|
||||
@@ -123,7 +123,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
}
|
||||
|
||||
private fun setupObservers() {
|
||||
viewModel.getPassList().observe(viewLifecycleOwner, { satPasses ->
|
||||
viewModel.getPasses().observe(viewLifecycleOwner, { satPasses ->
|
||||
when (satPasses) {
|
||||
is Result.Success -> {
|
||||
if (satPasses.data.isNotEmpty()) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.rtbishop.look4sat.Look4SatApp
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.dagger.ViewModelFactory
|
||||
import com.rtbishop.look4sat.data.Result
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
import com.rtbishop.look4sat.data.SatPass
|
||||
import com.rtbishop.look4sat.databinding.FragmentPassesBinding
|
||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||
@@ -51,7 +52,8 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
private lateinit var binding: FragmentPassesBinding
|
||||
private var isTimerSet: Boolean = false
|
||||
private val passesAdapter = PassesAdapter()
|
||||
private var satPassList = mutableListOf<SatPass>()
|
||||
private var selectedEntries = listOf<SatEntry>()
|
||||
private var passes = mutableListOf<SatPass>()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -62,20 +64,24 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
setupComponents()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (passesAdapter.itemCount == 0) {
|
||||
viewModel.calculatePasses()
|
||||
}
|
||||
}
|
||||
// override fun onStart() {
|
||||
// super.onStart()
|
||||
// if (selectedEntries.isEmpty()) {
|
||||
// viewModel.calculatePassesForEntries(selectedEntries)
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun setupObservers() {
|
||||
viewModel.getPassList().observe(viewLifecycleOwner, { result ->
|
||||
viewModel.getEntries().observe(viewLifecycleOwner, { allEntries ->
|
||||
selectedEntries = allEntries.filter { it.isSelected }
|
||||
// viewModel.calculatePassesForEntries(selectedEntries)
|
||||
})
|
||||
viewModel.getPasses().observe(viewLifecycleOwner, { result ->
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
satPassList = result.data
|
||||
passesAdapter.setList(satPassList)
|
||||
setTimer()
|
||||
passes = result.data
|
||||
passesAdapter.setList(passes)
|
||||
setTimerForPasses(passes)
|
||||
}
|
||||
is Result.InProgress -> {
|
||||
}
|
||||
@@ -95,11 +101,11 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
val passPrefs = viewModel.getPassPrefs()
|
||||
showSatPassPrefsDialog(passPrefs.hoursAhead, passPrefs.minEl)
|
||||
}
|
||||
passesFab.setOnClickListener { viewModel.calculatePasses() }
|
||||
passesFab.setOnClickListener { viewModel.calculatePassesForEntries(selectedEntries) }
|
||||
}
|
||||
passesAdapter.setShouldUseUTC(viewModel.shouldUseUTC())
|
||||
passesAdapter.setList(satPassList)
|
||||
setTimer()
|
||||
passesAdapter.setList(passes)
|
||||
setTimerForPasses(passes)
|
||||
}
|
||||
|
||||
private fun showSatPassPrefsDialog(hoursAhead: Int, minEl: Double) {
|
||||
@@ -125,7 +131,7 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
}
|
||||
else -> {
|
||||
viewModel.setPassPrefs(hours, elevation)
|
||||
viewModel.calculatePasses()
|
||||
viewModel.calculatePassesForEntries(selectedEntries)
|
||||
}
|
||||
}
|
||||
} else getString(R.string.err_enter_value).snack(requireView())
|
||||
@@ -140,8 +146,8 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTimer() {
|
||||
if (satPassList.isNotEmpty()) {
|
||||
private fun setTimerForPasses(passes: List<SatPass>) {
|
||||
if (passes.isNotEmpty()) {
|
||||
resetTimer()
|
||||
val timeNow = Date()
|
||||
try {
|
||||
@@ -158,11 +164,11 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
}
|
||||
|
||||
private fun setTimerForNext(timeNow: Date) {
|
||||
val nextPass = satPassList.first { it.pass.startTime.after(timeNow) }
|
||||
val nextPass = passes.first { it.pass.startTime.after(timeNow) }
|
||||
val millisBeforeStart = nextPass.pass.startTime.time.minus(timeNow.time)
|
||||
aosTimer = object : CountDownTimer(millisBeforeStart, 1000) {
|
||||
override fun onFinish() {
|
||||
setTimer()
|
||||
setTimerForPasses(passes)
|
||||
}
|
||||
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
@@ -173,11 +179,11 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
}
|
||||
|
||||
private fun setTimerForLast(timeNow: Date) {
|
||||
val lastPass = satPassList.last()
|
||||
val lastPass = passes.last()
|
||||
val millisBeforeEnd = lastPass.pass.endTime.time.minus(timeNow.time)
|
||||
aosTimer = object : CountDownTimer(millisBeforeEnd, 1000) {
|
||||
override fun onFinish() {
|
||||
viewModel.calculatePasses()
|
||||
viewModel.calculatePassesForEntries(selectedEntries)
|
||||
}
|
||||
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
|
||||
@@ -107,7 +107,7 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||
}
|
||||
|
||||
private fun observePasses() {
|
||||
viewModel.getPassList().observe(viewLifecycleOwner, { result ->
|
||||
viewModel.getPasses().observe(viewLifecycleOwner, { result ->
|
||||
if (result is Result.Success) {
|
||||
satPass = result.data[args.satPassIndex]
|
||||
polarView = PolarView(mainActivity, satPass)
|
||||
|
||||
@@ -48,7 +48,7 @@ class SourcesDialog(sources: List<TleSource>, private val viewModel: SharedViewM
|
||||
tleSourcesBtnPos.setOnClickListener {
|
||||
val filteredSources = sourcesAdapter.getSources()
|
||||
.filter { it.url != String() && it.url != " " && it.url.contains("https://") }
|
||||
viewModel.updateSatelliteData(filteredSources)
|
||||
viewModel.updateEntriesFromSources(filteredSources)
|
||||
dismiss()
|
||||
}
|
||||
tleSourcesBtnNeg.setOnClickListener { dismiss() }
|
||||
|
||||
@@ -68,7 +68,7 @@ class PrefsManager @Inject constructor(
|
||||
return GroundStationPosition(lat, lon, alt)
|
||||
}
|
||||
|
||||
fun updateStationPosition() {
|
||||
fun setStationPositionFromGPS() {
|
||||
try {
|
||||
locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)?.let {
|
||||
val lat = it.latitude.round(4)
|
||||
|
||||
Reference in new issue
Block a user