X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FDownloadLocationHelper.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FDownloadLocationHelper.java;h=0000000000000000000000000000000000000000;hb=d4f39c36beb5e6c3568a1e075274ad66defd8e8e;hp=f23aaea28918d18b1170ecceea3ffd257b99b6c8;hpb=f825cc15f0383acce10bb16443e027edb869a11e;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DownloadLocationHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/DownloadLocationHelper.java deleted file mode 100644 index f23aaea2..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DownloadLocationHelper.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright © 2020 Soren Stoutner . - * - * This file is part of Privacy Browser . - * - * Privacy Browser is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privacy Browser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . - */ - -package com.stoutner.privacybrowser.helpers; - -import android.Manifest; -import android.content.Context; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.os.Environment; - -import androidx.core.content.ContextCompat; -import androidx.preference.PreferenceManager; - -import com.stoutner.privacybrowser.R; - -import java.io.File; - -public class DownloadLocationHelper { - public String getDownloadLocation(Context context) { - // Get the download location entry values string array. - String[] downloadLocationEntryValuesStringArray = context.getResources().getStringArray(R.array.download_location_entry_values); - - // Get the two standard download directories. - File publicDownloadDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); - File publicAppFilesDirectory = context.getExternalFilesDir(null); - - // Remove the incorrect lint warning below that the public app files directory might be null. - assert publicAppFilesDirectory != null; - - // Convert the download directories to strings. - String publicDownloadDirectoryString = publicDownloadDirectory.toString(); - String publicAppFilesDirectoryString = publicAppFilesDirectory.toString(); - - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - - // Get the download location strings from the preferences. - String downloadLocationString = sharedPreferences.getString("download_location", context.getString(R.string.download_location_default_value)); - String downloadCustomLocationString = sharedPreferences.getString("download_custom_location", context.getString(R.string.download_custom_location_default_value)); - - // Define a string for the default file path. - String defaultFilePath; - - // Set the default file path according to the download location. - if (downloadLocationString.equals(downloadLocationEntryValuesStringArray[0])) { // the download location is set to auto. - // Set the download location summary text according to the storage permission status. - if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { // The storage permission has been granted. - // Use the public download directory. - defaultFilePath = publicDownloadDirectoryString; - } else { // The storage permission has not been granted. - // Use the public app files directory. - defaultFilePath = publicAppFilesDirectoryString; - } - } else if (downloadLocationString.equals(downloadLocationEntryValuesStringArray[1])) { // The download location is set to the app directory. - // Use the public app files directory. - defaultFilePath = publicAppFilesDirectoryString; - } else if (downloadLocationString.equals(downloadLocationEntryValuesStringArray[2])) { // The download location is set to the public directory. - // Use the public download directory. - defaultFilePath = publicDownloadDirectoryString; - } else { // The download location is set to custom. - // Use the download custom location. - defaultFilePath = downloadCustomLocationString; - } - - // Return the default file path. - return defaultFilePath; - } -} \ No newline at end of file