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'
pkgNameSuffix = 'all.tachidesk'
extClass = '.Tachidesk'
extVersionCode = 1
extVersionCode = 2
libVersion = '1.2'
containsNsfw = true
}

View File

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