|
|
|
@ -14,46 +14,34 @@ import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.browser.BaseBrowserActivity
|
|
|
|
import org.koitharu.kotatsu.browser.BaseBrowserActivity
|
|
|
|
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.core.model.MangaSource
|
|
|
|
import org.koitharu.kotatsu.core.model.getTitle
|
|
|
|
import org.koitharu.kotatsu.core.nav.AppRouter
|
|
|
|
import org.koitharu.kotatsu.core.nav.AppRouter
|
|
|
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.parser.ParserMangaRepository
|
|
|
|
import org.koitharu.kotatsu.core.parser.ParserMangaRepository
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.configureForParser
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
|
|
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
|
|
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaParserSource
|
|
|
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
|
|
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
|
|
|
import org.koitharu.kotatsu.settings.sources.SourceSettingsFragment.Companion.EXTRA_SOURCE
|
|
|
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
|
@AndroidEntryPoint
|
|
|
|
class SourceAuthActivity : BaseBrowserActivity(), BrowserCallback {
|
|
|
|
class SourceAuthActivity : BaseBrowserActivity(), BrowserCallback {
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
|
|
|
lateinit var mangaRepositoryFactory: MangaRepository.Factory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var authProvider: MangaParserAuthProvider
|
|
|
|
private lateinit var authProvider: MangaParserAuthProvider
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate2(savedInstanceState: Bundle?) {
|
|
|
|
override fun onCreate2(savedInstanceState: Bundle?, source: MangaSource, repository: ParserMangaRepository?) {
|
|
|
|
val source = MangaSource(intent?.getStringExtra(EXTRA_SOURCE))
|
|
|
|
if (repository == null) {
|
|
|
|
if (source !is MangaParserSource) {
|
|
|
|
|
|
|
|
finishAfterTransition()
|
|
|
|
finishAfterTransition()
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val repository = mangaRepositoryFactory.create(source) as? ParserMangaRepository
|
|
|
|
authProvider = repository.getAuthProvider() ?: run {
|
|
|
|
authProvider = (repository)?.getAuthProvider() ?: run {
|
|
|
|
|
|
|
|
Toast.makeText(
|
|
|
|
Toast.makeText(
|
|
|
|
this,
|
|
|
|
this,
|
|
|
|
getString(R.string.auth_not_supported_by, source.title),
|
|
|
|
getString(R.string.auth_not_supported_by, source.getTitle(this)),
|
|
|
|
Toast.LENGTH_SHORT,
|
|
|
|
Toast.LENGTH_SHORT,
|
|
|
|
).show()
|
|
|
|
).show()
|
|
|
|
finishAfterTransition()
|
|
|
|
finishAfterTransition()
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setDisplayHomeAsUp(true, true)
|
|
|
|
setDisplayHomeAsUp(isEnabled = true, showUpAsClose = true)
|
|
|
|
viewBinding.webView.configureForParser(repository.getRequestHeaders()[CommonHeaders.USER_AGENT])
|
|
|
|
viewBinding.webView.webViewClient = BrowserClient(this)
|
|
|
|
viewBinding.webView.webViewClient = BrowserClient(proxyProvider, this)
|
|
|
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
lifecycleScope.launch {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
proxyProvider.applyWebViewConfig()
|
|
|
|
proxyProvider.applyWebViewConfig()
|
|
|
|
@ -63,7 +51,7 @@ class SourceAuthActivity : BaseBrowserActivity(), BrowserCallback {
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
val url = authProvider.authUrl
|
|
|
|
val url = authProvider.authUrl
|
|
|
|
onTitleChanged(
|
|
|
|
onTitleChanged(
|
|
|
|
source.title,
|
|
|
|
source.getTitle(this@SourceAuthActivity),
|
|
|
|
getString(R.string.loading_),
|
|
|
|
getString(R.string.loading_),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
viewBinding.webView.loadUrl(url)
|
|
|
|
viewBinding.webView.loadUrl(url)
|
|
|
|
@ -92,13 +80,10 @@ class SourceAuthActivity : BaseBrowserActivity(), BrowserCallback {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Contract : ActivityResultContract<MangaSource, Boolean>() {
|
|
|
|
class Contract : ActivityResultContract<MangaSource, Boolean>() {
|
|
|
|
override fun createIntent(context: Context, input: MangaSource): Intent {
|
|
|
|
|
|
|
|
return AppRouter.sourceAuthIntent(context, input)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
|
|
|
|
override fun createIntent(context: Context, input: MangaSource) = AppRouter.sourceAuthIntent(context, input)
|
|
|
|
return resultCode == RESULT_OK
|
|
|
|
|
|
|
|
}
|
|
|
|
override fun parseResult(resultCode: Int, intent: Intent?) = resultCode == RESULT_OK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
|