mirror of
https://github.com/revanced/revanced-patches
synced 2025-02-20 23:56:50 +01:00
we show stats now
This commit is contained in:
parent
505ac42fb0
commit
4b13b8bc10
@ -17,8 +17,13 @@ import android.preference.SwitchPreference;
|
|||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import pl.jakubweg.objects.UserStats;
|
||||||
|
import pl.jakubweg.requests.Requester;
|
||||||
|
|
||||||
|
import static android.text.Html.fromHtml;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
|
import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
|
||||||
@ -37,7 +42,7 @@ import static pl.jakubweg.StringRef.str;
|
|||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecation"}) // injected
|
@SuppressWarnings({"unused", "deprecation"}) // injected
|
||||||
public class SponsorBlockPreferenceFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class SponsorBlockPreferenceFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
private static final DecimalFormat FORMATTER = new DecimalFormat("#,###,###");
|
||||||
private final ArrayList<Preference> preferencesToDisableWhenSBDisabled = new ArrayList<>();
|
private final ArrayList<Preference> preferencesToDisableWhenSBDisabled = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,6 +110,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
|||||||
|
|
||||||
addGeneralCategory(context, preferenceScreen);
|
addGeneralCategory(context, preferenceScreen);
|
||||||
addSegmentsCategory(context, preferenceScreen);
|
addSegmentsCategory(context, preferenceScreen);
|
||||||
|
addStatsCategory(context, preferenceScreen);
|
||||||
addAboutCategory(context, preferenceScreen);
|
addAboutCategory(context, preferenceScreen);
|
||||||
|
|
||||||
enableCategoriesIfNeeded(SponsorBlockSettings.isSponsorBlockEnabled);
|
enableCategoriesIfNeeded(SponsorBlockSettings.isSponsorBlockEnabled);
|
||||||
@ -159,6 +165,48 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addStatsCategory(Context context, PreferenceScreen screen) {
|
||||||
|
PreferenceCategory category = new PreferenceCategory(context);
|
||||||
|
screen.addPreference(category);
|
||||||
|
category.setTitle("stats");
|
||||||
|
|
||||||
|
UserStats stats = Requester.getUserStats();
|
||||||
|
|
||||||
|
{
|
||||||
|
EditTextPreference preference = new EditTextPreference(context);
|
||||||
|
screen.addPreference(preference);
|
||||||
|
String userName = stats.getUserName();
|
||||||
|
preference.setTitle(fromHtml("Your username: <b>" + userName + "</b>"));
|
||||||
|
preference.setSummary("Click to change your username");
|
||||||
|
preference.setText(userName);
|
||||||
|
preference.setOnPreferenceChangeListener((preference1, newUsername) -> {
|
||||||
|
Requester.setUsername((String) newUsername);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Preference preference = new Preference(context);
|
||||||
|
screen.addPreference(preference);
|
||||||
|
String formatted = FORMATTER.format(stats.getSegmentCount());
|
||||||
|
preference.setTitle(fromHtml("Submissions: <b>" + formatted + "</b>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Preference preference = new Preference(context);
|
||||||
|
screen.addPreference(preference);
|
||||||
|
String formatted = FORMATTER.format(stats.getViewCount());
|
||||||
|
|
||||||
|
double saved = stats.getMinutesSaved();
|
||||||
|
int hoursSaved = (int) (saved / 60);
|
||||||
|
double minutesSaved = saved % 60;
|
||||||
|
String formattedSaved = String.format("%dh %.1f minutes", hoursSaved, minutesSaved);
|
||||||
|
|
||||||
|
preference.setTitle(fromHtml("You've saved people from <b>" + formatted + "</b> segments."));
|
||||||
|
preference.setSummary(fromHtml("That's <b>" + formattedSaved + "</b> of their lives."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addAboutCategory(Context context, PreferenceScreen screen) {
|
private void addAboutCategory(Context context, PreferenceScreen screen) {
|
||||||
PreferenceCategory category = new PreferenceCategory(context);
|
PreferenceCategory category = new PreferenceCategory(context);
|
||||||
screen.addPreference(category);
|
screen.addPreference(category);
|
||||||
|
@ -3,6 +3,7 @@ package pl.jakubweg.requests;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -152,7 +153,17 @@ public class Requester {
|
|||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return new UserStats("", 0, 0, 0);
|
return new UserStats("N/A", -1, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUsername(String username) {
|
||||||
|
try {
|
||||||
|
HttpURLConnection connection = getConnectionFromRoute(Route.CHANGE_USERNAME, SponsorBlockSettings.uuid, username);
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
|
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
|
||||||
|
@ -7,7 +7,8 @@ import static pl.jakubweg.requests.Route.Method.*;
|
|||||||
public class Route {
|
public class Route {
|
||||||
public static final Route GET_SEGMENTS = new Route(GET, "skipSegments?videoID={video_id}&categories={categories}");
|
public static final Route GET_SEGMENTS = new Route(GET, "skipSegments?videoID={video_id}&categories={categories}");
|
||||||
public static final Route VIEWED_SEGMENT = new Route(POST, "viewedVideoSponsorTime?UUID={segment_id}");
|
public static final Route VIEWED_SEGMENT = new Route(POST, "viewedVideoSponsorTime?UUID={segment_id}");
|
||||||
public static final Route GET_USER_STATS = new Route(GET, "userInfo");
|
public static final Route GET_USER_STATS = new Route(GET, "userInfo?userID={user_id}");
|
||||||
|
public static final Route CHANGE_USERNAME = new Route(POST, "setUsername?userID={user_id}&username={username}");
|
||||||
public static final Route SUBMIT_SEGMENTS = new Route(POST, "skipSegments?videoID={video_id}&userID={user_id}&startTime={start_time}&endTime={end_time}&category={category}");
|
public static final Route SUBMIT_SEGMENTS = new Route(POST, "skipSegments?videoID={video_id}&userID={user_id}&startTime={start_time}&endTime={end_time}&category={category}");
|
||||||
public static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&type={type}");
|
public static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&type={type}");
|
||||||
public static final Route VOTE_ON_SEGMENT_CATEGORY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&category={category}");
|
public static final Route VOTE_ON_SEGMENT_CATEGORY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&category={category}");
|
||||||
@ -31,8 +32,8 @@ public class Route {
|
|||||||
|
|
||||||
public CompiledRoute compile(String... params) {
|
public CompiledRoute compile(String... params) {
|
||||||
if (params.length != paramCount)
|
if (params.length != paramCount)
|
||||||
throw new IllegalArgumentException("Error Compiling Route: [" + route + "], incorrect amount of parameters provided." +
|
throw new IllegalArgumentException("Error compiling route [" + route + "], incorrect amount of parameters provided. " +
|
||||||
"Expected: " + paramCount + ", Provided: " + params.length);
|
"Expected: " + paramCount + ", provided: " + params.length);
|
||||||
|
|
||||||
StringBuilder compiledRoute = new StringBuilder(route);
|
StringBuilder compiledRoute = new StringBuilder(route);
|
||||||
for (int i = 0; i < paramCount; i++) {
|
for (int i = 0; i < paramCount; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user