]> gitweb.stoutner.com Git - PrivacyCell.git/blobdiff - 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
diff --git a/app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt b/app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt
new file mode 100644 (file)
index 0000000..279d836
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2021 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
+ *
+ * Privacy Cell 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.
+ *
+ * Privacy Cell 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 Privacy Cell.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.stoutner.privacycell.activities
+
+import android.os.Bundle
+import android.view.MenuItem
+
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.Toolbar
+import androidx.preference.PreferenceManager
+
+import com.stoutner.privacycell.R
+import com.stoutner.privacycell.fragments.SettingsFragment
+
+class SettingsActivity : AppCompatActivity() {
+    override fun onCreate(savedInstanceState: Bundle?) {
+        // Run the default commands.
+        super.onCreate(savedInstanceState)
+
+        // Get a handle for the shared preferences.
+        val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
+
+        // Get the bottom app bar preference.
+        val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
+
+        // Set the content view.
+        if (bottomAppBar) {
+            setContentView(R.layout.settings_bottom_appbar)
+        } else {
+            setContentView(R.layout.settings_top_appbar)
+        }
+
+        // Get a handle for the toolbar.
+        val toolbar = findViewById<Toolbar>(R.id.toolbar)
+
+        // Set the support action bar.
+        setSupportActionBar(toolbar)
+
+        // Get a handle for the action bar.
+        val actionBar = supportActionBar!!
+
+        // Display the home arrow on the action bar.
+        actionBar.setDisplayHomeAsUpEnabled(true)
+
+        // Load the preferences fragment.
+        supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit()
+    }
+
+    override fun onOptionsItemSelected(item: MenuItem): Boolean {
+        // As there is only one option, go back.
+        onBackPressed()
+
+        // Consume the event.
+        return true
+    }
+}
\ No newline at end of file