mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-10 23:27:54 +02:00
feat(YouTube): Show about preference with the patch release version
This commit is contained in:
parent
eaa2e1139c
commit
48eeb7ef6a
|
@ -27,6 +27,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.text.Bidi;
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -44,33 +45,73 @@ public class Utils {
|
|||
|
||||
private static String versionName;
|
||||
|
||||
private static String versionReleaseLocaleString;
|
||||
|
||||
private Utils() {
|
||||
} // utility class
|
||||
|
||||
public static String getVersionName() {
|
||||
if (versionName != null) return versionName;
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static String getPatchesReleaseVersion() {
|
||||
return ""; // Value is replaced during patching.
|
||||
}
|
||||
|
||||
PackageInfo packageInfo;
|
||||
try {
|
||||
final var packageName = Objects.requireNonNull(getContext()).getPackageName();
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
private static String getPatchesReleaseTimestamp() {
|
||||
return ""; // Value is replaced during patching.
|
||||
}
|
||||
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||
packageInfo = packageManager.getPackageInfo(
|
||||
packageName,
|
||||
PackageManager.PackageInfoFlags.of(0)
|
||||
);
|
||||
else
|
||||
packageInfo = packageManager.getPackageInfo(
|
||||
packageName,
|
||||
0
|
||||
);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Logger.printException(() -> "Failed to get package info", e);
|
||||
return null;
|
||||
/**
|
||||
* @return The 'Timestamp' entry of the patches jar used during patching,
|
||||
* parsed to "day, month, year" using the device locale.
|
||||
*/
|
||||
public static String getPatchesReleaseDate() {
|
||||
if (versionReleaseLocaleString == null) {
|
||||
String timestamp = getPatchesReleaseTimestamp();
|
||||
try {
|
||||
Date date = new Date(Long.parseLong(timestamp));
|
||||
DateFormat formatter = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
|
||||
versionReleaseLocaleString = formatter.format(date);
|
||||
} catch (Exception ex) {
|
||||
Logger.printInfo(() -> "Could not parse timestamp: " + timestamp, ex);
|
||||
versionReleaseLocaleString = "Unknown (" + timestamp + ")";
|
||||
}
|
||||
}
|
||||
return versionReleaseLocaleString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The version name of the app, such as "YouTube".
|
||||
*/
|
||||
public static String getAppVersionName() {
|
||||
if (versionName == null) {
|
||||
try {
|
||||
final var packageName = Objects.requireNonNull(getContext()).getPackageName();
|
||||
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
PackageInfo packageInfo;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
packageInfo = packageManager.getPackageInfo(
|
||||
packageName,
|
||||
PackageManager.PackageInfoFlags.of(0)
|
||||
);
|
||||
} else {
|
||||
packageInfo = packageManager.getPackageInfo(
|
||||
packageName,
|
||||
0
|
||||
);
|
||||
}
|
||||
versionName = packageInfo.versionName;
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "Failed to get package info", ex);
|
||||
versionName = "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
return versionName = packageInfo.versionName;
|
||||
return versionName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -479,6 +520,7 @@ public class Utils {
|
|||
* If a preference has no key or no {@link Sort} suffix,
|
||||
* then the preferences are left unsorted.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void sortPreferenceGroups(@NonNull PreferenceGroup group) {
|
||||
Sort sort = Sort.fromKey(group.getKey());
|
||||
SortedMap<String, Preference> preferences = new TreeMap<>();
|
||||
|
|
|
@ -37,7 +37,7 @@ final class PlayerRoutes {
|
|||
|
||||
JSONObject client = new JSONObject();
|
||||
client.put("clientName", "ANDROID");
|
||||
client.put("clientVersion", Utils.getVersionName());
|
||||
client.put("clientVersion", Utils.getAppVersionName());
|
||||
client.put("androidSdkVersion", 34);
|
||||
|
||||
context.put("client", client);
|
||||
|
@ -85,7 +85,7 @@ final class PlayerRoutes {
|
|||
|
||||
connection.setRequestProperty(
|
||||
"User-Agent", "com.google.android.youtube/" +
|
||||
Utils.getVersionName() +
|
||||
Utils.getAppVersionName() +
|
||||
" (Linux; U; Android 12; GB) gzip"
|
||||
);
|
||||
connection.setRequestProperty("X-Goog-Api-Format-Version", "2");
|
||||
|
|
|
@ -24,7 +24,7 @@ public class Requester {
|
|||
String url = apiUrl + route.getCompiledRoute();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod(route.getMethod().name());
|
||||
connection.setRequestProperty("User-Agent", System.getProperty("http.agent") + "; ReVanced/" + Utils.getVersionName());
|
||||
connection.setRequestProperty("User-Agent", System.getProperty("http.agent") + "; ReVanced/" + Utils.getAppVersionName());
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package app.revanced.integrations.youtube.settings.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.shared.Utils;
|
||||
|
||||
/**
|
||||
* Allows tapping to open the ReVanced website.
|
||||
*/
|
||||
@SuppressWarnings({"unused", "deprecation"})
|
||||
public class ReVancedAboutPreference extends Preference {
|
||||
|
||||
private void init() {
|
||||
setOnPreferenceClickListener(pref -> {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("https://revanced.app"));
|
||||
pref.getContext().startActivity(i);
|
||||
return false;
|
||||
});
|
||||
|
||||
String summary = getSummary().toString()
|
||||
.replace("${PATCHES_RELEASE_VERSION}", Utils.getPatchesReleaseVersion())
|
||||
.replace("${PATCHES_RELEASE_DATE}", Utils.getPatchesReleaseDate());
|
||||
setSummary(summary);
|
||||
}
|
||||
|
||||
public ReVancedAboutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
public ReVancedAboutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
public ReVancedAboutPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
public ReVancedAboutPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user