/
SettingsActivity.kt
47 lines (39 loc) · 1.38 KB
/
SettingsActivity.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.reference.browser.settings
import android.R.id.content
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import mozilla.components.support.base.feature.BackHandler
class SettingsActivity : AppCompatActivity(), SettingsFragment.ActionBarUpdater {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
with(supportFragmentManager.beginTransaction()) {
replace(content, SettingsFragment())
commit()
}
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
android.R.id.home -> {
onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
override fun updateTitle(titleResId: Int) {
setTitle(titleResId)
}
override fun onBackPressed() {
supportFragmentManager.fragments.forEach {
if (it is BackHandler && it.onBackPressed()) {
return
} else {
super.onBackPressed()
}
}
}
}