mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-06 01:55:50 +01:00
feat(YouTube Music): Add Settings
patch
This commit is contained in:
parent
27421fb578
commit
c5a6e271ba
@ -0,0 +1,86 @@
|
||||
package app.revanced.integrations.music.settings;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import app.revanced.integrations.music.settings.preference.ReVancedPreferenceFragment;
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static app.revanced.integrations.shared.Utils.getChildView;
|
||||
import static app.revanced.integrations.shared.Utils.getResourceIdentifier;
|
||||
|
||||
/**
|
||||
* Hooks FullStackTraceActivityHook.
|
||||
* <p>
|
||||
* This class is responsible for injecting our own fragment by replacing the FullStackTraceActivityHook.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class FullStackTraceActivityHook {
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
* <p>
|
||||
* Hooks FullStackTraceActivityHook#onCreate in order to inject our own fragment.
|
||||
*/
|
||||
public static void initialize(Activity fullStackTraceActivityHook) {
|
||||
try {
|
||||
// ThemeHelper.setActivityTheme(fullStackTraceActivityHook);
|
||||
fullStackTraceActivityHook.setContentView(
|
||||
getResourceIdentifier("revanced_settings_with_toolbar", "layout"));
|
||||
setBackButton(fullStackTraceActivityHook);
|
||||
|
||||
PreferenceFragment fragment;
|
||||
String toolbarTitleResourceName;
|
||||
String dataString = fullStackTraceActivityHook.getIntent().getDataString();
|
||||
switch (dataString) {
|
||||
case "revanced_settings_intent":
|
||||
toolbarTitleResourceName = "revanced_settings_title";
|
||||
fragment = new ReVancedPreferenceFragment();
|
||||
break;
|
||||
default:
|
||||
Logger.printException(() -> "Unknown setting: " + dataString);
|
||||
return;
|
||||
}
|
||||
|
||||
setToolbarTitle(fullStackTraceActivityHook, toolbarTitleResourceName);
|
||||
fullStackTraceActivityHook.getFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(getResourceIdentifier("revanced_settings_fragments", "id"), fragment)
|
||||
.commit();
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "onCreate failure", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setToolbarTitle(Activity activity, String toolbarTitleResourceName) {
|
||||
ViewGroup toolbar = activity.findViewById(getToolbarResourceId());
|
||||
TextView toolbarTextView = Objects.requireNonNull(getChildView(toolbar, view -> view instanceof TextView));
|
||||
toolbarTextView.setText(getResourceIdentifier(toolbarTitleResourceName, "string"));
|
||||
}
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
private static void setBackButton(Activity activity) {
|
||||
ViewGroup toolbar = activity.findViewById(getToolbarResourceId());
|
||||
ImageButton imageButton = Objects.requireNonNull(getChildView(toolbar, view -> view instanceof ImageButton));
|
||||
final int backButtonResource = getResourceIdentifier(false // ThemeHelper.isDarkTheme()
|
||||
? "yt_outline_arrow_left_white_24"
|
||||
: "yt_outline_arrow_left_black_24",
|
||||
"drawable");
|
||||
imageButton.setImageDrawable(activity.getResources().getDrawable(backButtonResource));
|
||||
imageButton.setOnClickListener(view -> activity.onBackPressed());
|
||||
}
|
||||
|
||||
private static int getToolbarResourceId() {
|
||||
final int toolbarResourceId = getResourceIdentifier("revanced_toolbar", "id");
|
||||
if (toolbarResourceId == 0) {
|
||||
throw new IllegalStateException("Could not find back button resource");
|
||||
}
|
||||
return toolbarResourceId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package app.revanced.integrations.music.settings;
|
||||
|
||||
import app.revanced.integrations.shared.settings.BaseSettings;
|
||||
|
||||
public class Settings extends BaseSettings {
|
||||
// TODO Add settings
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package app.revanced.integrations.music.settings.preference;
|
||||
|
||||
import app.revanced.integrations.music.settings.Settings;
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.shared.settings.preference.AbstractPreferenceFragment;
|
||||
|
||||
/**
|
||||
* Preference fragment for ReVanced settings.
|
||||
*/
|
||||
public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {
|
||||
@Override
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
|
||||
// Do anything that forces this apps Settings bundle to load.
|
||||
if (Settings.DEBUG.get()) {
|
||||
Logger.printDebug(() -> "Debug logging enabled"); // Any statement that references the app settings.
|
||||
}
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ public class AppCompatActivityHook {
|
||||
* @return Returns string resource id
|
||||
*/
|
||||
public static int getReVancedSettingsString() {
|
||||
return app.revanced.integrations.twitch.Utils.getStringId("revanced_settings");
|
||||
return app.revanced.integrations.twitch.Utils.getStringId("revanced_settings_title");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +101,7 @@ public class AppCompatActivityHook {
|
||||
ReVancedPreferenceFragment fragment = new ReVancedPreferenceFragment();
|
||||
ActionBar supportActionBar = base.getSupportActionBar();
|
||||
if (supportActionBar != null)
|
||||
supportActionBar.setTitle(app.revanced.integrations.twitch.Utils.getStringId("revanced_settings"));
|
||||
supportActionBar.setTitle(app.revanced.integrations.twitch.Utils.getStringId("revanced_settings_title"));
|
||||
|
||||
base.getFragmentManager()
|
||||
.beginTransaction()
|
||||
|
Loading…
Reference in New Issue
Block a user