@@ -26,18 +26,12 @@ import java.security.MessageDigest
26
26
/* *
27
27
* A simple implementation for sources from a website.
28
28
*/
29
+ @Suppress(" unused" )
29
30
abstract class HttpSource : CatalogueSource {
30
31
/* *
31
32
* Network service.
32
33
*/
33
- val network: NetworkHelper by injectLazy()
34
-
35
- // /**
36
- // * Preferences that a source may need.
37
- // */
38
- // val preferences: SharedPreferences by lazy {
39
- // Injekt.get<Application>().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
40
- // }
34
+ protected val network: NetworkHelper by injectLazy()
41
35
42
36
/* *
43
37
* Base url of the website without the trailing slash, like: http://mysite.com
@@ -60,7 +54,7 @@ abstract class HttpSource : CatalogueSource {
60
54
*
61
55
* Note: the generated ID sets the sign bit to `0`.
62
56
*/
63
- override val id by lazy { generateId(name, lang, versionId ) }
57
+ override val id by lazy { generateId() }
64
58
65
59
/* *
66
60
* Headers used for requests.
@@ -73,6 +67,10 @@ abstract class HttpSource : CatalogueSource {
73
67
open val client: OkHttpClient
74
68
get() = network.client
75
69
70
+ private fun generateId (): Long {
71
+ return generateId(name, lang, versionId)
72
+ }
73
+
76
74
/* *
77
75
* Generates a unique ID for the source based on the provided [name], [lang] and
78
76
* [versionId]. It will use the first 16 characters (64 bits) of the MD5 of the string
@@ -89,6 +87,7 @@ abstract class HttpSource : CatalogueSource {
89
87
* @param versionId [Int] the version ID of the source
90
88
* @return a unique ID for the source
91
89
*/
90
+ @Suppress(" MemberVisibilityCanBePrivate" )
92
91
protected fun generateId (
93
92
name : String ,
94
93
lang : String ,
@@ -155,8 +154,15 @@ abstract class HttpSource : CatalogueSource {
155
154
query : String ,
156
155
filters : FilterList ,
157
156
): Observable <MangasPage > {
158
- return client.newCall(searchMangaRequest(page, query, filters))
159
- .asObservableSuccess()
157
+ return Observable .defer {
158
+ try {
159
+ client.newCall(searchMangaRequest(page, query, filters)).asObservableSuccess()
160
+ } catch (e: NoClassDefFoundError ) {
161
+ // RxJava doesn't handle Errors, which tends to happen during global searches
162
+ // if an old extension using non-existent classes is still around
163
+ throw RuntimeException (e)
164
+ }
165
+ }
160
166
.map { response ->
161
167
searchMangaParse(response)
162
168
}
@@ -387,7 +393,7 @@ abstract class HttpSource : CatalogueSource {
387
393
*
388
394
* @param page the chapter whose page list has to be fetched
389
395
*/
390
- open fun imageRequest (page : Page ): Request {
396
+ protected open fun imageRequest (page : Page ): Request {
391
397
return GET (page.imageUrl!! , headers)
392
398
}
393
399
@@ -418,7 +424,7 @@ abstract class HttpSource : CatalogueSource {
418
424
*/
419
425
private fun getUrlWithoutDomain (orig : String ): String {
420
426
return try {
421
- val uri = URI (orig)
427
+ val uri = URI (orig.replace( " " , " %20 " ) )
422
428
var out = uri.path
423
429
if (uri.query != null ) {
424
430
out + = " ?" + uri.query
0 commit comments