X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FOpenDialog.java;h=59aa177ba945c1fa58288357987a22c69570bfa9;hb=ba4a1c032dbffde044b70c804f9d3c1f1ba7b939;hp=2d6a776153b3dc746e37a02a9703175d6530c4f5;hpb=a87ea266a0df9aca50f9bc8a58066a4c962ea515;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/OpenDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/OpenDialog.java index 2d6a7761..59aa177b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/OpenDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/OpenDialog.java @@ -48,6 +48,7 @@ import androidx.preference.PreferenceManager; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.MainWebViewActivity; +import com.stoutner.privacybrowser.helpers.DownloadLocationHelper; import java.io.File; @@ -143,9 +144,6 @@ public class OpenDialog extends DialogFragment { TextView storagePermissionTextView = alertDialog.findViewById(R.id.storage_permission_textview); Button openButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); - // Create a string for the default file path. - String defaultFilePath; - // Update the status of the open button when the file name changes. fileNameEditText.addTextChangedListener(new TextWatcher() { @Override @@ -183,17 +181,11 @@ public class OpenDialog extends DialogFragment { } }); - // Set the default file path according to the storage permission state. - if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { // The storage permission has been granted. - // Set the default file path to use the external public directory. - defaultFilePath = Environment.getExternalStorageDirectory() + "/"; + // Instantiate the download location helper. + DownloadLocationHelper downloadLocationHelper = new DownloadLocationHelper(); - // Hide the storage permission text view. - storagePermissionTextView.setVisibility(View.GONE); - } else { // The storage permission has not been granted. - // Set the default file path to use the external private directory. - defaultFilePath = context.getExternalFilesDir(null) + "/"; - } + // Get the default file path. + String defaultFilePath = downloadLocationHelper.getDownloadLocation(context) + "/"; // Display the default file path. fileNameEditText.setText(defaultFilePath); @@ -201,6 +193,11 @@ public class OpenDialog extends DialogFragment { // Move the cursor to the end of the default file path. fileNameEditText.setSelection(defaultFilePath.length()); + // Hide the storage permission text view if the permission has already been granted. + if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + storagePermissionTextView.setVisibility(View.GONE); + } + // Handle clicks on the browse button. browseButton.setOnClickListener((View view) -> { // Create the file picker intent.