Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Added a data model and an adapter for TLE custom sources dialog

Arty Bishopec03c76fa182
diff --git a/app/src/main/java/com/rtbishop/look4sat/data/TleSource.kt b/app/src/main/java/com/rtbishop/look4sat/data/TleSource.kt
new file mode 100644
index 00000000..a5c1521a
--- /dev/null
+++ b/app/src/main/java/com/rtbishop/look4sat/data/TleSource.kt
@@ -0,0 +1,3 @@
+package com.rtbishop.look4sat.data
+
+data class TleSource(var url: String)
\ No newline at end of file
diff --git a/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt
index 9368337e..9757db95 100644
--- a/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/ui/SharedViewModel.kt
@@ -151,6 +151,14 @@ class SharedViewModel @Inject constructor(
}
}
+ fun getTleSources(): Set<String> {
+ return prefsManager.getTleSources()
+ }
+
+ fun setTleSource(sources: Set<String>) {
+ prefsManager.setTleSources(sources)
+ }
+
private fun getPassesForEntries(
entry: SatEntry,
dateNow: Date,
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.kt
new file mode 100644
index 00000000..380e26e2
--- /dev/null
+++ b/app/src/main/java/com/rtbishop/look4sat/ui/adapters/TleSourcesAdapter.kt
@@ -0,0 +1,50 @@
+package com.rtbishop.look4sat.ui.adapters
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.core.widget.addTextChangedListener
+import androidx.recyclerview.widget.RecyclerView
+import com.rtbishop.look4sat.data.TleSource
+import com.rtbishop.look4sat.databinding.ItemTleSourceBinding
+
+class TleSourcesAdapter(private var sources: MutableList<TleSource>) :
+ RecyclerView.Adapter<TleSourcesAdapter.TleSourceHolder>() {
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {
+ val binding = ItemTleSourceBinding
+ .inflate(LayoutInflater.from(parent.context), parent, false)
+ return TleSourceHolder(binding.root, binding)
+ }
+
+ override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
+ holder.bind(sources[position])
+ }
+
+ override fun getItemCount(): Int {
+ return sources.size
+ }
+
+ fun setSources(sources: MutableList<TleSource>) {
+ this.sources = sources
+ }
+
+ fun getSources(): MutableList<TleSource> {
+ return sources
+ }
+
+ inner class TleSourceHolder(itemView: View, private val binding: ItemTleSourceBinding) :
+ RecyclerView.ViewHolder(itemView) {
+
+ fun bind(source: TleSource) {
+ binding.tleSourceBtnDel.setOnClickListener {
+ sources.remove(source)
+ notifyItemRemoved(adapterPosition)
+ }
+ binding.tleSourceUrl.addTextChangedListener {
+ source.url = it.toString()
+ notifyItemChanged(adapterPosition)
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt b/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt
index 5cd802a2..ddaec5da 100644
--- a/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/utility/PrefsManager.kt
@@ -37,6 +37,7 @@ class PrefsManager @Inject constructor(
private val keyRefreshRate = "rate"
private val keyCompass = "compass"
private val keyTleUrl = "tleUrl"
+ private val keyTleSources = "tleSources"
private val defaultHoursAhead = 8
private val defaultMinEl = 16.0
private val defaultRefreshRate = "3000"
@@ -84,13 +85,6 @@ class PrefsManager @Inject constructor(
}
}
- fun setRefreshRate(rate: Long) {
- preferences.edit {
- putLong(keyRefreshRate, rate)
- apply()
- }
- }
-
fun setPosition(gsp: GroundStationPosition) {
preferences.edit {
putString(keyLatitude, gsp.latitude.toString())
@@ -106,6 +100,16 @@ class PrefsManager @Inject constructor(
}
}
+ fun getTleSources(): Set<String> {
+ return preferences.getStringSet(keyTleSources, null) ?: emptySet()
+ }
+
+ fun setTleSources(sources: Set<String>) {
+ preferences.edit {
+ putStringSet(keyTleSources, sources)
+ }
+ }
+
private fun SharedPreferences.Editor.putDouble(key: String, double: Double) {
putLong(key, double.toRawBits())
}
diff --git a/app/src/main/res/layout/dialog_tle_sources.xml b/app/src/main/res/layout/dialog_tle_sources.xml
index b70cb6e4..4b4dc31e 100644
--- a/app/src/main/res/layout/dialog_tle_sources.xml
+++ b/app/src/main/res/layout/dialog_tle_sources.xml
@@ -20,15 +20,16 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tleSourcesRecycler"
android:layout_width="0dp"
- android:layout_height="0dp"
+ android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"
+ app:layout_constraintBottom_toTopOf="@+id/tleSourceBtnAdd"
app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle" />
+ app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle"
+ app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/tleSourcesBtnNeg"
@@ -48,4 +49,18 @@
android:text="@string/btn_ok"
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" />
+
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file