Tachidesk: fix crash issues (#8735)
* fix tachidesk crash issues * re-format file
This commit is contained in:
parent
9df25cc3fc
commit
dd07318201
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 -> {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue