kopia lustrzana https://github.com/rt-bishop/Look4Sat
Now storing tle sources in shared prefs, restoring defaults. Added DB migration.
rodzic
a15e789e70
commit
ef51f671b7
|
@ -22,8 +22,8 @@ package com.rtbishop.look4sat.di
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.rtbishop.look4sat.repository.localData.EntriesDao
|
import com.rtbishop.look4sat.repository.localData.EntriesDao
|
||||||
|
import com.rtbishop.look4sat.repository.localData.MIGRATION_1_2
|
||||||
import com.rtbishop.look4sat.repository.localData.SatelliteDb
|
import com.rtbishop.look4sat.repository.localData.SatelliteDb
|
||||||
import com.rtbishop.look4sat.repository.localData.SourcesDao
|
|
||||||
import com.rtbishop.look4sat.repository.localData.TransmittersDao
|
import com.rtbishop.look4sat.repository.localData.TransmittersDao
|
||||||
import com.rtbishop.look4sat.utility.RoomConverters
|
import com.rtbishop.look4sat.utility.RoomConverters
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
|
@ -44,12 +44,6 @@ object RepositoryModule {
|
||||||
return db.entriesDao()
|
return db.entriesDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideSourcesDao(db: SatelliteDb): SourcesDao {
|
|
||||||
return db.sourcesDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideTransmittersDao(db: SatelliteDb): TransmittersDao {
|
fun provideTransmittersDao(db: SatelliteDb): TransmittersDao {
|
||||||
|
@ -60,6 +54,8 @@ object RepositoryModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||||
RoomConverters.initialize(moshi)
|
RoomConverters.initialize(moshi)
|
||||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb").build()
|
return Room.databaseBuilder(context, SatelliteDb::class.java, "satDb")
|
||||||
|
.addMigrations(MIGRATION_1_2)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,40 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Look4Sat. Amateur radio satellite tracker and pass predictor.
|
Look4Sat. Amateur radio satellite tracker and pass predictor.
|
||||||
Copyright (C) 2019, 2020 Arty Bishop (bishop.arty@gmail.com)
|
Copyright (C) 2019, 2020 Arty Bishop (bishop.arty@gmail.com)
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
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.,
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
package com.rtbishop.look4sat.utility
|
package com.rtbishop.look4sat.repository
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.hardware.GeomagneticField
|
import android.hardware.GeomagneticField
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.github.amsacode.predict4java.GroundStationPosition
|
import com.github.amsacode.predict4java.GroundStationPosition
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.Types
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
|
class PrefsRepo @Inject constructor(val preferences: SharedPreferences, val moshi: Moshi) {
|
||||||
|
|
||||||
|
private val sourcesType = Types.newParameterizedType(List::class.java, TleSource::class.java)
|
||||||
|
private val sourcesAdapter = moshi.adapter<List<TleSource>>(sourcesType)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val keySources = "tleSources"
|
||||||
const val keyLatitude = "latitude"
|
const val keyLatitude = "latitude"
|
||||||
const val keyLongitude = "longitude"
|
const val keyLongitude = "longitude"
|
||||||
const val keyAltitude = "altitude"
|
const val keyAltitude = "altitude"
|
||||||
|
@ -94,7 +100,25 @@ class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
|
||||||
preferences.edit { putBoolean(keyIsFirstLaunch, false) }
|
preferences.edit { putBoolean(keyIsFirstLaunch, false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDefaultSources(): List<TleSource> {
|
fun loadTleSources(): List<TleSource> {
|
||||||
|
preferences.getString(keySources, null)?.let { sourcesJson ->
|
||||||
|
sourcesAdapter.fromJson(sourcesJson)?.let { loadedSources ->
|
||||||
|
return if (loadedSources.isNotEmpty()) {
|
||||||
|
loadedSources
|
||||||
|
} else {
|
||||||
|
loadDefaultSources()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return loadDefaultSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveTleSources(sources: List<TleSource>) {
|
||||||
|
val sourcesJson = sourcesAdapter.toJson(sources)
|
||||||
|
preferences.edit { putString(keySources, sourcesJson) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadDefaultSources(): List<TleSource> {
|
||||||
return listOf(
|
return listOf(
|
||||||
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")
|
|
@ -1,36 +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.repository
|
|
||||||
|
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
|
||||||
import com.rtbishop.look4sat.repository.localData.SourcesDao
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class SourcesRepo @Inject constructor(private val sourcesDao: SourcesDao) {
|
|
||||||
|
|
||||||
fun getSources(): Flow<List<TleSource>> {
|
|
||||||
return sourcesDao.getSources()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun updateSources(sources: List<TleSource>) {
|
|
||||||
sourcesDao.updateSources(sources)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,18 +22,23 @@ package com.rtbishop.look4sat.repository.localData
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import com.rtbishop.look4sat.data.SatEntry
|
import com.rtbishop.look4sat.data.SatEntry
|
||||||
import com.rtbishop.look4sat.data.SatTrans
|
import com.rtbishop.look4sat.data.SatTrans
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
|
||||||
import com.rtbishop.look4sat.utility.RoomConverters
|
import com.rtbishop.look4sat.utility.RoomConverters
|
||||||
|
|
||||||
@Database(entities = [TleSource::class, SatEntry::class, SatTrans::class], version = 1)
|
@Database(entities = [SatEntry::class, SatTrans::class], version = 2)
|
||||||
@TypeConverters(RoomConverters::class)
|
@TypeConverters(RoomConverters::class)
|
||||||
abstract class SatelliteDb : RoomDatabase() {
|
abstract class SatelliteDb : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun sourcesDao(): SourcesDao
|
|
||||||
|
|
||||||
abstract fun entriesDao(): EntriesDao
|
abstract fun entriesDao(): EntriesDao
|
||||||
|
|
||||||
abstract fun transmittersDao(): TransmittersDao
|
abstract fun transmittersDao(): TransmittersDao
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("DROP TABLE sources")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,43 +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.repository.localData
|
|
||||||
|
|
||||||
import androidx.room.*
|
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface SourcesDao {
|
|
||||||
|
|
||||||
@Query("SELECT * FROM sources")
|
|
||||||
fun getSources(): Flow<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>)
|
|
||||||
}
|
|
|
@ -25,7 +25,7 @@ import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import com.rtbishop.look4sat.R
|
import com.rtbishop.look4sat.R
|
||||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import javax.inject.Inject
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var prefsManager: PrefsManager
|
lateinit var prefsRepo: PrefsRepo
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setTheme(R.style.AppTheme)
|
setTheme(R.style.AppTheme)
|
||||||
|
@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
setContentView(root)
|
setContentView(root)
|
||||||
val navHost = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
|
val navHost = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
|
||||||
navBottom.setupWithNavController(navHost.navController)
|
navBottom.setupWithNavController(navHost.navController)
|
||||||
if (prefsManager.isFirstLaunch()) navHost.navController.navigate(R.id.nav_dialog_splash)
|
if (prefsRepo.isFirstLaunch()) navHost.navController.navigate(R.id.nav_dialog_splash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,9 +24,8 @@ import androidx.lifecycle.*
|
||||||
import com.github.amsacode.predict4java.SatelliteFactory
|
import com.github.amsacode.predict4java.SatelliteFactory
|
||||||
import com.rtbishop.look4sat.data.*
|
import com.rtbishop.look4sat.data.*
|
||||||
import com.rtbishop.look4sat.repository.EntriesRepo
|
import com.rtbishop.look4sat.repository.EntriesRepo
|
||||||
import com.rtbishop.look4sat.repository.SourcesRepo
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import com.rtbishop.look4sat.repository.TransmittersRepo
|
import com.rtbishop.look4sat.repository.TransmittersRepo
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
|
||||||
import com.rtbishop.look4sat.utility.getPredictor
|
import com.rtbishop.look4sat.utility.getPredictor
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -37,8 +36,7 @@ import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SharedViewModel @Inject constructor(
|
class SharedViewModel @Inject constructor(
|
||||||
private val prefsManager: PrefsManager,
|
private val prefsRepo: PrefsRepo,
|
||||||
private val sourcesRepo: SourcesRepo,
|
|
||||||
private val entriesRepo: EntriesRepo,
|
private val entriesRepo: EntriesRepo,
|
||||||
private val transmittersRepo: TransmittersRepo
|
private val transmittersRepo: TransmittersRepo
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
@ -49,9 +47,9 @@ class SharedViewModel @Inject constructor(
|
||||||
private var shouldTriggerCalculation = true
|
private var shouldTriggerCalculation = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (prefsManager.isFirstLaunch()) {
|
if (prefsRepo.isFirstLaunch()) {
|
||||||
updateDefaultSourcesAndEntries()
|
updateDefaultSourcesAndEntries()
|
||||||
prefsManager.setFirstLaunchDone()
|
prefsRepo.setFirstLaunchDone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +61,7 @@ class SharedViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSources() = sourcesRepo.getSources().asLiveData()
|
fun getSources() = liveData { emit(prefsRepo.loadTleSources()) }
|
||||||
fun getEntries() = entriesRepo.getEntries().asLiveData()
|
fun getEntries() = entriesRepo.getEntries().asLiveData()
|
||||||
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
||||||
fun getTransmittersForSat(satId: Int) =
|
fun getTransmittersForSat(satId: Int) =
|
||||||
|
@ -103,16 +101,11 @@ class SharedViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateEntriesFromSources(sources: List<TleSource>) {
|
fun updateEntriesFromSources(sources: List<TleSource>) {
|
||||||
val sourcesList = if (sources.isEmpty()) {
|
|
||||||
prefsManager.getDefaultSources()
|
|
||||||
} else {
|
|
||||||
sources
|
|
||||||
}
|
|
||||||
postAppEvent(Event(0))
|
postAppEvent(Event(0))
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
sourcesRepo.updateSources(sourcesList)
|
prefsRepo.saveTleSources(sources)
|
||||||
entriesRepo.updateEntriesFromWeb(sourcesList)
|
entriesRepo.updateEntriesFromWeb(sources)
|
||||||
transmittersRepo.updateTransmitters()
|
transmittersRepo.updateTransmitters()
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
postAppEvent(Event(1))
|
postAppEvent(Event(1))
|
||||||
|
@ -133,28 +126,28 @@ class SharedViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPasses(entry: SatEntry, dateNow: Date): MutableList<SatPass> {
|
private fun getPasses(entry: SatEntry, dateNow: Date): MutableList<SatPass> {
|
||||||
val gsp = prefsManager.getStationPosition()
|
val gsp = prefsRepo.getStationPosition()
|
||||||
val predictor = SatelliteFactory.createSatellite(entry.tle).getPredictor(gsp)
|
val predictor = SatelliteFactory.createSatellite(entry.tle).getPredictor(gsp)
|
||||||
val hoursAhead = prefsManager.getHoursAhead()
|
val hoursAhead = prefsRepo.getHoursAhead()
|
||||||
val passes = predictor.getPasses(dateNow, hoursAhead, true)
|
val passes = predictor.getPasses(dateNow, hoursAhead, true)
|
||||||
val passList = passes.map { SatPass(entry.tle, predictor, it) }
|
val passList = passes.map { SatPass(entry.tle, predictor, it) }
|
||||||
return passList as MutableList<SatPass>
|
return passList as MutableList<SatPass>
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sortList(passes: MutableList<SatPass>, dateNow: Date): MutableList<SatPass> {
|
private fun sortList(passes: MutableList<SatPass>, dateNow: Date): MutableList<SatPass> {
|
||||||
val hoursAhead = prefsManager.getHoursAhead()
|
val hoursAhead = prefsRepo.getHoursAhead()
|
||||||
val dateFuture = Calendar.getInstance().apply {
|
val dateFuture = Calendar.getInstance().apply {
|
||||||
this.time = dateNow
|
this.time = dateNow
|
||||||
this.add(Calendar.HOUR, hoursAhead)
|
this.add(Calendar.HOUR, hoursAhead)
|
||||||
}.time
|
}.time
|
||||||
passes.removeAll { it.pass.startTime.after(dateFuture) }
|
passes.removeAll { it.pass.startTime.after(dateFuture) }
|
||||||
passes.removeAll { it.pass.endTime.before(dateNow) }
|
passes.removeAll { it.pass.endTime.before(dateNow) }
|
||||||
passes.removeAll { it.pass.maxEl < prefsManager.getMinElevation() }
|
passes.removeAll { it.pass.maxEl < prefsRepo.getMinElevation() }
|
||||||
passes.sortBy { it.pass.startTime }
|
passes.sortBy { it.pass.startTime }
|
||||||
return passes
|
return passes
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDefaultSourcesAndEntries() {
|
private fun updateDefaultSourcesAndEntries() {
|
||||||
updateEntriesFromSources(prefsManager.getDefaultSources())
|
updateEntriesFromSources(prefsRepo.loadTleSources())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import com.rtbishop.look4sat.data.SatPass
|
||||||
import com.rtbishop.look4sat.data.SelectedSat
|
import com.rtbishop.look4sat.data.SelectedSat
|
||||||
import com.rtbishop.look4sat.databinding.FragmentMapBinding
|
import com.rtbishop.look4sat.databinding.FragmentMapBinding
|
||||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.osmdroid.config.Configuration
|
import org.osmdroid.config.Configuration
|
||||||
import org.osmdroid.tileprovider.tilesource.ITileSource
|
import org.osmdroid.tileprovider.tilesource.ITileSource
|
||||||
|
@ -53,7 +53,7 @@ import javax.inject.Inject
|
||||||
class MapFragment : Fragment(R.layout.fragment_map) {
|
class MapFragment : Fragment(R.layout.fragment_map) {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var prefsManager: PrefsManager
|
lateinit var prefsRepo: PrefsRepo
|
||||||
private lateinit var binding: FragmentMapBinding
|
private lateinit var binding: FragmentMapBinding
|
||||||
private val mapViewModel: MapViewModel by viewModels()
|
private val mapViewModel: MapViewModel by viewModels()
|
||||||
private val sharedViewModel: SharedViewModel by activityViewModels()
|
private val sharedViewModel: SharedViewModel by activityViewModels()
|
||||||
|
@ -62,7 +62,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
Configuration.getInstance().load(requireContext(), prefsManager.preferences)
|
Configuration.getInstance().load(requireContext(), prefsRepo.preferences)
|
||||||
binding = FragmentMapBinding.bind(view).apply {
|
binding = FragmentMapBinding.bind(view).apply {
|
||||||
mapView.apply {
|
mapView.apply {
|
||||||
setMultiTouchControls(true)
|
setMultiTouchControls(true)
|
||||||
|
@ -129,7 +129,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||||
binding.apply {
|
binding.apply {
|
||||||
val markers = FolderOverlay()
|
val markers = FolderOverlay()
|
||||||
map.entries.forEach {
|
map.entries.forEach {
|
||||||
if (prefsManager.shouldUseTextLabels()) {
|
if (prefsRepo.shouldUseTextLabels()) {
|
||||||
Marker(mapView).apply {
|
Marker(mapView).apply {
|
||||||
setInfoWindow(null)
|
setInfoWindow(null)
|
||||||
textLabelFontSize = 24
|
textLabelFontSize = 24
|
||||||
|
|
|
@ -29,7 +29,7 @@ import com.github.amsacode.predict4java.Position
|
||||||
import com.github.amsacode.predict4java.SatPos
|
import com.github.amsacode.predict4java.SatPos
|
||||||
import com.rtbishop.look4sat.data.SatPass
|
import com.rtbishop.look4sat.data.SatPass
|
||||||
import com.rtbishop.look4sat.data.SelectedSat
|
import com.rtbishop.look4sat.data.SelectedSat
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import com.rtbishop.look4sat.utility.QthConverter
|
import com.rtbishop.look4sat.utility.QthConverter
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -49,7 +49,7 @@ import kotlin.math.sqrt
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MapViewModel @Inject constructor(
|
class MapViewModel @Inject constructor(
|
||||||
private val prefsManager: PrefsManager,
|
private val prefsRepo: PrefsRepo,
|
||||||
private val qthConverter: QthConverter
|
private val qthConverter: QthConverter
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ class MapViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getStationPosition(): Position {
|
private fun getStationPosition(): Position {
|
||||||
val stationPosition = prefsManager.getStationPosition()
|
val stationPosition = prefsRepo.getStationPosition()
|
||||||
return getOsmPosition(stationPosition.latitude, stationPosition.longitude, false)
|
return getOsmPosition(stationPosition.latitude, stationPosition.longitude, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import com.rtbishop.look4sat.data.Result
|
||||||
import com.rtbishop.look4sat.data.SatPass
|
import com.rtbishop.look4sat.data.SatPass
|
||||||
import com.rtbishop.look4sat.databinding.FragmentPassesBinding
|
import com.rtbishop.look4sat.databinding.FragmentPassesBinding
|
||||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import com.rtbishop.look4sat.utility.RecyclerDivider
|
import com.rtbishop.look4sat.utility.RecyclerDivider
|
||||||
import com.rtbishop.look4sat.utility.formatForTimer
|
import com.rtbishop.look4sat.utility.formatForTimer
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
@ -41,7 +41,7 @@ import javax.inject.Inject
|
||||||
class PassesFragment : Fragment(R.layout.fragment_passes) {
|
class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var prefsManager: PrefsManager
|
lateinit var prefsRepo: PrefsRepo
|
||||||
|
|
||||||
private var binding: FragmentPassesBinding? = null
|
private var binding: FragmentPassesBinding? = null
|
||||||
private var passesAdapter: PassesAdapter? = null
|
private var passesAdapter: PassesAdapter? = null
|
||||||
|
@ -90,7 +90,7 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupComponents() {
|
private fun setupComponents() {
|
||||||
passesAdapter = PassesAdapter(requireContext(), prefsManager.shouldUseUTC())
|
passesAdapter = PassesAdapter(requireContext(), prefsRepo.shouldUseUTC())
|
||||||
binding?.apply {
|
binding?.apply {
|
||||||
passesRecycler.apply {
|
passesRecycler.apply {
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
|
|
|
@ -36,7 +36,7 @@ import com.rtbishop.look4sat.data.Result
|
||||||
import com.rtbishop.look4sat.data.SatPass
|
import com.rtbishop.look4sat.data.SatPass
|
||||||
import com.rtbishop.look4sat.databinding.FragmentPolarBinding
|
import com.rtbishop.look4sat.databinding.FragmentPolarBinding
|
||||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import com.rtbishop.look4sat.utility.RecyclerDivider
|
import com.rtbishop.look4sat.utility.RecyclerDivider
|
||||||
import com.rtbishop.look4sat.utility.formatForTimer
|
import com.rtbishop.look4sat.utility.formatForTimer
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
@ -48,7 +48,7 @@ import kotlin.math.round
|
||||||
class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var prefsManager: PrefsManager
|
lateinit var prefsRepo: PrefsRepo
|
||||||
|
|
||||||
private lateinit var transmitterAdapter: TransAdapter
|
private lateinit var transmitterAdapter: TransAdapter
|
||||||
private lateinit var binding: FragmentPolarBinding
|
private lateinit var binding: FragmentPolarBinding
|
||||||
|
@ -62,13 +62,13 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding = FragmentPolarBinding.bind(view)
|
binding = FragmentPolarBinding.bind(view)
|
||||||
sensorManager = requireContext().getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
sensorManager = requireContext().getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||||
magneticDeclination = prefsManager.getMagDeclination()
|
magneticDeclination = prefsRepo.getMagDeclination()
|
||||||
observePasses()
|
observePasses()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (prefsManager.shouldUseCompass()) {
|
if (prefsRepo.shouldUseCompass()) {
|
||||||
sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR).also { sensor ->
|
sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR).also { sensor ->
|
||||||
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI)
|
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
if (prefsManager.shouldUseCompass()) {
|
if (prefsRepo.shouldUseCompass()) {
|
||||||
sensorManager.unregisterListener(this)
|
sensorManager.unregisterListener(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.rtbishop.look4sat.R
|
import com.rtbishop.look4sat.R
|
||||||
import com.rtbishop.look4sat.utility.PrefsManager
|
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||||
import com.rtbishop.look4sat.utility.QthConverter
|
import com.rtbishop.look4sat.utility.QthConverter
|
||||||
import com.rtbishop.look4sat.utility.round
|
import com.rtbishop.look4sat.utility.round
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
@ -43,7 +43,7 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
||||||
lateinit var locationManager: LocationManager
|
lateinit var locationManager: LocationManager
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var prefsManager: PrefsManager
|
lateinit var prefsRepo: PrefsRepo
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var qthConverter: QthConverter
|
lateinit var qthConverter: QthConverter
|
||||||
|
@ -64,14 +64,14 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
findPreference<Preference>(PrefsManager.keyPositionGPS)?.apply {
|
findPreference<Preference>(PrefsRepo.keyPositionGPS)?.apply {
|
||||||
setOnPreferenceClickListener {
|
setOnPreferenceClickListener {
|
||||||
setPositionFromGPS()
|
setPositionFromGPS()
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<Preference>(PrefsManager.keyPositionQTH)?.apply {
|
findPreference<Preference>(PrefsRepo.keyPositionQTH)?.apply {
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
setPositionFromQth(newValue.toString())
|
setPositionFromQth(newValue.toString())
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
||||||
showSnack(getString(R.string.pref_pos_qth_error))
|
showSnack(getString(R.string.pref_pos_qth_error))
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
prefsManager.setStationPosition(loc.latitude, loc.longitude, loc.heightAMSL)
|
prefsRepo.setStationPosition(loc.latitude, loc.longitude, loc.heightAMSL)
|
||||||
showSnack(getString(R.string.pref_pos_success))
|
showSnack(getString(R.string.pref_pos_success))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
||||||
val latitude = location.latitude.round(4)
|
val latitude = location.latitude.round(4)
|
||||||
val longitude = location.longitude.round(4)
|
val longitude = location.longitude.round(4)
|
||||||
val altitude = location.altitude.round(1)
|
val altitude = location.altitude.round(1)
|
||||||
prefsManager.setStationPosition(latitude, longitude, altitude)
|
prefsRepo.setStationPosition(latitude, longitude, altitude)
|
||||||
showSnack(getString(R.string.pref_pos_success))
|
showSnack(getString(R.string.pref_pos_success))
|
||||||
} else showSnack(getString(R.string.pref_pos_gps_null))
|
} else showSnack(getString(R.string.pref_pos_gps_null))
|
||||||
} else requestPermissionLauncher.launch(locPermString)
|
} else requestPermissionLauncher.launch(locPermString)
|
||||||
|
|
|
@ -26,9 +26,19 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
import com.rtbishop.look4sat.data.TleSource
|
||||||
import com.rtbishop.look4sat.databinding.ItemTleSourceBinding
|
import com.rtbishop.look4sat.databinding.ItemTleSourceBinding
|
||||||
|
|
||||||
class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf()) :
|
class SourcesAdapter : RecyclerView.Adapter<SourcesAdapter.TleSourceHolder>() {
|
||||||
RecyclerView.Adapter<SourcesAdapter.TleSourceHolder>() {
|
|
||||||
|
private val sources = mutableListOf<TleSource>()
|
||||||
|
|
||||||
|
fun getSources(): List<TleSource> {
|
||||||
|
return sources.filter { it.url != String() && it.url != " " && it.url.contains("https://") }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSources(list: List<TleSource>) {
|
||||||
|
sources.clear()
|
||||||
|
sources.addAll(list)
|
||||||
|
}
|
||||||
|
|
||||||
fun addSource() {
|
fun addSource() {
|
||||||
val emptySource = TleSource()
|
val emptySource = TleSource()
|
||||||
if (!sources.contains(emptySource)) {
|
if (!sources.contains(emptySource)) {
|
||||||
|
@ -36,17 +46,13 @@ class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf
|
||||||
notifyItemInserted(itemCount - 1)
|
notifyItemInserted(itemCount - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSources(): List<TleSource> {
|
|
||||||
return sources.filter { it.url != String() && it.url != " " && it.url.contains("https://") }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {
|
||||||
val binding = ItemTleSourceBinding
|
val binding = ItemTleSourceBinding
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return TleSourceHolder(binding)
|
return TleSourceHolder(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
|
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
|
||||||
holder.bind(sources[position])
|
holder.bind(sources[position])
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,8 @@ import androidx.appcompat.app.AppCompatDialogFragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.rtbishop.look4sat.R
|
import com.rtbishop.look4sat.R
|
||||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
|
||||||
import com.rtbishop.look4sat.data.TleSource
|
|
||||||
import com.rtbishop.look4sat.databinding.DialogSourcesBinding
|
import com.rtbishop.look4sat.databinding.DialogSourcesBinding
|
||||||
|
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
|
@ -45,7 +44,8 @@ class SourcesDialog : AppCompatDialogFragment() {
|
||||||
override fun onViewCreated(view: View, state: Bundle?) {
|
override fun onViewCreated(view: View, state: Bundle?) {
|
||||||
super.onViewCreated(view, state)
|
super.onViewCreated(view, state)
|
||||||
viewModel.getSources().observe(viewLifecycleOwner, { sources ->
|
viewModel.getSources().observe(viewLifecycleOwner, { sources ->
|
||||||
val sourcesAdapter = SourcesAdapter(sources as MutableList<TleSource>)
|
val sourcesAdapter = SourcesAdapter()
|
||||||
|
sourcesAdapter.setSources(sources)
|
||||||
DialogSourcesBinding.bind(view).apply {
|
DialogSourcesBinding.bind(view).apply {
|
||||||
dialog?.window?.setLayout(
|
dialog?.window?.setLayout(
|
||||||
WindowManager.LayoutParams.MATCH_PARENT,
|
WindowManager.LayoutParams.MATCH_PARENT,
|
||||||
|
|
Ładowanie…
Reference in New Issue