From e5992ae7182c5e1a6338d34fb9f0919a6428513b Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 10 Nov 2020 16:33:21 -0700 Subject: [PATCH] Exit back to the main activity when deleting a directly accessed domain setting. https://redmine.stoutner.com/issues/564 --- app/src/main/assets/de/about_licenses.html | 9 +- app/src/main/assets/en/about_licenses.html | 2 +- app/src/main/assets/es/about_licenses.html | 19 ++- app/src/main/assets/fr/about_licenses.html | 2 +- app/src/main/assets/it/about_licenses.html | 8 +- app/src/main/assets/ru/about_licenses.html | 8 +- app/src/main/assets/tr/about_licenses.html | 2 +- .../activities/DomainsActivity.java | 149 ++++++++++-------- build.gradle | 2 +- 9 files changed, 110 insertions(+), 91 deletions(-) diff --git a/app/src/main/assets/de/about_licenses.html b/app/src/main/assets/de/about_licenses.html index a6da274a..0baa882f 100644 --- a/app/src/main/assets/de/about_licenses.html +++ b/app/src/main/assets/de/about_licenses.html @@ -95,10 +95,11 @@

cookie was created by Google. It is released under the Apache License 2.0 and can be downloaded from Material Design Icons. It is unchanged except for layout information like color and size.

-

mastodon comes from the - Mastodon project, - which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+

mastodon stammt vom + Mastodon-Projekt ab, + welches unter der AGPLv3+ Lizenz veröffentlicht wird. Den gesamte Text dieser Lizenz finden Sie unterhalb. + Das Bild ist ein unverändertes Exzerpt zur Darstellung von Layout-Informationen wie Farbe, Größe und Rahmen. + Es ist in Privacy Browser unter Beachtung der Bestimmungen von Sektion 13 der Lizenz enthalten.

The following icons come from the Android Material icon set, which is released under the Apache License 2.0. They are unchanged except for layout information like color and size. Some of them have been renamed to match their use in the code. The original icons and names are shown below.

diff --git a/app/src/main/assets/en/about_licenses.html b/app/src/main/assets/en/about_licenses.html index 51d8c029..2d8f933d 100644 --- a/app/src/main/assets/en/about_licenses.html +++ b/app/src/main/assets/en/about_licenses.html @@ -97,7 +97,7 @@

mastodon comes from the Mastodon project, which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+ The image is unchanged except for layout information like color, size, and margin. It is included in Privacy Browser under the provisions in section 13 of the license.

The following icons come from the Android Material icon set, which is released under the Apache License 2.0. They are unchanged except for layout information like color and size. Some of them have been renamed to match their use in the code. The original icons and names are shown below.

diff --git a/app/src/main/assets/es/about_licenses.html b/app/src/main/assets/es/about_licenses.html index 56f55468..b7d4573a 100644 --- a/app/src/main/assets/es/about_licenses.html +++ b/app/src/main/assets/es/about_licenses.html @@ -82,11 +82,13 @@ que es parte del conjunto de iconos Android Material y es liberado bajo la Licencia Apache 2.0. Copyright de modificaciones © 2017 Soren Stoutner. La imagen resultante se libera bajo la licencia GPLv3+.

-

deriva de exit_to_app, que es parte del conjunto de iconos Android Material - y es liberado bajo la Licencia Apache 2.0. Copyright de modificaciones © 2017 Soren Stoutner. +

deriva de exit_to_app, + que es parte del conjunto de iconos Android Material y es liberado bajo la Licencia Apache 2.0. + Copyright de modificaciones © 2017 Soren Stoutner. La imagen resultante se libera bajo la licencia GPLv3+.

-

deriva de compare, que es parte del conjunto de iconos Android Material - y es liberado bajo la Licencia Apache 2.0. Copyright de modificaciones © 2017 Soren Stoutner. +

deriva de compare, + que es parte del conjunto de iconos Android Material y es liberado bajo la Licencia Apache 2.0. + Copyright de modificaciones © 2017 Soren Stoutner. La imagen resultante se libera bajo la licencia GPLv3+.

deriva de sort, que es parte del conjunto de iconos Android Material y es liberado bajo la Licencia Apache 2.0. Copyright de modificaciones © 2019 Soren Stoutner. @@ -95,10 +97,11 @@ Es liberado bajo la licencia Apache 2.0 y puede ser descargado desde Material Design Icons. Está sin cambios, excepto por la información de diseño como el color y el tamaño.

-

mastodon comes from the - Mastodon project, - which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+

mastodon proviene del + proyecto Mastodon, + que se libera bajo la licencia AGPLv3+. El texto completo de la licencia está abajo. + La imagen no ha cambiado excepto por la información de diseño como el color, el tamaño y el margen. + Está incluida en el Navegador de Privacidad bajo las disposiciones de la sección 13 de la licencia.

Los siguientes iconos proceden de conjunto de iconos Android Material, el cual es liberado bajo la licencia Apache 2.0. Están sin cambios, excepto por la información de diseño como el color y el tamaño. Algunos de ellos se han renombrado para que coincida con su uso en el código. diff --git a/app/src/main/assets/fr/about_licenses.html b/app/src/main/assets/fr/about_licenses.html index 09ed9195..8d5336ec 100644 --- a/app/src/main/assets/fr/about_licenses.html +++ b/app/src/main/assets/fr/about_licenses.html @@ -102,7 +102,7 @@

mastodon comes from the Mastodon project, which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+ The image is unchanged except for layout information like color, size, and margin. It is included in Privacy Browser under the provisions in section 13 of the license.

Les icônes suivantes proviennent de l'ensemble d'icônes Matériel Android, qui est publié sous la Licence Apache 2.0. Ils sont inchangés sauf pour les informations de mise en page comme la couleur et la taille. Certains d'entre eux ont été renommés pour correspondre à leur utilisation dans le code. diff --git a/app/src/main/assets/it/about_licenses.html b/app/src/main/assets/it/about_licenses.html index 2899b5a8..51324b91 100644 --- a/app/src/main/assets/it/about_licenses.html +++ b/app/src/main/assets/it/about_licenses.html @@ -99,10 +99,10 @@

cookie è stata creata da Google. E' stata rilasciata con Licenza Apache 2.0 e può essere scaricata dirattamente dal Material Design Icons.Non è stata modificata ad eccezione del colore e della dimensione.

-

mastodon comes from the - Mastodon project, - which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+

mastodon deriva dal + progetto Mastodon, + che è rilasciato sotto licenza AGPLv3+. Il testo completo della licenza è riportato qui sotto. + L'immagine non è stata modificata ad eccezione del layout come il colore, le dimensioni, i bordi. E' inclusa in Privacy Browser in accordo con quanto indicato nella sezione 13 della licenza.

Le seguenti icone derivano dall'Android Material icon set, che è rilasciato sotto Licenza Apache 2.0. Non sono state modificatae ad eccezione del colore e della dimensione. Alcune sono state rinominate per coerenza con il tipo di utilizzo all'interno del codice. diff --git a/app/src/main/assets/ru/about_licenses.html b/app/src/main/assets/ru/about_licenses.html index 399b547a..e8239c08 100644 --- a/app/src/main/assets/ru/about_licenses.html +++ b/app/src/main/assets/ru/about_licenses.html @@ -94,10 +94,10 @@

cookie были созданы Google. Они выпущены под Apache License 2.0 и могут быть загружены из Material Design Icons. Он неизменен, за исключением такой информации, как цвет и размер.

-

mastodon comes from the - Mastodon project, - which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+

mastodon является частью + проекта Mastodon, + который выпускается под лицензией AGPLv3+. Полный текст лицензии приведен ниже. + Изображение не было изменено, за исключением информации о верстке, в том числе цвет, размеры и отступы. В соответствии с положениями раздела 13 лицензии оно включено в Privacy Browser.

Следующие значки взяты изAndroid Material icon set, которые выпущены под Apache License 2.0. Они неизменны, за исключением такой информации, как цвет и размер. Некоторые из них были переименованы в соответствии с их использованием в коде. Оригинальные значки и имена показаны ниже.

diff --git a/app/src/main/assets/tr/about_licenses.html b/app/src/main/assets/tr/about_licenses.html index 23c0632e..d33fc875 100644 --- a/app/src/main/assets/tr/about_licenses.html +++ b/app/src/main/assets/tr/about_licenses.html @@ -98,7 +98,7 @@

mastodon comes from the Mastodon project, which is released under the AGPLv3+ license. The full text of the license is below. - The image is unchanged except for layout information like color and size. It is included in Privacy Browser under the provisions in section 13 of the license.

+ The image is unchanged except for layout information like color, size, and margin. It is included in Privacy Browser under the provisions in section 13 of the license.

Aşağıdaki simgeler Apache License 2.0 altında yayınlanan Android Material simge setinden gelmektedir. Renk ve ebat gibi düzen bilgileri dışında herhangi bir değişiklik yapılmamıştır. Bazıları koddaki kullanımlarıyla uygun olacak şekilde yeniden adlandırıldı. Orijinal simgeler ve adlar aşağıda gösterilmiştir.

diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java index 574dc725..2283277f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java @@ -335,83 +335,93 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo // Get a handle for the fragment manager. FragmentManager fragmentManager = getSupportFragmentManager(); - switch (menuItemId) { - case android.R.id.home: // The home arrow is identified as `android.R.id.home`, not just `R.id.home`. - if (twoPanedMode) { // The device is in two-paned mode. - // Save the current domain settings if the domain settings fragment is displayed. - if (findViewById(R.id.domain_settings_scrollview) != null) { - saveDomainSettings(coordinatorLayout, resources); - } - - // Dismiss the undo delete `SnackBar` if it is shown. - if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) { - // Set the close flag. - closeActivityAfterDismissingSnackbar = true; - - // Dismiss the snackbar. - undoDeleteSnackbar.dismiss(); - } else { - // Go home. - NavUtils.navigateUpFromSameTask(this); - } - } else if (closeOnBack) { // Go directly back to the main WebView activity because the domains activity was launched from the options menu. - // Save the current domain settings. + // Run the command according to the selected menu item. + if (menuItemId == android.R.id.home) { // The home arrow is identified as `android.R.id.home`, not just `R.id.home`. + // Check if the device is in two-paned mode. + if (twoPanedMode) { // The device is in two-paned mode. + // Save the current domain settings if the domain settings fragment is displayed. + if (findViewById(R.id.domain_settings_scrollview) != null) { saveDomainSettings(coordinatorLayout, resources); + } + + // Dismiss the undo delete snackbar if it is shown. + if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) { + // Set the close flag. + closeActivityAfterDismissingSnackbar = true; + // Dismiss the snackbar. + undoDeleteSnackbar.dismiss(); + } else { // Go home. NavUtils.navigateUpFromSameTask(this); - } else if (findViewById(R.id.domain_settings_scrollview) != null) { // The device is in single-paned mode and the domain settings fragment is displayed. - // Save the current domain settings. - saveDomainSettings(coordinatorLayout, resources); + } + } else if (closeOnBack) { // Go directly back to the main WebView activity because the domains activity was launched from the options menu. + // Save the current domain settings. + saveDomainSettings(coordinatorLayout, resources); - // Display the domains list fragment. - DomainsListFragment domainsListFragment = new DomainsListFragment(); - fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit(); - fragmentManager.executePendingTransactions(); + // Go home. + NavUtils.navigateUpFromSameTask(this); + } else if (findViewById(R.id.domain_settings_scrollview) != null) { // The device is in single-paned mode and the domain settings fragment is displayed. + // Save the current domain settings. + saveDomainSettings(coordinatorLayout, resources); - // Populate the list of domains. `-1` highlights the first domain if in two-paned mode. It has no effect in single-paned mode. - populateDomainsListView(-1, domainsListViewPosition); + // Display the domains list fragment. + DomainsListFragment domainsListFragment = new DomainsListFragment(); + fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit(); + fragmentManager.executePendingTransactions(); - // Show the add domain floating action button. - addDomainFAB.show(); + // Populate the list of domains. `-1` highlights the first domain if in two-paned mode. It has no effect in single-paned mode. + populateDomainsListView(-1, domainsListViewPosition); - // Hide the delete menu item. - deleteMenuItem.setVisible(false); - } else { // The device is in single-paned mode and `DomainsListFragment` is displayed. - // Dismiss the undo delete `SnackBar` if it is shown. - if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) { - // Set the close flag. - closeActivityAfterDismissingSnackbar = true; - - // Dismiss the snackbar. - undoDeleteSnackbar.dismiss(); - } else { - // Go home. - NavUtils.navigateUpFromSameTask(this); - } - } - break; + // Show the add domain floating action button. + addDomainFAB.show(); + + // Hide the delete menu item. + deleteMenuItem.setVisible(false); + } else { // The device is in single-paned mode and domains list fragment is displayed. + // Dismiss the undo delete `SnackBar` if it is shown. + if (undoDeleteSnackbar != null && undoDeleteSnackbar.isShown()) { + // Set the close flag. + closeActivityAfterDismissingSnackbar = true; - case R.id.delete_domain: + // Dismiss the snackbar. + undoDeleteSnackbar.dismiss(); + } else { + // Go home. + NavUtils.navigateUpFromSameTask(this); + } + } + } else if (menuItemId == R.id.delete_domain) { // Delete. + // Get a handle for the activity. + Activity activity = this; + + // Check to see if the domain settings were loaded directly for editing of this app in single-paned mode. + if (closeOnBack && !twoPanedMode) { // The activity should delete the domain settings and exit straight to the the main WebView activity. + // Delete the selected domain. + domainsDatabaseHelper.deleteDomain(currentDomainDatabaseId); + + // Go home. + NavUtils.navigateUpFromSameTask(activity); + } else { // A snackbar should be shown before deleting the domain settings. // Reset close-on-back, which otherwise can cause errors if the system attempts to save settings for a domain that no longer exists. closeOnBack = false; - // Store a copy of `currentDomainDatabaseId` because it could change while the `Snackbar` is displayed. + // Store a copy of the current domain database ID because it could change while the snackbar is displayed. final int databaseIdToDelete = currentDomainDatabaseId; // Update the fragments and menu items. if (twoPanedMode) { // Two-paned mode. - // Store the deleted domain position, which is needed if `Undo` is selected in the `Snackbar`. + // Store the deleted domain position, which is needed if undo is selected in the snackbar. deletedDomainPosition = domainsListView.getCheckedItemPosition(); - // Disable the options `MenuItems`. + // Disable the options menu items. deleteMenuItem.setEnabled(false); deleteMenuItem.setIcon(R.drawable.delete_disabled); // Remove the domain settings fragment. fragmentManager.beginTransaction().remove(Objects.requireNonNull(fragmentManager.findFragmentById(R.id.domain_settings_fragment_container))).commit(); } else { // Single-paned mode. - // Display `DomainsListFragment`. + // Display the domains list fragment. DomainsListFragment domainsListFragment = new DomainsListFragment(); fragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commit(); fragmentManager.executePendingTransactions(); @@ -423,35 +433,36 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo deleteMenuItem.setVisible(false); } - // Get a `Cursor` that does not show the domain to be deleted. + // Get a cursor that does not show the domain to be deleted. Cursor domainsPendingDeleteCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomainExcept(databaseIdToDelete); - // Setup `domainsPendingDeleteCursorAdapter` with `this` context. `false` disables `autoRequery`. + // Setup the domains pending delete cursor adapter. CursorAdapter domainsPendingDeleteCursorAdapter = new CursorAdapter(this, domainsPendingDeleteCursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - // Inflate the individual item layout. `false` does not attach it to the root. + // Inflate the individual item layout. return getLayoutInflater().inflate(R.layout.domain_name_linearlayout, parent, false); } @Override public void bindView(View view, Context context, Cursor cursor) { - // Set the domain name. + // Get the domain name string. String domainNameString = cursor.getString(cursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)); + + // Get a handle for the domain name text view. TextView domainNameTextView = view.findViewById(R.id.domain_name_textview); + + // Display the domain name. domainNameTextView.setText(domainNameString); } }; - // Update the handle for the current `domains_listview`. + // Update the handle for the current domains list view. domainsListView = findViewById(R.id.domains_listview); - // Update the `ListView`. + // Update the list view. domainsListView.setAdapter(domainsPendingDeleteCursorAdapter); - // Get a handle for the activity. - Activity activity = this; - // Display a snackbar. undoDeleteSnackbar = Snackbar.make(domainsListView, R.string.domain_deleted, Snackbar.LENGTH_LONG) .setAction(R.string.undo, (View v) -> { @@ -477,22 +488,26 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo // Display the correct fragments. if (twoPanedMode) { // The device in in two-paned mode. - // Get a `Cursor` with the current contents of the domains database. + // Get a cursor with the current contents of the domains database. Cursor undoDeleteDomainsCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomain(); - // Setup `domainsCursorAdapter` with `this` context. `false` disables `autoRequery`. + // Setup the domains cursor adapter. CursorAdapter undoDeleteDomainsCursorAdapter = new CursorAdapter(getApplicationContext(), undoDeleteDomainsCursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - // Inflate the individual item layout. `false` does not attach it to the root. + // Inflate the individual item layout. return getLayoutInflater().inflate(R.layout.domain_name_linearlayout, parent, false); } @Override public void bindView(View view, Context context, Cursor cursor) { - // Set the domain name. + /// Get the domain name string. String domainNameString = cursor.getString(cursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)); + + // Get a handle for the domain name text view. TextView domainNameTextView = view.findViewById(R.id.domain_name_textview); + + // Display the domain name. domainNameTextView.setText(domainNameString); } }; @@ -578,7 +593,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo // Show the Snackbar. undoDeleteSnackbar.show(); - break; + } } // Consume the event. diff --git a/build.gradle b/build.gradle index 3cdc9df9..d65b3ccb 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:4.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10" // NOTE: Do not place your application dependencies here; they belong -- 2.43.0