Skip to content

Commit af54e91

Browse files
committed
fix: Add scrollable content to modern style settings dialogs
This fix dialog layout to prevent buttons from being pushed off-screen
1 parent f15003a commit af54e91

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

extensions/shared/library/src/main/java/app/revanced/extension/shared/Utils.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import android.widget.FrameLayout;
4343
import android.widget.LinearLayout;
4444
import android.widget.RelativeLayout;
45+
import android.widget.ScrollView;
4546
import android.widget.TextView;
4647
import android.widget.Toast;
4748
import android.widget.Toolbar;
@@ -773,16 +774,15 @@ public static Pair<Dialog, LinearLayout> createCustomDialog(
773774
Dialog dialog = new Dialog(context);
774775
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // Remove default title bar.
775776

776-
// Create main layout.
777-
LinearLayout mainLayout = new LinearLayout(context);
778-
mainLayout.setOrientation(LinearLayout.VERTICAL);
779-
780777
// Preset size constants.
781778
final int dip4 = dipToPixels(4);
782779
final int dip8 = dipToPixels(8);
783780
final int dip16 = dipToPixels(16);
784781
final int dip24 = dipToPixels(24);
785782

783+
// Create main layout.
784+
LinearLayout mainLayout = new LinearLayout(context);
785+
mainLayout.setOrientation(LinearLayout.VERTICAL);
786786
mainLayout.setPadding(dip24, dip16, dip24, dip24);
787787
// Set rounded rectangle background.
788788
ShapeDrawable mainBackground = new ShapeDrawable(new RoundRectShape(
@@ -807,6 +807,18 @@ public static Pair<Dialog, LinearLayout> createCustomDialog(
807807
mainLayout.addView(titleView);
808808
}
809809

810+
// Create content container (message/EditText) inside a ScrollView.
811+
ScrollView contentScrollView = new ScrollView(context);
812+
LinearLayout contentContainer = new LinearLayout(context);
813+
contentContainer.setOrientation(LinearLayout.VERTICAL);
814+
LinearLayout.LayoutParams contentParams = new LinearLayout.LayoutParams(
815+
ViewGroup.LayoutParams.MATCH_PARENT,
816+
0,
817+
1.0f // Weight to take available space.
818+
);
819+
contentScrollView.setLayoutParams(contentParams);
820+
contentScrollView.addView(contentContainer);
821+
810822
// Message (if not replaced by EditText).
811823
if (editText == null && message != null) {
812824
TextView messageView = new TextView(context);
@@ -821,9 +833,9 @@ public static Pair<Dialog, LinearLayout> createCustomDialog(
821833
ViewGroup.LayoutParams.MATCH_PARENT,
822834
ViewGroup.LayoutParams.WRAP_CONTENT
823835
);
824-
messageParams.setMargins(0, dip8, 0, dip16);
836+
messageParams.setMargins(dip8, dip8, dip8, dip16);
825837
messageView.setLayoutParams(messageParams);
826-
mainLayout.addView(messageView);
838+
contentContainer.addView(messageView);
827839
}
828840

829841
// EditText (if provided).
@@ -847,10 +859,7 @@ public static Pair<Dialog, LinearLayout> createCustomDialog(
847859
LinearLayout.LayoutParams.WRAP_CONTENT
848860
);
849861
editTextParams.setMargins(0, dip8, 0, dip16);
850-
// Prevent buttons from moving off the screen by fixing the height of the EditText.
851-
final int maxHeight = (int) (context.getResources().getDisplayMetrics().heightPixels * 0.6);
852-
editText.setMaxHeight(maxHeight);
853-
mainLayout.addView(editText, 1, editTextParams);
862+
contentContainer.addView(editText, editTextParams);
854863
}
855864

856865
// Button container.
@@ -1036,6 +1045,8 @@ public static Pair<Dialog, LinearLayout> createCustomDialog(
10361045
}
10371046
}
10381047

1048+
// Add content and buttons to main layout.
1049+
mainLayout.addView(contentScrollView);
10391050
mainLayout.addView(buttonContainer);
10401051
dialog.setContentView(mainLayout);
10411052

extensions/shared/library/src/main/java/app/revanced/extension/shared/checks/Check.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ static void issueWarning(Activity activity, Collection<Check> failedChecks) {
129129
ImageView iconView = new ImageView(activity);
130130
iconView.setImageResource(Utils.getResourceIdentifier("revanced_ic_dialog_alert", "drawable"));
131131
iconView.setColorFilter(Utils.getAppForegroundColor(), PorterDuff.Mode.SRC_IN);
132-
final int dip8 = dipToPixels(8);
133-
iconView.setPadding(0, dip8, 0, dip8);
132+
iconView.setPadding(0, 0, 0, 0);
134133
LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(
135134
LinearLayout.LayoutParams.WRAP_CONTENT,
136135
LinearLayout.LayoutParams.WRAP_CONTENT

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/SearchViewController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.widget.TextView;
2020
import android.widget.Toolbar;
2121

22+
import androidx.annotation.ColorInt;
2223
import androidx.annotation.NonNull;
2324

2425
import java.util.ArrayList;
@@ -72,10 +73,17 @@ private static GradientDrawable createBackgroundDrawable(Context context) {
7273
private static GradientDrawable createSuggestionBackgroundDrawable(Context context) {
7374
GradientDrawable background = new GradientDrawable();
7475
background.setShape(GradientDrawable.RECTANGLE);
75-
background.setCornerRadius(8 * context.getResources().getDisplayMetrics().density); // 8dp corner radius.
76+
background.setColor(getSearchViewBackground());
7677
return background;
7778
}
7879

80+
@ColorInt
81+
public static int getSearchViewBackground() {
82+
return Utils.isDarkModeEnabled()
83+
? Utils.adjustColorBrightness(Utils.getDialogBackgroundColor(), 1.11f)
84+
: Utils.adjustColorBrightness(Utils.getThemeLightColor(), 0.95f);
85+
}
86+
7987
/**
8088
* Adds search view components to the activity.
8189
*/
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="48dp"
3-
android:height="48dp"
4-
android:viewportWidth="48"
5-
android:viewportHeight="48">
2+
android:width="40dp"
3+
android:height="40dp"
4+
android:viewportWidth="40"
5+
android:viewportHeight="40">
66
<path
77
android:fillColor="#000000"
88
android:fillType="evenOdd"
9-
android:pathData="M26.5977,6.29688 L43.8672,36.2031 C45.0195,38.2031,43.5781,40.7031,41.2695,40.7031 L6.73047,40.7031 C4.42188,40.7031,2.98047,38.2031,4.13281,36.2031 L21.4023,6.29688 C22.5547,4.29688,25.4453,4.29688,26.5977,6.29688 Z M24,30 C22.8945,30,22,30.8945,22,32 C22,33.1055,22.8945,34,24,34 C25.1055,34,26,33.1055,26,32 C26,30.8945,25.1055,30,24,30 Z M24,16 C22.9727,16,22.1289,16.7734,22.0117,17.7656 L22,18 L22,26 C22,27.1055,22.8945,28,24,28 C25.0273,28,25.8711,27.2266,25.9883,26.2344 L26,26 L26,18 C26,16.8945,25.1055,16,24,16 Z M24,16" />
9+
android:pathData="M22.1641,5.24609 L36.5547,30.168 C37.5156,31.8359,36.3164,33.918,34.3906,33.918 L5.60938,33.918 C3.68359,33.918,2.48438,31.8359,3.44531,30.168 L17.8359,5.24609 C18.7969,3.58203,21.2031,3.58203,22.1641,5.24609 Z M20,25 C19.0781,25,18.332,25.7461,18.332,26.668 C18.332,27.5898,19.0781,28.332,20,28.332 C20.9219,28.332,21.668,27.5898,21.668,26.668 C21.668,25.7461,20.9219,25,20,25 Z M20,13.332 C19.1445,13.332,18.4414,13.9766,18.3438,14.8047 L18.332,15 L18.332,21.668 C18.332,22.5898,19.0781,23.332,20,23.332 C20.8555,23.332,21.5586,22.6875,21.6563,21.8633 L21.668,21.668 L21.668,15 C21.668,14.0781,20.9219,13.332,20,13.332 Z M20,13.332" />
1010
</vector>

0 commit comments

Comments
 (0)