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

pull/30/head
Arty Bishop 2020-05-18 14:37:35 +01:00
rodzic 23ce89c7c6
commit ec03c76fa1
5 zmienionych plików z 91 dodań i 11 usunięć

Wyświetl plik

@ -0,0 +1,3 @@
package com.rtbishop.look4sat.data
data class TleSource(var url: String)

Wyświetl plik

@ -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,

Wyświetl plik

@ -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)
}
}
}
}

Wyświetl plik

@ -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())
}

Wyświetl plik

@ -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>