Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Fixed SourcesDialog behaviour, code cleanup
Arty Bishope38ee6384ed0
diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SourcesAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SourcesAdapter.ktindex 9a52052c..885ba397 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SourcesAdapter.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/SourcesAdapter.kt@@ -31,6 +31,15 @@ import com.rtbishop.look4sat.databinding.ItemTleSourceBindingclass SourcesAdapter(private var sources: MutableList<TleSource>) :RecyclerView.Adapter<SourcesAdapter.TleSourceHolder>() {+ fun getSources(): MutableList<TleSource> {+ return sources+ }++ fun setSources(list: MutableList<TleSource>) {+ sources = list+ notifyDataSetChanged()+ }+override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {val binding = ItemTleSourceBinding.inflate(LayoutInflater.from(parent.context), parent, false)@@ -46,19 +55,8 @@ class SourcesAdapter(private var sources: MutableList<TleSource>) :return sources.size}- fun getSources(): MutableList<TleSource> {- return sources- }-- fun setSources(list: MutableList<TleSource>) {- sources = list- notifyDataSetChanged()- }-inner class TleSourceHolder(- itemView: View,- val binding: ItemTleSourceBinding,- val textWatcher: TleSourceWatcher+ itemView: View, val binding: ItemTleSourceBinding, val textWatcher: TleSourceWatcher) :RecyclerView.ViewHolder(itemView) {diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/EntriesFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/EntriesFragment.ktindex 6159b35e..bfbc81c3 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/EntriesFragment.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/EntriesFragment.kt@@ -20,8 +20,7 @@ import com.rtbishop.look4sat.ui.SharedViewModelimport com.rtbishop.look4sat.ui.adapters.EntriesAdapterimport javax.inject.Inject-class EntriesFragment : Fragment(R.layout.fragment_entries),- SourcesDialog.SourcesSubmitListener {+class EntriesFragment : Fragment(R.layout.fragment_entries) {@Injectlateinit var factory: ViewModelFactory@@ -37,16 +36,12 @@ class EntriesFragment : Fragment(R.layout.fragment_entries),binding = FragmentEntriesBinding.bind(view)(requireActivity().application as Look4SatApp).appComponent.inject(this)viewModel = ViewModelProvider(requireActivity(), factory).get(SharedViewModel::class.java)- setupUI()+ setupComponents()setupObservers()}- private fun setupUI() {+ private fun setupComponents() {binding.apply {- importWeb.setOnClickListener { showSourcesDialog() }- importFile.setOnClickListener { showFileDialog() }- searchBar.setOnQueryTextListener(entriesAdapter)- selectAll.setOnClickListener { entriesAdapter.selectAll() }entriesRecycler.apply {val linearLayoutMgr = LinearLayoutManager(requireContext())val divider = DividerItemDecoration(requireContext(), linearLayoutMgr.orientation)@@ -57,36 +52,33 @@ class EntriesFragment : Fragment(R.layout.fragment_entries),adapter = entriesAdapteraddItemDecoration(divider)}+ importWeb.setOnClickListener { showImportFromWebDialog() }+ importFile.setOnClickListener { showImportFromFileDialog() }+ searchBar.setOnQueryTextListener(entriesAdapter)+ selectAll.setOnClickListener { entriesAdapter.selectAll() }entriesFab.setOnClickListener { goToPassesAndCalculateForSelection() }}}private fun setupObservers() {- viewModel.tleSources.observe(viewLifecycleOwner, { sources ->- tleSources = sources- })- viewModel.allEntries.observe(viewLifecycleOwner, { entries ->- entriesAdapter.setEntries(entries as MutableList<SatEntry>)+ viewModel.tleSources.observe(viewLifecycleOwner, { tleSources = it })+ viewModel.allEntries.observe(viewLifecycleOwner, {+ entriesAdapter.setEntries(it as MutableList<SatEntry>)})}- // Entries update from web-- private fun showSourcesDialog() {- val fragmentManager = childFragmentManager- SourcesDialog(tleSources).apply {- setSourcesListener(this@EntriesFragment)- show(fragmentManager, "TleSourcesDialog")- }+ private fun goToPassesAndCalculateForSelection() {+ val catNumList = mutableListOf<Int>()+ entriesAdapter.getEntries().forEach { if (it.isSelected) catNumList.add(it.catNum) }+ viewModel.updateEntriesSelection(catNumList)+ requireView().findNavController().navigate(R.id.action_entries_to_passes)}- override fun onSourcesSubmit(list: List<TleSource>) {- viewModel.updateSatelliteData(list)+ private fun showImportFromWebDialog() {+ SourcesDialog(tleSources, viewModel).show(childFragmentManager, "SourcesDialog")}- // Entries update from file-- private fun showFileDialog() {+ private fun showImportFromFileDialog() {Intent(Intent.ACTION_OPEN_DOCUMENT).apply {addCategory(Intent.CATEGORY_OPENABLE)type = "*/*"@@ -99,14 +91,4 @@ class EntriesFragment : Fragment(R.layout.fragment_entries),data?.data?.also { uri -> viewModel.updateEntriesFromFile(uri) }} else super.onActivityResult(requestCode, resultCode, data)}-- // Search and select entries-- private fun goToPassesAndCalculateForSelection() {- val catNumList = mutableListOf<Int>().apply {- entriesAdapter.getEntries().forEach { if (it.isSelected) this.add(it.catNum) }- }- viewModel.updateEntriesSelection(catNumList)- requireView().findNavController().navigate(R.id.action_entries_to_passes)- }}\ No newline at end of filediff --git a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/SourcesDialog.kt b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/SourcesDialog.ktindex 5414b307..ebf2d4a2 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/SourcesDialog.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/SourcesDialog.kt@@ -22,58 +22,44 @@ package com.rtbishop.look4sat.ui.fragmentsimport android.app.Dialogimport android.os.Bundleimport android.view.ViewGroup-import android.view.Windowimport androidx.appcompat.app.AppCompatDialogFragmentimport androidx.recyclerview.widget.LinearLayoutManagerimport com.rtbishop.look4sat.data.TleSourceimport com.rtbishop.look4sat.databinding.DialogSourcesBinding+import com.rtbishop.look4sat.ui.SharedViewModelimport com.rtbishop.look4sat.ui.adapters.SourcesAdapter-class SourcesDialog(sources: List<TleSource>) : AppCompatDialogFragment() {+class SourcesDialog(sources: List<TleSource>, private val viewModel: SharedViewModel) :+ AppCompatDialogFragment() {- private lateinit var sourcesListener: SourcesSubmitListener- private val sourcesAdapter = SourcesAdapter(sources.toMutableList())+ private val sourcesAdapter = SourcesAdapter(sources as MutableList<TleSource>)override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {- val binding = DialogSourcesBinding.inflate(requireActivity().layoutInflater)- val tleSourcesDialog = Dialog(requireActivity()).apply {- window?.requestFeature(Window.FEATURE_NO_TITLE)+ val binding = DialogSourcesBinding.inflate(requireActivity().layoutInflater).apply {+ tleSourcesRecycler.apply {+ layoutManager = LinearLayoutManager(requireContext())+ adapter = sourcesAdapter+ }+ tleSourceBtnAdd.setOnClickListener {+ val tempSources = sourcesAdapter.getSources()+ tempSources.add(TleSource(String()))+ sourcesAdapter.setSources(tempSources)+ }+ tleSourcesBtnPos.setOnClickListener {+ val filteredSources = sourcesAdapter.getSources()+ .filter { it.url != String() && it.url != " " && it.url.contains("https://") }+ viewModel.updateSatelliteData(filteredSources)+ dismiss()+ }+ tleSourcesBtnNeg.setOnClickListener { dismiss() }+ }++ return Dialog(requireActivity()).apply {setContentView(binding.root)window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)}-- binding.tleSourcesRecycler.apply {- layoutManager = LinearLayoutManager(activity)- adapter = sourcesAdapter- }-- binding.tleSourceBtnAdd.setOnClickListener {- val tempSources = sourcesAdapter.getSources()- tempSources.add(TleSource(""))- sourcesAdapter.setSources(tempSources)- sourcesAdapter.notifyDataSetChanged()- }-- binding.tleSourcesBtnNeg.setOnClickListener { dismiss() }- binding.tleSourcesBtnPos.setOnClickListener {- val filteredSources = sourcesAdapter.getSources()- .filter { it.url != String() && it.url != " " && it.url.contains("https://") }- sourcesListener.onSourcesSubmit(filteredSources)- dismiss()- }-- return tleSourcesDialog- }-- fun setSourcesListener(listener: SourcesSubmitListener): SourcesDialog {- sourcesListener = listener- return this- }-- interface SourcesSubmitListener {- fun onSourcesSubmit(list: List<TleSource>)}}\ No newline at end of file