mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Switched to using Kotlin Flow in repository, zoom fix
This commit is contained in:
1 parent
271719c651
commit
c929e94d0e
8 files changed
+25
-27
No files matched your search
@@ -20,10 +20,7 @@
|
||||
package com.rtbishop.look4sat
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.*
|
||||
import com.rtbishop.look4sat.data.*
|
||||
import com.rtbishop.look4sat.repo.EntriesRepo
|
||||
import com.rtbishop.look4sat.repo.SourcesRepo
|
||||
@@ -50,7 +47,7 @@ class SharedViewModel @Inject constructor(
|
||||
private val _appEvent = MutableLiveData<Event<Int>>()
|
||||
private var selectedEntries = emptyList<SatEntry>()
|
||||
private var shouldTriggerCalculation = true
|
||||
|
||||
|
||||
init {
|
||||
if (prefsManager.isFirstLaunch()) {
|
||||
updateDefaultSourcesAndEntries()
|
||||
@@ -58,21 +55,22 @@ class SharedViewModel @Inject constructor(
|
||||
}
|
||||
startApplicationTimer()
|
||||
}
|
||||
|
||||
|
||||
fun getAppEvent(): LiveData<Event<Int>> = _appEvent
|
||||
fun getAppTimer(): LiveData<Long> = _appTimer
|
||||
fun getSources() = sourcesRepo.getSources()
|
||||
fun getEntries() = entriesRepo.getEntries()
|
||||
fun getSources() = sourcesRepo.getSources().asLiveData()
|
||||
fun getEntries() = entriesRepo.getEntries().asLiveData()
|
||||
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
||||
fun getTransmittersForSat(satId: Int) = transmittersRepo.getTransmittersForSat(satId)
|
||||
|
||||
fun getTransmittersForSat(satId: Int) =
|
||||
transmittersRepo.getTransmittersForSat(satId).asLiveData()
|
||||
|
||||
fun triggerCalculation() {
|
||||
if (shouldTriggerCalculation) {
|
||||
shouldTriggerCalculation = false
|
||||
calculatePasses()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun calculatePasses(dateNow: Date = Date(System.currentTimeMillis())) {
|
||||
shouldTriggerCalculation = false
|
||||
_passes.value = Result.InProgress
|
||||
|
||||
@@ -21,12 +21,12 @@ package com.rtbishop.look4sat.repo
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.github.amsacode.predict4java.TLE
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
@@ -39,7 +39,7 @@ class EntriesRepo @Inject constructor(
|
||||
private val entriesDao: EntriesDao
|
||||
) {
|
||||
|
||||
fun getEntries(): LiveData<List<SatEntry>> {
|
||||
fun getEntries(): Flow<List<SatEntry>> {
|
||||
return entriesDao.getEntries()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
|
||||
package com.rtbishop.look4sat.repo
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
|
||||
class SourcesRepo @Inject constructor(private val sourcesDao: SourcesDao) {
|
||||
|
||||
fun getSources(): LiveData<List<TleSource>> {
|
||||
fun getSources(): Flow<List<TleSource>> {
|
||||
return sourcesDao.getSources()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
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 kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
|
||||
class TransmittersRepo @Inject constructor(
|
||||
@@ -30,7 +30,7 @@ class TransmittersRepo @Inject constructor(
|
||||
private val transmittersApi: TransmittersApi
|
||||
) {
|
||||
|
||||
fun getTransmittersForSat(satId: Int): LiveData<List<SatTrans>> {
|
||||
fun getTransmittersForSat(satId: Int): Flow<List<SatTrans>> {
|
||||
return transmittersDao.getTransmittersForSat(satId)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface EntriesDao {
|
||||
|
||||
|
||||
@Query("SELECT * FROM entries ORDER BY name ASC")
|
||||
fun getEntries(): LiveData<List<SatEntry>>
|
||||
fun getEntries(): Flow<List<SatEntry>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertEntries(entries: List<SatEntry>)
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface SourcesDao {
|
||||
|
||||
|
||||
@Query("SELECT * FROM sources")
|
||||
fun getSources(): LiveData<List<TleSource>>
|
||||
fun getSources(): Flow<List<TleSource>>
|
||||
|
||||
@Transaction
|
||||
suspend fun updateSources(sources: List<TleSource>) {
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
package com.rtbishop.look4sat.repo.local
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.rtbishop.look4sat.data.SatTrans
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface TransmittersDao {
|
||||
|
||||
|
||||
@Query("SELECT * FROM transmitters WHERE isAlive = 1 and catNum = :satId")
|
||||
fun getTransmittersForSat(satId: Int): LiveData<List<SatTrans>>
|
||||
fun getTransmittersForSat(satId: Int): Flow<List<SatTrans>>
|
||||
|
||||
@Transaction
|
||||
suspend fun updateTransmitters(transmitters: List<SatTrans>) {
|
||||
|
||||
@@ -68,7 +68,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
setMultiTouchControls(true)
|
||||
setTileSource(getTileSource())
|
||||
val minZoom = getMinZoom(resources.displayMetrics.heightPixels)
|
||||
minZoomLevel = 2.5
|
||||
minZoomLevel = minZoom
|
||||
maxZoomLevel = 6.0
|
||||
controller.setZoom(minZoom + 0.5)
|
||||
zoomController.setVisibility(CustomZoomButtonsController.Visibility.NEVER)
|
||||
|
||||
Reference in new issue
Block a user