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 androidx.room.Room
|
||||
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.SourcesDao
|
||||
import com.rtbishop.look4sat.repository.localData.TransmittersDao
|
||||
import com.rtbishop.look4sat.utility.RoomConverters
|
||||
import com.squareup.moshi.Moshi
|
||||
|
@ -44,12 +44,6 @@ object RepositoryModule {
|
|||
return db.entriesDao()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSourcesDao(db: SatelliteDb): SourcesDao {
|
||||
return db.sourcesDao()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideTransmittersDao(db: SatelliteDb): TransmittersDao {
|
||||
|
@ -60,6 +54,8 @@ object RepositoryModule {
|
|||
@Singleton
|
||||
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||
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.
|
||||
Copyright (C) 2019, 2020 Arty Bishop (bishop.arty@gmail.com)
|
||||
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 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.
|
||||
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.
|
||||
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.utility
|
||||
package com.rtbishop.look4sat.repository
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.hardware.GeomagneticField
|
||||
import androidx.core.content.edit
|
||||
import com.github.amsacode.predict4java.GroundStationPosition
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
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 {
|
||||
const val keySources = "tleSources"
|
||||
const val keyLatitude = "latitude"
|
||||
const val keyLongitude = "longitude"
|
||||
const val keyAltitude = "altitude"
|
||||
|
@ -94,7 +100,25 @@ class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
|
|||
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(
|
||||
TleSource("https://celestrak.com/NORAD/elements/active.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.RoomDatabase
|
||||
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.SatTrans
|
||||
import com.rtbishop.look4sat.data.TleSource
|
||||
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)
|
||||
abstract class SatelliteDb : RoomDatabase() {
|
||||
|
||||
abstract fun sourcesDao(): SourcesDao
|
||||
|
||||
abstract fun entriesDao(): EntriesDao
|
||||
|
||||
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 com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||
import com.rtbishop.look4sat.utility.PrefsManager
|
||||
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -33,7 +33,7 @@ import javax.inject.Inject
|
|||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var prefsManager: PrefsManager
|
||||
lateinit var prefsRepo: PrefsRepo
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(R.style.AppTheme)
|
||||
|
@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() {
|
|||
setContentView(root)
|
||||
val navHost = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
|
||||
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.rtbishop.look4sat.data.*
|
||||
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.utility.PrefsManager
|
||||
import com.rtbishop.look4sat.utility.getPredictor
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -37,8 +36,7 @@ import javax.inject.Inject
|
|||
|
||||
@HiltViewModel
|
||||
class SharedViewModel @Inject constructor(
|
||||
private val prefsManager: PrefsManager,
|
||||
private val sourcesRepo: SourcesRepo,
|
||||
private val prefsRepo: PrefsRepo,
|
||||
private val entriesRepo: EntriesRepo,
|
||||
private val transmittersRepo: TransmittersRepo
|
||||
) : ViewModel() {
|
||||
|
@ -49,9 +47,9 @@ class SharedViewModel @Inject constructor(
|
|||
private var shouldTriggerCalculation = true
|
||||
|
||||
init {
|
||||
if (prefsManager.isFirstLaunch()) {
|
||||
if (prefsRepo.isFirstLaunch()) {
|
||||
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 getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
||||
fun getTransmittersForSat(satId: Int) =
|
||||
|
@ -103,16 +101,11 @@ class SharedViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun updateEntriesFromSources(sources: List<TleSource>) {
|
||||
val sourcesList = if (sources.isEmpty()) {
|
||||
prefsManager.getDefaultSources()
|
||||
} else {
|
||||
sources
|
||||
}
|
||||
postAppEvent(Event(0))
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
sourcesRepo.updateSources(sourcesList)
|
||||
entriesRepo.updateEntriesFromWeb(sourcesList)
|
||||
prefsRepo.saveTleSources(sources)
|
||||
entriesRepo.updateEntriesFromWeb(sources)
|
||||
transmittersRepo.updateTransmitters()
|
||||
} catch (exception: Exception) {
|
||||
postAppEvent(Event(1))
|
||||
|
@ -133,28 +126,28 @@ class SharedViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
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 hoursAhead = prefsManager.getHoursAhead()
|
||||
val hoursAhead = prefsRepo.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.getHoursAhead()
|
||||
val hoursAhead = prefsRepo.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.getMinElevation() }
|
||||
passes.removeAll { it.pass.maxEl < prefsRepo.getMinElevation() }
|
||||
passes.sortBy { it.pass.startTime }
|
||||
return passes
|
||||
}
|
||||
|
||||
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.databinding.FragmentMapBinding
|
||||
import com.rtbishop.look4sat.ui.SharedViewModel
|
||||
import com.rtbishop.look4sat.utility.PrefsManager
|
||||
import com.rtbishop.look4sat.repository.PrefsRepo
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.osmdroid.config.Configuration
|
||||
import org.osmdroid.tileprovider.tilesource.ITileSource
|
||||
|
@ -53,7 +53,7 @@ import javax.inject.Inject
|
|||
class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
|
||||
@Inject
|
||||
lateinit var prefsManager: PrefsManager
|
||||
lateinit var prefsRepo: PrefsRepo
|
||||
private lateinit var binding: FragmentMapBinding
|
||||
private val mapViewModel: MapViewModel by viewModels()
|
||||
private val sharedViewModel: SharedViewModel by activityViewModels()
|
||||
|
@ -62,7 +62,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
Configuration.getInstance().load(requireContext(), prefsManager.preferences)
|
||||
Configuration.getInstance().load(requireContext(), prefsRepo.preferences)
|
||||
binding = FragmentMapBinding.bind(view).apply {
|
||||
mapView.apply {
|
||||
setMultiTouchControls(true)
|
||||
|
@ -129,7 +129,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
|||
binding.apply {
|
||||
val markers = FolderOverlay()
|
||||
map.entries.forEach {
|
||||
if (prefsManager.shouldUseTextLabels()) {
|
||||
if (prefsRepo.shouldUseTextLabels()) {
|
||||
Marker(mapView).apply {
|
||||
setInfoWindow(null)
|
||||
textLabelFontSize = 24
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.github.amsacode.predict4java.Position
|
|||
import com.github.amsacode.predict4java.SatPos
|
||||
import com.rtbishop.look4sat.data.SatPass
|
||||
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 dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -49,7 +49,7 @@ import kotlin.math.sqrt
|
|||
|
||||
@HiltViewModel
|
||||
class MapViewModel @Inject constructor(
|
||||
private val prefsManager: PrefsManager,
|
||||
private val prefsRepo: PrefsRepo,
|
||||
private val qthConverter: QthConverter
|
||||
) : ViewModel() {
|
||||
|
||||
|
@ -176,7 +176,7 @@ class MapViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun getStationPosition(): Position {
|
||||
val stationPosition = prefsManager.getStationPosition()
|
||||
val stationPosition = prefsRepo.getStationPosition()
|
||||
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.databinding.FragmentPassesBinding
|
||||
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.formatForTimer
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
@ -41,7 +41,7 @@ import javax.inject.Inject
|
|||
class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
|
||||
@Inject
|
||||
lateinit var prefsManager: PrefsManager
|
||||
lateinit var prefsRepo: PrefsRepo
|
||||
|
||||
private var binding: FragmentPassesBinding? = null
|
||||
private var passesAdapter: PassesAdapter? = null
|
||||
|
@ -90,7 +90,7 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
|||
}
|
||||
|
||||
private fun setupComponents() {
|
||||
passesAdapter = PassesAdapter(requireContext(), prefsManager.shouldUseUTC())
|
||||
passesAdapter = PassesAdapter(requireContext(), prefsRepo.shouldUseUTC())
|
||||
binding?.apply {
|
||||
passesRecycler.apply {
|
||||
setHasFixedSize(true)
|
||||
|
|
|
@ -36,7 +36,7 @@ import com.rtbishop.look4sat.data.Result
|
|||
import com.rtbishop.look4sat.data.SatPass
|
||||
import com.rtbishop.look4sat.databinding.FragmentPolarBinding
|
||||
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.formatForTimer
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
@ -48,7 +48,7 @@ import kotlin.math.round
|
|||
class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
||||
|
||||
@Inject
|
||||
lateinit var prefsManager: PrefsManager
|
||||
lateinit var prefsRepo: PrefsRepo
|
||||
|
||||
private lateinit var transmitterAdapter: TransAdapter
|
||||
private lateinit var binding: FragmentPolarBinding
|
||||
|
@ -62,13 +62,13 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
binding = FragmentPolarBinding.bind(view)
|
||||
sensorManager = requireContext().getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
magneticDeclination = prefsManager.getMagDeclination()
|
||||
magneticDeclination = prefsRepo.getMagDeclination()
|
||||
observePasses()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (prefsManager.shouldUseCompass()) {
|
||||
if (prefsRepo.shouldUseCompass()) {
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR).also { sensor ->
|
||||
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class PolarFragment : Fragment(R.layout.fragment_polar), SensorEventListener {
|
|||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (prefsManager.shouldUseCompass()) {
|
||||
if (prefsRepo.shouldUseCompass()) {
|
||||
sensorManager.unregisterListener(this)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import androidx.preference.Preference
|
|||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
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.round
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
@ -43,7 +43,7 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
|||
lateinit var locationManager: LocationManager
|
||||
|
||||
@Inject
|
||||
lateinit var prefsManager: PrefsManager
|
||||
lateinit var prefsRepo: PrefsRepo
|
||||
|
||||
@Inject
|
||||
lateinit var qthConverter: QthConverter
|
||||
|
@ -64,14 +64,14 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
findPreference<Preference>(PrefsManager.keyPositionGPS)?.apply {
|
||||
findPreference<Preference>(PrefsRepo.keyPositionGPS)?.apply {
|
||||
setOnPreferenceClickListener {
|
||||
setPositionFromGPS()
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<Preference>(PrefsManager.keyPositionQTH)?.apply {
|
||||
findPreference<Preference>(PrefsRepo.keyPositionQTH)?.apply {
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
setPositionFromQth(newValue.toString())
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
|||
showSnack(getString(R.string.pref_pos_qth_error))
|
||||
false
|
||||
} else {
|
||||
prefsManager.setStationPosition(loc.latitude, loc.longitude, loc.heightAMSL)
|
||||
prefsRepo.setStationPosition(loc.latitude, loc.longitude, loc.heightAMSL)
|
||||
showSnack(getString(R.string.pref_pos_success))
|
||||
true
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ class PrefsFragment : PreferenceFragmentCompat() {
|
|||
val latitude = location.latitude.round(4)
|
||||
val longitude = location.longitude.round(4)
|
||||
val altitude = location.altitude.round(1)
|
||||
prefsManager.setStationPosition(latitude, longitude, altitude)
|
||||
prefsRepo.setStationPosition(latitude, longitude, altitude)
|
||||
showSnack(getString(R.string.pref_pos_success))
|
||||
} else showSnack(getString(R.string.pref_pos_gps_null))
|
||||
} else requestPermissionLauncher.launch(locPermString)
|
||||
|
|
|
@ -26,9 +26,19 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.rtbishop.look4sat.data.TleSource
|
||||
import com.rtbishop.look4sat.databinding.ItemTleSourceBinding
|
||||
|
||||
class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf()) :
|
||||
RecyclerView.Adapter<SourcesAdapter.TleSourceHolder>() {
|
||||
|
||||
class SourcesAdapter : 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() {
|
||||
val emptySource = TleSource()
|
||||
if (!sources.contains(emptySource)) {
|
||||
|
@ -36,17 +46,13 @@ class SourcesAdapter(private var sources: MutableList<TleSource> = mutableListOf
|
|||
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 {
|
||||
val binding = ItemTleSourceBinding
|
||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return TleSourceHolder(binding)
|
||||
}
|
||||
|
||||
|
||||
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
|
||||
holder.bind(sources[position])
|
||||
}
|
||||
|
|
|
@ -28,9 +28,8 @@ import androidx.appcompat.app.AppCompatDialogFragment
|
|||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
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.ui.SharedViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
|
@ -45,7 +44,8 @@ class SourcesDialog : AppCompatDialogFragment() {
|
|||
override fun onViewCreated(view: View, state: Bundle?) {
|
||||
super.onViewCreated(view, state)
|
||||
viewModel.getSources().observe(viewLifecycleOwner, { sources ->
|
||||
val sourcesAdapter = SourcesAdapter(sources as MutableList<TleSource>)
|
||||
val sourcesAdapter = SourcesAdapter()
|
||||
sourcesAdapter.setSources(sources)
|
||||
DialogSourcesBinding.bind(view).apply {
|
||||
dialog?.window?.setLayout(
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
|
|
Ładowanie…
Reference in New Issue