1313import android .widget .Toast ;
1414
1515import androidx .annotation .Nullable ;
16+ import androidx .annotation .StringRes ;
1617import androidx .core .graphics .ColorUtils ;
1718
1819import com .fox2code .mmm .Constants ;
2324import com .fox2code .mmm .utils .Http ;
2425import com .fox2code .mmm .utils .IntentHelper ;
2526import com .google .android .material .chip .Chip ;
27+ import com .google .android .material .chip .ChipGroup ;
2628import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
2729import com .topjohnwu .superuser .Shell ;
2830import com .topjohnwu .superuser .internal .UiThreadHandler ;
@@ -87,6 +89,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8789 .getBoolean (Constants .EXTRA_MARKDOWN_CHANGE_BOOT );
8890 boolean needs_ramdisk = intent .getExtras ()
8991 .getBoolean (Constants .EXTRA_MARKDOWN_NEEDS_RAMDISK );
92+ int min_magisk = intent .getExtras ()
93+ .getInt (Constants .EXTRA_MARKDOWN_MIN_MAGISK );
94+ int min_api = intent .getExtras ()
95+ .getInt (Constants .EXTRA_MARKDOWN_MIN_API );
96+ int max_api = intent .getExtras ()
97+ .getInt (Constants .EXTRA_MARKDOWN_MAX_API );
9098 if (title != null && !title .isEmpty ()) {
9199 this .setTitle (title );
92100 }
@@ -111,10 +119,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
111119 setContentView (R .layout .markdown_view );
112120 final ViewGroup markdownBackground = findViewById (R .id .markdownBackground );
113121 final TextView textView = findViewById (R .id .markdownView );
114- final Chip chip_can_change_boot = findViewById (R .id .chip_change_boot );
115- final Chip chip_needs_ramdisk = findViewById (R .id .chip_needs_ramdisk );
116122 final HorizontalScrollView chip_holder = findViewById (R .id .chip_holder );
117- final Chip min_magisk = findViewById (R .id .chip_min_magisk );
118123 final TextView footer = findViewById (R .id .markdownFooter );
119124 UiThreadHandler .handler .postDelayed (() -> // Fix footer height
120125 footer .setMinHeight (this .getNavigationBarHeight ()), 1L );
@@ -123,38 +128,19 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
123128 if (MainApplication .isChipsDisabled ()) {
124129 chip_holder .setVisibility (View .GONE );
125130 } else {
126- if (change_boot ) {
127- chip_can_change_boot .setVisibility (View .VISIBLE );
128- chip_can_change_boot .setOnClickListener (_view -> {
129- MaterialAlertDialogBuilder builder =
130- new MaterialAlertDialogBuilder (this );
131-
132- builder
133- .setTitle (R .string .module_can_change_boot )
134- .setMessage ("This module may change the boot image" )
135- .setCancelable (true )
136- .setPositiveButton (R .string .ok , (x , y ) -> {
137- x .dismiss ();
138- }).show ();
139-
140- });
141- }
142- if (needs_ramdisk ) {
143- chip_needs_ramdisk .setVisibility (View .VISIBLE );
144- chip_needs_ramdisk .setOnClickListener (_view -> {
145- MaterialAlertDialogBuilder builder =
146- new MaterialAlertDialogBuilder (this );
147-
148- builder
149- .setTitle (R .string .module_needs_ramdisk )
150- .setMessage ("This module need boot ramdisk to be installed" )
151- .setCancelable (true )
152- .setPositiveButton (R .string .ok , (x , y ) -> {
153- x .dismiss ();
154- }).show ();
155-
156- });
157- }
131+ // set "message" to null to disable dialog
132+ this .setChips (change_boot ,
133+ getString (R .string .module_can_change_boot ),
134+ "This module may change the boot image" );
135+ this .setChips (needs_ramdisk ,
136+ getString (R .string .module_needs_ramdisk ),
137+ "This module need boot ramdisk to be installed" );
138+ this .setChips (min_magisk , "Min. Magisk \" " + min_magisk + "\" " ,
139+ null );
140+ this .setChips (min_api , "Min. Android " + min_api ,
141+ null );
142+ this .setChips (max_api , "Max. Android " + max_api ,
143+ null );
158144 }
159145
160146 new Thread (() -> {
@@ -185,6 +171,56 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
185171 }, "Markdown load thread" ).start ();
186172 }
187173
174+ private void setChips (boolean bool , String title , String message ) {
175+ final ChipGroup chip_group_holder = findViewById (R .id .chip_group_holder );
176+ if (bool ) {
177+ Chip chip = new Chip (this );
178+ chip .setText (title );
179+ chip .setVisibility (View .VISIBLE );
180+ if (message != null ) {
181+ chip .setOnClickListener (_view -> {
182+ MaterialAlertDialogBuilder builder =
183+ new MaterialAlertDialogBuilder (this );
184+
185+ builder
186+ .setTitle (title )
187+ .setMessage (message )
188+ .setCancelable (true )
189+ .setPositiveButton (R .string .ok , (x , y ) -> {
190+ x .dismiss ();
191+ }).show ();
192+
193+ });
194+ }
195+ chip_group_holder .addView (chip );
196+ }
197+ }
198+
199+ private void setChips (int i , String title , String message ) {
200+ final ChipGroup chip_group_holder = findViewById (R .id .chip_group_holder );
201+ if (i != 0 ) {
202+ Chip chip = new Chip (this );
203+ chip .setText (title );
204+ chip .setVisibility (View .VISIBLE );
205+ if (message != null ) {
206+ chip .setOnClickListener (_view -> {
207+ MaterialAlertDialogBuilder builder =
208+ new MaterialAlertDialogBuilder (this );
209+
210+ builder
211+ .setTitle (title )
212+ .setMessage (message )
213+ .setCancelable (true )
214+ .setPositiveButton (R .string .ok , (x , y ) -> {
215+ x .dismiss ();
216+ }).show ();
217+
218+ });
219+ }
220+ chip_group_holder .addView (chip );
221+ }
222+ }
223+
188224 @ Override
189225 protected void onResume () {
190226 super .onResume ();
0 commit comments