mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-27 22:36:51 +01:00
fix(YouTube - SponsorBlock): Export local statistics with saved settings (#542)
This commit is contained in:
parent
aedb3eddd6
commit
0ed8e5a298
@ -597,8 +597,6 @@ public enum SettingsEnum {
|
||||
case SB_LAST_VIP_CHECK:
|
||||
case SB_HIDE_EXPORT_WARNING:
|
||||
case SB_SEEN_GUIDELINES:
|
||||
case SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS:
|
||||
case SB_LOCAL_TIME_SAVED_MILLISECONDS:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -26,8 +26,6 @@ import android.widget.EditText;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import app.revanced.integrations.settings.SettingsEnum;
|
||||
import app.revanced.integrations.settings.SharedPrefCategory;
|
||||
import app.revanced.integrations.sponsorblock.SegmentPlaybackController;
|
||||
@ -471,8 +469,6 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private static final DecimalFormat statsNumberOfSegmentsSkippedFormatter = new DecimalFormat("#,###,###");
|
||||
|
||||
private void addUserStats(@NonNull Preference loadingPlaceholder, @Nullable UserStats stats) {
|
||||
ReVancedUtils.verifyOnMainThread();
|
||||
try {
|
||||
@ -514,7 +510,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment {
|
||||
// number of segment submissions (does not include ignored segments)
|
||||
Preference preference = new Preference(context);
|
||||
statsCategory.addPreference(preference);
|
||||
String formatted = statsNumberOfSegmentsSkippedFormatter.format(stats.segmentCount);
|
||||
String formatted = SponsorBlockUtils.getNumberOfSkipsString(stats.segmentCount);
|
||||
preference.setTitle(fromHtml(str("sb_stats_submissions", formatted)));
|
||||
if (stats.totalSegmentCountIncludingIgnored == 0) {
|
||||
preference.setSelectable(false);
|
||||
@ -550,7 +546,8 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment {
|
||||
stats_saved = str("sb_stats_saved_zero");
|
||||
stats_saved_sum = str("sb_stats_saved_sum_zero");
|
||||
} else {
|
||||
stats_saved = str("sb_stats_saved", statsNumberOfSegmentsSkippedFormatter.format(stats.viewCount));
|
||||
stats_saved = str("sb_stats_saved",
|
||||
SponsorBlockUtils.getNumberOfSkipsString(stats.viewCount));
|
||||
stats_saved_sum = str("sb_stats_saved_sum", SponsorBlockUtils.getTimeSavedString((long) (60 * stats.minutesSaved)));
|
||||
}
|
||||
preference.setTitle(fromHtml(stats_saved));
|
||||
@ -573,7 +570,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment {
|
||||
statsCategory.addPreference(preference);
|
||||
|
||||
Runnable updateStatsSelfSaved = () -> {
|
||||
String formatted = statsNumberOfSegmentsSkippedFormatter.format(SettingsEnum.SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS.getInt());
|
||||
String formatted = SponsorBlockUtils.getNumberOfSkipsString(SettingsEnum.SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS.getInt());
|
||||
preference.setTitle(fromHtml(str("sb_stats_self_saved", formatted)));
|
||||
String formattedSaved = SponsorBlockUtils.getTimeSavedString(SettingsEnum.SB_LOCAL_TIME_SAVED_MILLISECONDS.getLong() / 1000);
|
||||
preference.setSummary(fromHtml(str("sb_stats_self_saved_sum", formattedSaved)));
|
||||
|
@ -12,6 +12,7 @@ import android.widget.EditText;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
@ -39,6 +40,7 @@ public class SponsorBlockUtils {
|
||||
private static final SimpleDateFormat manualEditTimeFormatter = new SimpleDateFormat(MANUAL_EDIT_TIME_FORMAT);
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
private static final SimpleDateFormat voteSegmentTimeFormatter = new SimpleDateFormat();
|
||||
private static final NumberFormat statsNumberFormatter = NumberFormat.getNumberInstance();
|
||||
static {
|
||||
TimeZone utc = TimeZone.getTimeZone("UTC");
|
||||
manualEditTimeFormatter.setTimeZone(utc);
|
||||
@ -402,19 +404,27 @@ public class SponsorBlockUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getNumberOfSkipsString(int viewCount) {
|
||||
return statsNumberFormatter.format(viewCount);
|
||||
}
|
||||
|
||||
public static String getTimeSavedString(long totalSecondsSaved) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
Duration duration = Duration.ofSeconds(totalSecondsSaved);
|
||||
final long hoursSaved = duration.toHours();
|
||||
final long minutesSaved = duration.toMinutes() % 60;
|
||||
if (hoursSaved > 0) {
|
||||
return str("sb_stats_saved_hour_format", hoursSaved, minutesSaved);
|
||||
final long hours = duration.toHours();
|
||||
final long minutes = duration.toMinutes() % 60;
|
||||
// Format all numbers so non-western numbers use a consistent appearance.
|
||||
String minutesFormatted = statsNumberFormatter.format(minutes);
|
||||
if (hours > 0) {
|
||||
String hoursFormatted = statsNumberFormatter.format(hours);
|
||||
return str("sb_stats_saved_hour_format", hoursFormatted, minutesFormatted);
|
||||
}
|
||||
final long secondsSaved = duration.getSeconds() % 60;
|
||||
if (minutesSaved > 0) {
|
||||
return str("sb_stats_saved_minute_format", minutesSaved, secondsSaved);
|
||||
final long seconds = duration.getSeconds() % 60;
|
||||
String secondsFormatted = statsNumberFormatter.format(seconds);
|
||||
if (minutes > 0) {
|
||||
return str("sb_stats_saved_minute_format", minutesFormatted, secondsFormatted);
|
||||
}
|
||||
return str("sb_stats_saved_second_format", secondsSaved);
|
||||
return str("sb_stats_saved_second_format", secondsFormatted);
|
||||
}
|
||||
return "error"; // will never be reached. YouTube requires Android O or greater
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user