Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.

Commit d525b04

Browse files
committed
sponsorblock: move fetching VideoSegment's to DownloadDialog
- move fetching VideoSegment's to DownloadDialog - integrate ProgressBar to show that we are fetching VideoSegment's
1 parent 5d222fc commit d525b04

3 files changed

Lines changed: 62 additions & 37 deletions

File tree

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.download;
22

33
import static org.schabi.newpipe.extractor.stream.DeliveryMethod.PROGRESSIVE_HTTP;
4+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
45
import static org.schabi.newpipe.util.ListHelper.getStreamsOfSpecifiedDelivery;
56
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
67

@@ -66,6 +67,7 @@
6667
import org.schabi.newpipe.util.PermissionHelper;
6768
import org.schabi.newpipe.util.SecondaryStreamHelper;
6869
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
70+
import org.schabi.newpipe.util.SponsorBlockUtils;
6971
import org.schabi.newpipe.util.StreamItemAdapter;
7072
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
7173
import org.schabi.newpipe.util.ThemeHelper;
@@ -80,7 +82,10 @@
8082

8183
import icepick.Icepick;
8284
import icepick.State;
85+
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
86+
import io.reactivex.rxjava3.core.Single;
8387
import io.reactivex.rxjava3.disposables.CompositeDisposable;
88+
import io.reactivex.rxjava3.schedulers.Schedulers;
8489
import us.shandian.giga.get.MissionRecoveryInfo;
8590
import us.shandian.giga.postprocessing.Postprocessing;
8691
import us.shandian.giga.service.DownloadManager;
@@ -260,7 +265,7 @@ public void onServiceConnected(final ComponentName cname, final IBinder service)
260265
downloadManager = mgr.getDownloadManager();
261266
askForSavePath = mgr.askForSavePath();
262267

263-
okButton.setEnabled(true);
268+
checkForYoutubeVideoSegments();
264269

265270
context.unbindService(this);
266271
}
@@ -301,6 +306,8 @@ public void onViewCreated(@NonNull final View view,
301306

302307
dialogBinding.videoAudioGroup.setOnCheckedChangeListener(this);
303308

309+
showLoading();
310+
304311
initToolbar(dialogBinding.toolbarLayout.toolbar);
305312
setupDownloadOptions();
306313

@@ -1077,4 +1084,37 @@ private void continueSelectedDownload(@NonNull final StoredFileHelper storage) {
10771084

10781085
dismiss();
10791086
}
1087+
1088+
private void checkForYoutubeVideoSegments() {
1089+
disposables.add(Single.fromCallable(() -> {
1090+
VideoSegment[] videoSegments = null;
1091+
try {
1092+
videoSegments = SponsorBlockUtils
1093+
.getYouTubeVideoSegments(getContext(), currentInfo);
1094+
} catch (final Exception e) {
1095+
// TODO: handle?
1096+
}
1097+
1098+
return videoSegments == null
1099+
? new VideoSegment[0]
1100+
: videoSegments;
1101+
})
1102+
.subscribeOn(Schedulers.io())
1103+
.observeOn(AndroidSchedulers.mainThread())
1104+
.subscribe(videoSegments -> {
1105+
setVideoSegments(videoSegments);
1106+
okButton.setEnabled(true);
1107+
hideLoading();
1108+
}));
1109+
}
1110+
1111+
public void showLoading() {
1112+
dialogBinding.fileName.setVisibility(View.GONE);
1113+
animate(dialogBinding.loadingProgressBar, true, 400);
1114+
}
1115+
1116+
public void hideLoading() {
1117+
animate(dialogBinding.loadingProgressBar, false, 0);
1118+
dialogBinding.fileName.setVisibility(View.VISIBLE);
1119+
}
10801120
}

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,13 @@
108108
import org.schabi.newpipe.util.DeviceUtils;
109109
import org.schabi.newpipe.util.ExtractorHelper;
110110
import org.schabi.newpipe.util.ReturnYouTubeDislikeUtils;
111-
import org.schabi.newpipe.util.VideoSegment;
112111
import org.schabi.newpipe.util.external_communication.KoreUtils;
113112
import org.schabi.newpipe.util.ListHelper;
114113
import org.schabi.newpipe.util.Localization;
115114
import org.schabi.newpipe.util.NavigationHelper;
116115
import org.schabi.newpipe.util.PermissionHelper;
117116
import org.schabi.newpipe.util.PicassoHelper;
118117
import org.schabi.newpipe.util.StreamTypeUtil;
119-
import org.schabi.newpipe.util.SponsorBlockUtils;
120118
import org.schabi.newpipe.util.external_communication.ShareUtils;
121119
import org.schabi.newpipe.util.ThemeHelper;
122120

@@ -131,7 +129,6 @@
131129

132130
import icepick.State;
133131
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
134-
import io.reactivex.rxjava3.core.Single;
135132
import io.reactivex.rxjava3.disposables.CompositeDisposable;
136133
import io.reactivex.rxjava3.disposables.Disposable;
137134
import io.reactivex.rxjava3.schedulers.Schedulers;
@@ -212,8 +209,6 @@ public final class VideoDetailFragment
212209
private final CompositeDisposable disposables = new CompositeDisposable();
213210
@Nullable
214211
private Disposable positionSubscriber = null;
215-
@Nullable
216-
private Disposable videoSegmentsSubscriber = null;
217212

218213
private BottomSheetBehavior<FrameLayout> bottomSheetBehavior;
219214
private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback;
@@ -407,9 +402,6 @@ public void onDestroy() {
407402
if (positionSubscriber != null) {
408403
positionSubscriber.dispose();
409404
}
410-
if (videoSegmentsSubscriber != null) {
411-
videoSegmentsSubscriber.dispose();
412-
}
413405
if (currentWorker != null) {
414406
currentWorker.dispose();
415407
}
@@ -1683,32 +1675,13 @@ public void openDownloadDialog() {
16831675
return;
16841676
}
16851677

1686-
videoSegmentsSubscriber = Single.fromCallable(() -> {
1687-
VideoSegment[] videoSegments = null;
1688-
1689-
try {
1690-
videoSegments =
1691-
SponsorBlockUtils.getYouTubeVideoSegments(getContext(), currentInfo);
1692-
} catch (final Exception e) {
1693-
// TODO: handle?
1694-
}
1695-
1696-
return videoSegments == null
1697-
? new VideoSegment[0]
1698-
: videoSegments;
1699-
})
1700-
.subscribeOn(Schedulers.io())
1701-
.observeOn(AndroidSchedulers.mainThread())
1702-
.subscribe(videoSegments -> {
1703-
try {
1704-
final DownloadDialog downloadDialog = new DownloadDialog(activity, currentInfo);
1705-
downloadDialog.setVideoSegments(videoSegments);
1706-
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
1707-
} catch (final Exception e) {
1708-
ErrorUtil.showSnackbar(activity, new ErrorInfo(e, UserAction.DOWNLOAD_OPEN_DIALOG,
1709-
"Showing download dialog", currentInfo));
1710-
}
1711-
});
1678+
try {
1679+
final DownloadDialog downloadDialog = new DownloadDialog(activity, currentInfo);
1680+
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
1681+
} catch (final Exception e) {
1682+
ErrorUtil.showSnackbar(activity, new ErrorInfo(e, UserAction.DOWNLOAD_OPEN_DIALOG,
1683+
"Showing download dialog", currentInfo));
1684+
}
17121685
}
17131686

17141687
/*//////////////////////////////////////////////////////////////////////////

app/src/main/res/layout/download_dialog.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@
1818
android:layout_marginBottom="6dp"
1919
android:text="@string/msg_name" />
2020

21+
<ProgressBar
22+
android:id="@+id/loading_progress_bar"
23+
style="@style/Widget.AppCompat.ProgressBar"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_below="@id/file_name_text_view"
27+
android:indeterminate="true"
28+
android:visibility="gone"
29+
tools:visibility="visible" />
30+
2131
<org.schabi.newpipe.views.NewPipeEditText
2232
android:id="@+id/file_name"
2333
android:layout_width="match_parent"
2434
android:layout_height="wrap_content"
25-
android:layout_below="@+id/file_name_text_view"
35+
android:layout_below="@id/loading_progress_bar"
2636
android:layout_marginLeft="20dp"
2737
android:layout_marginRight="20dp"
2838
android:layout_marginBottom="6dp"
2939
android:inputType="text"
30-
android:maxLines="1" />
40+
android:maxLines="1"
41+
android:visibility="gone"
42+
tools:visibility="visible" />
3143

3244
<RadioGroup
3345
android:id="@+id/video_audio_group"

0 commit comments

Comments
 (0)