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.PodcastIndexPodcastSearcher;
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;
@ -162,15 +165,25 @@ public class AddFeedFragment extends Fragment {
intent.setData(uri);
startActivity(intent);
} 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) {
return;
return null;
}
try {
getActivity().getContentResolver()
.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), uri);
@ -181,12 +194,8 @@ public class AddFeedFragment extends Fragment {
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 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())
.subscribe(
() -> ((MainActivity) getActivity())
.showSnackbarAbovePlayer(R.string.add_local_folder_success, Snackbar.LENGTH_SHORT),
.showSnackbarAbovePlayer(android.R.string.ok, Snackbar.LENGTH_SHORT),
error -> ((MainActivity) getActivity())
.showSnackbarAbovePlayer(error.getLocalizedMessage(), Snackbar.LENGTH_LONG));
}

View File

@ -742,7 +742,6 @@
<string name="discover_powered_by_itunes">Suggestions by iTunes</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_success">Adding local folder succeeded</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="local_feed_description">This virtual podcast was created by adding a folder to AntennaPod.</string>