Merge pull request #4628 from ByteHamster/local-feeds-metadata

Fixed local feed metadata, show directly
This commit is contained in:
ByteHamster 2020-11-01 17:00:27 +01:00 committed by GitHub
commit 23763eb87f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 22 deletions

View File

@ -35,6 +35,9 @@ import de.danoeh.antennapod.discovery.FyydPodcastSearcher;
import de.danoeh.antennapod.discovery.ItunesPodcastSearcher; import de.danoeh.antennapod.discovery.ItunesPodcastSearcher;
import de.danoeh.antennapod.discovery.PodcastIndexPodcastSearcher; import de.danoeh.antennapod.discovery.PodcastIndexPodcastSearcher;
import de.danoeh.antennapod.fragment.gpodnet.GpodnetMainFragment; import de.danoeh.antennapod.fragment.gpodnet.GpodnetMainFragment;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.Collections; import java.util.Collections;
@ -162,31 +165,37 @@ public class AddFeedFragment extends Fragment {
intent.setData(uri); intent.setData(uri);
startActivity(intent); startActivity(intent);
} else if (requestCode == REQUEST_CODE_ADD_LOCAL_FOLDER) { } else if (requestCode == REQUEST_CODE_ADD_LOCAL_FOLDER) {
addLocalFolder(uri); Observable.fromCallable(() -> addLocalFolder(uri))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
feed -> {
Fragment fragment = FeedItemlistFragment.newInstance(feed.getId());
((MainActivity) getActivity()).loadChildFragment(fragment);
}, error -> {
Log.e(TAG, Log.getStackTraceString(error));
((MainActivity) getActivity())
.showSnackbarAbovePlayer(error.getLocalizedMessage(), Snackbar.LENGTH_LONG);
});
} }
} }
private void addLocalFolder(Uri uri) { private Feed addLocalFolder(Uri uri) throws DownloadRequestException {
if (Build.VERSION.SDK_INT < 21) { if (Build.VERSION.SDK_INT < 21) {
return; return null;
} }
try { getActivity().getContentResolver()
getActivity().getContentResolver() .takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), uri);
DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), uri); if (documentFile == null) {
if (documentFile == null) { throw new IllegalArgumentException("Unable to retrieve document tree");
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);
} }
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);
Feed fromDatabase = DBTasks.updateFeed(getContext(), dirFeed, false);
DBTasks.forceRefreshFeed(getContext(), fromDatabase, true);
return fromDatabase;
} }
} }

View File

@ -369,7 +369,7 @@ public class FeedInfoFragment extends Fragment {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
() -> ((MainActivity) getActivity()) () -> ((MainActivity) getActivity())
.showSnackbarAbovePlayer(R.string.add_local_folder_success, Snackbar.LENGTH_SHORT), .showSnackbarAbovePlayer(android.R.string.ok, Snackbar.LENGTH_SHORT),
error -> ((MainActivity) getActivity()) error -> ((MainActivity) getActivity())
.showSnackbarAbovePlayer(error.getLocalizedMessage(), Snackbar.LENGTH_LONG)); .showSnackbarAbovePlayer(error.getLocalizedMessage(), Snackbar.LENGTH_LONG));
} }

View File

@ -742,7 +742,6 @@
<string name="discover_powered_by_itunes">Suggestions by iTunes</string> <string name="discover_powered_by_itunes">Suggestions by iTunes</string>
<string name="search_powered_by">Results by %1$s</string> <string name="search_powered_by">Results by %1$s</string>
<string name="add_local_folder">Add local folder</string> <string name="add_local_folder">Add local folder</string>
<string name="add_local_folder_success">Adding local folder succeeded</string>
<string name="reconnect_local_folder">Re-connect local folder</string> <string name="reconnect_local_folder">Re-connect local folder</string>
<string name="reconnect_local_folder_warning">In case of permission denials, you can use this to re-connect to the exact same folder. Do not select another folder.</string> <string name="reconnect_local_folder_warning">In case of permission denials, you can use this to re-connect to the exact same folder. Do not select another folder.</string>
<string name="local_feed_description">This virtual podcast was created by adding a folder to AntennaPod.</string> <string name="local_feed_description">This virtual podcast was created by adding a folder to AntennaPod.</string>