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;
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
// 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;
}
// 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;
}
// 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;
}
// 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.
// 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;
}
// 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
@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());
}
});
// 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;
}
});
// 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);
}