1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 00:50:32 +00:00

Provide mime type to file picker to gray out unselectable files

This commit is contained in:
Stypox 2021-08-01 13:52:32 +02:00
parent cd713db029
commit 32dffb577c
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 19 additions and 10 deletions

View File

@ -179,7 +179,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
} }
private fun onImportPreviousSelected() { private fun onImportPreviousSelected() {
requestImportLauncher.launch(StoredFileHelper.getPicker(activity)) requestImportLauncher.launch(StoredFileHelper.getPicker(activity, JSON_MIME_TYPE))
} }
private fun onExportSelected() { private fun onExportSelected() {
@ -187,7 +187,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
val exportName = "newpipe_subscriptions_$date.json" val exportName = "newpipe_subscriptions_$date.json"
requestExportLauncher.launch( requestExportLauncher.launch(
StoredFileHelper.getNewPicker(activity, exportName, "application/json", null) StoredFileHelper.getNewPicker(activity, exportName, JSON_MIME_TYPE, null)
) )
} }
@ -195,7 +195,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
FeedGroupReorderDialog().show(parentFragmentManager, null) FeedGroupReorderDialog().show(parentFragmentManager, null)
} }
fun requestExportResult(result: ActivityResult) { private fun requestExportResult(result: ActivityResult) {
if (result.data != null && result.resultCode == Activity.RESULT_OK) { if (result.data != null && result.resultCode == Activity.RESULT_OK) {
activity.startService( activity.startService(
Intent(activity, SubscriptionsExportService::class.java) Intent(activity, SubscriptionsExportService::class.java)
@ -204,7 +204,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
} }
} }
fun requestImportResult(result: ActivityResult) { private fun requestImportResult(result: ActivityResult) {
if (result.data != null && result.resultCode == Activity.RESULT_OK) { if (result.data != null && result.resultCode == Activity.RESULT_OK) {
ImportConfirmationDialog.show( ImportConfirmationDialog.show(
this, this,
@ -407,4 +407,8 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
super.hideLoading() super.hideLoading()
binding.itemsList.animate(true, 200) binding.itemsList.animate(true, 200)
} }
companion object {
const val JSON_MIME_TYPE = "application/json"
}
} }

View File

@ -177,7 +177,8 @@ public class SubscriptionsImportFragment extends BaseFragment {
} }
public void onImportFile() { public void onImportFile() {
requestImportFileLauncher.launch(StoredFileHelper.getPicker(activity)); // leave */* mime type to support all services with different mime types and file extensions
requestImportFileLauncher.launch(StoredFileHelper.getPicker(activity, "*/*"));
} }
private void requestImportFileResult(final ActivityResult result) { private void requestImportFileResult(final ActivityResult result) {

View File

@ -77,7 +77,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
final Preference importDataPreference = requirePreference(R.string.import_data); final Preference importDataPreference = requirePreference(R.string.import_data);
importDataPreference.setOnPreferenceClickListener((Preference p) -> { importDataPreference.setOnPreferenceClickListener((Preference p) -> {
requestImportPathLauncher.launch( requestImportPathLauncher.launch(
StoredFileHelper.getPicker(requireContext(), getImportExportDataUri())); StoredFileHelper.getPicker(requireContext(),
ZIP_MIME_TYPE, getImportExportDataUri()));
return true; return true;
}); });

View File

@ -459,11 +459,12 @@ public class StoredFileHelper implements Serializable {
return !str1.equals(str2); return !str1.equals(str2);
} }
public static Intent getPicker(@NonNull final Context ctx) { public static Intent getPicker(@NonNull final Context ctx,
@NonNull final String mimeType) {
if (NewPipeSettings.useStorageAccessFramework(ctx)) { if (NewPipeSettings.useStorageAccessFramework(ctx)) {
return new Intent(Intent.ACTION_OPEN_DOCUMENT) return new Intent(Intent.ACTION_OPEN_DOCUMENT)
.putExtra("android.content.extra.SHOW_ADVANCED", true) .putExtra("android.content.extra.SHOW_ADVANCED", true)
.setType("*/*") .setType(mimeType)
.addCategory(Intent.CATEGORY_OPENABLE) .addCategory(Intent.CATEGORY_OPENABLE)
.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION .addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| StoredDirectoryHelper.PERMISSION_FLAGS); | StoredDirectoryHelper.PERMISSION_FLAGS);
@ -477,8 +478,10 @@ public class StoredFileHelper implements Serializable {
} }
} }
public static Intent getPicker(@NonNull final Context ctx, @Nullable final Uri initialPath) { public static Intent getPicker(@NonNull final Context ctx,
return applyInitialPathToPickerIntent(ctx, getPicker(ctx), initialPath, null); @NonNull final String mimeType,
@Nullable final Uri initialPath) {
return applyInitialPathToPickerIntent(ctx, getPicker(ctx, mimeType), initialPath, null);
} }
public static Intent getNewPicker(@NonNull final Context ctx, public static Intent getNewPicker(@NonNull final Context ctx,