-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
MainActivity.kt
90 lines (75 loc) · 2.76 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.cookiegames.smartcookie
import android.content.Intent
import android.os.Build
import android.view.KeyEvent
import android.view.Menu
import android.webkit.CookieManager
import android.webkit.CookieSyncManager
import androidx.appcompat.view.menu.MenuBuilder
import com.cookiegames.smartcookie.browser.activity.BrowserActivity
import io.reactivex.Completable
class MainActivity : BrowserActivity() {
@Suppress("DEPRECATION")
public override fun updateCookiePreference(): Completable = Completable.fromAction {
val cookieManager = CookieManager.getInstance()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this@MainActivity)
}
cookieManager.setAcceptCookie(userPreferences.cookiesEnabled)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
if(userPreferences.bottomBar){
menuInflater.inflate(R.menu.inverted, menu)
}
else{
menuInflater.inflate(R.menu.main, menu)
}
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)
}
menu.findItem(R.id.quit_app).setVisible(userPreferences.showExtraOptions)
return super.onCreateOptionsMenu(menu)
}
override fun onNewIntent(intent: Intent) =
if (intent.action == INTENT_PANIC_TRIGGER) {
// TODO: investigate why this is here and why removing it fixes an intent issue
//panicClean()
} else {
handleNewIntent(intent)
super.onNewIntent(intent)
}
override fun onPause() {
super.onPause()
saveOpenTabs()
}
override fun onResume(){
super.onResume()
invalidateOptionsMenu()
}
override fun updateHistory(title: String?, url: String) = addItemToHistory(title, url)
override fun isIncognito() = false
override fun closeActivity() = closeDrawers {
performExitCleanUp()
moveTaskToBack(true)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
super.finishAndRemoveTask()
}
else {
super.finish()
}
}
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (event.action == KeyEvent.ACTION_DOWN && event.isCtrlPressed) {
when (event.keyCode) {
KeyEvent.KEYCODE_P ->
// Open a new private window
if (event.isShiftPressed) {
startActivity(IncognitoActivity.createIntent(this))
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale)
return true
}
}
}
return super.dispatchKeyEvent(event)
}
}