From 319571edf364580259972219a0e4edf65b337335 Mon Sep 17 00:00:00 2001 From: jobobby04 Date: Sat, 4 Apr 2020 00:13:54 -0400 Subject: [PATCH] Remove EH custom incognito webview in favor of new activity webview from Dev(I could not get it working with the new system.) --- .../java/exh/ui/webview/EhWebViewActivity.kt | 180 ------------------ 1 file changed, 180 deletions(-) delete mode 100644 app/src/main/java/exh/ui/webview/EhWebViewActivity.kt diff --git a/app/src/main/java/exh/ui/webview/EhWebViewActivity.kt b/app/src/main/java/exh/ui/webview/EhWebViewActivity.kt deleted file mode 100644 index 9be4a9448..000000000 --- a/app/src/main/java/exh/ui/webview/EhWebViewActivity.kt +++ /dev/null @@ -1,180 +0,0 @@ -package exh.ui.webview - -import android.content.ClipData -import android.content.Intent -import android.graphics.Bitmap -import android.net.Uri -import android.os.Build -import android.os.Bundle -import android.util.TypedValue -import android.view.Menu -import android.view.MenuItem -import android.webkit.CookieManager -import android.webkit.WebView -import android.webkit.WebViewClient -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.ui.base.activity.BaseActivity -import eu.kanade.tachiyomi.util.system.clipboardManager -import eu.kanade.tachiyomi.util.system.toast -import exh.ui.login.LoginController -import kotlinx.android.synthetic.main.activity_webview.* -import uy.kohesive.injekt.injectLazy - -class EhWebViewActivity : BaseActivity() { - private val prefs: PreferencesHelper by injectLazy() - private var mobileUserAgent: String? = null - private var isDesktop: Boolean = false - - override fun onCreate(savedInstanceState: Bundle?) { - setTheme(when (prefs.theme()) { - 2 -> R.style.Theme_Tachiyomi_Dark - 3 -> R.style.Theme_Tachiyomi_Amoled - else -> R.style.Theme_Tachiyomi - }) - - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_webview) - setSupportActionBar(toolbar) - - // Opaque status bar - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - val typedValue = TypedValue() - theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true) - window.statusBarColor = typedValue.data - } - - // Show close button - supportActionBar?.setDisplayHomeAsUpEnabled(true) - supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp) - - val url = intent.getStringExtra(KEY_URL) - - // Set immediately (required for correct title after rotation) - title = url - // Configure webview - webview.settings.javaScriptEnabled = true - webview.settings.domStorageEnabled = true - webview.settings.databaseEnabled = true - webview.settings.useWideViewPort = true - webview.settings.loadWithOverviewMode = true - webview.settings.builtInZoomControls = true - webview.settings.displayZoomControls = false - webview.webViewClient = object : WebViewClient() { - override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { - super.onPageStarted(view, url, favicon) - invalidateOptionsMenu() - appbar.setExpanded(true, true) - title = "Loading: $url" - } - - override fun onPageFinished(view: WebView?, url: String?) { - super.onPageFinished(view, url) - title = url - invalidateOptionsMenu() - } - } - - // Configure E-Hentai/ExHentai cookies - for(domain in listOf( - "www.exhentai.org", - "exhentai.org", - "www.e-hentai.org", - "e-hentai.org", - "g.e-hentai.org" - )) { - for(cookie in listOf( - LoginController.MEMBER_ID_COOKIE to prefs.memberIdVal().getOrDefault(), - LoginController.PASS_HASH_COOKIE to prefs.passHashVal().getOrDefault(), - LoginController.IGNEOUS_COOKIE to prefs.igneousVal().getOrDefault() - )) { - val cookieString = "${cookie.first}=${cookie.second}; domain=$domain; path=/;" - CookieManager.getInstance().setCookie(domain, cookieString) - } - } - - // Long-click to copy URL - toolbar.setOnLongClickListener { - toast("URL copied.") - clipboardManager.primaryClip = ClipData.newUri( - contentResolver, - webview.title, - Uri.parse(webview.url) - ) - true - } - - if(savedInstanceState == null) { - mobileUserAgent = webview.settings.userAgentString - - if(url == null) { - toast("No URL supplied!") - finish() - return - } - - webview.loadUrl(url) - } - } - - override fun onRestoreInstanceState(savedInstanceState: Bundle?) { - super.onRestoreInstanceState(savedInstanceState) - savedInstanceState?.getString(STATE_KEY_MOBILE_USER_AGENT)?.let { - mobileUserAgent = it - } - savedInstanceState?.getBoolean(STATE_KEY_IS_DESKTOP)?.let { - isDesktop = it - } - webview.restoreState(savedInstanceState) - } - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState?.putString(STATE_KEY_MOBILE_USER_AGENT, mobileUserAgent) - outState?.putBoolean(STATE_KEY_IS_DESKTOP, isDesktop) - webview.saveState(outState) - } - - override fun onPrepareOptionsMenu(menu: Menu?): Boolean { - menu?.findItem(R.id.action_forward)?.isEnabled = webview.canGoForward() - - return super.onPrepareOptionsMenu(menu) - } - - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.menu_webview, menu) - return super.onCreateOptionsMenu(menu) - } - - override fun onBackPressed() { - if(webview.canGoBack()) - webview.goBack() - else - super.onBackPressed() - } - - override fun onOptionsItemSelected(item: MenuItem?): Boolean { - when(item?.itemId) { - android.R.id.home -> finish() - R.id.action_refresh -> webview.reload() - R.id.action_forward -> webview.goForward() - R.id.action_open_in_browser -> { - val url = webview.url - if(url != null) { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) - } else { - toast("An error occurred while opening this page in your browser!") - } - } - } - return super.onOptionsItemSelected(item) - } - - companion object { - const val KEY_URL = "url" - - const val STATE_KEY_MOBILE_USER_AGENT = "mobile_user_agent" - const val STATE_KEY_IS_DESKTOP = "is_desktop" - } -}