From 114dc8ffa08d25c130e27af25ed24ad5f84e58cc Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 16 Jan 2021 15:15:16 +0100 Subject: [PATCH] Pass mime type so that SAF treats file extension correctly --- .../java/org/schabi/newpipe/download/DownloadDialog.java | 2 +- .../newpipe/local/subscription/SubscriptionFragment.kt | 2 +- .../schabi/newpipe/settings/ContentSettingsFragment.java | 3 ++- .../org/schabi/newpipe/streams/io/StoredFileHelper.java | 8 +++++--- .../us/shandian/giga/ui/fragment/MissionsFragment.java | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 4cb597b6e..d3b57631f 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -717,7 +717,7 @@ public class DownloadDialog extends DialogFragment } startActivityForResult(StoredFileHelper.getNewPicker(context, startPath, - filenameTmp), REQUEST_DOWNLOAD_SAVE_AS); + filenameTmp, mimeTmp), REQUEST_DOWNLOAD_SAVE_AS); return; } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 4f3128aaa..d6c08a269 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -191,7 +191,7 @@ class SubscriptionFragment : BaseStateFragment() { val date = SimpleDateFormat("yyyyMMddHHmm", Locale.ENGLISH).format(Date()) val exportName = "newpipe_subscriptions_$date.json" - startActivityForResult(StoredFileHelper.getNewPicker(activity, null, exportName), REQUEST_EXPORT_CODE) + startActivityForResult(StoredFileHelper.getNewPicker(activity, null, exportName, "application/json"), REQUEST_EXPORT_CODE) } private fun openReorderDialog() { diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index c9b36e2a7..45325dc6c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -66,7 +66,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment { exportDataPreference.setOnPreferenceClickListener((final Preference p) -> { final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); startActivityForResult(StoredFileHelper.getNewPicker(getContext(), null, - "NewPipeData-" + sdf.format(new Date()) + ".zip"), REQUEST_EXPORT_PATH); + "NewPipeData-" + sdf.format(new Date()) + ".zip", "application/zip"), + REQUEST_EXPORT_PATH); return true; }); diff --git a/app/src/main/java/org/schabi/newpipe/streams/io/StoredFileHelper.java b/app/src/main/java/org/schabi/newpipe/streams/io/StoredFileHelper.java index d2b694247..893114dc1 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/io/StoredFileHelper.java +++ b/app/src/main/java/org/schabi/newpipe/streams/io/StoredFileHelper.java @@ -467,13 +467,15 @@ public class StoredFileHelper implements Serializable { } } - public static Intent getNewPicker(@NonNull final Context ctx, @Nullable final String startPath, - @Nullable final String filename) { + public static Intent getNewPicker(@NonNull final Context ctx, + @Nullable final String startPath, + @Nullable final String filename, + @NonNull final String mimeType) { final Intent i; if (NewPipeSettings.useStorageAccessFramework(ctx)) { i = new Intent(Intent.ACTION_CREATE_DOCUMENT) .putExtra("android.content.extra.SHOW_ADVANCED", true) - .setType("*/*") + .setType(mimeType) .addCategory(Intent.CATEGORY_OPENABLE) .addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | StoredDirectoryHelper.PERMISSION_FLAGS); diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index ac3579b79..c56587c55 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -256,7 +256,7 @@ public class MissionsFragment extends Fragment { } startActivityForResult(StoredFileHelper.getNewPicker(mContext, startPath, - mission.storage.getName()), REQUEST_DOWNLOAD_SAVE_AS); + mission.storage.getName(), mission.storage.getType()), REQUEST_DOWNLOAD_SAVE_AS); } @Override