-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Load uploaderUrl when showing Channel Details from Play Queue #7538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Stypox
merged 1 commit into
TeamNewPipe:dev
from
ktprograms:fix-queue-channel-details-not-in-db
Jan 26, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/src/main/java/org/schabi/newpipe/util/SaveUploaderUrlHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package org.schabi.newpipe.util; | ||
|
|
||
| import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | ||
|
|
||
| import android.content.Context; | ||
| import android.widget.Toast; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.fragment.app.Fragment; | ||
|
|
||
| import org.schabi.newpipe.NewPipeDatabase; | ||
| import org.schabi.newpipe.R; | ||
| import org.schabi.newpipe.error.ErrorInfo; | ||
| import org.schabi.newpipe.error.ErrorUtil; | ||
| import org.schabi.newpipe.error.UserAction; | ||
| import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||
| import org.schabi.newpipe.player.playqueue.PlayQueueItem; | ||
|
|
||
| import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; | ||
| import io.reactivex.rxjava3.schedulers.Schedulers; | ||
|
|
||
| /** | ||
| * Utility class for putting the uploader url into the database - when required. | ||
| */ | ||
| public final class SaveUploaderUrlHelper { | ||
| private SaveUploaderUrlHelper() { | ||
| } | ||
|
|
||
| // Public functions which call the function that does | ||
| // the actual work with the correct parameters | ||
| public static void saveUploaderUrlIfNeeded(@NonNull final Fragment fragment, | ||
| @NonNull final StreamInfoItem infoItem, | ||
| @NonNull final SaveUploaderUrlCallback callback) { | ||
| saveUploaderUrlIfNeeded(fragment.requireContext(), | ||
| infoItem.getServiceId(), | ||
| infoItem.getUrl(), | ||
| infoItem.getUploaderUrl(), | ||
| callback); | ||
| } | ||
| public static void saveUploaderUrlIfNeeded(@NonNull final Context context, | ||
| @NonNull final PlayQueueItem queueItem, | ||
| @NonNull final SaveUploaderUrlCallback callback) { | ||
| saveUploaderUrlIfNeeded(context, | ||
| queueItem.getServiceId(), | ||
| queueItem.getUrl(), | ||
| queueItem.getUploaderUrl(), | ||
| callback); | ||
| } | ||
|
|
||
| /** | ||
| * Fetches and saves the uploaderUrl if it is empty (meaning that it does | ||
| * not exist in the video item). The callback is called with either the | ||
| * fetched uploaderUrl, or the already saved uploaderUrl, but it is always | ||
| * called with a valid uploaderUrl that can be used to show channel details. | ||
| * | ||
| * @param context Context | ||
| * @param serviceId The serviceId of the item | ||
| * @param url The item url | ||
| * @param uploaderUrl The uploaderUrl of the item, if null or empty, it | ||
| * will be fetched using the item url. | ||
| * @param callback The callback that returns the fetched or existing | ||
| * uploaderUrl | ||
| */ | ||
Stypox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static void saveUploaderUrlIfNeeded(@NonNull final Context context, | ||
| final int serviceId, | ||
| @NonNull final String url, | ||
| // Only used if not null or empty | ||
| @Nullable final String uploaderUrl, | ||
| @NonNull final SaveUploaderUrlCallback callback) { | ||
| if (isNullOrEmpty(uploaderUrl)) { | ||
| Toast.makeText(context, R.string.loading_channel_details, | ||
| Toast.LENGTH_SHORT).show(); | ||
| ExtractorHelper.getStreamInfo(serviceId, url, false) | ||
| .subscribeOn(Schedulers.io()) | ||
| .observeOn(AndroidSchedulers.mainThread()) | ||
| .subscribe(result -> { | ||
| NewPipeDatabase.getInstance(context).streamDAO() | ||
| .setUploaderUrl(serviceId, url, result.getUploaderUrl()) | ||
| .subscribeOn(Schedulers.io()).subscribe(); | ||
| callback.onCallback(result.getUploaderUrl()); | ||
| }, throwable -> ErrorUtil.createNotification(context, | ||
| new ErrorInfo(throwable, UserAction.REQUESTED_CHANNEL, | ||
| "Could not load channel details") | ||
| )); | ||
| } else { | ||
| callback.onCallback(uploaderUrl); | ||
| } | ||
| } | ||
|
|
||
| public interface SaveUploaderUrlCallback { | ||
| void onCallback(@NonNull String uploaderUrl); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.