Code cleanup

This commit is contained in:
Jobobby04
2020-08-04 19:32:36 -04:00
parent 29e1697d2e
commit bb87392eef
18 changed files with 107 additions and 190 deletions
@@ -30,13 +30,13 @@ class BatchAddPresenter : BasePresenter<BatchAddController>() {
testedGalleries = if (regex.containsMatchIn(galleries)) {
regex.findAll(galleries).map { galleryKeys ->
val LinkParts = galleryKeys.value.split(".")
val Link = "${if (Injekt.get<PreferencesHelper>().enableExhentai().get()) {
val linkParts = galleryKeys.value.split(".")
val link = "${if (Injekt.get<PreferencesHelper>().enableExhentai().get()) {
"https://exhentai.org/g/"
} else {
"https://e-hentai.org/g/"
}}${LinkParts[0]}/${LinkParts[1].replace(":", "")}"
Link
}}${linkParts[0]}/${linkParts[1].replace(":", "")}"
link
}.joinToString(separator = "\n")
} else {
galleries
@@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.system.setDefaultSettings
import exh.source.DelegatedHttpSource
import exh.util.melt
import java.io.Serializable
@@ -33,7 +34,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import rx.Observable
import rx.Single
import rx.schedulers.Schedulers
@@ -81,7 +82,7 @@ class BrowserActionActivity : AppCompatActivity() {
val url: String? = intent.getStringExtra(URL_EXTRA)
val actionName = intent.getStringExtra(ACTION_NAME_EXTRA)
@Suppress("NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE")
@Suppress("NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE", "UNCHECKED_CAST")
val verifyComplete = if (source != null) {
source::verifyComplete!!
} else intent.getSerializableExtra(VERIFY_LAMBDA_EXTRA) as? (String) -> Boolean
@@ -106,8 +107,7 @@ class BrowserActionActivity : AppCompatActivity() {
cm.setCookie(url, cookieString)
}
webview.settings.javaScriptEnabled = true
webview.settings.domStorageEnabled = true
webview.setDefaultSettings()
headers.entries.find { it.key.equals("user-agent", true) }?.let {
webview.settings.userAgentString = it.value
}
@@ -277,7 +277,7 @@ class BrowserActionActivity : AppCompatActivity() {
}
}
fun performRecognize(url: String): Single<String> {
private fun performRecognize(url: String): Single<String> {
return credentialsObservable.flatMap { token ->
httpClient.newCall(
Request.Builder()
@@ -304,7 +304,11 @@ class BrowserActionActivity : AppCompatActivity() {
.addFormDataPart(
"audio.mp3",
"audio.mp3",
RequestBody.create("audio/mp3".toMediaTypeOrNull(), audioFile)
audioFile.toRequestBody(
"audio/mp3".toMediaTypeOrNull(),
0,
audioFile.size
)
)
.build()
)
@@ -315,7 +319,7 @@ class BrowserActionActivity : AppCompatActivity() {
}.toSingle()
}
fun doStageCheckbox(loopId: String) {
private fun doStageCheckbox(loopId: String) {
if (loopId != currentLoopId) return
webview.evaluateJavascript(
@@ -346,7 +350,7 @@ class BrowserActionActivity : AppCompatActivity() {
)
}
fun getAudioButtonLocation(loopId: String) {
private fun getAudioButtonLocation(loopId: String) {
webview.evaluateJavascript(
"""
(function() {
@@ -381,7 +385,7 @@ class BrowserActionActivity : AppCompatActivity() {
)
}
fun doStageDownloadAudio(loopId: String) {
private fun doStageDownloadAudio(loopId: String) {
webview.evaluateJavascript(
"""
(function() {
@@ -409,7 +413,7 @@ class BrowserActionActivity : AppCompatActivity() {
)
}
fun typeResult(loopId: String, result: String) {
private fun typeResult(loopId: String, result: String) {
webview.evaluateJavascript(
"""
(function() {
@@ -478,7 +482,7 @@ class BrowserActionActivity : AppCompatActivity() {
}
}
fun runValidateCaptcha(loopId: String) {
private fun runValidateCaptcha(loopId: String) {
if (loopId != validateCurrentLoopId) return
webview.evaluateJavascript(
@@ -93,13 +93,13 @@ class InterceptActivity : BaseActivity<EhActivityInterceptBinding>() {
private val galleryAdder = GalleryAdder()
val status = BehaviorSubject.create<InterceptResult>(InterceptResult.Idle())
val status: BehaviorSubject<InterceptResult> = BehaviorSubject.create<InterceptResult>(InterceptResult.Idle)
@Synchronized
fun loadGallery(gallery: String) {
// Do not load gallery if already loading
if (status.value is InterceptResult.Idle) {
status.onNext(InterceptResult.Loading())
status.onNext(InterceptResult.Loading)
// Load gallery async
thread {
@@ -119,8 +119,8 @@ class InterceptActivity : BaseActivity<EhActivityInterceptBinding>() {
}
sealed class InterceptResult {
class Idle : InterceptResult()
class Loading : InterceptResult()
object Idle : InterceptResult()
object Loading : InterceptResult()
data class Success(val mangaId: Long) : InterceptResult()
data class Failure(val reason: String) : InterceptResult()
}
@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.databinding.EhActivityLoginBinding
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.setDefaultSettings
import exh.uconfig.WarnConfigureDialogController
import java.net.HttpCookie
import timber.log.Timber
@@ -39,53 +40,50 @@ class LoginController : NucleusController<EhActivityLoginBinding, LoginPresenter
override fun onViewCreated(view: View) {
super.onViewCreated(view)
with(view) {
binding.btnCancel.setOnClickListener { router.popCurrentController() }
binding.btnCancel.setOnClickListener { router.popCurrentController() }
binding.btnAdvanced.setOnClickListener {
binding.advancedOptions.isVisible = true
binding.webview.isVisible = false
binding.btnAdvanced.isEnabled = false
binding.btnCancel.isEnabled = false
}
binding.btnAdvanced.setOnClickListener {
binding.advancedOptions.isVisible = true
binding.webview.isVisible = false
binding.btnAdvanced.isEnabled = false
binding.btnCancel.isEnabled = false
}
binding.btnClose.setOnClickListener {
hideAdvancedOptions(this)
}
binding.btnClose.setOnClickListener {
hideAdvancedOptions()
}
binding.btnRecheck.setOnClickListener {
hideAdvancedOptions(this)
binding.webview.loadUrl("https://exhentai.org/")
}
binding.btnRecheck.setOnClickListener {
hideAdvancedOptions()
binding.webview.loadUrl("https://exhentai.org/")
}
binding.btnAltLogin.setOnClickListener {
hideAdvancedOptions(this)
binding.webview.loadUrl("https://e-hentai.org/bounce_login.php")
}
binding.btnAltLogin.setOnClickListener {
hideAdvancedOptions()
binding.webview.loadUrl("https://e-hentai.org/bounce_login.php")
}
binding.btnSkipRestyle.setOnClickListener {
hideAdvancedOptions(this)
binding.webview.loadUrl("https://forums.e-hentai.org/index.php?act=Login&$PARAM_SKIP_INJECT=true")
}
binding.btnSkipRestyle.setOnClickListener {
hideAdvancedOptions()
binding.webview.loadUrl("https://forums.e-hentai.org/index.php?act=Login&$PARAM_SKIP_INJECT=true")
}
CookieManager.getInstance().removeAllCookies {
launchUI {
startWebview(view)
}
CookieManager.getInstance().removeAllCookies {
launchUI {
startWebview()
}
}
}
private fun hideAdvancedOptions(view: View) {
private fun hideAdvancedOptions() {
binding.advancedOptions.isVisible = false
binding.webview.isVisible = true
binding.btnAdvanced.isEnabled = true
binding.btnCancel.isEnabled = true
}
fun startWebview(view: View) {
binding.webview.settings.javaScriptEnabled = true
binding.webview.settings.domStorageEnabled = true
private fun startWebview() {
binding.webview.setDefaultSettings()
binding.webview.loadUrl("https://forums.e-hentai.org/index.php?act=Login")
@@ -169,9 +167,9 @@ class LoginController : NucleusController<EhActivityLoginBinding, LoginPresenter
return false
}
fun getCookies(url: String): List<HttpCookie>? =
CookieManager.getInstance().getCookie(url)?.let {
it.split("; ").flatMap {
private fun getCookies(url: String): List<HttpCookie>? =
CookieManager.getInstance().getCookie(url)?.let { cookie ->
cookie.split("; ").flatMap {
HttpCookie.parse(it)
}
}
@@ -13,18 +13,14 @@ import eu.kanade.tachiyomi.ui.browse.source.SourceController
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartSearchBinding, SmartSearchPresenter>(), CoroutineScope {
override val coroutineContext = Job() + Dispatchers.Main
class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartSearchBinding, SmartSearchPresenter>() {
private val sourceManager: SourceManager by injectLazy()
private val source = sourceManager.get(bundle?.getLong(ARG_SOURCE_ID, -1) ?: -1) as? CatalogueSource
@@ -55,7 +51,7 @@ class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartS
// Init presenter now to resolve threading issues
presenter
launch(Dispatchers.Default) {
scope.launch(Dispatchers.Default) {
for (event in presenter.smartSearchChannel) {
if (event is SmartSearchPresenter.SearchResults.Found) {
val transaction = MangaController(event.manga, true, smartSearchConfig).withFadeTransaction()
@@ -81,7 +77,7 @@ class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartS
override fun onDestroy() {
super.onDestroy()
cancel()
scope.cancel()
}
companion object {
@@ -3,7 +3,6 @@ package exh.ui.smartsearch
import android.os.Bundle
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.browse.source.SourceController
import exh.smartsearch.SmartSearchEngine
@@ -16,19 +15,19 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
class SmartSearchPresenter(private val source: CatalogueSource?, private val config: SourceController.SmartSearchConfig?) :
BasePresenter<SmartSearchController>(), CoroutineScope {
BasePresenter<SmartSearchController>() {
override val coroutineContext = Job() + Dispatchers.Main
val scope = CoroutineScope(Job() + Dispatchers.Main)
val smartSearchChannel = Channel<SearchResults>()
private val smartSearchEngine = SmartSearchEngine(coroutineContext)
private val smartSearchEngine = SmartSearchEngine(scope.coroutineContext)
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
if (source != null && config != null) {
launch(Dispatchers.Default) {
scope.launch(Dispatchers.Default) {
val result = try {
val resultManga = smartSearchEngine.smartSearch(source, config.origTitle)
if (resultManga != null) {
@@ -53,11 +52,9 @@ class SmartSearchPresenter(private val source: CatalogueSource?, private val con
override fun onDestroy() {
super.onDestroy()
cancel()
scope.cancel()
}
data class SearchEntry(val manga: SManga, val dist: Double)
sealed class SearchResults {
data class Found(val manga: Manga) : SearchResults()
object NotFound : SearchResults()