This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube Music): Add
Settings
patch
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
app/src/main/java/app/revanced/integrations/music/settings/FullStackTraceActivityHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/app/revanced/integrations/music/settings/Settings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
20 changes: 20 additions & 0 deletions
20
.../java/app/revanced/integrations/music/settings/preference/ReVancedPreferenceFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters