11package com .lijukay .quotesAltDesign .activities ;
22
33import android .annotation .SuppressLint ;
4- import android .app .DownloadManager ;
5- import android .content .BroadcastReceiver ;
6- import android .content .Context ;
74import android .content .Intent ;
8- import android .content .IntentFilter ;
95import android .content .SharedPreferences ;
106import android .content .pm .ActivityInfo ;
117import android .content .res .Configuration ;
128import android .content .res .Resources ;
13- import android .net .ConnectivityManager ;
14- import android .net .NetworkInfo ;
159import android .net .Uri ;
1610import android .os .Build ;
1711import android .os .Bundle ;
18- import android .os .Environment ;
19- import android .os .Handler ;
2012import android .util .DisplayMetrics ;
21- import android .widget .Toast ;
2213
2314import androidx .appcompat .app .ActionBar ;
2415import androidx .appcompat .app .AppCompatActivity ;
2516import androidx .browser .customtabs .CustomTabColorSchemeParams ;
2617import androidx .browser .customtabs .CustomTabsIntent ;
27- import androidx .core .content .FileProvider ;
2818import androidx .preference .Preference ;
2919import androidx .preference .PreferenceFragmentCompat ;
30- import androidx .swiperefreshlayout .widget .SwipeRefreshLayout ;
3120
32- import com .android .volley .Cache ;
33- import com .android .volley .Request ;
34- import com .android .volley .RequestQueue ;
35- import com .android .volley .toolbox .JsonObjectRequest ;
36- import com .android .volley .toolbox .Volley ;
3721import com .google .android .material .appbar .MaterialToolbar ;
3822import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
3923import com .google .android .material .elevation .SurfaceColors ;
40- import com .lijukay .quotesAltDesign .BuildConfig ;
4124import com .lijukay .quotesAltDesign .R ;
4225import com .lijukay .quotesAltDesign .service .InternetService ;
4326
44- import org .json .JSONArray ;
45- import org .json .JSONException ;
46- import org .json .JSONObject ;
47-
48- import java .io .File ;
4927import java .util .Locale ;
5028
51- import rikka .material .preference .MaterialSwitchPreference ;
52-
5329public class Settings extends AppCompatActivity {
5430
55- public static final String BroadcastStringForAction = "checkInternet" ;
5631 static Intent starterIntent ;
57- //static String versionNameBeta, versionName, apkUrl, apkBeta, changelogMessage, changelogBeta
5832 static String languageCode , colorS ;
59- //static int versionC, versionA, versionB;
6033 static SharedPreferences betaSP , language , sharedPreferencesColors ;
6134 static SharedPreferences .Editor betaEditor , languageEditor , colorEditor ;
62- //private static RequestQueue mRequestQueueU;
63- //static boolean betaA = false, updateStatus = false, internet;
64-
65- @ SuppressLint ("StaticFieldLeak" )
66-
67- /*public final BroadcastReceiver InternetReceiver = new BroadcastReceiver() {
68- @Override
69- public void onReceive(Context context, Intent intent) {
70- if (intent.getAction().equals(BroadcastStringForAction)) {
71- internet = intent.getStringExtra("online_status").equals("true");
72- }
73- }
74- };*/
75- //------Creating the SwipeRefreshLayout------//
76- private SwipeRefreshLayout swipeRefreshLayout ;
77- //------Creating an IntentFilter------//
78- private IntentFilter mIntentFilter ;
79-
80- /*private static void parseJSONVersion() {
81- String url = "https://lijukay.github.io/PrUp/prUp.json";
82-
83- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, jsonObject -> {
84- try {
85- JSONArray jsonArray = jsonObject.getJSONArray("Qwotable");
86-
87- for (int a = 0; a < jsonArray.length(); a++) {
88-
89- JSONObject v = jsonArray.getJSONObject(a);
90-
91- versionC = BuildConfig.VERSION_CODE;
92- versionA = v.getInt("versionsCode");
93- versionB = v.getInt("versionsCodeBeta");
94- apkUrl = v.getString("apkUrl");
95- apkBeta = v.getString("apkUrlBeta");
96- changelogMessage = v.getString("changelog");
97- changelogBeta = v.getString("changelogBeta");
98- versionName = v.getString("versionsName");
99- versionNameBeta = v.getString("versionsNameBeta");
100- }
101-
102- if (versionB > versionC) {
103- betaA = true;
104- }
105-
106- if (versionA > versionC) {
107- betaA = false;
108- updateStatus = true;
109- } else {
110- updateStatus = false;
111- }
112-
113-
114- } catch (JSONException e) {
115- e.printStackTrace();
116- }
117- }, Throwable::printStackTrace);
118- mRequestQueueU.add(jsonObjectRequest);
119-
120-
121- }*/
122-
123- /*public static void InstallUpdate(Context context, String url, String versionName) {
124-
125- //------Set the destination as a string------//
126- String destination = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + context.getString(R.string.app_name) + "." + versionName + ".apk";
127- //------Set the file uri------//
128- Uri fileUri = Uri.parse("file://" + destination);
129-
130- File file = new File(destination);
131-
132- if (file.exists()) //noinspection ResultOfMethodCallIgnored
133- file.delete();
13435
135- DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
136- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
137-
138- request.setMimeType("application/vnd.android.package-archive");
139- request.setTitle(context.getString(R.string.app_name) + " Update");
140- request.setDescription(versionName);
141- request.setDestinationUri(fileUri);
142-
143- BroadcastReceiver onComplete = new BroadcastReceiver() {
144- public void onReceive(Context ctxt, Intent intent) {
145-
146- Uri apkFileUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", new File(destination));
147-
148- Intent install = new Intent(Intent.ACTION_VIEW);
149-
150- install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
151- install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
152- install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
153- install.setDataAndType(apkFileUri, "application/vnd.android.package-archive");
154-
155- context.startActivity(install);
156- context.unregisterReceiver(this);
157- }
158- };
159- context.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
160- downloadManager.enqueue(request);
161- }*/
16236
16337 @ SuppressLint ({"InflateParams" , "SourceLockedOrientationActivity" })
16438 @ Override
@@ -211,9 +85,6 @@ protected void onCreate(Bundle savedInstanceState) {
21185
21286 float smallestWidth = Math .min (widthDp , heightDp );
21387
214-
215-
216- //------Set the contentView to the layout of settings_activity------//
21788 setContentView (R .layout .settings_activity );
21889
21990 MaterialToolbar materialToolbar = findViewById (R .id .topAppBar );
@@ -232,68 +103,21 @@ else if (smallestWidth < 600) {
232103 setRequestedOrientation (ActivityInfo .SCREEN_ORIENTATION_PORTRAIT );
233104 }
234105
235- //------IF ANYONE KNOWS WHAT THE CONDITION OF THE IF LOOP HERE IS, PWEASE EXPLAIN ME!------//
236106 if (savedInstanceState == null ) {
237107 getSupportFragmentManager ().beginTransaction ().replace (R .id .settings , new SettingsFragment ()).commit ();
238108 }
239109
240110 ActionBar actionBar = getSupportActionBar ();
241- //------Check if actionBar is null------//
242111 if (actionBar != null ) {
243- //------IF ANYONE KNOWS WHAT THIS THING DOES, PWEASE EXPLAIN. I HAVE NO IDEA!------//
244112 actionBar .setDisplayHomeAsUpEnabled (true );
245113 }
246114
247- /*mRequestQueueU = Volley.newRequestQueue(this);
248- swipeRefreshLayout = findViewById(R.id.settingsSRL);
249- swipeRefreshLayout.setOnRefreshListener(() -> {
250- Toast.makeText(this, getString(R.string.toast_message_settings), Toast.LENGTH_SHORT).show();
251- new Handler().postDelayed(() -> {
252- swipeRefreshLayout.setRefreshing(false);
253- Cache cache = mRequestQueueU.getCache();
254- cache.clear();
255- parseJSONVersion();
256- }, 2000);
257- });*/
258-
259- //------getIntent() returns the intent that started the activity------//
260- starterIntent = getIntent ();
261115
262- mIntentFilter = new IntentFilter ();
263- //------Action of this IntentFilter: Checking the internet------//
264- mIntentFilter .addAction (BroadcastStringForAction );
265- //------Referring to the class where the service is written down and starting the service------//
116+ starterIntent = getIntent ();
266117 Intent serviceIntent = new Intent (this , InternetService .class );
267118 startService (serviceIntent );
268- //------Checking if the Application is online------//
269- //internet = isOnline(getApplicationContext());
270-
271- //parseJSONVersion();
272- }
273-
274- /*public boolean isOnline(Context c) {
275- ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
276- NetworkInfo ni = cm.getActiveNetworkInfo();
277- return ni != null && ni.isConnectedOrConnecting();
278- }
279-
280- @Override
281- protected void onRestart() {
282- super.onRestart();
283- registerReceiver(InternetReceiver, mIntentFilter);
284- }
285-
286- @Override
287- protected void onPause() {
288- super.onPause();
289- unregisterReceiver(InternetReceiver);
290119 }
291120
292- @Override
293- protected void onResume() {
294- super.onResume();
295- registerReceiver(InternetReceiver, mIntentFilter);
296- }*/
297121
298122 public static class SettingsFragment extends PreferenceFragmentCompat {
299123
@@ -397,29 +221,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
397221 });
398222 }
399223
400-
401- /*MaterialSwitchPreference beta = findPreference("beta");
402- assert beta != null;
403-
404- if (beta.isChecked()){
405- beta.setSummary(getString(R.string.beta_switch_preference_summary_positive));
406- } else {
407- beta.setSummary(getString(R.string.beta_switch_preference_summary_negative));
408- }
409-
410- beta.setOnPreferenceChangeListener((preference, newValue) -> {
411- if (!beta.isChecked()){
412- beta.setSummary(getString(R.string.beta_switch_preference_summary_positive));
413- } else {
414- beta.setSummary(getString(R.string.beta_switch_preference_summary_negative));
415- }
416- betaEditor.putBoolean("beta", !beta.isChecked());
417- betaEditor.apply();
418-
419- return true;
420- });*/
421-
422-
423224 Preference qwrequest = findPreference ("qwrequest" );
424225 assert qwrequest != null ;
425226 qwrequest .setOnPreferenceClickListener (preference -> {
@@ -498,38 +299,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
498299 return false ;
499300 });
500301
501- /*Preference updater = findPreference("updateCheck");
502-
503- assert updater != null;
504- updater.setOnPreferenceClickListener(preference -> {
505-
506- if (!internet) {
507- Toast.makeText(requireContext(), getString(R.string.no_internet_toast_message), Toast.LENGTH_SHORT).show();
508- } else if (!updateStatus && !betaA && betaSP.getBoolean("beta", false) || !updateStatus && !betaSP.getBoolean("beta", false)){
509- Toast.makeText(requireContext(), getString(R.string.no_update_toast_message), Toast.LENGTH_SHORT).show();
510- } else if (updateStatus){
511- new MaterialAlertDialogBuilder(requireContext(), com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
512- .setTitle(getString(R.string.updater_dialog_title))
513- .setMessage(BuildConfig.VERSION_NAME +" -> " + versionName + "\n\n" +changelogMessage)
514- .setIcon(R.drawable.ic_baseline_system_update_24)
515- .setPositiveButton(getString(R.string.updater_positive_button), (dialog, which) -> InstallUpdate(requireActivity(), apkUrl, versionName))
516- .setNeutralButton(getString(R.string.updater_negative_button), (dialog, which) -> dialog.dismiss())
517- .show();
518- } else if (betaA && betaSP.getBoolean("beta", false)){
519- new MaterialAlertDialogBuilder(requireContext(), com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
520- .setTitle(getString(R.string.updater_dialog_title))
521- .setMessage(BuildConfig.VERSION_NAME +" -> " + versionNameBeta + "\n\n" +changelogBeta)
522- .setIcon(R.drawable.ic_baseline_system_update_24)
523- .setPositiveButton(R.string.updater_positive_button, (dialog, which) -> InstallUpdate(requireActivity(), apkBeta, versionNameBeta))
524- .setNeutralButton(R.string.updater_negative_button, (dialog, which) -> dialog.dismiss())
525- .show();
526-
527- }
528-
529- return false;
530-
531- });*/
532-
533302 Preference bug_report = findPreference ("reportBug" );
534303
535304 assert bug_report != null ;
0 commit comments