@@ -37,6 +37,7 @@ class Rokahon : ConfigurableSource, UnmeteredSource, HttpSource() {
37
37
private const val ADDRESS_TITLE = " Server URL"
38
38
private const val ADDRESS_DEFAULT = " http://192.168.1.170:1770"
39
39
}
40
+
40
41
override val baseUrl by lazy { preferences.getString(ADDRESS_TITLE , ADDRESS_DEFAULT )!! }
41
42
42
43
private val json: Json by injectLazy()
@@ -53,12 +54,11 @@ class Rokahon : ConfigurableSource, UnmeteredSource, HttpSource() {
53
54
override fun latestUpdatesRequest (page : Int ): Request = throw Exception (" Not supported" )
54
55
override fun latestUpdatesParse (response : Response ): MangasPage = throw Exception (" Not supported" )
55
56
override fun imageUrlParse (response : Response ): String = throw Exception (" Not supported" )
56
- override fun pageListParse (response : Response ): List <Page > = throw UnsupportedOperationException (" Not used" )
57
57
58
- // MANGA SEARCH + PARSE
58
+ // MANGA SEARCH
59
59
override fun searchMangaRequest (page : Int , query : String , filters : FilterList ): Request {
60
60
// Response will be available in searchMangaParse
61
- println (" searchMangaRequest" )
61
+ println (" FN_CALL searchMangaRequest" )
62
62
val url = " $baseUrl /search"
63
63
.toHttpUrl()
64
64
.newBuilder()
@@ -67,8 +67,9 @@ class Rokahon : ConfigurableSource, UnmeteredSource, HttpSource() {
67
67
.build()
68
68
return GET (url, headers)
69
69
}
70
+
70
71
override fun searchMangaParse (response : Response ): MangasPage {
71
- println (" searchMangaParse" )
72
+ println (" FN_CALL searchMangaParse" )
72
73
var rokaResponse = json.decodeFromString<RokahonResponse <List <RokahonSimpBook >>>(response.body.string())
73
74
if (rokaResponse.isError) {
74
75
val msg = rokaResponse.data.toString()
@@ -83,7 +84,6 @@ class Rokahon : ConfigurableSource, UnmeteredSource, HttpSource() {
83
84
title = book.title
84
85
url = " $baseUrl /book/" + book.id
85
86
thumbnail_url = " $baseUrl /image?id=" + book.cover.id
86
- genre = " sample"
87
87
status = SManga .ONGOING
88
88
},
89
89
)
@@ -92,80 +92,69 @@ class Rokahon : ConfigurableSource, UnmeteredSource, HttpSource() {
92
92
return MangasPage (items, false )
93
93
}
94
94
95
- // POPULAR MANGA REQUEST + PARSE
95
+ // POPULAR MANGA
96
96
override fun popularMangaRequest (page : Int ) = searchMangaRequest(1 , " " , FilterList ())
97
97
98
- override fun popularMangaParse (response : Response ): MangasPage {
99
- return searchMangaParse(response)
100
- }
98
+ override fun popularMangaParse (response : Response ) = searchMangaParse(response)
101
99
102
100
// MANGA DETAILS
103
101
override fun fetchMangaDetails (manga : SManga ): Observable <SManga > {
104
- println (" fetchMangaDetails " + manga.title)
102
+ println (" FN_CALL fetchMangaDetails " + manga.title + " :: " + manga.url )
105
103
return Observable .just(manga)
106
104
}
107
105
108
- override fun mangaDetailsRequest (manga : SManga ): Request {
109
- println (" mangaDetailsRequest " + manga.title)
110
- return super .mangaDetailsRequest(manga)
111
- }
112
-
113
- override fun mangaDetailsParse (response : Response ) = throw UnsupportedOperationException (" Not used." )
106
+ override fun mangaDetailsParse (response : Response ) = throw UnsupportedOperationException (" mangaDetailsParse :: Not used" )
114
107
115
- // CHAPTER LIST + PARSE
116
- // override fun prepareNewChapter(chapter: SChapter, manga: SManga) {
117
- // println("prepareNewChapter " + chapter .url)
118
- // super.prepareNewChapter(chapter, manga )
119
- // }
108
+ // CHAPTER LIST
109
+ override fun chapterListRequest ( manga : SManga ): Request {
110
+ println (" FN_CALL chapterListRequest " + manga.title + " :: " + manga .url)
111
+ return GET (manga.url, headers )
112
+ }
120
113
121
- override fun fetchChapterList (manga : SManga ): Observable <List <SChapter >> {
122
- println (" fetchChapterList " + manga.title)
123
- var response = GET (manga.url, headers)
124
- val rokaResponse = json.decodeFromString<RokahonResponse <RokahonSimpBook >>(response.body.toString())
114
+ override fun chapterListParse (response : Response ): List <SChapter > {
115
+ println (" FN_CALL chapterListParse " + response.request.url)
116
+ val rokaResponse = json.decodeFromString<RokahonResponse <RokahonSimpBook >>(response.body.string())
125
117
if (rokaResponse.isError) {
126
118
val msg = rokaResponse.data.toString()
127
119
Log .e(" Search" , msg)
120
+ throw Exception (msg)
128
121
}
129
122
val book = rokaResponse.data
130
- val chapters = book.chapters.map {
123
+ return book.chapters.map {
131
124
SChapter .create().apply {
132
- url = " $baseUrl /pages /" + book.id + " /" + it.id
125
+ url = " $baseUrl /chapter /" + book.id + " /" + it.id
133
126
name = it.title
134
127
}
135
128
}
136
- return Observable .just(chapters)
137
129
}
138
130
139
- override fun chapterListRequest (manga : SManga ): Request {
140
- println (" chapterListRequest " + manga.title + " :: " + manga.url)
141
- return GET (manga.url, headers)
131
+ // PAGE
132
+ override fun pageListRequest (chapter : SChapter ): Request {
133
+ println (" FN_CALL pageListRequest " + chapter.url)
134
+ return GET (chapter.url, headers)
142
135
}
143
136
144
- override fun chapterListParse (response : Response ): List <SChapter > {
145
- println (" chapterListParse " + response.request.url)
146
- val rokaResponse = json.decodeFromString<RokahonResponse <RokahonSimpBook >>(response.body.toString ())
137
+ override fun pageListParse (response : Response ): List <Page > {
138
+ println (" FN_CALL pageListParse " + response.request.url)
139
+ val rokaResponse = json.decodeFromString<RokahonResponse <RokahonChapter >>(response.body.string ())
147
140
if (rokaResponse.isError) {
148
141
val msg = rokaResponse.data.toString()
149
142
Log .e(" Search" , msg)
150
143
throw Exception (msg)
151
144
}
152
- val book = rokaResponse.data
153
- return book.chapters .map {
154
- SChapter .create(). apply {
155
- url = " $baseUrl /pages/ " + book.id + " / " + it.id
156
- name = it.title
157
- }
145
+ val chapter = rokaResponse.data
146
+ return chapter.pages .map {
147
+ Page (
148
+ index = it.number,
149
+ imageUrl = " $baseUrl /image?id= " + it.image.id,
150
+ )
158
151
}
159
152
}
160
153
161
- override fun pageListRequest (chapter : SChapter ): Request {
162
- TODO (" page list request" )
163
- }
164
-
165
154
// Settings/UI
166
155
167
156
override fun setupPreferenceScreen (screen : PreferenceScreen ) {
168
- screen.addPreference(screen.editTextPreference(ADDRESS_TITLE , ADDRESS_DEFAULT , baseUrl, false , " i.e. http://192.168.1.115:4567 " ))
157
+ screen.addPreference(screen.editTextPreference(ADDRESS_TITLE , ADDRESS_DEFAULT , baseUrl, false , " http://192.168.1.170:1770 " ))
169
158
}
170
159
171
160
private val preferences: SharedPreferences by lazy {
@@ -194,7 +183,7 @@ class Rokahon : ConfigurableSource, UnmeteredSource, HttpSource() {
194
183
setOnPreferenceChangeListener { _, newValue ->
195
184
try {
196
185
val res = preferences.edit().putString(title, newValue as String ).commit()
197
- Toast .makeText(context, " Restart Tachiyomi to apply new setting." , Toast .LENGTH_LONG ).show()
186
+ Toast .makeText(context, " Restart application to apply new setting." , Toast .LENGTH_LONG ).show()
198
187
res
199
188
} catch (e: Exception ) {
200
189
Log .e(" Rokahon" , " Exception while setting text preference" , e)
0 commit comments