]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.kt
Add a bottom app bar to Settings. https://redmine.stoutner.com/issues/716
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / AboutActivity.kt
1 /*
2  * Copyright 2016-2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
5  *
6  * Privacy Browser Android 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 Browser Android 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 Browser Android.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.activities
21
22 import android.os.Bundle
23 import android.view.WindowManager
24
25 import androidx.appcompat.app.AppCompatActivity
26 import androidx.appcompat.widget.Toolbar
27 import androidx.preference.PreferenceManager
28 import androidx.viewpager.widget.ViewPager
29
30 import com.google.android.material.tabs.TabLayout
31
32 import com.stoutner.privacybrowser.R
33 import com.stoutner.privacybrowser.adapters.AboutPagerAdapter
34
35 class AboutActivity : AppCompatActivity() {
36     companion object {
37         // Define the companion object constants.  These can be move to being public constants once MainWebViewActivity has been converted to Kotlin.
38         const val BLOCKLIST_VERSIONS = "blocklist_versions"
39     }
40
41     override fun onCreate(savedInstanceState: Bundle?) {
42         // Get a handle for the shared preferences.
43         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
44
45         // Get the preferences.
46         val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)
47         val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
48
49         // Disable screenshots if not allowed.
50         if (!allowScreenshots) {
51             window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
52         }
53
54         // Run the default commands.
55         super.onCreate(savedInstanceState)
56
57         // Get the intent that launched the activity.
58         val launchingIntent = intent
59
60         // Store the blocklist versions.
61         val blocklistVersions = launchingIntent.getStringArrayExtra(BLOCKLIST_VERSIONS)!!
62
63         // Set the content view.
64         if (bottomAppBar) {
65             setContentView(R.layout.about_bottom_appbar)
66         } else {
67             setContentView(R.layout.about_top_appbar)
68         }
69
70         // Get handles for the views.
71         val toolbar = findViewById<Toolbar>(R.id.about_toolbar)
72         val aboutTabLayout = findViewById<TabLayout>(R.id.about_tablayout)
73         val aboutViewPager = findViewById<ViewPager>(R.id.about_viewpager)
74
75         // Set the support action bar.
76         setSupportActionBar(toolbar)
77
78         // Get a handle for the action bar.
79         val actionBar = supportActionBar!!
80
81         // Display the home arrow on the action bar.
82         actionBar.setDisplayHomeAsUpEnabled(true)
83
84         // Initialize the about pager adapter.
85         val aboutPagerAdapter = AboutPagerAdapter(supportFragmentManager, applicationContext, blocklistVersions)
86
87         // Set the view pager adapter.
88         aboutViewPager.adapter = aboutPagerAdapter
89
90         // Keep all the tabs in memory.  This prevents the memory usage updater from running multiple times.
91         aboutViewPager.offscreenPageLimit = 10
92
93         // Connect the tab layout to the view pager.
94         aboutTabLayout.setupWithViewPager(aboutViewPager)
95     }
96 }