]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.kt
Switch the FragmentPagerAdapters to FragmentStateAdapters. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / GuideActivity.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.GuideStateAdapter
35
36 class GuideActivity : AppCompatActivity() {
37     override fun onCreate(savedInstanceState: Bundle?) {
38         // Get a handle for the shared preferences.
39         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
40
41         // Get the preferences.
42         val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)
43         val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
44
45         // Disable screenshots if not allowed.
46         if (!allowScreenshots) {
47             window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
48         }
49
50         // Run the default commands.
51         super.onCreate(savedInstanceState)
52
53         // Set the content view.
54         if (bottomAppBar) {
55             setContentView(R.layout.guide_bottom_appbar)
56         } else {
57             setContentView(R.layout.guide_top_appbar)
58         }
59
60         // Get handles for the views.
61         val toolbar = findViewById<Toolbar>(R.id.guide_toolbar)
62         val guideTabLayout = findViewById<TabLayout>(R.id.guide_tablayout)
63         val guideViewPager2 = findViewById<ViewPager2>(R.id.guide_viewpager2)
64
65         // Set the support action bar.
66         setSupportActionBar(toolbar)
67
68         // Get a handle for the action bar.
69         val actionBar = supportActionBar!!
70
71         // Display the home arrow on the action bar.
72         actionBar.setDisplayHomeAsUpEnabled(true)
73
74         // Initialize the guide state adapter.
75         val guideStateAdapter = GuideStateAdapter(this)
76
77         // Set the view pager adapter.
78         guideViewPager2.adapter = guideStateAdapter
79
80         // Create a tab layout mediator.  Tab numbers start at 0.
81         TabLayoutMediator(guideTabLayout, guideViewPager2) { tab, position ->
82             // Set the tab text based on the position.
83             tab.text = when (position) {
84                 0 -> getString(R.string.overview)
85                 1 -> getString(R.string.javascript)
86                 2 -> getString(R.string.local_storage)
87                 3 -> getString(R.string.user_agent)
88                 4 -> getString(R.string.requests)
89                 5 -> getString(R.string.domain_settings)
90                 6 -> getString(R.string.ssl_certificates)
91                 7 -> getString(R.string.proxies)
92                 8 -> getString(R.string.tracking_ids)
93                 9 -> getString(R.string.gui)
94                 else -> ""
95             }
96         }.attach()
97     }
98 }