Merge pull request #309 from bravenewpipe/move-fetching-VideoSegments-to-DownloadDialog
sponsorblock: move fetching VideoSegment's to DownloadDialog
This commit is contained in:
commit
fa86c2632b
3 changed files with 62 additions and 37 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.download;
|
||||
|
||||
import static org.schabi.newpipe.extractor.stream.DeliveryMethod.PROGRESSIVE_HTTP;
|
||||
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
||||
import static org.schabi.newpipe.util.ListHelper.getStreamsOfSpecifiedDelivery;
|
||||
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
||||
|
||||
|
@ -66,6 +67,7 @@ import org.schabi.newpipe.util.ListHelper;
|
|||
import org.schabi.newpipe.util.PermissionHelper;
|
||||
import org.schabi.newpipe.util.SecondaryStreamHelper;
|
||||
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
|
||||
import org.schabi.newpipe.util.SponsorBlockUtils;
|
||||
import org.schabi.newpipe.util.StreamItemAdapter;
|
||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
@ -80,7 +82,10 @@ import java.util.Optional;
|
|||
|
||||
import icepick.Icepick;
|
||||
import icepick.State;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import us.shandian.giga.get.MissionRecoveryInfo;
|
||||
import us.shandian.giga.postprocessing.Postprocessing;
|
||||
import us.shandian.giga.service.DownloadManager;
|
||||
|
@ -260,7 +265,7 @@ public class DownloadDialog extends DialogFragment
|
|||
downloadManager = mgr.getDownloadManager();
|
||||
askForSavePath = mgr.askForSavePath();
|
||||
|
||||
okButton.setEnabled(true);
|
||||
checkForYoutubeVideoSegments();
|
||||
|
||||
context.unbindService(this);
|
||||
}
|
||||
|
@ -301,6 +306,8 @@ public class DownloadDialog extends DialogFragment
|
|||
|
||||
dialogBinding.videoAudioGroup.setOnCheckedChangeListener(this);
|
||||
|
||||
showLoading();
|
||||
|
||||
initToolbar(dialogBinding.toolbarLayout.toolbar);
|
||||
setupDownloadOptions();
|
||||
|
||||
|
@ -1077,4 +1084,37 @@ public class DownloadDialog extends DialogFragment
|
|||
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void checkForYoutubeVideoSegments() {
|
||||
disposables.add(Single.fromCallable(() -> {
|
||||
VideoSegment[] videoSegments = null;
|
||||
try {
|
||||
videoSegments = SponsorBlockUtils
|
||||
.getYouTubeVideoSegments(getContext(), currentInfo);
|
||||
} catch (final Exception e) {
|
||||
// TODO: handle?
|
||||
}
|
||||
|
||||
return videoSegments == null
|
||||
? new VideoSegment[0]
|
||||
: videoSegments;
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(videoSegments -> {
|
||||
setVideoSegments(videoSegments);
|
||||
okButton.setEnabled(true);
|
||||
hideLoading();
|
||||
}));
|
||||
}
|
||||
|
||||
public void showLoading() {
|
||||
dialogBinding.fileName.setVisibility(View.GONE);
|
||||
animate(dialogBinding.loadingProgressBar, true, 400);
|
||||
}
|
||||
|
||||
public void hideLoading() {
|
||||
animate(dialogBinding.loadingProgressBar, false, 0);
|
||||
dialogBinding.fileName.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,6 @@ import org.schabi.newpipe.util.Constants;
|
|||
import org.schabi.newpipe.util.DeviceUtils;
|
||||
import org.schabi.newpipe.util.ExtractorHelper;
|
||||
import org.schabi.newpipe.util.ReturnYouTubeDislikeUtils;
|
||||
import org.schabi.newpipe.util.VideoSegment;
|
||||
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
||||
import org.schabi.newpipe.util.ListHelper;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
|
@ -113,7 +112,6 @@ import org.schabi.newpipe.util.NavigationHelper;
|
|||
import org.schabi.newpipe.util.PermissionHelper;
|
||||
import org.schabi.newpipe.util.PicassoHelper;
|
||||
import org.schabi.newpipe.util.StreamTypeUtil;
|
||||
import org.schabi.newpipe.util.SponsorBlockUtils;
|
||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
|
@ -128,7 +126,6 @@ import java.util.function.Consumer;
|
|||
|
||||
import icepick.State;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
@ -209,8 +206,6 @@ public final class VideoDetailFragment
|
|||
private final CompositeDisposable disposables = new CompositeDisposable();
|
||||
@Nullable
|
||||
private Disposable positionSubscriber = null;
|
||||
@Nullable
|
||||
private Disposable videoSegmentsSubscriber = null;
|
||||
|
||||
private BottomSheetBehavior<FrameLayout> bottomSheetBehavior;
|
||||
private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback;
|
||||
|
@ -404,9 +399,6 @@ public final class VideoDetailFragment
|
|||
if (positionSubscriber != null) {
|
||||
positionSubscriber.dispose();
|
||||
}
|
||||
if (videoSegmentsSubscriber != null) {
|
||||
videoSegmentsSubscriber.dispose();
|
||||
}
|
||||
if (currentWorker != null) {
|
||||
currentWorker.dispose();
|
||||
}
|
||||
|
@ -1672,32 +1664,13 @@ public final class VideoDetailFragment
|
|||
return;
|
||||
}
|
||||
|
||||
videoSegmentsSubscriber = Single.fromCallable(() -> {
|
||||
VideoSegment[] videoSegments = null;
|
||||
|
||||
try {
|
||||
videoSegments =
|
||||
SponsorBlockUtils.getYouTubeVideoSegments(getContext(), currentInfo);
|
||||
} catch (final Exception e) {
|
||||
// TODO: handle?
|
||||
}
|
||||
|
||||
return videoSegments == null
|
||||
? new VideoSegment[0]
|
||||
: videoSegments;
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(videoSegments -> {
|
||||
try {
|
||||
final DownloadDialog downloadDialog = new DownloadDialog(activity, currentInfo);
|
||||
downloadDialog.setVideoSegments(videoSegments);
|
||||
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
|
||||
} catch (final Exception e) {
|
||||
ErrorUtil.showSnackbar(activity, new ErrorInfo(e, UserAction.DOWNLOAD_OPEN_DIALOG,
|
||||
"Showing download dialog", currentInfo));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -18,16 +18,28 @@
|
|||
android:layout_marginBottom="6dp"
|
||||
android:text="@string/msg_name" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading_progress_bar"
|
||||
style="@style/Widget.AppCompat.ProgressBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/file_name_text_view"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<org.schabi.newpipe.views.NewPipeEditText
|
||||
android:id="@+id/file_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/file_name_text_view"
|
||||
android:layout_below="@id/loading_progress_bar"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:inputType="text"
|
||||
android:maxLines="1" />
|
||||
android:maxLines="1"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/video_audio_group"
|
||||
|
|
Loading…
Reference in a new issue