mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Switched to multiple repositories
This commit is contained in:
1 parent
1c7ce3f726
commit
81074941b0
10 files changed
+116
-103
No files matched your search
@@ -73,7 +73,6 @@ dependencies {
|
|||||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
|
|
||||||
implementation "androidx.room:room-runtime:$room_version"
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
implementation "androidx.room:room-ktx:$room_version"
|
implementation "androidx.room:room-ktx:$room_version"
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ import com.rtbishop.look4sat.data.Result
|
|||||||
import com.rtbishop.look4sat.data.SatEntry
|
import com.rtbishop.look4sat.data.SatEntry
|
||||||
import com.rtbishop.look4sat.data.SatPass
|
import com.rtbishop.look4sat.data.SatPass
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
import com.rtbishop.look4sat.repo.Repository
|
import com.rtbishop.look4sat.repo.EntriesRepo
|
||||||
|
import com.rtbishop.look4sat.repo.SourcesRepo
|
||||||
|
import com.rtbishop.look4sat.repo.TransmittersRepo
|
||||||
import com.rtbishop.look4sat.utility.PassPredictor
|
import com.rtbishop.look4sat.utility.PassPredictor
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.utility.PrefsManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -39,7 +41,9 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class SharedViewModel @ViewModelInject constructor(
|
class SharedViewModel @ViewModelInject constructor(
|
||||||
private val prefsManager: PrefsManager,
|
private val prefsManager: PrefsManager,
|
||||||
private val repository: Repository,
|
private val sourcesRepo: SourcesRepo,
|
||||||
|
private val entriesRepo: EntriesRepo,
|
||||||
|
private val transmittersRepo: TransmittersRepo,
|
||||||
@Assisted private val savedStateHandle: SavedStateHandle
|
@Assisted private val savedStateHandle: SavedStateHandle
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
@@ -53,10 +57,10 @@ class SharedViewModel @ViewModelInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSources() = repository.getSources()
|
fun getSources() = sourcesRepo.getSources()
|
||||||
fun getEntries() = repository.getEntries()
|
fun getEntries() = entriesRepo.getEntries()
|
||||||
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
||||||
fun getTransmittersForSat(satId: Int) = repository.getTransmittersForSat(satId)
|
fun getTransmittersForSat(satId: Int) = transmittersRepo.getTransmittersForSat(satId)
|
||||||
|
|
||||||
fun triggerCalculation() {
|
fun triggerCalculation() {
|
||||||
if (shouldTriggerCalculation) {
|
if (shouldTriggerCalculation) {
|
||||||
@@ -71,15 +75,15 @@ class SharedViewModel @ViewModelInject constructor(
|
|||||||
|
|
||||||
fun updateEntriesFromFile(uri: Uri) {
|
fun updateEntriesFromFile(uri: Uri) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.updateEntriesFromFile(uri)
|
entriesRepo.updateEntriesFromFile(uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateEntriesFromSources(sources: List<TleSource>) {
|
fun updateEntriesFromSources(sources: List<TleSource>) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.updateSources(sources)
|
sourcesRepo.updateSources(sources)
|
||||||
repository.updateEntriesFromSources(sources)
|
entriesRepo.updateEntriesFromSources(sources)
|
||||||
repository.updateTransmitters()
|
transmittersRepo.updateTransmitters()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +91,7 @@ class SharedViewModel @ViewModelInject constructor(
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
selectedEntries = entries.filter { it.isSelected }
|
selectedEntries = entries.filter { it.isSelected }
|
||||||
calculatePasses()
|
calculatePasses()
|
||||||
repository.updateEntriesSelection(selectedEntries.map { it.catNum })
|
entriesRepo.updateEntriesSelection(selectedEntries.map { it.catNum })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +115,7 @@ class SharedViewModel @ViewModelInject constructor(
|
|||||||
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
|
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
|
||||||
TleSource("https://amsat.org/tle/current/nasabare.txt")
|
TleSource("https://amsat.org/tle/current/nasabare.txt")
|
||||||
)
|
)
|
||||||
repository.updateSources(defaultTleSources)
|
sourcesRepo.updateSources(defaultTleSources)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ package com.rtbishop.look4sat.di
|
|||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.rtbishop.look4sat.repo.DefaultRepository
|
import com.rtbishop.look4sat.repo.*
|
||||||
import com.rtbishop.look4sat.repo.Repository
|
|
||||||
import com.rtbishop.look4sat.repo.local.EntriesDao
|
import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||||
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
||||||
@@ -47,21 +46,26 @@ class RepoModule {
|
|||||||
|
|
||||||
@ActivityScoped
|
@ActivityScoped
|
||||||
@Provides
|
@Provides
|
||||||
fun provideDefaultRepository(
|
fun provideEntriesRepo(
|
||||||
resolver: ContentResolver,
|
resolver: ContentResolver,
|
||||||
client: OkHttpClient,
|
client: OkHttpClient,
|
||||||
transmittersApi: TransmittersApi,
|
entriesDao: EntriesDao
|
||||||
entriesDao: EntriesDao,
|
): EntriesRepo {
|
||||||
|
return DefaultEntriesRepo(resolver, client, entriesDao)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActivityScoped
|
||||||
|
@Provides
|
||||||
|
fun provideSourcesRepo(sourcesDao: SourcesDao): SourcesRepo {
|
||||||
|
return DefaultSourcesRepo(sourcesDao)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActivityScoped
|
||||||
|
@Provides
|
||||||
|
fun provideTransmittersRepo(
|
||||||
transmittersDao: TransmittersDao,
|
transmittersDao: TransmittersDao,
|
||||||
sourcesDao: SourcesDao
|
transmittersApi: TransmittersApi
|
||||||
): Repository {
|
): TransmittersRepo {
|
||||||
return DefaultRepository(
|
return DefaultTransmittersRepo(transmittersDao, transmittersApi)
|
||||||
resolver,
|
|
||||||
client,
|
|
||||||
transmittersApi,
|
|
||||||
entriesDao,
|
|
||||||
sourcesDao,
|
|
||||||
transmittersDao
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-46
@@ -1,22 +1,3 @@
|
|||||||
/*
|
|
||||||
* Look4Sat. Amateur radio and weather satellite tracker and passes predictor for Android.
|
|
||||||
* Copyright (C) 2019, 2020 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 2 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, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.rtbishop.look4sat.repo
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
@@ -24,12 +5,8 @@ import android.net.Uri
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import com.github.amsacode.predict4java.TLE
|
import com.github.amsacode.predict4java.TLE
|
||||||
import com.rtbishop.look4sat.data.SatEntry
|
import com.rtbishop.look4sat.data.SatEntry
|
||||||
import com.rtbishop.look4sat.data.SatTrans
|
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
import com.rtbishop.look4sat.repo.local.EntriesDao
|
import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
|
||||||
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
|
||||||
import com.rtbishop.look4sat.repo.remote.TransmittersApi
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@@ -37,22 +14,11 @@ import okhttp3.Request
|
|||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DefaultRepository @Inject constructor(
|
class DefaultEntriesRepo @Inject constructor(
|
||||||
private val resolver: ContentResolver,
|
private val resolver: ContentResolver,
|
||||||
private val client: OkHttpClient,
|
private val client: OkHttpClient,
|
||||||
private val api: TransmittersApi,
|
private val entriesDao: EntriesDao
|
||||||
private val entriesDao: EntriesDao,
|
) : EntriesRepo {
|
||||||
private val sourcesDao: SourcesDao,
|
|
||||||
private val transmittersDao: TransmittersDao
|
|
||||||
) : Repository {
|
|
||||||
|
|
||||||
override fun getSources(): LiveData<List<TleSource>> {
|
|
||||||
return sourcesDao.getSources()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateSources(sources: List<TleSource>) {
|
|
||||||
sourcesDao.updateSources(sources)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getEntries(): LiveData<List<SatEntry>> {
|
override fun getEntries(): LiveData<List<SatEntry>> {
|
||||||
return entriesDao.getEntries()
|
return entriesDao.getEntries()
|
||||||
@@ -91,12 +57,4 @@ class DefaultRepository @Inject constructor(
|
|||||||
override suspend fun updateEntriesSelection(satIds: List<Int>) {
|
override suspend fun updateEntriesSelection(satIds: List<Int>) {
|
||||||
entriesDao.updateEntriesSelection(satIds)
|
entriesDao.updateEntriesSelection(satIds)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
override fun getTransmittersForSat(satId: Int): LiveData<List<SatTrans>> {
|
|
||||||
return transmittersDao.getTransmittersForSat(satId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateTransmitters() {
|
|
||||||
transmittersDao.updateTransmitters(api.getTransmitters())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
|
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DefaultSourcesRepo @Inject constructor(private val sourcesDao: SourcesDao) :
|
||||||
|
SourcesRepo {
|
||||||
|
|
||||||
|
override fun getSources(): LiveData<List<TleSource>> {
|
||||||
|
return sourcesDao.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateSources(sources: List<TleSource>) {
|
||||||
|
sourcesDao.updateSources(sources)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.rtbishop.look4sat.data.SatTrans
|
||||||
|
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
||||||
|
import com.rtbishop.look4sat.repo.remote.TransmittersApi
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DefaultTransmittersRepo @Inject constructor(
|
||||||
|
private val transmittersDao: TransmittersDao,
|
||||||
|
private val transmittersApi: TransmittersApi
|
||||||
|
) : TransmittersRepo {
|
||||||
|
|
||||||
|
override fun getTransmittersForSat(satId: Int): LiveData<List<SatTrans>> {
|
||||||
|
return transmittersDao.getTransmittersForSat(satId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateTransmitters() {
|
||||||
|
transmittersDao.updateTransmitters(transmittersApi.getTransmitters())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.rtbishop.look4sat.data.SatEntry
|
||||||
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
|
|
||||||
|
interface EntriesRepo {
|
||||||
|
|
||||||
|
fun getEntries(): LiveData<List<SatEntry>>
|
||||||
|
|
||||||
|
suspend fun updateEntriesFromFile(fileUri: Uri)
|
||||||
|
|
||||||
|
suspend fun updateEntriesFromSources(sources: List<TleSource>)
|
||||||
|
|
||||||
|
suspend fun updateEntriesSelection(satIds: List<Int>)
|
||||||
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.rtbishop.look4sat.repo
|
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import com.rtbishop.look4sat.data.SatEntry
|
|
||||||
import com.rtbishop.look4sat.data.SatTrans
|
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
|
||||||
|
|
||||||
interface Repository {
|
|
||||||
|
|
||||||
fun getSources(): LiveData<List<TleSource>>
|
|
||||||
|
|
||||||
suspend fun updateSources(sources: List<TleSource>)
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
fun getEntries(): LiveData<List<SatEntry>>
|
|
||||||
|
|
||||||
suspend fun updateEntriesFromFile(fileUri: Uri)
|
|
||||||
|
|
||||||
suspend fun updateEntriesFromSources(sources: List<TleSource>)
|
|
||||||
|
|
||||||
suspend fun updateEntriesSelection(satIds: List<Int>)
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
suspend fun updateTransmitters()
|
|
||||||
|
|
||||||
fun getTransmittersForSat(satId: Int): LiveData<List<SatTrans>>
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
|
|
||||||
|
interface SourcesRepo {
|
||||||
|
|
||||||
|
fun getSources(): LiveData<List<TleSource>>
|
||||||
|
|
||||||
|
suspend fun updateSources(sources: List<TleSource>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.rtbishop.look4sat.data.SatTrans
|
||||||
|
|
||||||
|
interface TransmittersRepo {
|
||||||
|
|
||||||
|
suspend fun updateTransmitters()
|
||||||
|
|
||||||
|
fun getTransmittersForSat(satId: Int): LiveData<List<SatTrans>>
|
||||||
|
}
|
||||||
Reference in new issue
Block a user