v3.1.1 - R4UAB source, minor fixes, libs update

This commit is contained in:
Arty Bishop committed 2022-08-07 13:33:21 +01:00
1 parent bf1ac5fc2c
commit bbb89b7e6b
14 files changed
+29 -254

No files matched your search

@@ -29,7 +29,6 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
companion object {
const val keyFirstEverLaunch = "isFirstEverLaunch"
const val keyDataSources = "dataSources"
const val keyModes = "satModes"
const val keyCompass = "compass"
const val keyRadarSweep = "radarSweep"
@@ -203,15 +202,6 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
prefs.edit { putString(keyBTFormat, value) }
}
override fun loadDataSources(): List<String> {
val sourcesList = prefs.getStringSet(keyDataSources, null)?.toList()
return if (sourcesList.isNullOrEmpty()) defaultSources else sourcesList.sortedDescending()
}
override fun saveDataSources(sources: List<String>) {
if (sources.isNotEmpty()) prefs.edit { putStringSet(keyDataSources, sources.toSet()) }
}
private fun SharedPreferences.getDouble(key: String, default: Double): Double {
return Double.fromBits(getLong(key, default.toRawBits()))
}
@@ -42,7 +42,7 @@ class PassesViewModel @Inject constructor(
init {
viewModelScope.launch {
if (!settings.isFirstEverLaunchDone()) {
repository.updateFromWebNew()
repository.updateFromWeb()
settings.setFirstEverLaunchDone()
}
}
@@ -45,7 +45,7 @@ class SettingsViewModel @Inject constructor(
fun updateDataFromWeb() {
// settings.saveDataSources(sources)
// repository.updateFromWeb(sources)
repository.updateFromWebNew()
repository.updateFromWeb()
}
fun clearData() {
@@ -1,88 +0,0 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2022 Arty Bishop (bishop.arty@gmail.com)
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
package com.rtbishop.look4sat.presentation.settingsScreen
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.widget.doOnTextChanged
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.rtbishop.look4sat.databinding.ItemSourceBinding
import com.rtbishop.look4sat.framework.model.DataSource
class SourcesAdapter(private val clickListener: SourcesClickListener) :
RecyclerView.Adapter<SourcesAdapter.SourceHolder>() {
private val diffCallback = object : DiffUtil.ItemCallback<DataSource>() {
override fun areItemsTheSame(oldItem: DataSource, newItem: DataSource): Boolean {
return oldItem.url == newItem.url
}
override fun areContentsTheSame(oldItem: DataSource, newItem: DataSource): Boolean {
return oldItem.url == newItem.url
}
}
private val differ = AsyncListDiffer(this, diffCallback)
private val httpsString = "https://"
fun getSources() = differ.currentList.filter { source -> source.url.contains(httpsString) }
fun addSource() {
submitList((getSources() as MutableList).apply { add(DataSource(httpsString)) })
}
fun removeSource(source: DataSource) {
submitList((getSources() as MutableList).apply { remove(source) })
}
fun submitList(items: List<DataSource>) = differ.submitList(items)
override fun getItemCount(): Int = differ.currentList.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SourceHolder {
return SourceHolder.from(parent)
}
override fun onBindViewHolder(holder: SourceHolder, position: Int) {
holder.bind(differ.currentList[position], clickListener)
}
class SourceHolder(private val binding: ItemSourceBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(source: DataSource, listener: SourcesClickListener) {
binding.run {
sourceText.setText(source.url)
sourceText.doOnTextChanged { text, _, _, _ -> source.url = text.toString() }
sourceInput.setEndIconOnClickListener { listener.removeSource(source) }
}
}
companion object {
fun from(parent: ViewGroup): SourceHolder {
val inflater = LayoutInflater.from(parent.context)
return SourceHolder(ItemSourceBinding.inflate(inflater, parent, false))
}
}
}
interface SourcesClickListener {
fun removeSource(source: DataSource)
}
}
@@ -1,76 +0,0 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2022 Arty Bishop (bishop.arty@gmail.com)
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
package com.rtbishop.look4sat.presentation.settingsScreen
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.databinding.DialogSourcesBinding
import com.rtbishop.look4sat.domain.ISettingsManager
import com.rtbishop.look4sat.framework.model.DataSource
import com.rtbishop.look4sat.presentation.setNavResult
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@AndroidEntryPoint
class SourcesDialog : AppCompatDialogFragment(), SourcesAdapter.SourcesClickListener {
@Inject
lateinit var settings: ISettingsManager
private lateinit var binding: DialogSourcesBinding
private lateinit var sourcesAdapter: SourcesAdapter
override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View {
binding = DialogSourcesBinding.inflate(inflater, group, false)
return binding.root
}
override fun onViewCreated(view: View, state: Bundle?) {
super.onViewCreated(view, state)
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
dialog?.window?.setLayout(
(resources.displayMetrics.widthPixels * 0.94).toInt(),
WindowManager.LayoutParams.WRAP_CONTENT
)
lifecycleScope.launchWhenResumed {
val sources = settings.loadDataSources().map { url -> DataSource(url) }
val layoutManager = LinearLayoutManager(requireContext())
sourcesAdapter = SourcesAdapter(this@SourcesDialog).apply { submitList(sources) }
binding.run {
sourcesRecycler.apply {
this.adapter = sourcesAdapter
this.layoutManager = layoutManager
}
sourcesBtnAdd.setOnClickListener { sourcesAdapter.addSource() }
sourcesBtnNeg.setOnClickListener { dismiss() }
sourcesBtnPos.setOnClickListener {
setNavResult("sources", sourcesAdapter.getSources().map { item -> item.url })
dismiss()
}
}
}
}
override fun removeSource(source: DataSource) = sourcesAdapter.removeSource(source)
}
-11
View File
@@ -54,13 +54,6 @@
android:id="@+id/nav_settings"
android:name="com.rtbishop.look4sat.presentation.settingsScreen.SettingsFragment"
tools:layout="@layout/fragment_settings">
<action
android:id="@+id/settings_to_sources"
app:destination="@id/nav_sources"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<dialog
android:id="@+id/nav_modes"
@@ -70,10 +63,6 @@
android:id="@+id/nav_filter"
android:name="com.rtbishop.look4sat.presentation.passesScreen.FilterDialog"
tools:layout="@layout/dialog_filter" />
<dialog
android:id="@+id/nav_sources"
android:name="com.rtbishop.look4sat.presentation.settingsScreen.SourcesDialog"
tools:layout="@layout/dialog_sources" />
<dialog
android:id="@+id/nav_position"
android:name="com.rtbishop.look4sat.presentation.settingsScreen.PositionDialog"