forked from TeamNewPipe/NewPipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load uploaderUrl when showing Channel Details from Play Queue
This checks if the uploaderUrl is in the database, if not it gets the uploaderUrl and puts it in the database. This is similar to the fetching of uploaderUrl when it doesn't exist done in TeamNewPipe#6919. Also use createNotification when error occurs in getStreamInfo.
- Loading branch information
1 parent
1475ff8
commit c39c0b1
Showing
3 changed files
with
85 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
75 changes: 75 additions & 0 deletions
75
app/src/main/java/org/schabi/newpipe/util/SaveUploaderUrlHelper.java
This file contains 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,75 @@ | ||
package org.schabi.newpipe.util; | ||
|
||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | ||
|
||
import android.content.Context; | ||
import android.widget.Toast; | ||
|
||
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; | ||
|
||
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(final Fragment fragment, | ||
final StreamInfoItem infoItem, | ||
final SaveUploaderUrlCallback callback) { | ||
saveUploaderUrlIfNeeded(fragment.requireContext(), | ||
infoItem.getServiceId(), | ||
infoItem.getUrl(), | ||
infoItem.getUploaderUrl(), | ||
callback); | ||
} | ||
public static void saveUploaderUrlIfNeeded(final Context context, | ||
final PlayQueueItem queueItem, | ||
final SaveUploaderUrlCallback callback) { | ||
saveUploaderUrlIfNeeded(context, | ||
queueItem.getServiceId(), | ||
queueItem.getUrl(), | ||
queueItem.getUploaderUrl(), | ||
callback); | ||
} | ||
|
||
private static void saveUploaderUrlIfNeeded(final Context context, | ||
final int serviceId, | ||
final String url, | ||
// Only used if not null or empty | ||
final String uploaderUrl, | ||
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(String uploaderUrl); | ||
} | ||
} |
This file contains 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