fix(Twitch - Settings): Fix missing style resources (#5970)

This commit is contained in:
MarcaD
2025-09-22 19:02:34 +03:00
committed by GitHub
parent c5eb88bbf6
commit 8c229954d7
8 changed files with 37 additions and 36 deletions

View File

@@ -5,12 +5,15 @@ import static app.revanced.extension.shared.Utils.getResourceIdentifierOrThrow;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
@@ -23,6 +26,7 @@ import android.widget.SearchView;
import android.widget.Toolbar;
import androidx.annotation.ColorInt;
import androidx.annotation.RequiresApi;
import java.util.ArrayList;
import java.util.Collections;
@@ -118,6 +122,14 @@ public abstract class BaseSearchViewController {
searchView.setBackground(createBackgroundDrawable());
searchView.setQueryHint(str("revanced_settings_search_hint"));
// Set text size.
searchEditText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
// Set cursor color.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
setCursorColor(searchEditText);
}
// Configure RTL support based on app language.
AppLanguage appLanguage = BaseSettings.REVANCED_LANGUAGE.get();
if (Utils.isRightToLeftLocale(appLanguage.getLocale())) {
@@ -126,6 +138,24 @@ public abstract class BaseSearchViewController {
}
}
/**
* Sets the cursor color (for Android 10+ devices).
*/
@RequiresApi(api = Build.VERSION_CODES.Q)
private void setCursorColor(EditText editText) {
// Get the cursor color based on the current theme.
final int cursorColor = Utils.isDarkModeEnabled() ? Color.WHITE : Color.BLACK;
// Create cursor drawable.
GradientDrawable cursorDrawable = new GradientDrawable();
cursorDrawable.setShape(GradientDrawable.RECTANGLE);
cursorDrawable.setSize(Utils.dipToPixels(2), -1); // Width: 2dp, Height: match text height.
cursorDrawable.setColor(cursorColor);
// Set cursor drawable.
editText.setTextCursorDrawable(cursorDrawable);
}
/**
* Initializes the overlay container for displaying search results and history.
*/

View File

@@ -42,6 +42,8 @@ private val settingsResourcePatch = resourcePatch {
execute {
// Set the style for the ReVanced settings to follow the style of the music settings,
// namely: action bar height, menu item padding and remove horizontal dividers.
val targetResource = "values/styles.xml"
inputStreamFromBundledResource(
"settings/music",
@@ -53,7 +55,7 @@ private val settingsResourcePatch = resourcePatch {
).close()
}
// Remove horizontal divider from the settings Preferences.
// Remove horizontal dividers from the music settings.
val styleFile = get("res/values/styles.xml")
styleFile.writeText(
styleFile.readText()

View File

@@ -18,7 +18,9 @@ import app.revanced.util.returnEarly
import org.w3c.dom.Node
// TODO: Delete this on next major version bump.
@Deprecated("Use non deprecated settings patch function")
@Deprecated("Use non deprecated settings patch function",
ReplaceWith("settingsPatch(listOf(rootPreference), preferences)")
)
fun settingsPatch (
rootPreference: Pair<IntentPreference, String>,
preferences: Set<BasePreference>,
@@ -69,8 +71,8 @@ fun settingsPatch (
ResourceGroup("drawable",
// CustomListPreference resources.
"revanced_ic_dialog_alert.xml",
// Search resources.
"revanced_settings_arrow_time.xml",
"revanced_settings_cursor.xml",
"revanced_settings_custom_checkmark.xml",
"revanced_settings_search_icon.xml",
"revanced_settings_search_remove.xml",

View File

@@ -95,20 +95,6 @@ private val settingsResourcePatch = resourcePatch {
)
)
// Copy style properties used to fix over-sized copy menu that appear in EditTextPreference.
// For a full explanation of how this fixes the issue, see the comments in this style file
// and the comments in the extension code.
val targetResource = "values/styles.xml"
inputStreamFromBundledResource(
"settings/youtube",
targetResource,
)!!.let { inputStream ->
"resources".copyXmlNode(
document(inputStream),
document("res/$targetResource"),
).close()
}
// Remove horizontal divider from the settings Preferences
// To better match the appearance of the stock YouTube settings.
document("res/values/styles.xml").use { document ->

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:id="@+id/revanced_settings_cursor">
<solid android:color="?android:attr/textColorPrimary" />
<size android:width="1dp" />
</shape>

View File

@@ -46,7 +46,6 @@
android:iconifiedByDefault="false"
android:searchIcon="@null"
android:queryBackground="@null"
android:theme="@style/revanced_searchbar_cursor"
android:padding="2dp" />
</FrameLayout>

View File

@@ -5,8 +5,4 @@
<item name="android:listPreferredItemPaddingStart">@dimen/item_extra_extra_large_spacing</item>
<item name="android:listDivider">@null</item>
</style>
<style name="revanced_searchbar_cursor">
<item name="android:textCursorDrawable">@drawable/revanced_settings_cursor</item>
<item name="android:textSize">16sp</item>
</style>
</resources>

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="revanced_searchbar_cursor">
<item name="android:textCursorDrawable">@drawable/revanced_settings_cursor</item>
<item name="android:textSize">16sp</item>
</style>
</resources>