Skip to content

Commit

Permalink
disable multi-window mode by long pressing translation action; fix in…
Browse files Browse the repository at this point in the history
…cognito mode sync issue
  • Loading branch information
plateaukao committed Jun 7, 2021
1 parent aad59fb commit aa89961
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 11 additions & 3 deletions app/src/main/java/de/baumann/browser/activity/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
if (text == "null") {
NinjaToast.showShort(this@BrowserActivity, "null string")
} else {
enableMultiWindow()
toggleMultiWindow(true)
try {
val intent = Intent().apply {
action = "com.onyx.intent.ACTION_DICT_TRANSLATION"
Expand All @@ -741,8 +741,10 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
}
}

private fun enableMultiWindow() {
val intent = Intent().apply { action = "com.onyx.action.START_MULTI_WINDOW" }
private fun toggleMultiWindow(isEnabled: Boolean) {
val intent = Intent().apply {
action = if (isEnabled) "com.onyx.action.START_MULTI_WINDOW" else "com.onyx.action.QUIT_MULTI_WINDOW"
}
sendBroadcast(intent)
}

Expand Down Expand Up @@ -919,9 +921,11 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener

binding.omniboxBookmark.setOnClickListener { openBookmarkPage() }
binding.omniboxBookmark.setOnLongClickListener { saveBookmark(); true }
binding.toolbarTranslate.setOnLongClickListener { toggleMultiWindow(false); true }

sp.registerOnSharedPreferenceChangeListener(preferenceChangeListener)


reorderToolbarIcons()
}

Expand All @@ -944,6 +948,10 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
}
key.equals(ConfigManager.K_IS_INCOGNITO_MODE) -> {
updateWebViewCountUI()
NinjaToast.showShort(
this,
"Incognito mode is " + if (config.isIncognitoMode) "enabled." else "disabled."
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class ConfigManager(private val context: Context) {

var shouldSaveTabs: Boolean
get() = sp.getBoolean(K_SHOULD_SAVE_TABS, false)
set(value) {sp.edit { putBoolean(K_SHOULD_SAVE_TABS, value) } }
set(value) { sp.edit { putBoolean(K_SHOULD_SAVE_TABS, value) } }

var isIncognitoMode: Boolean
get() = sp.getBoolean(K_IS_INCOGNITO_MODE, false)
set(value) {sp.edit { putBoolean(K_IS_INCOGNITO_MODE, value) } }
set(value) {
cookies = !value
saveHistory = !value
sp.edit { putBoolean(K_IS_INCOGNITO_MODE, value) }
}

var shouldInvert: Boolean
get() = sp.getBoolean(K_SHOULD_INVERT, false)
Expand Down

0 comments on commit aa89961

Please sign in to comment.