mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Minor improvements
This commit is contained in:
parent
2723aeeb5c
commit
6196480d1d
@ -1,7 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.data.network
|
package eu.kanade.tachiyomi.data.network
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import com.squareup.duktape.Duktape
|
import com.squareup.duktape.Duktape
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
@ -42,8 +42,8 @@ class CloudflareInterceptor(private val cookies: PersistentCookieStore) : Interc
|
|||||||
val domain = originalRequest.url().host()
|
val domain = originalRequest.url().host()
|
||||||
val content = response.body().string()
|
val content = response.body().string()
|
||||||
|
|
||||||
// CloudFlare requires waiting 5 seconds before resolving the challenge
|
// CloudFlare requires waiting 4 seconds before resolving the challenge
|
||||||
Thread.sleep(5000)
|
Thread.sleep(4000)
|
||||||
|
|
||||||
val operation = operationPattern.find(content)?.groups?.get(1)?.value
|
val operation = operationPattern.find(content)?.groups?.get(1)?.value
|
||||||
val challenge = challengePattern.find(content)?.groups?.get(1)?.value
|
val challenge = challengePattern.find(content)?.groups?.get(1)?.value
|
||||||
@ -65,10 +65,10 @@ class CloudflareInterceptor(private val cookies: PersistentCookieStore) : Interc
|
|||||||
|
|
||||||
val answer = "${result + domain.length}"
|
val answer = "${result + domain.length}"
|
||||||
|
|
||||||
val url = Uri.parse("http://$domain/cdn-cgi/l/chk_jschl").buildUpon()
|
val url = HttpUrl.parse("http://$domain/cdn-cgi/l/chk_jschl").newBuilder()
|
||||||
.appendQueryParameter("jschl_vc", challenge)
|
.addQueryParameter("jschl_vc", challenge)
|
||||||
.appendQueryParameter("pass", pass)
|
.addQueryParameter("pass", pass)
|
||||||
.appendQueryParameter("jschl_answer", answer)
|
.addQueryParameter("jschl_answer", answer)
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
val referer = originalRequest.url().toString()
|
val referer = originalRequest.url().toString()
|
||||||
|
@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.download.DownloadService
|
|||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
|
import eu.kanade.tachiyomi.util.plusAssign
|
||||||
import eu.kanade.tachiyomi.widget.NpaLinearLayoutManager
|
import eu.kanade.tachiyomi.widget.NpaLinearLayoutManager
|
||||||
import kotlinx.android.synthetic.main.fragment_download_queue.*
|
import kotlinx.android.synthetic.main.fragment_download_queue.*
|
||||||
import nucleus.factory.RequiresPresenter
|
import nucleus.factory.RequiresPresenter
|
||||||
@ -46,9 +47,9 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
|||||||
private var clearButton: MenuItem? = null
|
private var clearButton: MenuItem? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription list to be cleared during [onPause].
|
* Subscription list to be cleared during [onDestroyView].
|
||||||
*/
|
*/
|
||||||
private val resumeSubscriptions by lazy { CompositeSubscription() }
|
private val subscriptions by lazy { CompositeSubscription() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of subscriptions for active downloads.
|
* Map of subscriptions for active downloads.
|
||||||
@ -94,6 +95,28 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
|||||||
// Set the layout manager for the recycler and fixed size.
|
// Set the layout manager for the recycler and fixed size.
|
||||||
recycler.layoutManager = NpaLinearLayoutManager(activity)
|
recycler.layoutManager = NpaLinearLayoutManager(activity)
|
||||||
recycler.setHasFixedSize(true)
|
recycler.setHasFixedSize(true)
|
||||||
|
|
||||||
|
// Suscribe to changes
|
||||||
|
subscriptions += presenter.downloadManager.runningSubject
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { onQueueStatusChange(it) }
|
||||||
|
|
||||||
|
subscriptions += presenter.getStatusObservable()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { onStatusChange(it) }
|
||||||
|
|
||||||
|
subscriptions += presenter.getProgressObservable()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { onUpdateDownloadedPages(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
for (subscription in progressSubscriptions.values) {
|
||||||
|
subscription.unsubscribe()
|
||||||
|
}
|
||||||
|
progressSubscriptions.clear()
|
||||||
|
subscriptions.clear()
|
||||||
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
@ -131,33 +154,6 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
presenter.downloadManager.runningSubject
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { onQueueStatusChange(it) }
|
|
||||||
.apply { resumeSubscriptions.add(this) }
|
|
||||||
|
|
||||||
presenter.getStatusObservable()
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { onStatusChange(it) }
|
|
||||||
.apply { resumeSubscriptions.add(this) }
|
|
||||||
|
|
||||||
presenter.getProgressObservable()
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { onUpdateDownloadedPages(it) }
|
|
||||||
.apply { resumeSubscriptions.add(this) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
for (subscription in progressSubscriptions.values) {
|
|
||||||
subscription.unsubscribe()
|
|
||||||
}
|
|
||||||
progressSubscriptions.clear()
|
|
||||||
resumeSubscriptions.clear()
|
|
||||||
super.onPause()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the status of a download changes.
|
* Called when the status of a download changes.
|
||||||
*
|
*
|
||||||
|
@ -240,37 +240,27 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
|
|||||||
.negativeText(android.R.string.cancel)
|
.negativeText(android.R.string.cancel)
|
||||||
.items(modes.map { getString(it) })
|
.items(modes.map { getString(it) })
|
||||||
.itemsCallback { dialog, view, i, charSequence ->
|
.itemsCallback { dialog, view, i, charSequence ->
|
||||||
var chapters: MutableList<Chapter> = arrayListOf()
|
|
||||||
|
fun getUnreadChaptersSorted() = presenter.chapters
|
||||||
|
.filter { !it.read && !it.isDownloaded }
|
||||||
|
.sortedByDescending { it.source_order }
|
||||||
|
|
||||||
// i = 0: Download 1
|
// i = 0: Download 1
|
||||||
// i = 1: Download 5
|
// i = 1: Download 5
|
||||||
// i = 2: Download 10
|
// i = 2: Download 10
|
||||||
// i = 3: Download unread
|
// i = 3: Download unread
|
||||||
// i = 4: Download all
|
// i = 4: Download all
|
||||||
for (chapter in presenter.chapters) {
|
val chaptersToDownload = when (i) {
|
||||||
if (!chapter.isDownloaded) {
|
0 -> getUnreadChaptersSorted().take(1)
|
||||||
if (i == 4 || (i != 4 && !chapter.read)) {
|
1 -> getUnreadChaptersSorted().take(5)
|
||||||
chapters.add(chapter)
|
2 -> getUnreadChaptersSorted().take(10)
|
||||||
|
3 -> presenter.chapters.filter { !it.read }
|
||||||
|
4 -> presenter.chapters
|
||||||
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
if (chaptersToDownload.isNotEmpty()) {
|
||||||
if (chapters.size > 0) {
|
downloadChapters(chaptersToDownload)
|
||||||
if (!presenter.sortDescending()) {
|
|
||||||
chapters.reverse()
|
|
||||||
}
|
|
||||||
when (i) {
|
|
||||||
// Set correct chapters size if desired
|
|
||||||
0 -> chapters = chapters.subList(0, 1)
|
|
||||||
1 -> {
|
|
||||||
if (chapters.size >= 5)
|
|
||||||
chapters = chapters.subList(0, 5)
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (chapters.size >= 10)
|
|
||||||
chapters = chapters.subList(0, 10)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
downloadChapters(chapters)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
|
@ -114,13 +114,13 @@ class MangaInfoFragment : BaseRxFragment<MangaInfoPresenter>() {
|
|||||||
|
|
||||||
// Set cover if it wasn't already.
|
// Set cover if it wasn't already.
|
||||||
if (manga_cover.drawable == null && !manga.thumbnail_url.isNullOrEmpty()) {
|
if (manga_cover.drawable == null && !manga.thumbnail_url.isNullOrEmpty()) {
|
||||||
Glide.with(context)
|
Glide.with(this)
|
||||||
.load(manga)
|
.load(manga)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(manga_cover)
|
.into(manga_cover)
|
||||||
|
|
||||||
Glide.with(context)
|
Glide.with(this)
|
||||||
.load(manga)
|
.load(manga)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
|
@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalReader
|
|||||||
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonReader
|
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonReader
|
||||||
import eu.kanade.tachiyomi.util.GLUtil
|
import eu.kanade.tachiyomi.util.GLUtil
|
||||||
import eu.kanade.tachiyomi.util.SharedData
|
import eu.kanade.tachiyomi.util.SharedData
|
||||||
|
import eu.kanade.tachiyomi.util.plusAssign
|
||||||
import eu.kanade.tachiyomi.util.toast
|
import eu.kanade.tachiyomi.util.toast
|
||||||
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
||||||
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
||||||
@ -451,10 +452,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeSettings() {
|
private fun initializeSettings() {
|
||||||
subscriptions.add(preferences.showPageNumber().asObservable()
|
subscriptions += preferences.showPageNumber().asObservable()
|
||||||
.subscribe { setPageNumberVisibility(it) })
|
.subscribe { setPageNumberVisibility(it) }
|
||||||
|
|
||||||
subscriptions.add(preferences.rotation().asObservable()
|
subscriptions += preferences.rotation().asObservable()
|
||||||
.subscribe {
|
.subscribe {
|
||||||
setRotation(it)
|
setRotation(it)
|
||||||
|
|
||||||
@ -468,20 +469,20 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
R.drawable.ic_screen_lock_landscape_white_24dp
|
R.drawable.ic_screen_lock_landscape_white_24dp
|
||||||
|
|
||||||
lock_orientation.setImageResource(resourceId)
|
lock_orientation.setImageResource(resourceId)
|
||||||
})
|
}
|
||||||
|
|
||||||
subscriptions.add(preferences.hideStatusBar().asObservable()
|
subscriptions += preferences.hideStatusBar().asObservable()
|
||||||
.subscribe { setStatusBarVisibility(it) })
|
.subscribe { setStatusBarVisibility(it) }
|
||||||
|
|
||||||
subscriptions.add(preferences.keepScreenOn().asObservable()
|
subscriptions += preferences.keepScreenOn().asObservable()
|
||||||
.subscribe { setKeepScreenOn(it) })
|
.subscribe { setKeepScreenOn(it) }
|
||||||
|
|
||||||
subscriptions.add(preferences.customBrightness().asObservable()
|
subscriptions += preferences.customBrightness().asObservable()
|
||||||
.subscribe { setCustomBrightness(it) })
|
.subscribe { setCustomBrightness(it) }
|
||||||
|
|
||||||
subscriptions.add(preferences.readerTheme().asObservable()
|
subscriptions += preferences.readerTheme().asObservable()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe { applyTheme(it) })
|
.subscribe { applyTheme(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setRotation(rotation: Int) {
|
private fun setRotation(rotation: Int) {
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package eu.kanade.tachiyomi.util
|
||||||
|
|
||||||
|
import rx.Subscription
|
||||||
|
import rx.subscriptions.CompositeSubscription
|
||||||
|
|
||||||
|
fun Subscription?.isNullOrUnsubscribed() = this == null || isUnsubscribed
|
||||||
|
|
||||||
|
operator fun CompositeSubscription.plusAssign(subscription: Subscription) = add(subscription)
|
Loading…
Reference in New Issue
Block a user