X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FSaveWebpageDialog.java;h=72d0f20a6725cf7d65c7ca584243662f470fa4dc;hp=1c24e0bedc6ca95f4414c74ae3c92bd92001c205;hb=b235ba52731f112015d9058ade4c5a66abf7ed5c;hpb=5d3cafb4a4fbb2bf851d36f973cc1e8b23ecebab diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.java index 1c24e0be..72d0f20a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.java @@ -50,10 +50,6 @@ import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.MainWebViewActivity; public class SaveWebpageDialog extends DialogFragment { - // Define the save type constants. - public static final int ARCHIVE = 0; - public static final int IMAGE = 1; - // Define the save webpage listener. private SaveWebpageListener saveWebpageListener; @@ -88,7 +84,7 @@ public class SaveWebpageDialog extends DialogFragment { return saveWebpageDialog; } - // `@SuppressLing("InflateParams")` removes the warning about using null as the parent view group when inflating the alert dialog. + // `@SuppressLint("InflateParams")` removes the warning about using null as the parent view group when inflating the alert dialog. @SuppressLint("InflateParams") @Override @NonNull @@ -127,11 +123,11 @@ public class SaveWebpageDialog extends DialogFragment { // Set the icon according to the save type. switch (saveType) { - case ARCHIVE: + case StoragePermissionDialog.SAVE_ARCHIVE: dialogBuilder.setIcon(R.drawable.dom_storage_cleared_dark); break; - case IMAGE: + case StoragePermissionDialog.SAVE_IMAGE: dialogBuilder.setIcon(R.drawable.images_enabled_dark); break; } @@ -141,11 +137,11 @@ public class SaveWebpageDialog extends DialogFragment { // Set the icon according to the save type. switch (saveType) { - case ARCHIVE: + case StoragePermissionDialog.SAVE_ARCHIVE: dialogBuilder.setIcon(R.drawable.dom_storage_cleared_light); break; - case IMAGE: + case StoragePermissionDialog.SAVE_IMAGE: dialogBuilder.setIcon(R.drawable.images_enabled_light); break; } @@ -153,11 +149,11 @@ public class SaveWebpageDialog extends DialogFragment { // Set the title according to the type. switch (saveType) { - case ARCHIVE: + case StoragePermissionDialog.SAVE_ARCHIVE: dialogBuilder.setTitle(R.string.save_archive); break; - case IMAGE: + case StoragePermissionDialog.SAVE_IMAGE: dialogBuilder.setTitle(R.string.save_image); break; } @@ -177,7 +173,7 @@ public class SaveWebpageDialog extends DialogFragment { // Create an alert dialog from the builder. AlertDialog alertDialog = dialogBuilder.create(); - // Remove the incorrect lint warning below that `getWindow()` might be null. + // Remove the incorrect lint warning below that the window might be null. assert alertDialog.getWindow() != null; // Disable screenshots if not allowed. @@ -199,11 +195,11 @@ public class SaveWebpageDialog extends DialogFragment { // Set the default file name according to the type. switch (saveType) { - case ARCHIVE: + case StoragePermissionDialog.SAVE_ARCHIVE: defaultFileName = getString(R.string.webpage_mht); break; - case IMAGE: + case StoragePermissionDialog.SAVE_IMAGE: defaultFileName = getString(R.string.webpage_png); break; } @@ -223,6 +219,9 @@ public class SaveWebpageDialog extends DialogFragment { // Display the default file path. fileNameEditText.setText(defaultFilePath); + // Move the cursor to the end of the default file path. + fileNameEditText.setSelection(defaultFilePath.length()); + // Update the status of the save button when the file name changes. fileNameEditText.addTextChangedListener(new TextWatcher() { @Override @@ -237,7 +236,7 @@ public class SaveWebpageDialog extends DialogFragment { @Override public void afterTextChanged(Editable s) { - // // Enable the save button if a file name exists. + // Enable the save button if a file name exists. saveButton.setEnabled(!fileNameEditText.getText().toString().isEmpty()); } }); @@ -252,11 +251,11 @@ public class SaveWebpageDialog extends DialogFragment { // Set the initial file name according to the type. switch (saveType) { - case ARCHIVE: + case StoragePermissionDialog.SAVE_ARCHIVE: browseIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.webpage_mht)); break; - case IMAGE: + case StoragePermissionDialog.OPEN: browseIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.webpage_png)); break; } @@ -274,7 +273,7 @@ public class SaveWebpageDialog extends DialogFragment { }); // Hide the storage permission text view on API < 23 as permissions on older devices are automatically granted. - if (Build.VERSION.SDK_INT < 23) { + if (Build.VERSION.SDK_INT < 23 || (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) { storagePermissionTextView.setVisibility(View.GONE); }