Support authorization for MangaLib and HentaiLib #122

This commit is contained in:
Koitharu
2022-03-10 19:52:30 +02:00
parent 755f1e5747
commit a8a65e953f
3 changed files with 30 additions and 3 deletions

View File

@@ -68,6 +68,7 @@
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name="org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity" android:name="org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name="org.koitharu.kotatsu.core.ui.CrashActivity" android:name="org.koitharu.kotatsu.core.ui.CrashActivity"

View File

@@ -217,11 +217,17 @@ open class MangaLibRepository(loaderContext: MangaLoaderContext) :
} }
override fun isAuthorized(): Boolean { override fun isAuthorized(): Boolean {
return false return loaderContext.cookieJar.getCookies(getDomain()).any {
it.name.startsWith("remember_web_")
}
} }
override suspend fun getUsername(): String { override suspend fun getUsername(): String {
TODO("Not yet implemented") val body = loaderContext.httpGet("https://${getDomain()}/messages").parseHtml().body()
if (body.baseUri().endsWith("/login")) {
throw AuthRequiredException(source)
}
return body.selectFirst(".profile-user__username")?.text() ?: parseFailed("Cannot find username")
} }
private fun getSortKey(sortOrder: SortOrder?) = when (sortOrder) { private fun getSortKey(sortOrder: SortOrder?) = when (sortOrder) {

View File

@@ -16,6 +16,7 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.BaseActivity import org.koitharu.kotatsu.base.ui.BaseActivity
import org.koitharu.kotatsu.browser.BrowserCallback import org.koitharu.kotatsu.browser.BrowserCallback
import org.koitharu.kotatsu.browser.BrowserClient import org.koitharu.kotatsu.browser.BrowserClient
import org.koitharu.kotatsu.browser.ProgressChromeClient
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.parser.MangaRepositoryAuthProvider import org.koitharu.kotatsu.core.parser.MangaRepositoryAuthProvider
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
@@ -33,7 +34,7 @@ class SourceAuthActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallba
setContentView(ActivityBrowserBinding.inflate(layoutInflater)) setContentView(ActivityBrowserBinding.inflate(layoutInflater))
val source = intent?.getParcelableExtra<MangaSource>(EXTRA_SOURCE) val source = intent?.getParcelableExtra<MangaSource>(EXTRA_SOURCE)
if (source == null) { if (source == null) {
finish() finishAfterTransition()
return return
} }
repository = mangaRepositoryOf(source) as? MangaRepositoryAuthProvider ?: run { repository = mangaRepositoryOf(source) as? MangaRepositoryAuthProvider ?: run {
@@ -53,6 +54,10 @@ class SourceAuthActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallba
javaScriptEnabled = true javaScriptEnabled = true
} }
binding.webView.webViewClient = BrowserClient(this) binding.webView.webViewClient = BrowserClient(this)
binding.webView.webChromeClient = ProgressChromeClient(binding.progressBar)
if (savedInstanceState != null) {
return
}
val url = repository.authUrl val url = repository.authUrl
onTitleChanged( onTitleChanged(
source.title, source.title,
@@ -61,6 +66,21 @@ class SourceAuthActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallba
binding.webView.loadUrl(url) binding.webView.loadUrl(url)
} }
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
binding.webView.saveState(outState)
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
binding.webView.restoreState(savedInstanceState)
}
override fun onDestroy() {
super.onDestroy()
binding.webView.destroy()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
binding.webView.stopLoading() binding.webView.stopLoading()