mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added basic SatTypes spinner to EntriesFragment.kt
This commit is contained in:
1 parent
53697ef0c4
commit
7653de2cee
6 files changed
+63
-13
No files matched your search
@@ -19,6 +19,8 @@ package com.rtbishop.look4sat.presentation.entriesScreen
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
@@ -67,6 +69,29 @@ class EntriesFragment : Fragment(R.layout.fragment_entries) {
|
|||||||
}
|
}
|
||||||
entriesBtnSelect.clickWithDebounce { viewModel.selectCurrentItems(true) }
|
entriesBtnSelect.clickWithDebounce { viewModel.selectCurrentItems(true) }
|
||||||
entriesBtnClear.clickWithDebounce { viewModel.selectCurrentItems(false) }
|
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 ->
|
viewModel.satData.observe(viewLifecycleOwner) { satData ->
|
||||||
handleSatData(satData, entriesAdapter)
|
handleSatData(satData, entriesAdapter)
|
||||||
|
|||||||
+16
-1
@@ -33,19 +33,28 @@ class EntriesViewModel @Inject constructor(
|
|||||||
private val settings: ISettingsManager
|
private val settings: ISettingsManager
|
||||||
) : ViewModel(), EntriesAdapter.EntriesClickListener {
|
) : ViewModel(), EntriesAdapter.EntriesClickListener {
|
||||||
|
|
||||||
|
private val satType = MutableLiveData(String())
|
||||||
private val transModes = MutableLiveData(settings.loadModesSelection())
|
private val transModes = MutableLiveData(settings.loadModesSelection())
|
||||||
private val currentQuery = MutableLiveData(String())
|
private val currentQuery = MutableLiveData(String())
|
||||||
private val itemsFromRepo = liveData {
|
private val itemsFromRepo = liveData {
|
||||||
delay(125)
|
delay(125)
|
||||||
emit(loadEntriesWithSelection())
|
emit(loadEntriesWithSelection())
|
||||||
} as MutableLiveData
|
} as MutableLiveData
|
||||||
|
private val itemsWithType = satType.switchMap { type ->
|
||||||
|
itemsFromRepo.map { items -> filterByType(items, type) }
|
||||||
|
}
|
||||||
private val itemsWithModes = transModes.switchMap { modes ->
|
private val itemsWithModes = transModes.switchMap { modes ->
|
||||||
itemsFromRepo.map { items -> filterByModes(items, modes) }
|
itemsWithType.map { items -> filterByModes(items, modes) }
|
||||||
}
|
}
|
||||||
private val itemsWithQuery = currentQuery.switchMap { query ->
|
private val itemsWithQuery = currentQuery.switchMap { query ->
|
||||||
itemsWithModes.map { items -> filterByQuery(items, query) }
|
itemsWithModes.map { items -> filterByQuery(items, query) }
|
||||||
}
|
}
|
||||||
val satData = itemsWithQuery.map { items -> DataState.Success(items) }
|
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) {
|
fun selectCurrentItems(selectAll: Boolean) {
|
||||||
itemsWithQuery.value?.let { itemsWithQuery ->
|
itemsWithQuery.value?.let { itemsWithQuery ->
|
||||||
@@ -83,6 +92,12 @@ class EntriesViewModel @Inject constructor(
|
|||||||
return repository.getEntriesWithModes().onEach { it.isSelected = it.catnum in selectedIds }
|
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> {
|
private fun filterByModes(items: List<SatItem>, modes: List<String>): List<SatItem> {
|
||||||
if (modes.isEmpty()) return items
|
if (modes.isEmpty()) return items
|
||||||
return items.filter { item -> item.modes.any { mode -> mode in modes } }
|
return items.filter { item -> item.modes.any { mode -> mode in modes } }
|
||||||
|
|||||||
+3
-2
@@ -133,8 +133,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
private fun setupDataCard() {
|
private fun setupDataCard() {
|
||||||
binding.run {
|
binding.run {
|
||||||
settingsData.dataBtnWeb.clickWithDebounce {
|
settingsData.dataBtnWeb.clickWithDebounce {
|
||||||
val action = SettingsFragmentDirections.settingsToSources()
|
// val action = SettingsFragmentDirections.settingsToSources()
|
||||||
findNavController().navigate(action)
|
// findNavController().navigate(action)
|
||||||
|
viewModel.updateDataFromWeb(emptyList())
|
||||||
}
|
}
|
||||||
settingsData.dataBtnFile.clickWithDebounce { contentRequest.launch("*/*") }
|
settingsData.dataBtnFile.clickWithDebounce { contentRequest.launch("*/*") }
|
||||||
settingsData.dataBtnClear.clickWithDebounce { viewModel.clearData() }
|
settingsData.dataBtnClear.clickWithDebounce { viewModel.clearData() }
|
||||||
|
|||||||
+3
-2
@@ -43,8 +43,9 @@ class SettingsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateDataFromWeb(sources: List<String>) {
|
fun updateDataFromWeb(sources: List<String>) {
|
||||||
settings.saveDataSources(sources)
|
// settings.saveDataSources(sources)
|
||||||
repository.updateFromWeb(sources)
|
// repository.updateFromWeb(sources)
|
||||||
|
repository.updateFromWebNew()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearData() {
|
fun clearData() {
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:layout_marginEnd="52dp"
|
android:layout_marginEnd="52dp"
|
||||||
android:layout_marginBottom="4dp"
|
android:layout_marginBottom="4dp"
|
||||||
android:inputType="text"
|
|
||||||
android:hint="@string/entries_search_hint"
|
android:hint="@string/entries_search_hint"
|
||||||
android:importantForAutofill="no" />
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="text" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/entries_btn_modes"
|
android:id="@+id/entries_btn_modes"
|
||||||
@@ -38,12 +38,20 @@
|
|||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</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
|
<androidx.cardview.widget.CardView
|
||||||
style="@style/SurfaceCard"
|
style="@style/SurfaceCard"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="@dimen/view_default_margin"
|
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_marginEnd="@dimen/view_default_margin"
|
||||||
android:layout_marginBottom="@dimen/surface_margin_bot">
|
android:layout_marginBottom="@dimen/surface_margin_bot">
|
||||||
|
|
||||||
@@ -67,16 +75,16 @@
|
|||||||
android:id="@+id/entries_btn_select"
|
android:id="@+id/entries_btn_select"
|
||||||
style="@style/NormalButton"
|
style="@style/NormalButton"
|
||||||
android:layout_width="@dimen/button_width_max"
|
android:layout_width="@dimen/button_width_max"
|
||||||
android:layout_marginStart="@dimen/button_margin_side"
|
|
||||||
android:layout_gravity="start|center_vertical"
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:layout_marginStart="@dimen/button_margin_side"
|
||||||
android:text="@string/btn_select" />
|
android:text="@string/btn_select" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/entries_btn_clear"
|
android:id="@+id/entries_btn_clear"
|
||||||
style="@style/NormalButton"
|
style="@style/NormalButton"
|
||||||
android:layout_width="@dimen/button_width_max"
|
android:layout_width="@dimen/button_width_max"
|
||||||
android:layout_marginEnd="@dimen/button_margin_side"
|
|
||||||
android:layout_gravity="end|center_vertical"
|
android:layout_gravity="end|center_vertical"
|
||||||
|
android:layout_marginEnd="@dimen/button_margin_side"
|
||||||
android:text="@string/btn_clear_all" />
|
android:text="@string/btn_clear_all" />
|
||||||
|
|
||||||
</com.google.android.material.bottomappbar.BottomAppBar>
|
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||||
@@ -84,8 +92,8 @@
|
|||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/entries_fab"
|
android:id="@+id/entries_fab"
|
||||||
style="@style/FloatingActionButton"
|
style="@style/FloatingActionButton"
|
||||||
android:src="@drawable/ic_done"
|
|
||||||
android:contentDescription="@string/btn_done"
|
android:contentDescription="@string/btn_done"
|
||||||
|
android:src="@drawable/ic_done"
|
||||||
app:layout_anchor="@id/entries_bottom_bar" />
|
app:layout_anchor="@id/entries_bottom_bar" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
@@ -30,7 +30,8 @@ interface ISettingsManager {
|
|||||||
)
|
)
|
||||||
val sourcesMap: Map<String, String>
|
val sourcesMap: Map<String, String>
|
||||||
get() = mapOf(
|
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",
|
"Amateur" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=amateur&FORMAT=csv",
|
||||||
"Classified" to "https://www.prismnet.com/~mmccants/tles/classfd.zip",
|
"Classified" to "https://www.prismnet.com/~mmccants/tles/classfd.zip",
|
||||||
"Cubesat" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=cubesat&FORMAT=csv",
|
"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",
|
"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",
|
"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",
|
"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",
|
"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",
|
"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",
|
"Science" to "https://celestrak.com/NORAD/elements/gp.php?GROUP=science&FORMAT=csv",
|
||||||
|
|||||||
Reference in new issue
Block a user