Skip to content

Commit

Permalink
fix: power consumption due to touch area type update
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed May 16, 2023
1 parent 185d5fb commit cfdbca9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,7 @@ open class BrowserActivity : FragmentActivity(), BrowserController {

private val browserContainer: BrowserContainer = BrowserContainer()

private val touchController: TouchAreaViewController by lazy {
TouchAreaViewController(
rootView = binding.root,
pageUpAction = { ninjaWebView.pageUpWithNoAnimation() },
pageTopAction = { ninjaWebView.jumpToTop() },
pageDownAction = { ninjaWebView.pageDownWithNoAnimation() },
pageBottomAction = { ninjaWebView.jumpToBottom() },
)
}
private lateinit var touchController: TouchAreaViewController

private lateinit var twoPaneController: TwoPaneController

Expand Down Expand Up @@ -253,6 +245,8 @@ open class BrowserActivity : FragmentActivity(), BrowserController {
initTouchArea()
initActionModeViewModel()

initTouchAreaViewController()

downloadReceiver = createDownloadReceiver(this)
registerReceiver(downloadReceiver, IntentFilter(ACTION_DOWNLOAD_COMPLETE))
dispatchIntent(intent)
Expand All @@ -268,6 +262,16 @@ open class BrowserActivity : FragmentActivity(), BrowserController {
initLanguageLabel()
}

private fun initTouchAreaViewController() {
touchController = TouchAreaViewController(
rootView = binding.root,
pageUpAction = { ninjaWebView.pageUpWithNoAnimation() },
pageTopAction = { ninjaWebView.jumpToTop() },
pageDownAction = { ninjaWebView.pageDownWithNoAnimation() },
pageBottomAction = { ninjaWebView.jumpToBottom() },
)
}

private fun initActionModeViewModel() {
lifecycleScope.launch {
actionModeMenuViewModel.actionModeMenuState.collect { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ class TouchAreaViewController(
if (enabled) showTouchAreaHint()
}

private var disabledTemporarily = false
fun maybeDisableTemporarily() {
if (config.enableTouchTurn && config.touchAreaHint && config.hideTouchAreaWhenInput) {
if (this::touchAreaPageUp.isInitialized) {
disabledTemporarily = true
with(touchAreaPageUp) {
visibility = View.GONE
setOnLongClickListener(null)
Expand All @@ -205,7 +207,13 @@ class TouchAreaViewController(
}

fun maybeEnableAgain() {
if (config.enableTouchTurn && config.touchAreaHint && config.hideTouchAreaWhenInput) {
if (
disabledTemporarily &&
config.enableTouchTurn &&
config.touchAreaHint &&
config.hideTouchAreaWhenInput
) {
disabledTemporarily = false
updateTouchAreaType()
}
}
Expand Down

0 comments on commit cfdbca9

Please sign in to comment.