/*
- * Copyright © 2018-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2018-2020 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
import android.widget.Spinner;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar; // The AndroidX toolbar must be used until the minimum API >= 21.
+import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment;
import com.stoutner.privacybrowser.R;
public class RequestsActivity extends AppCompatActivity implements ViewRequestDialog.ViewRequestListener {
// The resource requests are populated by `MainWebViewActivity` before `RequestsActivity` is launched.
- public static ArrayList<String[]> resourceRequests;
+ public static List<String[]> resourceRequests;
- // The list view is used in `onCreate()` and `launchViewRequestDialog()`.
+ // Initialize the class constants.
+ private final String LISTVIEW_POSITION = "listview_position";
+
+ // Define the class views.
private ListView requestsListView;
@Override
// Get a handle for the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
- // Get the screenshot and theme preferences.
+ // Get the screenshot preference.
boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
- boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
// Disable screenshots if not allowed.
if (!allowScreenshots) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
- // Set the activity theme.
- if (darkTheme) {
- setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
- } else {
- setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
- }
+ // Set the theme.
+ setTheme(R.style.PrivacyBrowser);
// Run the default commands.
super.onCreate(savedInstanceState);
// Display the view request dialog. The list view is 0 based, so the position must be incremented by 1.
launchViewRequestDialog(position + 1);
});
+
+ // Check to see if the activity has been restarted.
+ if (savedInstanceState != null) {
+ // Scroll to the saved position.
+ requestsListView.post(() -> requestsListView.setSelection(savedInstanceState.getInt(LISTVIEW_POSITION)));
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
+ // Run the default commands.
+ super.onSaveInstanceState(savedInstanceState);
+
+ // Get the listview position.
+ int listViewPosition = requestsListView.getFirstVisiblePosition();
+
+ // Store the listview position in the bundle.
+ savedInstanceState.putInt(LISTVIEW_POSITION, listViewPosition);
}
@Override