Allow to unbind manga, closes #258. Fix some network calls leaking
This commit is contained in:
parent
81bce8ef76
commit
17c59657c3
@ -260,6 +260,14 @@ open class DatabaseHelper(context: Context) {
|
||||
|
||||
fun deleteMangaSync(manga: MangaSync) = db.delete().`object`(manga).prepare()
|
||||
|
||||
fun deleteMangaSyncForManga(manga: Manga) = db.delete()
|
||||
.byQuery(DeleteQuery.builder()
|
||||
.table(MangaSyncTable.TABLE)
|
||||
.where("${MangaSyncTable.COLUMN_MANGA_ID} = ?")
|
||||
.whereArgs(manga.id)
|
||||
.build())
|
||||
.prepare()
|
||||
|
||||
// Categories related queries
|
||||
|
||||
fun getCategories() = db.get()
|
||||
|
@ -44,10 +44,11 @@ class NetworkHelper(context: Context) {
|
||||
|
||||
@JvmOverloads
|
||||
fun request(request: Request, forceCache: Boolean = false): Observable<Response> {
|
||||
var response: Response? = null
|
||||
return Observable.fromCallable {
|
||||
val c = if (forceCache) forceCacheClient else client
|
||||
c.newCall(request).execute()
|
||||
}
|
||||
c.newCall(request).execute().apply { response = this }
|
||||
}.doOnUnsubscribe { response?.body()?.close() }
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
@ -57,6 +58,7 @@ class NetworkHelper(context: Context) {
|
||||
}
|
||||
|
||||
fun requestBodyProgress(request: Request, listener: ProgressListener): Observable<Response> {
|
||||
var response: Response? = null
|
||||
return Observable.fromCallable {
|
||||
val progressClient = client.newBuilder()
|
||||
.cache(null)
|
||||
@ -68,8 +70,8 @@ class NetworkHelper(context: Context) {
|
||||
}
|
||||
.build()
|
||||
|
||||
progressClient.newCall(request).execute()
|
||||
}.retry(1)
|
||||
progressClient.newCall(request).execute().apply { response = this }
|
||||
}.doOnUnsubscribe { response?.body()?.close() }.retry(1)
|
||||
}
|
||||
|
||||
val cookies: CookieStore
|
||||
|
@ -91,9 +91,7 @@ class MyAnimeListDialogFragment : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun onPositiveButtonClick() {
|
||||
selectedItem?.let {
|
||||
presenter.registerManga(it)
|
||||
}
|
||||
presenter.registerManga(selectedItem)
|
||||
}
|
||||
|
||||
private fun search(query: String) {
|
||||
|
@ -56,6 +56,10 @@ class MyAnimeListFragment : BaseRxFragment<MyAnimeListPresenter>() {
|
||||
myanimelist_status.text = presenter.myAnimeList.getStatus(it.status)
|
||||
} ?: run {
|
||||
myanimelist_title.setTextAppearance(context, R.style.TextAppearance_Medium_Button)
|
||||
myanimelist_title.setText(R.string.action_edit)
|
||||
myanimelist_chapters.text = ""
|
||||
myanimelist_score.text = ""
|
||||
myanimelist_status.text = ""
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -123,20 +123,24 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||
stop(GET_SEARCH_RESULTS)
|
||||
}
|
||||
|
||||
fun registerManga(sync: MangaSync) {
|
||||
sync.manga_id = manga.id
|
||||
add(myAnimeList.bind(sync)
|
||||
.flatMap { response ->
|
||||
if (response.isSuccessful) {
|
||||
db.insertMangaSync(sync).asRxObservable()
|
||||
} else {
|
||||
Observable.error(Exception("Could not bind manga"))
|
||||
fun registerManga(sync: MangaSync?) {
|
||||
if (sync != null) {
|
||||
sync.manga_id = manga.id
|
||||
add(myAnimeList.bind(sync)
|
||||
.flatMap { response ->
|
||||
if (response.isSuccessful) {
|
||||
db.insertMangaSync(sync).asRxObservable()
|
||||
} else {
|
||||
Observable.error(Exception("Could not bind manga"))
|
||||
}
|
||||
}
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ },
|
||||
{ error -> context.toast(error.message) }))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ },
|
||||
{ error -> context.toast(error.message) }))
|
||||
} else {
|
||||
db.deleteMangaSyncForManga(manga).executeAsBlocking()
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllStatus(): List<String> {
|
||||
|
@ -27,7 +27,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="Edit"
|
||||
android:text="@string/action_edit"
|
||||
style="@style/TextAppearance.Medium.Button"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user