mirror of
https://github.com/YTVanced/Integrations
synced 2024-11-30 15:13:03 +00:00
finish merging
This commit is contained in:
parent
b630bf8e84
commit
c84eb770e8
2 changed files with 39 additions and 3 deletions
|
@ -15,7 +15,6 @@ import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -56,8 +55,8 @@ public abstract class SponsorBlockUtils {
|
||||||
public static final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT);
|
public static final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT);
|
||||||
public static final SimpleDateFormat withoutSegmentsFormatter = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT);
|
public static final SimpleDateFormat withoutSegmentsFormatter = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT);
|
||||||
public static final SimpleDateFormat withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H);
|
public static final SimpleDateFormat withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H);
|
||||||
private static boolean videoHasSegments = false;
|
public static boolean videoHasSegments = false;
|
||||||
private static String timeWithoutSegments = "";
|
public static String timeWithoutSegments = "";
|
||||||
private static final int sponsorBtnId = 1234;
|
private static final int sponsorBtnId = 1234;
|
||||||
public static final View.OnClickListener sponsorBlockBtnListener = v -> {
|
public static final View.OnClickListener sponsorBlockBtnListener = v -> {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
@ -399,6 +398,37 @@ public abstract class SponsorBlockUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String appendTimeWithoutSegments(String totalTime) {
|
||||||
|
if (videoHasSegments && SponsorBlockSettings.showTimeWithoutSegments && !TextUtils.isEmpty(totalTime)) {
|
||||||
|
return totalTime + timeWithoutSegments;
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTimeWithoutSegments(List<SponsorSegment> sponsorSegmentsOfCurrentVideo) {
|
||||||
|
if (!SponsorBlockSettings.isSponsorBlockEnabled || !SponsorBlockSettings.showTimeWithoutSegments || sponsorSegmentsOfCurrentVideo == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
long timeWithoutSegments = PlayerController.getCurrentVideoLength();
|
||||||
|
for (SponsorSegment segment : sponsorSegmentsOfCurrentVideo) {
|
||||||
|
timeWithoutSegments -= segment.end - segment.start;
|
||||||
|
}
|
||||||
|
Date date = new Date(timeWithoutSegments);
|
||||||
|
return timeWithoutSegments >= 3600000 ? withoutSegmentsFormatterH.format(date) : withoutSegmentsFormatter.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playerTypeChanged(String playerType) {
|
||||||
|
try {
|
||||||
|
if (videoHasSegments && (playerType.equalsIgnoreCase("NONE"))) {
|
||||||
|
PlayerController.setCurrentVideoId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Log.e(TAG, "Player type changed caused a crash.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int countMatches(CharSequence seq, char c) {
|
public static int countMatches(CharSequence seq, char c) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < seq.length(); i++) {
|
for (int i = 0; i < seq.length(); i++) {
|
||||||
|
|
|
@ -25,6 +25,8 @@ import pl.jakubweg.SponsorBlockUtils.VoteOption;
|
||||||
import pl.jakubweg.objects.SponsorSegment;
|
import pl.jakubweg.objects.SponsorSegment;
|
||||||
import pl.jakubweg.objects.UserStats;
|
import pl.jakubweg.objects.UserStats;
|
||||||
|
|
||||||
|
import static pl.jakubweg.SponsorBlockUtils.timeWithoutSegments;
|
||||||
|
import static pl.jakubweg.SponsorBlockUtils.videoHasSegments;
|
||||||
import static pl.jakubweg.StringRef.str;
|
import static pl.jakubweg.StringRef.str;
|
||||||
|
|
||||||
public class Requester {
|
public class Requester {
|
||||||
|
@ -38,6 +40,8 @@ public class Requester {
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = getConnectionFromRoute(Route.GET_SEGMENTS, videoId, SponsorBlockSettings.sponsorBlockUrlCategories);
|
HttpURLConnection connection = getConnectionFromRoute(Route.GET_SEGMENTS, videoId, SponsorBlockSettings.sponsorBlockUrlCategories);
|
||||||
int responseCode = connection.getResponseCode();
|
int responseCode = connection.getResponseCode();
|
||||||
|
videoHasSegments = false;
|
||||||
|
timeWithoutSegments = "";
|
||||||
|
|
||||||
switch (responseCode) {
|
switch (responseCode) {
|
||||||
case 200:
|
case 200:
|
||||||
|
@ -57,6 +61,8 @@ public class Requester {
|
||||||
segments.add(sponsorSegment);
|
segments.add(sponsorSegment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
videoHasSegments = true;
|
||||||
|
timeWithoutSegments = SponsorBlockUtils.getTimeWithoutSegments(segments);
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue