From 16ecaff4eee0dc4c5aee96461b6f739f40414342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Kl=C3=BCber?= <48260138+sklueber@users.noreply.github.com> Date: Thu, 11 Jan 2024 14:57:02 -0600 Subject: [PATCH] [android][bookmarks] Allow selecting specific files for import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5413 Signed-off-by: Simon Klüber <48260138+sklueber@users.noreply.github.com> --- .../bookmarks/BookmarkCategoriesFragment.java | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java index 4e63ca97fc..5119ad33c2 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarkCategoriesFragment.java @@ -2,6 +2,7 @@ package app.organicmaps.bookmarks; import android.app.Activity; import android.app.ProgressDialog; +import android.content.ClipData; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; @@ -53,7 +54,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment= Build.VERSION_CODES.M) intent.putExtra(DocumentsContract.EXTRA_EXCLUDE_SELF, true); - startActivityForResult(intent, REQ_CODE_IMPORT_DIRECTORY); + startActivityForResult(intent, REQ_CODE_IMPORT_FILES); } @Override @@ -291,30 +298,44 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment { AtomicInteger found = new AtomicInteger(0); - StorageUtils.listContentProviderFilesRecursively( - resolver, rootUri, uri -> { - if (BookmarkManager.INSTANCE.importBookmarksFile(resolver, uri, tempDir)) - found.incrementAndGet(); - }); + + ClipData clipData = data.getClipData(); + if (clipData != null) + { + // Multiple files were selected + for (int i = 0; i < clipData.getItemCount(); i++) + { + Uri uri = clipData.getItemAt(i).getUri(); + if (BookmarkManager.INSTANCE.importBookmarksFile(resolver, uri, tempDir)) + found.incrementAndGet(); + } + } + else + { + // A single file was selected + Uri uri = data.getData(); + if (uri != null && BookmarkManager.INSTANCE.importBookmarksFile(resolver, uri, tempDir)) + found.incrementAndGet(); + } + UiThread.run(() -> { if (dialog.isShowing()) dialog.dismiss(); -- 2.45.3