Binding WebViewActivity + LoginPreference

when does this end
This commit is contained in:
Jays2Kings 2021-03-29 23:13:12 -04:00
parent ef737dd40b
commit d4addb2e13
4 changed files with 57 additions and 56 deletions

View File

@ -14,10 +14,10 @@ import eu.kanade.tachiyomi.databinding.SourceGlobalSearchControllerBinding
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.scrollViewWith
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.withFadeTransaction
import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.android.synthetic.main.source_global_search_controller.*
/**
@ -133,7 +133,7 @@ open class GlobalSearchController(
adapter = GlobalSearchAdapter(this)
recycler.updatePaddingRelative(
top = (activity?.toolbar?.height ?: 0) +
top = (activityBinding?.toolbar?.height ?: 0) +
(activity?.window?.decorView?.rootWindowInsets?.systemWindowInsetTop ?: 0)
)

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.webview
package eu.kanade.tachiyomi.ui.binding.webview
import android.content.res.Configuration
import android.graphics.Color
@ -25,7 +25,6 @@ import eu.kanade.tachiyomi.util.view.setStyle
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePadding
import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.webview_activity.*
open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
@ -33,17 +32,18 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = WebviewActivityBinding.inflate(layoutInflater)
delegate.localNightMode = ThemeUtil.nightMode(preferences.theme())
setContentView(R.layout.webview_activity)
setSupportActionBar(toolbar)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar.setNavigationOnClickListener {
binding.toolbar.setNavigationOnClickListener {
super.onBackPressed()
}
toolbar.navigationIcon?.setTint(getResourceColor(R.attr.actionBarTintColor))
binding.toolbar.navigationIcon?.setTint(getResourceColor(R.attr.actionBarTintColor))
val container: ViewGroup = findViewById(R.id.web_view_layout)
val content: LinearLayout = findViewById(R.id.web_linear_layout)
val content: LinearLayout = binding.webLinearLayout
container.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
content.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
@ -66,8 +66,8 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
insets.systemWindowInsetBottom
)
}
swipe_refresh.setStyle()
swipe_refresh.setOnRefreshListener {
binding.swipeRefresh.setStyle()
binding.swipeRefresh.setOnRefreshListener {
refreshPage()
}
@ -110,23 +110,23 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
insets
}
swipe_refresh.isEnabled = false
binding.swipeRefresh.isEnabled = false
if (bundle == null) {
webview.setDefaultSettings()
binding.webview.setDefaultSettings()
webview.webChromeClient = object : WebChromeClient() {
binding.webview.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) {
progressBar.visible()
progressBar.progress = newProgress
binding.progressBar.visible()
binding.progressBar.progress = newProgress
if (newProgress == 100) {
progressBar.invisible()
binding.progressBar.invisible()
}
super.onProgressChanged(view, newProgress)
}
}
val marginB = webview.marginBottom
webview.setOnApplyWindowInsetsListener { v, insets ->
val marginB = binding.webview.marginBottom
binding.webview.setOnApplyWindowInsetsListener { v, insets ->
val bottomInset = insets.systemWindowInsetBottom
v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = marginB + bottomInset
@ -134,13 +134,13 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
insets
}
} else {
webview.restoreState(bundle)
binding.webview.restoreState(bundle)
}
}
private fun refreshPage() {
swipe_refresh.isRefreshing = true
webview.reload()
binding.swipeRefresh.isRefreshing = true
binding.webview.reload()
}
override fun onConfigurationChanged(newConfig: Configuration) {
@ -153,14 +153,14 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
),
255
)
toolbar.setBackgroundColor(getResourceColor(R.attr.colorSecondary))
toolbar.popupTheme = if (lightMode) R.style.ThemeOverlay_MaterialComponents else R
binding.toolbar.setBackgroundColor(getResourceColor(R.attr.colorSecondary))
binding.toolbar.popupTheme = if (lightMode) R.style.ThemeOverlay_MaterialComponents else R
.style.ThemeOverlay_MaterialComponents_Dark
val tintColor = getResourceColor(R.attr.actionBarTintColor)
toolbar.navigationIcon?.setTint(tintColor)
toolbar.overflowIcon?.mutate()
toolbar.setTitleTextColor(tintColor)
toolbar.overflowIcon?.setTint(tintColor)
binding.toolbar.navigationIcon?.setTint(tintColor)
binding.toolbar.overflowIcon?.mutate()
binding.toolbar.setTitleTextColor(tintColor)
binding.toolbar.overflowIcon?.setTint(tintColor)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
window.navigationBarColor = getResourceColor(R.attr.colorPrimaryVariant)
@ -168,11 +168,11 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
window.navigationBarColor = getResourceColor(android.R.attr.colorBackground)
}
web_linear_layout.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
binding.webLinearLayout.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && lightMode) {
web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility.or(
binding.webLinearLayout.systemUiVisibility = binding.webLinearLayout.systemUiVisibility.or(
View
.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
)
@ -189,7 +189,7 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
}
}
override fun onBackPressed() {
if (webview.canGoBack()) webview.goBack()
if (binding.webview.canGoBack()) binding.webview.goBack()
else super.onBackPressed()
}
}

View File

@ -17,11 +17,11 @@ import androidx.core.graphics.ColorUtils
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.binding.webview.BaseWebViewActivity
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.android.synthetic.main.webview_activity.*
import uy.kohesive.injekt.injectLazy
open class WebViewActivity : BaseWebViewActivity() {
@ -52,14 +52,14 @@ open class WebViewActivity : BaseWebViewActivity() {
container.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
content.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
swipe_refresh.isEnabled = false
binding.swipeRefresh.isEnabled = false
if (bundle == null) {
val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource ?: return
val url = intent.extras!!.getString(URL_KEY) ?: return
val headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }
webview.webViewClient = object : WebViewClientCompat() {
binding.webview.webViewClient = object : WebViewClientCompat() {
override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean {
view.loadUrl(url)
return true
@ -69,10 +69,10 @@ open class WebViewActivity : BaseWebViewActivity() {
super.onPageFinished(view, url)
invalidateOptionsMenu()
title = view?.title
swipe_refresh.isEnabled = true
swipe_refresh?.isRefreshing = false
val thing = view?.evaluateJavascript("getComputedStyle(document.querySelector('body')).backgroundColor") {
nested_view.setBackgroundColor(parseHTMLColor(it))
binding.swipeRefresh.isEnabled = true
binding.swipeRefresh?.isRefreshing = false
view?.evaluateJavascript("getComputedStyle(document.querySelector('body')).backgroundColor") {
binding.nestedView.setBackgroundColor(parseHTMLColor(it))
}
}
@ -83,12 +83,12 @@ open class WebViewActivity : BaseWebViewActivity() {
override fun onPageCommitVisible(view: WebView?, url: String?) {
super.onPageCommitVisible(view, url)
nested_view.scrollTo(0, 0)
binding.nestedView.scrollTo(0, 0)
}
}
webview.settings.userAgentString = source.headers["User-Agent"]
webview.loadUrl(url, headers)
binding.webview.settings.userAgentString = source.headers["User-Agent"]
binding.webview.loadUrl(url, headers)
}
}
@ -116,22 +116,22 @@ open class WebViewActivity : BaseWebViewActivity() {
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
val backItem = toolbar.menu.findItem(R.id.action_web_back)
val forwardItem = toolbar.menu.findItem(R.id.action_web_forward)
backItem?.isEnabled = webview.canGoBack()
forwardItem?.isEnabled = webview.canGoForward()
val hasHistory = webview.canGoBack() || webview.canGoForward()
val backItem = binding.toolbar.menu.findItem(R.id.action_web_back)
val forwardItem = binding.toolbar.menu.findItem(R.id.action_web_forward)
backItem?.isEnabled = binding.webview.canGoBack()
forwardItem?.isEnabled = binding.webview.canGoForward()
val hasHistory = binding.webview.canGoBack() || binding.webview.canGoForward()
backItem?.isVisible = hasHistory
forwardItem?.isVisible = hasHistory
val tintColor = getResourceColor(R.attr.actionBarTintColor)
val translucentWhite = ColorUtils.setAlphaComponent(tintColor, 127)
backItem.icon?.setTint(if (webview.canGoBack()) tintColor else translucentWhite)
forwardItem?.icon?.setTint(if (webview.canGoForward()) tintColor else translucentWhite)
backItem.icon?.setTint(if (binding.webview.canGoBack()) tintColor else translucentWhite)
forwardItem?.icon?.setTint(if (binding.webview.canGoForward()) tintColor else translucentWhite)
return super.onPrepareOptionsMenu(menu)
}
override fun onBackPressed() {
if (webview.canGoBack()) webview.goBack()
if (binding.webview.canGoBack()) binding.webview.goBack()
else super.onBackPressed()
}
@ -141,8 +141,8 @@ open class WebViewActivity : BaseWebViewActivity() {
*/
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_web_back -> webview.goBack()
R.id.action_web_forward -> webview.goForward()
R.id.action_web_back -> binding.webview.goBack()
R.id.action_web_forward -> binding.webview.goForward()
R.id.action_web_share -> shareWebpage()
R.id.action_web_browser -> openInBrowser()
}
@ -153,7 +153,7 @@ open class WebViewActivity : BaseWebViewActivity() {
try {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, webview.url)
putExtra(Intent.EXTRA_TEXT, binding.webview.url)
}
startActivity(Intent.createChooser(intent, getString(R.string.share)))
} catch (e: Exception) {
@ -162,6 +162,6 @@ open class WebViewActivity : BaseWebViewActivity() {
}
private fun openInBrowser() {
openInBrowser(webview.url)
openInBrowser(binding.webview.url)
}
}

View File

@ -7,7 +7,7 @@ import android.util.AttributeSet
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import eu.kanade.tachiyomi.R
import kotlinx.android.synthetic.main.pref_widget_imageview.view.*
import eu.kanade.tachiyomi.databinding.PrefWidgetImageviewBinding
class LoginPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Preference(context, attrs) {
@ -18,12 +18,13 @@ class LoginPreference @JvmOverloads constructor(context: Context, attrs: Attribu
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val binding = PrefWidgetImageviewBinding.bind(holder.itemView)
holder.itemView.image_view.setImageResource(
binding.imageView.setImageResource(
if (getPersistedString("").isNullOrEmpty()) android.R.color.transparent
else R.drawable.ic_done_24dp
)
holder.itemView.image_view.imageTintList =
binding.imageView.imageTintList =
ColorStateList.valueOf(Color.parseColor("#FF4CAF50"))
}