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

This commit is contained in:
Arty Bishop committed 2020-05-18 14:37:35 +01:00
1 parent 23ce89c7c6
commit ec03c76fa1
5 files changed
+91 -11

No files matched your search

@@ -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(
entry: SatEntry,
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 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())
}