mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Using passes screen as a startDestination
This commit is contained in:
1 parent
ab811e4ead
commit
4705ff6915
4 files changed
+15
-22
No files matched your search
@@ -41,13 +41,13 @@ class SharedViewModel @Inject constructor(
|
||||
|
||||
private val _passes = MutableLiveData<Result<MutableList<SatPass>>>()
|
||||
private val _appEvent = MutableLiveData<Event<Int>>()
|
||||
private var shouldTriggerCalculation = true
|
||||
|
||||
init {
|
||||
if (prefsRepo.isFirstLaunch()) {
|
||||
updateDefaultSourcesAndEntries()
|
||||
prefsRepo.setFirstLaunchDone()
|
||||
}
|
||||
calculatePasses()
|
||||
}
|
||||
|
||||
fun getAppEvent(): LiveData<Event<Int>> = _appEvent
|
||||
@@ -64,15 +64,7 @@ class SharedViewModel @Inject constructor(
|
||||
fun getTransmittersForSat(satId: Int) =
|
||||
satelliteRepo.getTransmittersForSat(satId).asLiveData()
|
||||
|
||||
fun triggerCalculation() {
|
||||
if (shouldTriggerCalculation) {
|
||||
shouldTriggerCalculation = false
|
||||
calculatePasses()
|
||||
}
|
||||
}
|
||||
|
||||
fun calculatePasses(dateNow: Date = Date(System.currentTimeMillis())) {
|
||||
shouldTriggerCalculation = false
|
||||
_passes.value = Result.InProgress
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
val passes = mutableListOf<SatPass>()
|
||||
|
||||
@@ -51,7 +51,7 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding = FragmentEntriesBinding.bind(view)
|
||||
setupComponents()
|
||||
observeEntries()
|
||||
setupObservers()
|
||||
}
|
||||
|
||||
private fun setupComponents() {
|
||||
@@ -71,8 +71,8 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
||||
searchBar.clearFocus()
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeEntries() {
|
||||
|
||||
private fun setupObservers() {
|
||||
setLoading()
|
||||
viewModel.getSatItems().observe(viewLifecycleOwner, { satItems ->
|
||||
if (satItems.isNullOrEmpty()) setError()
|
||||
@@ -80,18 +80,20 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
||||
entriesAdapter?.setItems(satItems)
|
||||
setLoaded()
|
||||
}
|
||||
observeEvents()
|
||||
})
|
||||
}
|
||||
|
||||
private fun observeEvents() {
|
||||
viewModel.getAppEvent().observe(viewLifecycleOwner, { event ->
|
||||
event.getContentIfNotHandled()?.let {
|
||||
if (it == 0) setLoading()
|
||||
else if (it == 1) {
|
||||
event.getContentIfNotHandled()?.let { content ->
|
||||
if (content == 0) setLoading()
|
||||
else if (content == 1) {
|
||||
val errorMsg = getString(R.string.entries_update_error)
|
||||
Snackbar.make(requireView(), errorMsg, Snackbar.LENGTH_SHORT).show()
|
||||
setError()
|
||||
entriesAdapter?.let { adapter ->
|
||||
if (adapter.getItems().isEmpty()) {
|
||||
setError()
|
||||
} else {
|
||||
setLoaded()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -102,7 +102,6 @@ class PassesFragment : Fragment(R.layout.fragment_passes) {
|
||||
}
|
||||
passesFab.setOnClickListener { viewModel.calculatePasses() }
|
||||
}
|
||||
viewModel.triggerCalculation()
|
||||
}
|
||||
|
||||
private fun tickMainTimer(timeNow: Long) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/mobile_navigation"
|
||||
app:startDestination="@id/nav_entries">
|
||||
app:startDestination="@id/nav_passes">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_entries"
|
||||
|
||||
Reference in new issue
Block a user