kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added basic SatTypes spinner to EntriesFragment.kt
rodzic
53697ef0c4
commit
7653de2cee
|
@ -19,6 +19,8 @@ package com.rtbishop.look4sat.presentation.entriesScreen
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
|
@ -67,6 +69,29 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
|||
}
|
||||
entriesBtnSelect.clickWithDebounce { viewModel.selectCurrentItems(true) }
|
||||
entriesBtnClear.clickWithDebounce { viewModel.selectCurrentItems(false) }
|
||||
|
||||
val spinnerListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(
|
||||
parent: AdapterView<*>, view: View?,
|
||||
position: Int, id: Long
|
||||
) {
|
||||
viewModel.setSatType(parent.getItemAtPosition(position).toString())
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>) {
|
||||
viewModel.setSatType(String())
|
||||
}
|
||||
}
|
||||
ArrayAdapter(
|
||||
requireContext(),
|
||||
android.R.layout.simple_spinner_item,
|
||||
viewModel.satTypes
|
||||
).also { adapter ->
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
entriesSpinner.onItemSelectedListener = spinnerListener
|
||||
entriesSpinner.adapter = adapter
|
||||
}
|
||||
|
||||
}
|
||||
viewModel.satData.observe(viewLifecycleOwner) { satData ->
|
||||
handleSatData(satData, entriesAdapter)
|
||||
|
|
|
@ -33,19 +33,28 @@ class EntriesViewModel @Inject constructor(
|
|||
private val settings: ISettingsManager
|
||||
) : ViewModel(), EntriesAdapter.EntriesClickListener {
|
||||
|
||||
private val satType = MutableLiveData(String())
|
||||
private val transModes = MutableLiveData(settings.loadModesSelection())
|
||||
private val currentQuery = MutableLiveData(String())
|
||||
private val itemsFromRepo = liveData {
|
||||
delay(125)
|
||||
emit(loadEntriesWithSelection())
|
||||
} as MutableLiveData
|
||||
private val itemsWithType = satType.switchMap { type ->
|
||||
itemsFromRepo.map { items -> filterByType(items, type) }
|
||||
}
|
||||
private val itemsWithModes = transModes.switchMap { modes ->
|
||||
itemsFromRepo.map { items -> filterByModes(items, modes) }
|
||||
itemsWithType.map { items -> filterByModes(items, modes) }
|
||||
}
|
||||
private val itemsWithQuery = currentQuery.switchMap { query ->
|
||||
itemsWithModes.map { items -> filterByQuery(items, query) }
|
||||
}
|
||||
val satData = itemsWithQuery.map { items -> DataState.Success(items) }
|
||||
val satTypes: List<String> = settings.sourcesMap.keys.sorted()
|
||||
|
||||
fun setSatType(type: String) {
|
||||
satType.value = type
|
||||
}
|
||||
|
||||
fun selectCurrentItems(selectAll: Boolean) {
|
||||
itemsWithQuery.value?.let { itemsWithQuery ->
|
||||
|
@ -83,6 +92,12 @@ class EntriesViewModel @Inject constructor(
|
|||
return repository.getEntriesWithModes().onEach { it.isSelected = it.catnum in selectedIds }
|
||||
}
|
||||
|
||||
private fun filterByType(items: List<SatItem>, type: String): List<SatItem> {
|
||||
val catnums = settings.loadSatType(type)
|
||||
if (catnums.isEmpty()) return items
|
||||
return items.filter { item -> item.catnum in catnums }
|
||||
}
|
||||
|
||||
private fun filterByModes(items: List<SatItem>, modes: List<String>): List<SatItem> {
|
||||
if (modes.isEmpty()) return items
|
||||
return items.filter { item -> item.modes.any { mode -> mode in modes } }
|
||||
|
|
|
@ -133,8 +133,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||
private fun setupDataCard() {
|
||||
binding.run {
|
||||
settingsData.dataBtnWeb.clickWithDebounce {
|
||||
val action = SettingsFragmentDirections.settingsToSources()
|
||||
findNavController().navigate(action)
|
||||
// val action = SettingsFragmentDirections.settingsToSources()
|
||||
// findNavController().navigate(action)
|
||||
viewModel.updateDataFromWeb(emptyList())
|
||||
}
|
||||
settingsData.dataBtnFile.clickWithDebounce { contentRequest.launch("*/*") }
|
||||
settingsData.dataBtnClear.clickWithDebounce { viewModel.clearData() }
|
||||
|
|
|
@ -43,8 +43,9 @@ class SettingsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun updateDataFromWeb(sources: List<String>) {
|
||||
settings.saveDataSources(sources)
|
||||
repository.updateFromWeb(sources)
|
||||
// settings.saveDataSources(sources)
|
||||
// repository.updateFromWeb(sources)
|
||||
repository.updateFromWebNew()
|
||||
}
|
||||
|
||||
fun clearData() {
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="52dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:inputType="text"
|
||||
android:hint="@string/entries_search_hint"
|
||||
android:importantForAutofill="no" />
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="text" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/entries_btn_modes"
|
||||
|
@ -38,12 +38,20 @@
|
|||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/entries_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginStart="@dimen/view_default_margin"
|
||||
android:layout_marginTop="60dp"
|
||||
android:layout_marginEnd="@dimen/view_default_margin" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
style="@style/SurfaceCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="@dimen/view_default_margin"
|
||||
android:layout_marginTop="@dimen/surface_margin_top"
|
||||
android:layout_marginTop="98dp"
|
||||
android:layout_marginEnd="@dimen/view_default_margin"
|
||||
android:layout_marginBottom="@dimen/surface_margin_bot">
|
||||
|
||||
|
@ -67,16 +75,16 @@
|
|||
android:id="@+id/entries_btn_select"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="@dimen/button_width_max"
|
||||
android:layout_marginStart="@dimen/button_margin_side"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginStart="@dimen/button_margin_side"
|
||||
android:text="@string/btn_select" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/entries_btn_clear"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="@dimen/button_width_max"
|
||||
android:layout_marginEnd="@dimen/button_margin_side"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:layout_marginEnd="@dimen/button_margin_side"
|
||||
android:text="@string/btn_clear_all" />
|
||||
|
||||
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||
|
@ -84,8 +92,8 @@
|
|||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/entries_fab"
|
||||
style="@style/FloatingActionButton"
|
||||
android:src="@drawable/ic_done"
|
||||
android:contentDescription="@string/btn_done"
|
||||
android:src="@drawable/ic_done"
|
||||
app:layout_anchor="@id/entries_bottom_bar" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -30,7 +30,8 @@ interface ISettingsManager {
|
|||
)
|
||||
val sourcesMap: Map<String, String>
|
||||
get() = mapOf(
|
||||
"AMSAT" to "https://amsat.org/tle/current/nasabare.txt",
|
||||
"All" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=csv",
|
||||
"Amsat" to "https://amsat.org/tle/current/nasabare.txt",
|
||||
"Amateur" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=amateur&FORMAT=csv",
|
||||
"Classified" to "https://www.prismnet.com/~mmccants/tles/classfd.zip",
|
||||
"Cubesat" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=cubesat&FORMAT=csv",
|
||||
|
@ -46,7 +47,6 @@ interface ISettingsManager {
|
|||
"New" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=last-30-days&FORMAT=csv",
|
||||
"OneWeb" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=oneweb&FORMAT=csv",
|
||||
"Orbcomm" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=orbcomm&FORMAT=csv",
|
||||
"Other" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=csv",
|
||||
"Resource" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=resource&FORMAT=csv",
|
||||
"SatNOGS" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=satnogs&FORMAT=csv",
|
||||
"Science" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=science&FORMAT=csv",
|
||||
|
|
Ładowanie…
Reference in New Issue