mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
v2.2.1 - Hotfix for ClassCastException in SharedPrefs
This commit is contained in:
1 parent
dbae12a4e4
commit
6c78d17faf
7 files changed
+38
-39
No files matched your search
+2
-2
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId "com.rtbishop.look4sat"
|
applicationId "com.rtbishop.look4sat"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 220
|
versionCode 221
|
||||||
versionName "2.2.0"
|
versionName "2.2.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ import com.squareup.moshi.Moshi
|
|||||||
import com.squareup.moshi.Types
|
import com.squareup.moshi.Types
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PrefsRepo @Inject constructor(val preferences: SharedPreferences, val moshi: Moshi) {
|
class PrefsRepo @Inject constructor(val preferences: SharedPreferences, moshi: Moshi) {
|
||||||
|
|
||||||
private val sourcesType = Types.newParameterizedType(List::class.java, TleSource::class.java)
|
private val sourcesType = Types.newParameterizedType(List::class.java, TleSource::class.java)
|
||||||
private val sourcesAdapter = moshi.adapter<List<TleSource>>(sourcesType)
|
private val sourcesAdapter = moshi.adapter<List<TleSource>>(sourcesType)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val keySources = "tleSources"
|
const val keySources = "sourcesListJson"
|
||||||
const val keyLatitude = "latitude"
|
const val keyLatitude = "latitude"
|
||||||
const val keyLongitude = "longitude"
|
const val keyLongitude = "longitude"
|
||||||
const val keyAltitude = "altitude"
|
const val keyAltitude = "altitude"
|
||||||
@@ -99,16 +99,16 @@ class PrefsRepo @Inject constructor(val preferences: SharedPreferences, val mosh
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun loadTleSources(): List<TleSource> {
|
fun loadTleSources(): List<TleSource> {
|
||||||
preferences.getString(keySources, null)?.let { sourcesJson ->
|
return try {
|
||||||
sourcesAdapter.fromJson(sourcesJson)?.let { loadedSources ->
|
val sourcesString = preferences.getString(keySources, String())
|
||||||
return if (loadedSources.isNotEmpty()) {
|
if (sourcesString.isNullOrEmpty()) {
|
||||||
loadedSources
|
loadDefaultSources()
|
||||||
} else {
|
} else {
|
||||||
loadDefaultSources()
|
sourcesAdapter.fromJson(sourcesString) ?: loadDefaultSources()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (exception: ClassCastException) {
|
||||||
|
loadDefaultSources()
|
||||||
}
|
}
|
||||||
return loadDefaultSources()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveTleSources(sources: List<TleSource>) {
|
fun saveTleSources(sources: List<TleSource>) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class SharedViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSources() = liveData { emit(prefsRepo.loadTleSources()) }
|
fun getSources() = prefsRepo.loadTleSources()
|
||||||
fun getSatItems() = satelliteRepo.getSatItems().asLiveData()
|
fun getSatItems() = satelliteRepo.getSatItems().asLiveData()
|
||||||
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
|
||||||
fun getTransmittersForSat(satId: Int) =
|
fun getTransmittersForSat(satId: Int) =
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ class InfoFragment : Fragment(R.layout.fragment_info) {
|
|||||||
infoBmc.setOnClickListener {
|
infoBmc.setOnClickListener {
|
||||||
gotoUrl("https://www.buymeacoffee.com/rtbishop")
|
gotoUrl("https://www.buymeacoffee.com/rtbishop")
|
||||||
}
|
}
|
||||||
infoThanks.movementMethod = LinkMovementMethod.getInstance()
|
val moveMethod = LinkMovementMethod.getInstance()
|
||||||
|
infoThanks.movementMethod = moveMethod
|
||||||
|
infoWarranty.movementMethod = moveMethod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,27 +41,24 @@ class SourcesDialog : AppCompatDialogFragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, state: Bundle?) {
|
override fun onViewCreated(view: View, state: Bundle?) {
|
||||||
super.onViewCreated(view, state)
|
super.onViewCreated(view, state)
|
||||||
viewModel.getSources().observe(viewLifecycleOwner, { sources ->
|
val sourcesAdapter = SourcesAdapter().apply { setSources(viewModel.getSources()) }
|
||||||
val sourcesAdapter = SourcesAdapter()
|
DialogSourcesBinding.bind(view).apply {
|
||||||
sourcesAdapter.setSources(sources)
|
dialog?.window?.setLayout(
|
||||||
DialogSourcesBinding.bind(view).apply {
|
WindowManager.LayoutParams.MATCH_PARENT,
|
||||||
dialog?.window?.setLayout(
|
WindowManager.LayoutParams.WRAP_CONTENT
|
||||||
WindowManager.LayoutParams.MATCH_PARENT,
|
)
|
||||||
WindowManager.LayoutParams.WRAP_CONTENT
|
tleSourcesRecycler.apply {
|
||||||
)
|
adapter = sourcesAdapter
|
||||||
tleSourcesRecycler.apply {
|
layoutManager = LinearLayoutManager(requireContext())
|
||||||
adapter = sourcesAdapter
|
|
||||||
layoutManager = LinearLayoutManager(requireContext())
|
|
||||||
}
|
|
||||||
tleSourceBtnAdd.setOnClickListener {
|
|
||||||
sourcesAdapter.addSource()
|
|
||||||
}
|
|
||||||
tleSourcesBtnPos.setOnClickListener {
|
|
||||||
viewModel.updateEntriesFromSources(sourcesAdapter.getSources())
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
tleSourcesBtnNeg.setOnClickListener { dismiss() }
|
|
||||||
}
|
}
|
||||||
})
|
tleSourceBtnAdd.setOnClickListener {
|
||||||
|
sourcesAdapter.addSource()
|
||||||
|
}
|
||||||
|
tleSourcesBtnPos.setOnClickListener {
|
||||||
|
viewModel.updateEntriesFromSources(sourcesAdapter.getSources())
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
tleSourcesBtnNeg.setOnClickListener { dismiss() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +77,6 @@
|
|||||||
<a href="https://db.satnogs.org/">SatNOGS</a>, API и базу данных с огромным количеством информации о спутниках.
|
<a href="https://db.satnogs.org/">SatNOGS</a>, API и базу данных с огромным количеством информации о спутниках.
|
||||||
\n— <a href="https://square.github.io/">Square</a> за библиотеки OkHttp, Retrofit, Moshi и доступ
|
\n— <a href="https://square.github.io/">Square</a> за библиотеки OkHttp, Retrofit, Moshi и доступ
|
||||||
к ним по лицензии <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></string>
|
к ним по лицензии <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></string>
|
||||||
<string name="info_warranty"><a href="https://sites.google.com/view/look4sat-privacy-policy/home">Политика конфиденциальности</a>.
|
<string name="info_warranty"><a href="https://sites.google.com/view/look4sat-privacy-policy/home">Политика конфиденциальности</a>
|
||||||
Это ПО поставляется без гарантий. Подробности в лицензии <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPLv3</a>.</string>
|
\nЭто ПО поставляется без гарантий. \nПодробности в лицензии <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPLv3</a>.</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -97,6 +97,6 @@
|
|||||||
\n— <a href="https://square.github.io/">Square</a> for epic OkHttp, Retrofit and Moshi libs
|
\n— <a href="https://square.github.io/">Square</a> for epic OkHttp, Retrofit and Moshi libs
|
||||||
available under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a> license.
|
available under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a> license.
|
||||||
</string>
|
</string>
|
||||||
<string name="info_warranty"><a href="https://sites.google.com/view/look4sat-privacy-policy/home">Privacy Policy</a>.
|
<string name="info_warranty"><a href="https://sites.google.com/view/look4sat-privacy-policy/home">Privacy Policy</a>
|
||||||
This application comes with absolutely no warranty. See the <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPLv3</a> for details.</string>
|
\nThis app comes with no warranty. \nSee the <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPLv3</a> license for details.</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in new issue
Block a user