v2.2.1 - Hotfix for ClassCastException in SharedPrefs

pull/49/head
Arty Bishop 2021-03-07 18:01:11 +00:00
rodzic dbae12a4e4
commit 6c78d17faf
7 zmienionych plików z 38 dodań i 39 usunięć

Wyświetl plik

@ -13,8 +13,8 @@ android {
applicationId "com.rtbishop.look4sat"
minSdkVersion 21
targetSdkVersion 30
versionCode 220
versionName "2.2.0"
versionCode 221
versionName "2.2.1"
}
buildTypes {

Wyświetl plik

@ -26,13 +26,13 @@ import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
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 sourcesAdapter = moshi.adapter<List<TleSource>>(sourcesType)
companion object {
const val keySources = "tleSources"
const val keySources = "sourcesListJson"
const val keyLatitude = "latitude"
const val keyLongitude = "longitude"
const val keyAltitude = "altitude"
@ -99,16 +99,16 @@ class PrefsRepo @Inject constructor(val preferences: SharedPreferences, val mosh
}
fun loadTleSources(): List<TleSource> {
preferences.getString(keySources, null)?.let { sourcesJson ->
sourcesAdapter.fromJson(sourcesJson)?.let { loadedSources ->
return if (loadedSources.isNotEmpty()) {
loadedSources
} else {
loadDefaultSources()
}
return try {
val sourcesString = preferences.getString(keySources, String())
if (sourcesString.isNullOrEmpty()) {
loadDefaultSources()
} else {
sourcesAdapter.fromJson(sourcesString) ?: loadDefaultSources()
}
} catch (exception: ClassCastException) {
loadDefaultSources()
}
return loadDefaultSources()
}
fun saveTleSources(sources: List<TleSource>) {

Wyświetl plik

@ -56,7 +56,7 @@ class SharedViewModel @Inject constructor(
}
}
fun getSources() = liveData { emit(prefsRepo.loadTleSources()) }
fun getSources() = prefsRepo.loadTleSources()
fun getSatItems() = satelliteRepo.getSatItems().asLiveData()
fun getPasses(): LiveData<Result<MutableList<SatPass>>> = _passes
fun getTransmittersForSat(satId: Int) =

Wyświetl plik

@ -45,7 +45,9 @@ class InfoFragment : Fragment(R.layout.fragment_info) {
infoBmc.setOnClickListener {
gotoUrl("https://www.buymeacoffee.com/rtbishop")
}
infoThanks.movementMethod = LinkMovementMethod.getInstance()
val moveMethod = LinkMovementMethod.getInstance()
infoThanks.movementMethod = moveMethod
infoWarranty.movementMethod = moveMethod
}
}

Wyświetl plik

@ -41,27 +41,24 @@ class SourcesDialog : AppCompatDialogFragment() {
override fun onViewCreated(view: View, state: Bundle?) {
super.onViewCreated(view, state)
viewModel.getSources().observe(viewLifecycleOwner, { sources ->
val sourcesAdapter = SourcesAdapter()
sourcesAdapter.setSources(sources)
DialogSourcesBinding.bind(view).apply {
dialog?.window?.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
tleSourcesRecycler.apply {
adapter = sourcesAdapter
layoutManager = LinearLayoutManager(requireContext())
}
tleSourceBtnAdd.setOnClickListener {
sourcesAdapter.addSource()
}
tleSourcesBtnPos.setOnClickListener {
viewModel.updateEntriesFromSources(sourcesAdapter.getSources())
dismiss()
}
tleSourcesBtnNeg.setOnClickListener { dismiss() }
val sourcesAdapter = SourcesAdapter().apply { setSources(viewModel.getSources()) }
DialogSourcesBinding.bind(view).apply {
dialog?.window?.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
tleSourcesRecycler.apply {
adapter = sourcesAdapter
layoutManager = LinearLayoutManager(requireContext())
}
})
tleSourceBtnAdd.setOnClickListener {
sourcesAdapter.addSource()
}
tleSourcesBtnPos.setOnClickListener {
viewModel.updateEntriesFromSources(sourcesAdapter.getSources())
dismiss()
}
tleSourcesBtnNeg.setOnClickListener { dismiss() }
}
}
}

Wyświetl plik

@ -77,6 +77,6 @@
<a href="https://db.satnogs.org/">SatNOGS</a>, API и базу данных с огромным количеством информации о спутниках.
\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>
<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>
<string name="info_warranty"><a href="https://sites.google.com/view/look4sat-privacy-policy/home">Политика конфиденциальности</a>
\nЭто ПО поставляется без гарантий. \nПодробности в лицензии <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPLv3</a>.</string>
</resources>

Wyświetl plik

@ -97,6 +97,6 @@
\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.
</string>
<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>
<string name="info_warranty"><a href="https://sites.google.com/view/look4sat-privacy-policy/home">Privacy Policy</a>
\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>