kopia lustrzana https://github.com/rt-bishop/Look4Sat
Swapped the splash dialog for immediate initial setup
rodzic
e3e621e55f
commit
5de8787368
|
@ -40,7 +40,7 @@ class PreferencesProvider @Inject constructor(
|
|||
const val keyTimeUTC = "timeUTC"
|
||||
const val keyHoursAhead = "hoursAhead"
|
||||
const val keyMinElevation = "minElevation"
|
||||
const val keyIsFirstLaunch = "shouldShowSplash"
|
||||
const val keyInitialSetup = "initialSetupDone"
|
||||
const val keyRotator = "isRotatorEnabled"
|
||||
const val keyRotatorAddress = "rotatorAddress"
|
||||
const val keyRotatorPort = "rotatorPort"
|
||||
|
@ -123,12 +123,12 @@ class PreferencesProvider @Inject constructor(
|
|||
return preferences.getBoolean(keyCompass, true)
|
||||
}
|
||||
|
||||
override fun isFirstLaunch(): Boolean {
|
||||
return preferences.getBoolean(keyIsFirstLaunch, true)
|
||||
override fun isSetupDone(): Boolean {
|
||||
return preferences.getBoolean(keyInitialSetup, false)
|
||||
}
|
||||
|
||||
override fun setFirstLaunchDone() {
|
||||
preferences.edit { putBoolean(keyIsFirstLaunch, false) }
|
||||
override fun setSetupDone() {
|
||||
preferences.edit { putBoolean(keyInitialSetup, true) }
|
||||
}
|
||||
|
||||
override fun saveModesSelection(modes: List<String>) {
|
||||
|
|
|
@ -24,18 +24,12 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.data.PreferencesSource
|
||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||
import com.rtbishop.look4sat.utility.navigateSafe
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class Look4SatActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var preferenceSource: PreferencesSource
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
|
@ -45,9 +39,5 @@ class Look4SatActivity : AppCompatActivity() {
|
|||
setContentView(binding.root)
|
||||
val navHost = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
|
||||
binding.navBottom.setupWithNavController(navHost.navController)
|
||||
if (preferenceSource.isFirstLaunch()) {
|
||||
preferenceSource.setFirstLaunchDone()
|
||||
navHost.navController.navigateSafe(R.id.nav_dialog_splash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
*/
|
||||
package com.rtbishop.look4sat.presentation.satPassScreen
|
||||
|
||||
import android.Manifest
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
|
@ -26,12 +28,12 @@ import androidx.navigation.fragment.findNavController
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.framework.model.Result
|
||||
import com.rtbishop.look4sat.databinding.FragmentPassesBinding
|
||||
import com.rtbishop.look4sat.domain.predict4kotlin.SatPass
|
||||
import com.rtbishop.look4sat.framework.model.Result
|
||||
import com.rtbishop.look4sat.utility.RecyclerDivider
|
||||
import com.rtbishop.look4sat.utility.toTimerString
|
||||
import com.rtbishop.look4sat.utility.navigateSafe
|
||||
import com.rtbishop.look4sat.utility.toTimerString
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.*
|
||||
|
||||
|
@ -39,6 +41,10 @@ import java.util.*
|
|||
class SatPassFragment : Fragment(R.layout.fragment_passes), SatPassAdapter.PassesClickListener {
|
||||
|
||||
private val viewModel: SatPassViewModel by viewModels()
|
||||
private val permRequest = ActivityResultContracts.RequestPermission()
|
||||
private val permRequestLauncher = registerForActivityResult(permRequest) {
|
||||
viewModel.triggerInitialSetup()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
@ -61,6 +67,9 @@ class SatPassFragment : Fragment(R.layout.fragment_passes), SatPassAdapter.Passe
|
|||
viewModel.passes.observe(viewLifecycleOwner, { passesResult ->
|
||||
handleNewPasses(passesResult, passesAdapter, binding)
|
||||
})
|
||||
viewModel.isFirstLaunchDone.observe(viewLifecycleOwner, { setupDone ->
|
||||
if (!setupDone) permRequestLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
})
|
||||
}
|
||||
|
||||
private fun handleNewPasses(
|
||||
|
|
|
@ -35,17 +35,23 @@ import javax.inject.Inject
|
|||
class SatPassViewModel @Inject constructor(
|
||||
private val satDataRepository: SatDataRepository,
|
||||
private val satPassRepository: SatPassRepository,
|
||||
private val preferenceSource: PreferencesSource
|
||||
private val preferencesSource: PreferencesSource
|
||||
) : ViewModel() {
|
||||
|
||||
private val _passes = MutableLiveData<Result<List<SatPass>>>(Result.InProgress)
|
||||
private val _isFirstLaunchDone = MutableLiveData<Boolean>()
|
||||
private var passesProcessing: Job? = null
|
||||
val passes: LiveData<Result<List<SatPass>>> = _passes
|
||||
val isFirstLaunchDone: LiveData<Boolean> = _isFirstLaunchDone
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
_passes.postValue(Result.InProgress)
|
||||
satPassRepository.triggerCalculation(satDataRepository.getSelectedSatellites())
|
||||
if (preferencesSource.isSetupDone()) {
|
||||
viewModelScope.launch {
|
||||
_passes.postValue(Result.InProgress)
|
||||
satPassRepository.triggerCalculation(satDataRepository.getSelectedSatellites())
|
||||
}
|
||||
} else {
|
||||
_isFirstLaunchDone.value = false
|
||||
}
|
||||
viewModelScope.launch {
|
||||
satPassRepository.passes.collect { passes ->
|
||||
|
@ -55,6 +61,19 @@ class SatPassViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun triggerInitialSetup() {
|
||||
preferencesSource.updatePositionFromGPS()
|
||||
viewModelScope.launch {
|
||||
_passes.postValue(Result.InProgress)
|
||||
satDataRepository.updateEntriesFromWeb()
|
||||
val defaultCatNums = listOf(43700, 25544, 25338, 28654, 33591, 40069, 27607, 24278)
|
||||
satDataRepository.updateEntriesSelection(defaultCatNums, true)
|
||||
satPassRepository.forceCalculation(satDataRepository.getSelectedSatellites())
|
||||
preferencesSource.setSetupDone()
|
||||
_isFirstLaunchDone.value = true
|
||||
}
|
||||
}
|
||||
|
||||
fun forceCalculation() {
|
||||
viewModelScope.launch {
|
||||
_passes.postValue(Result.InProgress)
|
||||
|
@ -64,7 +83,7 @@ class SatPassViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun shouldUseUTC(): Boolean {
|
||||
return preferenceSource.shouldUseUTC()
|
||||
return preferencesSource.shouldUseUTC()
|
||||
}
|
||||
|
||||
private suspend fun tickPasses(passes: List<SatPass>) = withContext(Dispatchers.Default) {
|
||||
|
|
|
@ -26,9 +26,9 @@ interface PreferencesSource {
|
|||
|
||||
fun shouldUseCompass(): Boolean
|
||||
|
||||
fun isFirstLaunch(): Boolean
|
||||
fun isSetupDone(): Boolean
|
||||
|
||||
fun setFirstLaunchDone()
|
||||
fun setSetupDone()
|
||||
|
||||
fun saveModesSelection(modes: List<String>)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue