mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 01:15:14 +01:00
Minor improvements
This commit is contained in:
parent
2723aeeb5c
commit
6196480d1d
@ -1,7 +1,7 @@
|
||||
package eu.kanade.tachiyomi.data.network
|
||||
|
||||
import android.net.Uri
|
||||
import com.squareup.duktape.Duktape
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
@ -42,8 +42,8 @@ class CloudflareInterceptor(private val cookies: PersistentCookieStore) : Interc
|
||||
val domain = originalRequest.url().host()
|
||||
val content = response.body().string()
|
||||
|
||||
// CloudFlare requires waiting 5 seconds before resolving the challenge
|
||||
Thread.sleep(5000)
|
||||
// CloudFlare requires waiting 4 seconds before resolving the challenge
|
||||
Thread.sleep(4000)
|
||||
|
||||
val operation = operationPattern.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 url = Uri.parse("http://$domain/cdn-cgi/l/chk_jschl").buildUpon()
|
||||
.appendQueryParameter("jschl_vc", challenge)
|
||||
.appendQueryParameter("pass", pass)
|
||||
.appendQueryParameter("jschl_answer", answer)
|
||||
val url = HttpUrl.parse("http://$domain/cdn-cgi/l/chk_jschl").newBuilder()
|
||||
.addQueryParameter("jschl_vc", challenge)
|
||||
.addQueryParameter("pass", pass)
|
||||
.addQueryParameter("jschl_answer", answer)
|
||||
.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.ui.base.fragment.BaseRxFragment
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.util.plusAssign
|
||||
import eu.kanade.tachiyomi.widget.NpaLinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.fragment_download_queue.*
|
||||
import nucleus.factory.RequiresPresenter
|
||||
@ -46,9 +47,9 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
||||
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.
|
||||
@ -94,6 +95,28 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
||||
// Set the layout manager for the recycler and fixed size.
|
||||
recycler.layoutManager = NpaLinearLayoutManager(activity)
|
||||
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) {
|
||||
@ -131,33 +154,6 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
||||
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.
|
||||
*
|
||||
|
@ -240,37 +240,27 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
|
||||
.negativeText(android.R.string.cancel)
|
||||
.items(modes.map { getString(it) })
|
||||
.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 = 1: Download 5
|
||||
// i = 2: Download 10
|
||||
// i = 3: Download unread
|
||||
// i = 4: Download all
|
||||
for (chapter in presenter.chapters) {
|
||||
if (!chapter.isDownloaded) {
|
||||
if (i == 4 || (i != 4 && !chapter.read)) {
|
||||
chapters.add(chapter)
|
||||
}
|
||||
}
|
||||
val chaptersToDownload = when (i) {
|
||||
0 -> getUnreadChaptersSorted().take(1)
|
||||
1 -> getUnreadChaptersSorted().take(5)
|
||||
2 -> getUnreadChaptersSorted().take(10)
|
||||
3 -> presenter.chapters.filter { !it.read }
|
||||
4 -> presenter.chapters
|
||||
else -> emptyList()
|
||||
}
|
||||
if (chapters.size > 0) {
|
||||
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)
|
||||
|
||||
if (chaptersToDownload.isNotEmpty()) {
|
||||
downloadChapters(chaptersToDownload)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
|
@ -114,13 +114,13 @@ class MangaInfoFragment : BaseRxFragment<MangaInfoPresenter>() {
|
||||
|
||||
// Set cover if it wasn't already.
|
||||
if (manga_cover.drawable == null && !manga.thumbnail_url.isNullOrEmpty()) {
|
||||
Glide.with(context)
|
||||
Glide.with(this)
|
||||
.load(manga)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.into(manga_cover)
|
||||
|
||||
Glide.with(context)
|
||||
Glide.with(this)
|
||||
.load(manga)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.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.util.GLUtil
|
||||
import eu.kanade.tachiyomi.util.SharedData
|
||||
import eu.kanade.tachiyomi.util.plusAssign
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
||||
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
||||
@ -451,10 +452,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
}
|
||||
|
||||
private fun initializeSettings() {
|
||||
subscriptions.add(preferences.showPageNumber().asObservable()
|
||||
.subscribe { setPageNumberVisibility(it) })
|
||||
subscriptions += preferences.showPageNumber().asObservable()
|
||||
.subscribe { setPageNumberVisibility(it) }
|
||||
|
||||
subscriptions.add(preferences.rotation().asObservable()
|
||||
subscriptions += preferences.rotation().asObservable()
|
||||
.subscribe {
|
||||
setRotation(it)
|
||||
|
||||
@ -468,20 +469,20 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
R.drawable.ic_screen_lock_landscape_white_24dp
|
||||
|
||||
lock_orientation.setImageResource(resourceId)
|
||||
})
|
||||
}
|
||||
|
||||
subscriptions.add(preferences.hideStatusBar().asObservable()
|
||||
.subscribe { setStatusBarVisibility(it) })
|
||||
subscriptions += preferences.hideStatusBar().asObservable()
|
||||
.subscribe { setStatusBarVisibility(it) }
|
||||
|
||||
subscriptions.add(preferences.keepScreenOn().asObservable()
|
||||
.subscribe { setKeepScreenOn(it) })
|
||||
subscriptions += preferences.keepScreenOn().asObservable()
|
||||
.subscribe { setKeepScreenOn(it) }
|
||||
|
||||
subscriptions.add(preferences.customBrightness().asObservable()
|
||||
.subscribe { setCustomBrightness(it) })
|
||||
subscriptions += preferences.customBrightness().asObservable()
|
||||
.subscribe { setCustomBrightness(it) }
|
||||
|
||||
subscriptions.add(preferences.readerTheme().asObservable()
|
||||
subscriptions += preferences.readerTheme().asObservable()
|
||||
.distinctUntilChanged()
|
||||
.subscribe { applyTheme(it) })
|
||||
.subscribe { applyTheme(it) }
|
||||
}
|
||||
|
||||
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