Allow to unbind manga, closes #258. Fix some network calls leaking
This commit is contained in:
parent
81bce8ef76
commit
17c59657c3
6 changed files with 37 additions and 21 deletions
|
@ -260,6 +260,14 @@ open class DatabaseHelper(context: Context) {
|
||||||
|
|
||||||
fun deleteMangaSync(manga: MangaSync) = db.delete().`object`(manga).prepare()
|
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
|
// Categories related queries
|
||||||
|
|
||||||
fun getCategories() = db.get()
|
fun getCategories() = db.get()
|
||||||
|
|
|
@ -44,10 +44,11 @@ class NetworkHelper(context: Context) {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun request(request: Request, forceCache: Boolean = false): Observable<Response> {
|
fun request(request: Request, forceCache: Boolean = false): Observable<Response> {
|
||||||
|
var response: Response? = null
|
||||||
return Observable.fromCallable {
|
return Observable.fromCallable {
|
||||||
val c = if (forceCache) forceCacheClient else client
|
val c = if (forceCache) forceCacheClient else client
|
||||||
c.newCall(request).execute()
|
c.newCall(request).execute().apply { response = this }
|
||||||
}
|
}.doOnUnsubscribe { response?.body()?.close() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
|
@ -57,6 +58,7 @@ class NetworkHelper(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestBodyProgress(request: Request, listener: ProgressListener): Observable<Response> {
|
fun requestBodyProgress(request: Request, listener: ProgressListener): Observable<Response> {
|
||||||
|
var response: Response? = null
|
||||||
return Observable.fromCallable {
|
return Observable.fromCallable {
|
||||||
val progressClient = client.newBuilder()
|
val progressClient = client.newBuilder()
|
||||||
.cache(null)
|
.cache(null)
|
||||||
|
@ -68,8 +70,8 @@ class NetworkHelper(context: Context) {
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
progressClient.newCall(request).execute()
|
progressClient.newCall(request).execute().apply { response = this }
|
||||||
}.retry(1)
|
}.doOnUnsubscribe { response?.body()?.close() }.retry(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
val cookies: CookieStore
|
val cookies: CookieStore
|
||||||
|
|
|
@ -91,9 +91,7 @@ class MyAnimeListDialogFragment : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPositiveButtonClick() {
|
private fun onPositiveButtonClick() {
|
||||||
selectedItem?.let {
|
presenter.registerManga(selectedItem)
|
||||||
presenter.registerManga(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun search(query: String) {
|
private fun search(query: String) {
|
||||||
|
|
|
@ -56,6 +56,10 @@ class MyAnimeListFragment : BaseRxFragment<MyAnimeListPresenter>() {
|
||||||
myanimelist_status.text = presenter.myAnimeList.getStatus(it.status)
|
myanimelist_status.text = presenter.myAnimeList.getStatus(it.status)
|
||||||
} ?: run {
|
} ?: run {
|
||||||
myanimelist_title.setTextAppearance(context, R.style.TextAppearance_Medium_Button)
|
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,7 +123,8 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||||
stop(GET_SEARCH_RESULTS)
|
stop(GET_SEARCH_RESULTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerManga(sync: MangaSync) {
|
fun registerManga(sync: MangaSync?) {
|
||||||
|
if (sync != null) {
|
||||||
sync.manga_id = manga.id
|
sync.manga_id = manga.id
|
||||||
add(myAnimeList.bind(sync)
|
add(myAnimeList.bind(sync)
|
||||||
.flatMap { response ->
|
.flatMap { response ->
|
||||||
|
@ -137,6 +138,9 @@ class MyAnimeListPresenter : BasePresenter<MyAnimeListFragment>() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({ },
|
.subscribe({ },
|
||||||
{ error -> context.toast(error.message) }))
|
{ error -> context.toast(error.message) }))
|
||||||
|
} else {
|
||||||
|
db.deleteMangaSyncForManga(manga).executeAsBlocking()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllStatus(): List<String> {
|
fun getAllStatus(): List<String> {
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:text="Edit"
|
android:text="@string/action_edit"
|
||||||
style="@style/TextAppearance.Medium.Button"/>
|
style="@style/TextAppearance.Medium.Button"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Reference in a new issue