-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathQkActivity.kt
More file actions
112 lines (97 loc) · 3.64 KB
/
Copy pathQkActivity.kt
File metadata and controls
112 lines (97 loc) · 3.64 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.common.base
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.LinearLayoutManager
import com.moez.QKSMS.common.util.softKey.SoftKeyGuide
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.util.Preferences
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import javax.inject.Inject
abstract class QkActivity : AppCompatActivity() {
@Inject lateinit var prefs: Preferences
protected val menu: Subject<Menu> = BehaviorSubject.create()
protected val toolbar: Toolbar? get() = findViewById(R.id.toolbar)
protected val toolbarTitle: TextView? get() = findViewById(R.id.toolbarTitle)
// Create an instance for Kyocera soft keys
protected val softkey: SoftKeyGuide get() = SoftKeyGuide.create(window)
@SuppressLint("InlinedApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
onNewIntent(intent)
disableScreenshots(prefs.disableScreenshots.get())
}
override fun onResume() {
super.onResume()
disableScreenshots(prefs.disableScreenshots.get())
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun setContentView(layoutResID: Int) {
super.setContentView(layoutResID)
setSupportActionBar(toolbar)
title = title // The title may have been set before layout inflation
}
override fun setContentView(view: View?) {
super.setContentView(view)
setSupportActionBar(toolbar)
title = title // The title may have been set before layout inflation
}
override fun setTitle(titleId: Int) {
title = getString(titleId)
}
override fun setTitle(title: CharSequence?) {
super.setTitle(title)
toolbarTitle?.text = title
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val result = super.onCreateOptionsMenu(menu)
if (menu != null) {
this.menu.onNext(menu)
}
return result
}
protected open fun showBackButton(show: Boolean) {
supportActionBar?.setDisplayHomeAsUpEnabled(show)
}
private fun disableScreenshots(disableScreenshots: Boolean) {
if (disableScreenshots) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
}