mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-04 11:37:22 +00:00
Fetching satellite data asynchronously, increased build speed
This commit is contained in:
1 parent
5998a7e66d
commit
9b76d42707
12 files changed
+72
-146
No files matched your search
@@ -34,28 +34,24 @@ interface EntriesDao {
|
||||
|
||||
@Transaction
|
||||
suspend fun updateEntries(entries: List<SatEntry>) {
|
||||
val savedSelection = getSelection()
|
||||
val entriesSelection = getEntriesSelection()
|
||||
insertEntries(entries)
|
||||
restoreSelection(savedSelection, true)
|
||||
restoreSelection(entriesSelection, true)
|
||||
}
|
||||
|
||||
@Query("SELECT catnum FROM entries WHERE isSelected = 1")
|
||||
suspend fun getSelection(): List<Int>
|
||||
suspend fun getEntriesSelection(): List<Int>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertEntries(entries: List<SatEntry>)
|
||||
|
||||
@Transaction
|
||||
suspend fun restoreSelection(catnums: List<Int>, isSelected: Boolean) {
|
||||
clearEntriesSelection()
|
||||
updateSelection(catnums, isSelected)
|
||||
updateEntriesSelection(catnums, isSelected)
|
||||
}
|
||||
|
||||
@Query("UPDATE entries SET isSelected = 0")
|
||||
suspend fun clearEntriesSelection()
|
||||
|
||||
@Transaction
|
||||
suspend fun updateSelection(catnums: List<Int>, isSelected: Boolean) {
|
||||
suspend fun updateEntriesSelection(catnums: List<Int>, isSelected: Boolean) {
|
||||
catnums.forEach { catnum -> updateEntrySelection(catnum, isSelected) }
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,12 @@ package com.rtbishop.look4sat.framework.local
|
||||
|
||||
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.Transmitter
|
||||
import com.rtbishop.look4sat.domain.predict.Satellite
|
||||
import com.rtbishop.look4sat.framework.*
|
||||
import com.rtbishop.look4sat.framework.model.Source
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class LocalSource(
|
||||
@@ -30,31 +33,33 @@ class LocalSource(
|
||||
private val transmittersDao: TransmittersDao
|
||||
) : LocalDataSource {
|
||||
|
||||
override fun getSatelliteItems() = entriesDao.getSatelliteItems().map { it.toDomainItems() }
|
||||
|
||||
override suspend fun getSelectedSatellites() = entriesDao.getSelectedSatellites().map { entry ->
|
||||
entry.tle.createSat()
|
||||
override fun getSatelliteItems(): Flow<List<SatItem>> {
|
||||
return entriesDao.getSatelliteItems().map { items -> items.toDomainItems() }
|
||||
}
|
||||
|
||||
override suspend fun getSelectedSatellites(): List<Satellite> {
|
||||
return entriesDao.getSelectedSatellites().map { entry -> entry.tle.createSat() }
|
||||
}
|
||||
|
||||
override suspend fun getSources() = sourcesDao.getSources()
|
||||
|
||||
override suspend fun getTransmitters(catnum: Int): List<Transmitter> {
|
||||
return transmittersDao.getTransmitters(catnum).toDomain()
|
||||
}
|
||||
|
||||
override suspend fun getWebSources() = sourcesDao.getSources()
|
||||
|
||||
override suspend fun updateEntries(entries: List<SatEntry>) {
|
||||
entriesDao.updateEntries(entries.toFrameworkEntries())
|
||||
}
|
||||
|
||||
override suspend fun updateSelection(catnums: List<Int>, isSelected: Boolean) {
|
||||
entriesDao.updateSelection(catnums, isSelected)
|
||||
override suspend fun updateEntriesSelection(catnums: List<Int>, isSelected: Boolean) {
|
||||
entriesDao.updateEntriesSelection(catnums, isSelected)
|
||||
}
|
||||
|
||||
override suspend fun updateSources(sources: List<String>) {
|
||||
sourcesDao.updateSources(sources.map { sourceUrl -> Source(sourceUrl) })
|
||||
}
|
||||
|
||||
override suspend fun updateTransmitters(transmitters: List<Transmitter>) {
|
||||
transmittersDao.updateTransmitters(transmitters.toFramework())
|
||||
}
|
||||
|
||||
override suspend fun updateWebSources(sources: List<String>) {
|
||||
sourcesDao.updateSources(sources.map { Source(it) })
|
||||
}
|
||||
}
|
||||
@@ -28,27 +28,32 @@ import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object AppModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideContentResolver(@ApplicationContext context: Context): ContentResolver {
|
||||
return context.contentResolver
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideLocationManager(@ApplicationContext context: Context): LocationManager {
|
||||
return context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSensorManager(@ApplicationContext context: Context): SensorManager {
|
||||
return context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ object CoreModule {
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4).build()
|
||||
val localSource = LocalSource(db.entriesDao(), db.sourcesDao(), db.transmittersDao())
|
||||
val remoteSource = RemoteSource(ioDispatcher)
|
||||
return DefaultRepository(dataParser, localSource, remoteSource, ioDispatcher)
|
||||
return DefaultRepository(dataParser, localSource, remoteSource)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.presentation
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.URLUtil
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Lifecycle
|
||||
@@ -31,9 +29,6 @@ import androidx.navigation.Navigator
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.rtbishop.look4sat.R
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.security.MessageDigest
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -104,25 +99,13 @@ fun Date.toString(format: String): String {
|
||||
}
|
||||
|
||||
fun String.toDate(format: String): Date? {
|
||||
val dateFormatter = SimpleDateFormat(format, Locale.US)
|
||||
return try {
|
||||
dateFormatter.parse(this)
|
||||
return SimpleDateFormat(format, Locale.US).parse(this)
|
||||
} catch (e: ParseException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun String.toUri(): Uri? {
|
||||
return try {
|
||||
if (URLUtil.isValidUrl(this))
|
||||
Uri.parse(this)
|
||||
else
|
||||
null
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun String.md5(): String {
|
||||
val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray())
|
||||
return bytes.joinToString("") { "%02x".format(it) }
|
||||
@@ -139,76 +122,3 @@ fun String.isEmailValid(): Boolean {
|
||||
val matcher = pattern.matcher(this)
|
||||
return matcher.matches()
|
||||
}
|
||||
|
||||
fun String.getJsonObjectOrNull(): JSONObject? {
|
||||
return try {
|
||||
JSONObject(this)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun String.getJsonArrayOrNull(): JSONArray? {
|
||||
return try {
|
||||
JSONArray(this)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun JSONObject.getIntOrNull(name: String): Int? =
|
||||
try {
|
||||
getInt(name)
|
||||
} catch (e: JSONException) {
|
||||
val strValue = getStringOrNull(name)
|
||||
strValue?.toIntOrNull()
|
||||
}
|
||||
|
||||
fun JSONObject.getDoubleOrNull(name: String): Double? =
|
||||
try {
|
||||
getDouble(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getLongOrNull(name: String): Long? =
|
||||
try {
|
||||
getLong(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getStringOrNull(name: String): String? =
|
||||
try {
|
||||
getString(name).trim()
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getBooleanOrNull(name: String): Boolean? =
|
||||
try {
|
||||
getBoolean(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getObjectOrNull(name: String): JSONObject? =
|
||||
try {
|
||||
getJSONObject(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getArrayOrNull(name: String): JSONArray? =
|
||||
try {
|
||||
getJSONArray(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getArrayOrEmpty(name: String): JSONArray =
|
||||
try {
|
||||
getJSONArray(name)
|
||||
} catch (e: JSONException) {
|
||||
JSONArray()
|
||||
}
|
||||
Reference in new issue
Block a user