Tachidesk: fix crash issues (#8735)

* fix tachidesk crash issues

* re-format file
This commit is contained in:
Aria Moradi 2021-08-22 19:06:26 +04:30 committed by GitHub
parent 9df25cc3fc
commit dd07318201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Tachidesk' extName = 'Tachidesk'
pkgNameSuffix = 'all.tachidesk' pkgNameSuffix = 'all.tachidesk'
extClass = '.Tachidesk' extClass = '.Tachidesk'
extVersionCode = 1 extVersionCode = 2
libVersion = '1.2' libVersion = '1.2'
containsNsfw = true containsNsfw = true
} }

View File

@ -100,24 +100,36 @@ class Tachidesk : ConfigurableSource, HttpSource() {
override fun getFilterList(): FilterList = override fun getFilterList(): FilterList =
FilterList( FilterList(
CategorySelect(categoryList), CategorySelect(refreshCategoryList(baseUrl).let { categoryList }),
Filter.Header("Note: Restart tachiyomi to refresh categories!") Filter.Header("Press reset to attempt to fetch categories")
) )
private lateinit var categoryList: List<CategoryDataClass> private var categoryList: List<CategoryDataClass> = emptyList()
init {
private fun refreshCategoryList(baseUrl: String) {
Single.fromCallable { Single.fromCallable {
client.newCall(GET("$checkedBaseUrl/api/v1/category", headers)).execute() client.newCall(GET("$baseUrl/api/v1/category", headers)).execute()
} }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { response -> .subscribe(
categoryList = try { { response ->
json.decodeFromString<List<CategoryDataClass>>(response.body!!.string()) categoryList = try {
} catch (e: Exception) { json.decodeFromString<List<CategoryDataClass>>(response.body!!.string())
emptyList() } catch (e: Exception) {
} emptyList()
} }
},
{}
)
}
init {
val initBaseUrl = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000).getString(ADDRESS_TITLE, ADDRESS_DEFAULT)!!
if (initBaseUrl.isNotBlank()) {
refreshCategoryList(initBaseUrl)
}
} }
private val defaultCategoryId: Int private val defaultCategoryId: Int
@ -137,7 +149,8 @@ class Tachidesk : ConfigurableSource, HttpSource() {
is CategorySelect -> { is CategorySelect -> {
selectedFilter = categoryList[filter.state].id selectedFilter = categoryList[filter.state].id
} }
else -> {} else -> {
}
} }
} }