finish merging

This commit is contained in:
caneleex 2021-07-23 23:50:57 +02:00
parent b630bf8e84
commit c84eb770e8
2 changed files with 39 additions and 3 deletions

View File

@ -15,7 +15,6 @@ import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
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 withoutSegmentsFormatter = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT);
public static final SimpleDateFormat withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H);
private static boolean videoHasSegments = false;
private static String timeWithoutSegments = "";
public static boolean videoHasSegments = false;
public static String timeWithoutSegments = "";
private static final int sponsorBtnId = 1234;
public static final View.OnClickListener sponsorBlockBtnListener = v -> {
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) {
int count = 0;
for (int i = 0; i < seq.length(); i++) {

View File

@ -25,6 +25,8 @@ import pl.jakubweg.SponsorBlockUtils.VoteOption;
import pl.jakubweg.objects.SponsorSegment;
import pl.jakubweg.objects.UserStats;
import static pl.jakubweg.SponsorBlockUtils.timeWithoutSegments;
import static pl.jakubweg.SponsorBlockUtils.videoHasSegments;
import static pl.jakubweg.StringRef.str;
public class Requester {
@ -38,6 +40,8 @@ public class Requester {
try {
HttpURLConnection connection = getConnectionFromRoute(Route.GET_SEGMENTS, videoId, SponsorBlockSettings.sponsorBlockUrlCategories);
int responseCode = connection.getResponseCode();
videoHasSegments = false;
timeWithoutSegments = "";
switch (responseCode) {
case 200:
@ -57,6 +61,8 @@ public class Requester {
segments.add(sponsorSegment);
}
}
videoHasSegments = true;
timeWithoutSegments = SponsorBlockUtils.getTimeWithoutSegments(segments);
break;
case 404:
break;