]> gitweb.stoutner.com Git - PrivacyCell.git/blob - app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt
Add an option to use a bottom app bar. https://redmine.stoutner.com/issues/749
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / activities / SettingsActivity.kt
1 /*
2  * Copyright © 2021 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
5  *
6  * Privacy Cell is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Cell is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Cell.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacycell.activities
21
22 import android.os.Bundle
23 import android.view.MenuItem
24
25 import androidx.appcompat.app.AppCompatActivity
26 import androidx.appcompat.widget.Toolbar
27 import androidx.preference.PreferenceManager
28
29 import com.stoutner.privacycell.R
30 import com.stoutner.privacycell.fragments.SettingsFragment
31
32 class SettingsActivity : AppCompatActivity() {
33     override fun onCreate(savedInstanceState: Bundle?) {
34         // Run the default commands.
35         super.onCreate(savedInstanceState)
36
37         // Get a handle for the shared preferences.
38         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
39
40         // Get the bottom app bar preference.
41         val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
42
43         // Set the content view.
44         if (bottomAppBar) {
45             setContentView(R.layout.settings_bottom_appbar)
46         } else {
47             setContentView(R.layout.settings_top_appbar)
48         }
49
50         // Get a handle for the toolbar.
51         val toolbar = findViewById<Toolbar>(R.id.toolbar)
52
53         // Set the support action bar.
54         setSupportActionBar(toolbar)
55
56         // Get a handle for the action bar.
57         val actionBar = supportActionBar!!
58
59         // Display the home arrow on the action bar.
60         actionBar.setDisplayHomeAsUpEnabled(true)
61
62         // Load the preferences fragment.
63         supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit()
64     }
65
66     override fun onOptionsItemSelected(item: MenuItem): Boolean {
67         // As there is only one option, go back.
68         onBackPressed()
69
70         // Consume the event.
71         return true
72     }
73 }