Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Further changes to TLE custom sources dialog
Arty Bishop7f26d2b136a4
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/TleSource.kt b/app/src/main/java/com/rtbishop/look4sat/data/TleSource.ktindex a5c1521a..9d9aff94 100644--- a/app/src/main/java/com/rtbishop/look4sat/data/TleSource.kt+++ b/app/src/main/java/com/rtbishop/look4sat/data/TleSource.kt@@ -1,3 +1,3 @@package com.rtbishop.look4sat.data-data class TleSource(var url: String)\ No newline at end of file+data class TleSource(var url: String = String())\ No newline at end of filediff --git a/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt b/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.ktindex 39fc116b..8d2b24b2 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/MainActivity.kt@@ -45,15 +45,17 @@ import com.rtbishop.look4sat.Look4SatAppimport com.rtbishop.look4sat.Rimport com.rtbishop.look4sat.dagger.ViewModelFactoryimport com.rtbishop.look4sat.data.Result+import com.rtbishop.look4sat.data.TleSourceimport com.rtbishop.look4sat.databinding.ActivityMainBindingimport com.rtbishop.look4sat.databinding.DialogTleUrlBindingimport com.rtbishop.look4sat.databinding.DrawerHeaderBinding+import com.rtbishop.look4sat.ui.fragments.TleSourcesDialogFragmentimport com.rtbishop.look4sat.utility.GeneralUtils.toastimport kotlinx.coroutines.delayimport kotlinx.coroutines.launchimport javax.inject.Inject-class MainActivity : AppCompatActivity() {+class MainActivity : AppCompatActivity(), TleSourcesDialogFragment.SourcesSubmitListener {private val pickFileReqCode = 111private val permLocationCode = 101@@ -165,7 +167,7 @@ class MainActivity : AppCompatActivity() {it.lockButton()}drawerBinding.drawerBtnTleUrl.setOnClickListener {- showTleUrlDialog()+ showTleSourcesDialog()mainBinding.drawerLayout.closeDrawers()it.lockButton()}@@ -187,7 +189,7 @@ class MainActivity : AppCompatActivity() {dialogBinding.apply {var tleUrl = String()dialogTleInput.apply {- hint = viewModel.getTleUrl()+// hint = viewModel.getTleUrl()addTextChangedListener { tleUrl = it.toString() }}dialogTleNeg.setOnClickListener {@@ -201,6 +203,19 @@ class MainActivity : AppCompatActivity() {dialog.show()}+ private fun showTleSourcesDialog() {+ val sources = viewModel.getTleSources().map { TleSource(it) }+ TleSourcesDialogFragment(sources).apply {+ setSourcesListener(this@MainActivity)+ show(supportFragmentManager, "TleSourcesDialog")+ }+ }++ override fun onSourcesSubmit(list: List<TleSource>) {+ val sources = list.map { it.url }.toSet()+ viewModel.setTleSource(sources)+ }+private fun View.lockButton() {lifecycleScope.launch {[email protected] = falsediff --git a/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.ktindex 9757db95..1f50d76a 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt@@ -59,7 +59,6 @@ class SharedViewModel @Inject constructor(fun getRefreshRate() = prefsManager.getRefreshRate()fun getHoursAhead() = prefsManager.getHoursAhead()fun getMinElevation() = prefsManager.getMinElevation()- fun getTleUrl() = prefsManager.getTleUrl()fun setPositionFromPref() = _gsp.postValue(Result.Success(prefsManager.getPosition()))suspend fun getAllEntries() = repository.getAllEntries()@@ -102,15 +101,15 @@ class SharedViewModel @Inject constructor(fun updateEntriesFromWeb(tleUrl: String? = null) {viewModelScope.launch(Dispatchers.IO) {try {- val url = if (tleUrl.isNullOrEmpty()) {- prefsManager.getTleUrl()- } else {- prefsManager.setTleUrl(tleUrl)- tleUrl- }- val selected = repository.getSelectedEntries().map { it.catNum }- repository.updateEntriesFromUrl(url)- repository.updateEntriesSelection(selected)+// val url = if (tleUrl.isNullOrEmpty()) {+// prefsManager.getTleUrl()+// } else {+// prefsManager.setTleUrl(tleUrl)+// tleUrl+// }+// val selected = repository.getSelectedEntries().map { it.catNum }+// repository.updateEntriesFromUrl(url)+// repository.updateEntriesSelection(selected)_updateStatus.postValue(Result.Success(0))} catch (e: Exception) {_updateStatus.postValue(Result.Error(e))diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TleSourcesAdapter.kt b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TleSourcesAdapter.ktindex 380e26e2..c4d566e7 100644--- a/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TleSourcesAdapter.kt+++ b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TleSourcesAdapter.kt@@ -1,9 +1,28 @@+/*+ * Look4Sat. Amateur radio and weather satellite tracker and passes predictor for Android.+ * Copyright (C) 2019, 2020 Arty Bishop ([email protected])+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License along+ * with this program; if not, write to the Free Software Foundation, Inc.,+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.+ */+package com.rtbishop.look4sat.ui.adaptersimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroup-import androidx.core.widget.addTextChangedListener+import androidx.core.widget.doAfterTextChangedimport androidx.recyclerview.widget.RecyclerViewimport com.rtbishop.look4sat.data.TleSourceimport com.rtbishop.look4sat.databinding.ItemTleSourceBinding@@ -25,8 +44,9 @@ class TleSourcesAdapter(private var sources: MutableList<TleSource>) :return sources.size}- fun setSources(sources: MutableList<TleSource>) {- this.sources = sources+ fun setSources(list: MutableList<TleSource>) {+ sources = list+ notifyDataSetChanged()}fun getSources(): MutableList<TleSource> {@@ -37,14 +57,14 @@ class TleSourcesAdapter(private var sources: MutableList<TleSource>) :RecyclerView.ViewHolder(itemView) {fun bind(source: TleSource) {+ binding.tleSourceUrl.setText(source.url)+ binding.tleSourceUrl.doAfterTextChanged {+ source.url = it.toString()+ }binding.tleSourceBtnDel.setOnClickListener {sources.remove(source)notifyItemRemoved(adapterPosition)}- binding.tleSourceUrl.addTextChangedListener {- source.url = it.toString()- notifyItemChanged(adapterPosition)- }}}}\ No newline at end of filediff --git a/app/src/main/java/com/rtbishop/look4sat/ui/fragments/TleSourcesDialogFragment.kt b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/TleSourcesDialogFragment.ktnew file mode 100644index 00000000..af00514a--- /dev/null+++ b/app/src/main/java/com/rtbishop/look4sat/ui/fragments/TleSourcesDialogFragment.kt@@ -0,0 +1,76 @@+/*+ * Look4Sat. Amateur radio and weather satellite tracker and passes predictor for Android.+ * Copyright (C) 2019, 2020 Arty Bishop ([email protected])+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License along+ * with this program; if not, write to the Free Software Foundation, Inc.,+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.+ */++package com.rtbishop.look4sat.ui.fragments++import android.app.Dialog+import android.os.Bundle+import android.view.ViewGroup+import androidx.appcompat.app.AppCompatDialogFragment+import androidx.recyclerview.widget.LinearLayoutManager+import com.rtbishop.look4sat.data.TleSource+import com.rtbishop.look4sat.databinding.DialogTleSourcesBinding+import com.rtbishop.look4sat.ui.adapters.TleSourcesAdapter++class TleSourcesDialogFragment(sources: List<TleSource>) :+ AppCompatDialogFragment() {++ private lateinit var sourcesListener: SourcesSubmitListener+ private var sourcesAdapter = TleSourcesAdapter(sources.toMutableList())++ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {+ val binding = DialogTleSourcesBinding.inflate(requireActivity().layoutInflater)+ val tleSourcesDialog = 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 {+ sourcesListener.onSourcesSubmit(sourcesAdapter.getSources())+ dismiss()+ }++ return tleSourcesDialog+ }++ fun setSourcesListener(listener: SourcesSubmitListener): TleSourcesDialogFragment {+ sourcesListener = listener+ return this+ }++ interface SourcesSubmitListener {+ fun onSourcesSubmit(list: List<TleSource>)+ }+}\ No newline at end of filediff --git a/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt b/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.ktindex ddaec5da..511e5fa9 100644--- a/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt+++ b/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt@@ -36,7 +36,6 @@ class PrefsManager @Inject constructor(private val keyAltitude = "altitude"private val keyRefreshRate = "rate"private val keyCompass = "compass"- private val keyTleUrl = "tleUrl"private val keyTleSources = "tleSources"private val defaultHoursAhead = 8private val defaultMinEl = 16.0@@ -67,10 +66,6 @@ class PrefsManager @Inject constructor(return GroundStationPosition(lat, lon, alt)}- fun getTleUrl(): String {- return preferences.getString(keyTleUrl, defaultTleUrl)!!- }-fun setHoursAhead(hours: Int) {preferences.edit {putInt(keyHoursAhead, hours)@@ -94,19 +89,14 @@ class PrefsManager @Inject constructor(}}- fun setTleUrl(tleUrl: String) {- preferences.edit {- putString(keyTleUrl, tleUrl)- }- }-fun getTleSources(): Set<String> {- return preferences.getStringSet(keyTleSources, null) ?: emptySet()+ return preferences.getStringSet(keyTleSources, null) ?: setOf(defaultTleUrl)}fun setTleSources(sources: Set<String>) {preferences.edit {putStringSet(keyTleSources, sources)+ apply()}}diff --git a/app/src/main/res/layout/dialog_tle_sources.xml b/app/src/main/res/layout/dialog_tle_sources.xmlindex 4b4dc31e..40791a9c 100644--- a/app/src/main/res/layout/dialog_tle_sources.xml+++ b/app/src/main/res/layout/dialog_tle_sources.xml@@ -9,34 +9,65 @@android:id="@+id/tleSourcesTitle"android:layout_width="0dp"android:layout_height="wrap_content"- android:layout_marginStart="8dp"- android:layout_marginTop="8dp"- android:layout_marginEnd="8dp"- android:text="@string/placeholder"- app:layout_constraintEnd_toEndOf="parent"+ android:layout_marginStart="12dp"+ android:layout_marginTop="12dp"+ android:text="@string/manage_tle_sources"+ android:textSize="18sp"+ app:layout_constraintEnd_toStartOf="@+id/tleSourceBtnAdd"+ app:layout_constraintHorizontal_bias="0.51"+ app:layout_constraintHorizontal_chainStyle="spread_inside"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />+ <ImageView+ android:id="@+id/tleSourceBtnAdd"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_marginStart="8dp"+ android:layout_marginEnd="12dp"+ android:contentDescription="@string/placeholder"+ app:layout_constraintBottom_toBottomOf="@+id/tleSourcesTitle"+ app:layout_constraintEnd_toEndOf="parent"+ app:layout_constraintHorizontal_bias="0.5"+ app:layout_constraintStart_toEndOf="@+id/tleSourcesTitle"+ app:layout_constraintTop_toTopOf="@+id/tleSourcesTitle"+ app:srcCompat="@android:drawable/ic_menu_add" />+<androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/tleSourcesRecycler"android:layout_width="0dp"- android:layout_height="wrap_content"+ android:layout_height="0dp"android:layout_marginStart="8dp"- android:layout_marginTop="8dp"+ android:layout_marginTop="4dp"android:layout_marginEnd="8dp"- app:layout_constraintBottom_toTopOf="@+id/tleSourceBtnAdd"+ android:layout_marginBottom="4dp"+ app:layout_constraintBottom_toTopOf="@+id/tleSourcesWarning"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.5"app:layout_constraintStart_toStartOf="parent"- app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle"- app:layout_constraintVertical_chainStyle="packed" />+ app:layout_constraintTop_toBottomOf="@+id/tleSourceBtnAdd"+ app:layout_constraintVertical_chainStyle="packed">++ </androidx.recyclerview.widget.RecyclerView>++ <TextView+ android:id="@+id/tleSourcesWarning"+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_marginBottom="8dp"+ android:gravity="center"+ android:text="@string/please_make_sure_you_use_https_url_for_tle_source"+ app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"+ app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler"+ app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler" /><TextViewandroid:id="@+id/tleSourcesBtnNeg"android:layout_width="wrap_content"android:layout_height="wrap_content"- android:layout_marginEnd="24dp"+ android:layout_marginEnd="32dp"android:text="@string/btn_cancel"+ android:textSize="18sp"app:layout_constraintBaseline_toBaselineOf="@+id/tleSourcesBtnPos"app:layout_constraintEnd_toStartOf="@+id/tleSourcesBtnPos"app:layout_constraintHorizontal_chainStyle="spread_inside" />@@ -47,20 +78,8 @@android:layout_height="wrap_content"android:layout_marginBottom="8dp"android:text="@string/btn_ok"+ android:textSize="18sp"app:layout_constraintBottom_toBottomOf="parent"- app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler" />-- <ImageView- android:id="@+id/tleSourceBtnAdd"- android:layout_width="48dp"- android:layout_height="48dp"- android:layout_marginBottom="8dp"- android:contentDescription="@string/placeholder"- app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"- app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler"- app:layout_constraintHorizontal_bias="0.5"- app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler"- app:layout_constraintTop_toBottomOf="@+id/tleSourcesRecycler"- app:srcCompat="@android:drawable/ic_menu_add" />+ app:layout_constraintEnd_toEndOf="@+id/tleSourceBtnAdd" /></androidx.constraintlayout.widget.ConstraintLayout>\ No newline at end of filediff --git a/app/src/main/res/layout/item_tle_source.xml b/app/src/main/res/layout/item_tle_source.xmlindex 2d732f44..4835a8bd 100644--- a/app/src/main/res/layout/item_tle_source.xml+++ b/app/src/main/res/layout/item_tle_source.xml@@ -6,30 +6,38 @@android:layout_height="wrap_content"android:padding="4dp">- <EditText- android:id="@+id/tleSourceUrl"+ <com.google.android.material.textfield.TextInputLayout+ android:id="@+id/tleSourceInputLayout"android:layout_width="0dp"android:layout_height="wrap_content"- android:hint="@string/placeholder"- android:importantForAutofill="no"- android:inputType="textUri"- android:text="@string/placeholder"+ app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toStartOf="@+id/tleSourceBtnDel"app:layout_constraintHorizontal_bias="0.5"app:layout_constraintHorizontal_chainStyle="packed"app:layout_constraintStart_toStartOf="parent"- app:layout_constraintTop_toTopOf="parent" />+ app:layout_constraintTop_toTopOf="parent">++ <EditText+ android:id="@+id/tleSourceUrl"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:hint="@string/tle_source"+ android:importantForAutofill="no"+ android:inputType="textUri" />++ </com.google.android.material.textfield.TextInputLayout><ImageViewandroid:id="@+id/tleSourceBtnDel"android:layout_width="wrap_content"android:layout_height="0dp"+ android:layout_marginStart="8dp"android:contentDescription="@string/placeholder"- app:layout_constraintBottom_toBottomOf="@+id/tleSourceUrl"+ app:layout_constraintBottom_toBottomOf="@+id/tleSourceInputLayout"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.5"- app:layout_constraintStart_toEndOf="@+id/tleSourceUrl"- app:layout_constraintTop_toTopOf="@+id/tleSourceUrl"+ app:layout_constraintStart_toEndOf="@+id/tleSourceInputLayout"+ app:layout_constraintTop_toTopOf="@+id/tleSourceInputLayout"app:srcCompat="@android:drawable/ic_menu_close_clear_cancel" /></androidx.constraintlayout.widget.ConstraintLayout>\ No newline at end of filediff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xmlindex 3e313898..05f8630c 100644--- a/app/src/main/res/values-ru/strings.xml+++ b/app/src/main/res/values-ru/strings.xml@@ -141,4 +141,6 @@<string name="map_gsp">СТЦ</string><string name="update_loc_failure">Проверьте ваши настройки GPS</string>+ <string name="manage_tle_sources">Manage TLE sources</string>+ <string name="tle_source">TLE source</string></resources>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 0f3bcd4c..aba03515 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -166,4 +166,7 @@<string name="map_gsp">GSP</string><string name="placeholder" translatable="false">Placeholder</string>+ <string name="manage_tle_sources">Manage TLE sources</string>+ <string name="please_make_sure_you_use_https_url_for_tle_source" translatable="false">Please use HTTPS URLs only</string>+ <string name="tle_source">TLE source</string></resources>