Release 1.7.
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / activities / ProtocolsActivity.kt
1 /*
2  * Copyright © 2022 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.View
24 import android.widget.AdapterView
25 import android.widget.ListView
26 import android.widget.TextView
27
28 import androidx.appcompat.app.AppCompatActivity
29 import androidx.appcompat.widget.Toolbar
30 import androidx.preference.PreferenceManager
31
32 import com.stoutner.privacycell.R
33 import com.stoutner.privacycell.adapters.ProtocolArrayAdapter
34 import com.stoutner.privacycell.dataclasses.Protocol
35 import com.stoutner.privacycell.dialogs.WebViewDialog
36
37 class ProtocolsActivity : AppCompatActivity() {
38     public override fun onCreate(savedInstanceState: Bundle?) {
39         // Run the default commands.
40         super.onCreate(savedInstanceState)
41
42         // Get a handle for the shared preferences.
43         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
44
45         // Get the bottom app bar preference.
46         val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
47
48         // Set the content view.
49         if (bottomAppBar) {
50             setContentView(R.layout.protocols_bottom_appbar)
51         } else {
52             setContentView(R.layout.protocols_top_appbar)
53         }
54
55         // Get handles for the views.
56         val toolbar = findViewById<Toolbar>(R.id.toolbar)
57         val listView = findViewById<ListView>(R.id.listview)
58
59         // Set the toolbar as the action bar.
60         setSupportActionBar(toolbar)
61
62         // Get a handle for the action bar.
63         val actionBar = supportActionBar!!
64
65         // Display the back arrow in the action bar.
66         actionBar.setDisplayHomeAsUpEnabled(true)
67
68         // Create a protocol array list.
69         val protocolArrayList = ArrayList<Protocol>()
70
71         // Populate the protocol array list.  Headers are followed by `true`.
72         protocolArrayList.add(Protocol(getString(R.string.protocol_2g), isHeader = true, isAdditionalNetworkInfo = false))
73         protocolArrayList.add(Protocol(getString(R.string.cdma_detail), isHeader = false, isAdditionalNetworkInfo = false))
74         protocolArrayList.add(Protocol(getString(R.string.gsm_detail), isHeader = false, isAdditionalNetworkInfo = false))
75         protocolArrayList.add(Protocol(getString(R.string.iden_detail), isHeader = false, isAdditionalNetworkInfo = false))
76         protocolArrayList.add(Protocol(getString(R.string.gprs_detail), isHeader = false, isAdditionalNetworkInfo = false))
77         protocolArrayList.add(Protocol(getString(R.string.edge_detail), isHeader = false, isAdditionalNetworkInfo = false))
78
79         protocolArrayList.add(Protocol(getString(R.string.protocol_3g), isHeader = true, isAdditionalNetworkInfo = false))
80         protocolArrayList.add(Protocol(getString(R.string.rtt_detail), isHeader = false, isAdditionalNetworkInfo = false))
81         protocolArrayList.add(Protocol(getString(R.string.evdo_0_detail), isHeader = false, isAdditionalNetworkInfo = false))
82         protocolArrayList.add(Protocol(getString(R.string.evdo_a_detail), isHeader = false, isAdditionalNetworkInfo = false))
83         protocolArrayList.add(Protocol(getString(R.string.evdo_b_detail), isHeader = false, isAdditionalNetworkInfo = false))
84         protocolArrayList.add(Protocol(getString(R.string.ehrpd_detail), isHeader = false, isAdditionalNetworkInfo = false))
85         protocolArrayList.add(Protocol(getString(R.string.umts_detail), isHeader = false, isAdditionalNetworkInfo = false))
86         protocolArrayList.add(Protocol(getString(R.string.td_scdma_detail), isHeader = false, isAdditionalNetworkInfo = false))
87         protocolArrayList.add(Protocol(getString(R.string.hsdpa_detail), isHeader = false, isAdditionalNetworkInfo = false))
88         protocolArrayList.add(Protocol(getString(R.string.hsupa_detail), isHeader = false, isAdditionalNetworkInfo = false))
89         protocolArrayList.add(Protocol(getString(R.string.hspa_detail), isHeader = false, isAdditionalNetworkInfo = false))
90         protocolArrayList.add(Protocol(getString(R.string.hspap_detail), isHeader = false, isAdditionalNetworkInfo = false))
91
92         protocolArrayList.add(Protocol(getString(R.string.protocol_4g), isHeader = true, isAdditionalNetworkInfo = false))
93         protocolArrayList.add(Protocol(getString(R.string.lte_detail), isHeader = false, isAdditionalNetworkInfo = false))
94         protocolArrayList.add(Protocol(getString(R.string.lte_ca_detail), isHeader = false, isAdditionalNetworkInfo = true))
95         protocolArrayList.add(Protocol(getString(R.string.lte_advanced_pro_detail), isHeader = false, isAdditionalNetworkInfo = true))
96         protocolArrayList.add(Protocol(getString(R.string.nr_nsa_detail), isHeader = false, isAdditionalNetworkInfo = true))
97         protocolArrayList.add(Protocol(getString(R.string.nr_nsa_mmwave_detail), isHeader = false, isAdditionalNetworkInfo = true))
98
99         protocolArrayList.add(Protocol(getString(R.string.protocol_5g), isHeader = true, isAdditionalNetworkInfo = false))
100         protocolArrayList.add(Protocol(getString(R.string.nr_detail), isHeader = false, isAdditionalNetworkInfo = false))
101         protocolArrayList.add(Protocol(getString(R.string.nr_advanced_detail), isHeader = false, isAdditionalNetworkInfo = true))
102
103         protocolArrayList.add(Protocol(getString(R.string.protocol_other), isHeader = true, isAdditionalNetworkInfo = false))
104         protocolArrayList.add(Protocol(getString(R.string.iwlan_detail), isHeader = false, isAdditionalNetworkInfo = false))
105
106         // Instantiate the protocol array adapter.
107         val protocolArrayAdapter = ProtocolArrayAdapter(this, protocolArrayList)
108
109         // Set the list view adapter.
110         listView.adapter = protocolArrayAdapter
111
112         // Listen for clicks on items in the list view.
113         listView.onItemClickListener = AdapterView.OnItemClickListener { _: AdapterView<*>?, view: View, _: Int, _: Long ->
114             // Get a handle for the text view.
115             val textview = view.findViewById<TextView>(R.id.textview)
116
117             // Show an alert dialog if a protocol item was selected.
118             when (textview.text) {
119                 getString(R.string.gprs_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_GPRS)
120                 getString(R.string.edge_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_EDGE)
121                 getString(R.string.umts_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_UMTS)
122                 getString(R.string.cdma_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_CDMA)
123                 getString(R.string.evdo_0_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_0)
124                 getString(R.string.evdo_a_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_A)
125                 getString(R.string.rtt_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_1xRTT)
126                 getString(R.string.hsdpa_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_HSDPA)
127                 getString(R.string.hsupa_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_HSUPA)
128                 getString(R.string.hspa_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_HSPA)
129                 getString(R.string.iden_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_IDEN)
130                 getString(R.string.evdo_b_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_B)
131                 getString(R.string.lte_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_LTE)
132                 getString(R.string.ehrpd_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_EHRPD)
133                 getString(R.string.hspap_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_HSPAP)
134                 getString(R.string.gsm_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_GSM)
135                 getString(R.string.td_scdma_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_TD_SCDMA)
136                 getString(R.string.iwlan_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_IWLAN)
137                 getString(R.string.nr_detail) -> WebViewDialog().type(WebViewDialog.NETWORK_NR)
138                 getString(R.string.lte_ca_detail) -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_LTE_CA)
139                 getString(R.string.lte_advanced_pro_detail) -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_LTE_ADVANCED_PRO)
140                 getString(R.string.nr_nsa_detail) -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_NSA)
141                 getString(R.string.nr_nsa_mmwave_detail) -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_NSA_MMWAVE)
142                 getString(R.string.nr_advanced_detail) -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_ADVANCED)
143                 else -> null
144             }?.show(supportFragmentManager, getString(R.string.protocols))
145         }
146     }
147 }