kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added a data model and an adapter for TLE custom sources dialog
rodzic
23ce89c7c6
commit
ec03c76fa1
|
|
@ -0,0 +1,3 @@
|
||||||
|
package com.rtbishop.look4sat.data
|
||||||
|
|
||||||
|
data class TleSource(var url: String)
|
||||||
|
|
@ -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(
|
private fun getPassesForEntries(
|
||||||
entry: SatEntry,
|
entry: SatEntry,
|
||||||
dateNow: Date,
|
dateNow: Date,
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -37,6 +37,7 @@ class PrefsManager @Inject constructor(
|
||||||
private val keyRefreshRate = "rate"
|
private val keyRefreshRate = "rate"
|
||||||
private val keyCompass = "compass"
|
private val keyCompass = "compass"
|
||||||
private val keyTleUrl = "tleUrl"
|
private val keyTleUrl = "tleUrl"
|
||||||
|
private val keyTleSources = "tleSources"
|
||||||
private val defaultHoursAhead = 8
|
private val defaultHoursAhead = 8
|
||||||
private val defaultMinEl = 16.0
|
private val defaultMinEl = 16.0
|
||||||
private val defaultRefreshRate = "3000"
|
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) {
|
fun setPosition(gsp: GroundStationPosition) {
|
||||||
preferences.edit {
|
preferences.edit {
|
||||||
putString(keyLatitude, gsp.latitude.toString())
|
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) {
|
private fun SharedPreferences.Editor.putDouble(key: String, double: Double) {
|
||||||
putLong(key, double.toRawBits())
|
putLong(key, double.toRawBits())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,16 @@
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/tleSourcesRecycler"
|
android:id="@+id/tleSourcesRecycler"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:layout_marginBottom="8dp"
|
app:layout_constraintBottom_toTopOf="@+id/tleSourceBtnAdd"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle" />
|
app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tleSourcesBtnNeg"
|
android:id="@+id/tleSourcesBtnNeg"
|
||||||
|
|
@ -48,4 +49,18 @@
|
||||||
android:text="@string/btn_ok"
|
android:text="@string/btn_ok"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler" />
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Ładowanie…
Reference in New Issue