]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.kt
Switch the FragmentPagerAdapters to FragmentStateAdapters. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / AboutActivity.kt
1 /*
2  * Copyright 2016-2023 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.viewpager2.widget.ViewPager2
29
30 import com.google.android.material.tabs.TabLayout
31 import com.google.android.material.tabs.TabLayoutMediator
32
33 import com.stoutner.privacybrowser.R
34 import com.stoutner.privacybrowser.adapters.AboutStateAdapter
35
36 const val FILTERLIST_VERSIONS = "filterlist_versions"
37
38 class AboutActivity : AppCompatActivity() {
39     override fun onCreate(savedInstanceState: Bundle?) {
40         // Get a handle for the shared preferences.
41         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
42
43         // Get the preferences.
44         val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)
45         val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
46
47         // Disable screenshots if not allowed.
48         if (!allowScreenshots) {
49             window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
50         }
51
52         // Run the default commands.
53         super.onCreate(savedInstanceState)
54
55         // Get the intent that launched the activity.
56         val launchingIntent = intent
57
58         // Get the filter list versions.
59         val filterListVersions = launchingIntent.getStringArrayExtra(FILTERLIST_VERSIONS)!!
60
61         // Set the content view.
62         if (bottomAppBar)
63             setContentView(R.layout.about_bottom_appbar)
64         else
65             setContentView(R.layout.about_top_appbar)
66
67         // Get handles for the views.
68         val toolbar = findViewById<Toolbar>(R.id.about_toolbar)
69         val aboutTabLayout = findViewById<TabLayout>(R.id.about_tablayout)
70         val aboutViewPager2 = findViewById<ViewPager2>(R.id.about_viewpager2)
71
72         // Set the support action bar.
73         setSupportActionBar(toolbar)
74
75         // Get a handle for the action bar.
76         val actionBar = supportActionBar!!
77
78         // Display the home arrow on the action bar.
79         actionBar.setDisplayHomeAsUpEnabled(true)
80
81         // Initialize the about state adapter.
82         val aboutStateAdapter = AboutStateAdapter(this, filterListVersions)
83
84         // Set the view pager adapter.
85         aboutViewPager2.adapter = aboutStateAdapter
86
87         // Create a tab layout mediator.  Tab numbers start at 0.
88         TabLayoutMediator(aboutTabLayout, aboutViewPager2) { tab, position ->
89             // Set the tab text based on the position.
90             tab.text = when (position) {
91                 0 -> getString(R.string.version)
92                 1 -> getString(R.string.permissions)
93                 2 -> getString(R.string.privacy_policy)
94                 3 -> getString(R.string.changelog)
95                 4 -> getString(R.string.licenses)
96                 5 -> getString(R.string.contributors)
97                 6 -> getString(R.string.links)
98                 else -> ""
99             }
100         }.attach()
101     }
102 }