diff options
author | ByteHamster <info@bytehamster.com> | 2020-09-12 22:02:46 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-09-12 22:02:46 +0200 |
commit | 401da0a2074d3f86d23cab054cd38a79241a4b35 (patch) | |
tree | 89198f0d87989b991561a32b69c8040ceded7f35 /app/src/main/java/de/danoeh | |
parent | 5d96effbd500a8378d9058f78c3149c048f3caf8 (diff) | |
download | AntennaPod-401da0a2074d3f86d23cab054cd38a79241a4b35.zip |
Hide local feed button on old Android versions
Diffstat (limited to 'app/src/main/java/de/danoeh')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java index 290bf1845..5e014db3f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java @@ -6,6 +6,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -27,6 +28,7 @@ import de.danoeh.antennapod.activity.OnlineFeedViewActivity; import de.danoeh.antennapod.activity.OpmlImportActivity; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.storage.DBTasks; +import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.util.SortOrder; import de.danoeh.antennapod.discovery.CombinedSearcher; import de.danoeh.antennapod.discovery.FyydPodcastSearcher; @@ -83,6 +85,9 @@ public class AddFeedFragment extends Fragment { } }); root.findViewById(R.id.btn_add_local_folder).setOnClickListener(v -> { + if (Build.VERSION.SDK_INT < 21) { + return; + } try { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); @@ -91,6 +96,9 @@ public class AddFeedFragment extends Fragment { Log.e(TAG, "No activity found. Should never happen..."); } }); + if (Build.VERSION.SDK_INT < 21) { + root.findViewById(R.id.btn_add_local_folder).setVisibility(View.GONE); + } root.findViewById(R.id.search_icon).setOnClickListener(view -> performSearch()); return root; } @@ -151,25 +159,31 @@ public class AddFeedFragment extends Fragment { intent.setData(uri); startActivity(intent); } else if (requestCode == REQUEST_CODE_ADD_LOCAL_FOLDER) { - try { - getActivity().getContentResolver() - .takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); - DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), uri); - if (documentFile == null) { - throw new IllegalArgumentException("Unable to retrieve document tree"); - } - Feed dirFeed = new Feed(Feed.PREFIX_LOCAL_FOLDER + uri.toString(), null, documentFile.getName()); - dirFeed.setDescription(getString(R.string.local_feed_description)); - dirFeed.setItems(Collections.emptyList()); - dirFeed.setSortOrder(SortOrder.EPISODE_TITLE_A_Z); - DBTasks.forceRefreshFeed(getContext(), dirFeed, true); - ((MainActivity) getActivity()) - .showSnackbarAbovePlayer(R.string.add_local_folder_success, Snackbar.LENGTH_SHORT); - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - ((MainActivity) getActivity()) - .showSnackbarAbovePlayer(e.getLocalizedMessage(), Snackbar.LENGTH_LONG); + addLocalFolder(uri); + } + } + + private void addLocalFolder(Uri uri) { + if (Build.VERSION.SDK_INT < 21) { + return; + } + try { + getActivity().getContentResolver() + .takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); + DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), uri); + if (documentFile == null) { + throw new IllegalArgumentException("Unable to retrieve document tree"); } + Feed dirFeed = new Feed(Feed.PREFIX_LOCAL_FOLDER + uri.toString(), null, documentFile.getName()); + dirFeed.setDescription(getString(R.string.local_feed_description)); + dirFeed.setItems(Collections.emptyList()); + dirFeed.setSortOrder(SortOrder.EPISODE_TITLE_A_Z); + DBTasks.forceRefreshFeed(getContext(), dirFeed, true); + ((MainActivity) getActivity()) + .showSnackbarAbovePlayer(R.string.add_local_folder_success, Snackbar.LENGTH_SHORT); + } catch (DownloadRequestException | IllegalArgumentException e) { + Log.e(TAG, Log.getStackTraceString(e)); + ((MainActivity) getActivity()).showSnackbarAbovePlayer(e.getLocalizedMessage(), Snackbar.LENGTH_LONG); } } } |