diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a86f340f..e9ef5fb9 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -27,6 +27,7 @@ + Add devices by IP Noisy notifications Vibrate and play a sound when receiving a file + Customize destination directory + Received files will appear in Downloads + Files will be stored in the directory below + Destination directory Notification filter Notifications will be synchronized for the selected apps. Internal storage @@ -190,8 +194,8 @@ Find my tablet Rings this device so you can find it Found - Destination directory Open Close + diff --git a/res/xml/shareplugin_preferences.xml b/res/xml/shareplugin_preferences.xml index 4283ed36..0bc656c8 100644 --- a/res/xml/shareplugin_preferences.xml +++ b/res/xml/shareplugin_preferences.xml @@ -3,6 +3,14 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + = Build.VERSION_CODES.KITKAT)) { + customDownloads.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + updateFilePickerStatus((Boolean) newValue); + return true; + } + }); filePicker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -39,31 +52,45 @@ public class ShareSettingsActivity extends PluginSettingsActivity { } }); } else { + customDownloads.setEnabled(false); filePicker.setEnabled(false); } + boolean customized = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREFERENCE_CUSTOMIZE_DESTINATION, false); + updateFilePickerStatus(customized); + } + + void updateFilePickerStatus(boolean enabled) { + filePicker.setEnabled(enabled); String path = PreferenceManager.getDefaultSharedPreferences(this).getString(PREFERENCE_DESTINATION, null); - if (path != null) { + if (enabled && path != null) { filePicker.setSummary(Uri.parse(path).getPath()); } else { filePicker.setSummary(getDefaultDestinationDirectory().getAbsolutePath()); } } - private static File getDefaultDestinationDirectory() { + public static File getDefaultDestinationDirectory() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); } + public static boolean isCustomDestinationEnabled(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFERENCE_CUSTOMIZE_DESTINATION, false); + } + + //Will return the appropriate directory, whether it is customized or not public static DocumentFile getDestinationDirectory(Context context) { - String path = PreferenceManager.getDefaultSharedPreferences(context).getString(PREFERENCE_DESTINATION, null); - if (path != null) { - //There should be no way to enter here on api level < kitkat - DocumentFile treeDocumentFile = DocumentFile.fromTreeUri(context, Uri.parse(path)); - if (treeDocumentFile.canWrite()) { //Checks for FLAG_DIR_SUPPORTS_CREATE on directories - return treeDocumentFile; - } else { - //Maybe permission was revoked - Log.w("SharePlugin", "Share destination is not writable, falling back to default path."); + if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFERENCE_CUSTOMIZE_DESTINATION, false)) { + String path = PreferenceManager.getDefaultSharedPreferences(context).getString(PREFERENCE_DESTINATION, null); + if (path != null) { + //There should be no way to enter here on api level < kitkat + DocumentFile treeDocumentFile = DocumentFile.fromTreeUri(context, Uri.parse(path)); + if (treeDocumentFile.canWrite()) { //Checks for FLAG_DIR_SUPPORTS_CREATE on directories + return treeDocumentFile; + } else { + //Maybe permission was revoked + Log.w("SharePlugin", "Share destination is not writable, falling back to default path."); + } } } return DocumentFile.fromFile(getDefaultDestinationDirectory()); @@ -88,13 +115,6 @@ public class ShareSettingsActivity extends PluginSettingsActivity { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.edit().putString(PREFERENCE_DESTINATION, uri.toString()).apply(); } - /* else { // Here to ease debugging. Removes the setting so we use the default url. - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.edit().remove(PREFERENCE_DESTINATION).apply(); - Preference filePicker = findPreference("share_destination_folder_preference"); - filePicker.setSummary(getDefaultDestinationDirectory().getAbsolutePath()); - } */ - } }