mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Cleaned up dependencies, injecting Moshi in RoomConverters
This commit is contained in:
1 parent
decc24ea2a
commit
4fa2f13834
9 files changed
+33
-41
No files matched your search
@@ -58,8 +58,6 @@ dependencies {
|
||||
|
||||
implementation "com.google.dagger:hilt-android:$hilt_version"
|
||||
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
|
||||
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_viewmodel_version"
|
||||
kapt "androidx.hilt:hilt-compiler:$hilt_viewmodel_version"
|
||||
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
|
||||
|
||||
@@ -130,21 +130,21 @@ class SharedViewModel @Inject constructor(
|
||||
private fun getPasses(entry: SatEntry, dateNow: Date): MutableList<SatPass> {
|
||||
val gsp = prefsManager.getStationPosition()
|
||||
val predictor = SatelliteFactory.createSatellite(entry.tle).getPredictor(gsp)
|
||||
val hoursAhead = prefsManager.getPassPrefs().hoursAhead
|
||||
val hoursAhead = prefsManager.getHoursAhead()
|
||||
val passes = predictor.getPasses(dateNow, hoursAhead, true)
|
||||
val passList = passes.map { SatPass(entry.tle, predictor, it) }
|
||||
return passList as MutableList<SatPass>
|
||||
}
|
||||
|
||||
private fun sortList(passes: MutableList<SatPass>, dateNow: Date): MutableList<SatPass> {
|
||||
val hoursAhead = prefsManager.getPassPrefs().hoursAhead
|
||||
val hoursAhead = prefsManager.getHoursAhead()
|
||||
val dateFuture = Calendar.getInstance().apply {
|
||||
this.time = dateNow
|
||||
this.add(Calendar.HOUR, hoursAhead)
|
||||
}.time
|
||||
passes.removeAll { it.pass.startTime.after(dateFuture) }
|
||||
passes.removeAll { it.pass.endTime.before(dateNow) }
|
||||
passes.removeAll { it.pass.maxEl < prefsManager.getPassPrefs().minEl }
|
||||
passes.removeAll { it.pass.maxEl < prefsManager.getMinElevation() }
|
||||
passes.sortBy { it.pass.startTime }
|
||||
return passes
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/*******************************************************************************
|
||||
Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||
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.data
|
||||
|
||||
data class PassPrefs(val hoursAhead: Int, val minEl: Double)
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.rtbishop.look4sat.di
|
||||
|
||||
import com.rtbishop.look4sat.repo.remote.TransmittersApi
|
||||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -39,6 +40,12 @@ object NetworkModule {
|
||||
return OkHttpClient()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMoshi(): Moshi {
|
||||
return Moshi.Builder().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getTransmittersApi(): TransmittersApi {
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.rtbishop.look4sat.repo.local.EntriesDao
|
||||
import com.rtbishop.look4sat.repo.local.SatelliteDb
|
||||
import com.rtbishop.look4sat.repo.local.SourcesDao
|
||||
import com.rtbishop.look4sat.repo.local.TransmittersDao
|
||||
import com.rtbishop.look4sat.utility.TypeConverters
|
||||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -63,7 +65,8 @@ object RepositoryModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun getSatelliteDb(@ApplicationContext context: Context): SatelliteDb {
|
||||
fun getSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||
TypeConverters.initialize(moshi)
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb").build()
|
||||
}
|
||||
}
|
||||
@@ -25,14 +25,13 @@ import androidx.room.TypeConverters
|
||||
import com.rtbishop.look4sat.data.SatEntry
|
||||
import com.rtbishop.look4sat.data.SatTrans
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.utility.Converters
|
||||
|
||||
@Database(
|
||||
entities = [TleSource::class, SatEntry::class, SatTrans::class],
|
||||
version = 1,
|
||||
exportSchema = false
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
@TypeConverters(com.rtbishop.look4sat.utility.TypeConverters::class)
|
||||
abstract class SatelliteDb : RoomDatabase() {
|
||||
|
||||
abstract fun sourcesDao(): SourcesDao
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.SharedPreferences
|
||||
import android.hardware.GeomagneticField
|
||||
import androidx.core.content.edit
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
import com.rtbishop.look4sat.data.PassPrefs
|
||||
import javax.inject.Inject
|
||||
|
||||
class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
|
||||
@@ -41,10 +40,12 @@ class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
|
||||
const val keyIsFirstLaunch = "shouldShowSplash"
|
||||
}
|
||||
|
||||
fun getPassPrefs(): PassPrefs {
|
||||
val hoursAhead = preferences.getInt(keyHoursAhead, 8)
|
||||
val minEl = preferences.getInt(keyMinElevation, 16).toDouble()
|
||||
return PassPrefs(hoursAhead, minEl)
|
||||
fun getHoursAhead(): Int {
|
||||
return preferences.getInt(keyHoursAhead, 8)
|
||||
}
|
||||
|
||||
fun getMinElevation(): Double {
|
||||
return preferences.getInt(keyMinElevation, 16).toDouble()
|
||||
}
|
||||
|
||||
fun getStationPosition(): GroundStationPosition {
|
||||
|
||||
+12
-5
@@ -21,19 +21,26 @@ package com.rtbishop.look4sat.utility
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.github.amsacode.predict4java.TLE
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
class Converters {
|
||||
private val jsonConverter = Moshi.Builder().build()
|
||||
private val jsonAdapter = jsonConverter.adapter(TLE::class.java)
|
||||
object TypeConverters {
|
||||
|
||||
private lateinit var tleAdapter: JsonAdapter<TLE>
|
||||
|
||||
fun initialize(moshi: Moshi) {
|
||||
tleAdapter = moshi.adapter(TLE::class.java)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun tleToString(tle: TLE): String {
|
||||
return jsonAdapter.toJson(tle)
|
||||
return tleAdapter.toJson(tle)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun tleFromString(string: String): TLE? {
|
||||
return jsonAdapter.fromJson(string)
|
||||
return tleAdapter.fromJson(string)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ buildscript {
|
||||
preference_version = '1.1.1'
|
||||
room_version = '2.2.6'
|
||||
hilt_version = '2.33-beta'
|
||||
hilt_viewmodel_version = '1.0.0-alpha03'
|
||||
retrofit_version = '2.9.0'
|
||||
predict4java_version = '1.3.1'
|
||||
osmdroid_version = '6.1.10'
|
||||
|
||||
Reference in new issue
Block a user