1010
1111import androidx .annotation .DrawableRes ;
1212import androidx .appcompat .app .AlertDialog ;
13+ import androidx .core .content .ContextCompat ;
1314
1415import com .fox2code .mmm .MainApplication ;
1516import com .fox2code .mmm .R ;
2223import com .fox2code .mmm .manager .ModuleManager ;
2324import com .fox2code .mmm .module .ModuleHolder ;
2425import com .fox2code .mmm .utils .IntentHelper ;
26+ import com .google .android .material .chip .Chip ;
2527import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
2628
2729import io .noties .markwon .Markwon ;
2830
2931public enum ActionButtonType {
30- INFO (R . drawable . ic_baseline_info_24 ) {
32+ INFO () {
3133 @ Override
32- public void doAction (ImageButton button , ModuleHolder moduleHolder ) {
34+ public void update (Chip button , ModuleHolder moduleHolder ) {
35+ button .setChipIcon (button .getContext ().getResources ().getDrawable (R .drawable .ic_baseline_info_24 ));
36+ button .setText ("Description" );
37+ }
38+
39+ @ Override
40+ public void doAction (Chip button , ModuleHolder moduleHolder ) {
3341 String notesUrl = moduleHolder .repoModule .notesUrl ;
3442 if (notesUrl .startsWith ("https://api.androidacy.com/magisk/readme/?module=" ) ||
3543 notesUrl .startsWith ("https://www.androidacy.com/" )) {
@@ -46,31 +54,36 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
4654 }
4755
4856 @ Override
49- public boolean doActionLong (ImageButton button , ModuleHolder moduleHolder ) {
57+ public boolean doActionLong (Chip button , ModuleHolder moduleHolder ) {
5058 Context context = button .getContext ();
5159 Toast .makeText (context , context .getString (R .string .module_id_prefix ) +
52- moduleHolder .moduleId , Toast .LENGTH_SHORT ).show ();
60+ moduleHolder .moduleId , Toast .LENGTH_SHORT ).show ();
5361 return true ;
5462 }
5563 },
5664 UPDATE_INSTALL () {
5765 @ Override
58- public void update (ImageButton button , ModuleHolder moduleHolder ) {
66+ public void update (Chip button , ModuleHolder moduleHolder ) {
5967 int icon = moduleHolder .hasUpdate () ?
6068 R .drawable .ic_baseline_update_24 :
6169 R .drawable .ic_baseline_system_update_24 ;
62- button .setImageResource (icon );
70+ button .setChipIcon (button .getContext ().getResources ().getDrawable (icon ));
71+ if (moduleHolder .hasUpdate ()) {
72+ button .setText ("Update" );
73+ } else {
74+ button .setText ("Install" );
75+ }
6376 }
6477
6578 @ Override
66- public void doAction (ImageButton button , ModuleHolder moduleHolder ) {
79+ public void doAction (Chip button , ModuleHolder moduleHolder ) {
6780 ModuleInfo moduleInfo = moduleHolder .getMainModuleInfo ();
6881 if (moduleInfo == null ) return ;
6982 String updateZipUrl = moduleHolder .getUpdateZipUrl ();
7083 if (updateZipUrl == null ) return ;
7184 // Androidacy manage the selection between download and install
7285 if (updateZipUrl .startsWith ("https://www.androidacy.com/" ) ||
73- updateZipUrl .startsWith ("https://api.androidacy.com/magisk/info/?module=" )) {
86+ updateZipUrl .startsWith ("https://api.androidacy.com/magisk/info/?module=" )) {
7487 IntentHelper .openUrlAndroidacy (
7588 button .getContext (), updateZipUrl , true ,
7689 moduleInfo .name , moduleInfo .config );
@@ -127,18 +140,19 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
127140 },
128141 UNINSTALL () {
129142 @ Override
130- public void update (ImageButton button , ModuleHolder moduleHolder ) {
143+ public void update (Chip button , ModuleHolder moduleHolder ) {
131144 int icon = moduleHolder .hasFlag (ModuleInfo .FLAG_MODULE_UNINSTALLING ) ?
132145 R .drawable .ic_baseline_delete_outline_24 : (
133146 !moduleHolder .hasFlag (ModuleInfo .FLAG_MODULE_UPDATING ) ||
134- moduleHolder .hasFlag (ModuleInfo .FLAGS_MODULE_ACTIVE )) ?
135- R .drawable .ic_baseline_delete_24 :
136- R .drawable .ic_baseline_delete_forever_24 ;
137- button .setImageResource (icon );
147+ moduleHolder .hasFlag (ModuleInfo .FLAGS_MODULE_ACTIVE )) ?
148+ R .drawable .ic_baseline_delete_24 :
149+ R .drawable .ic_baseline_delete_forever_24 ;
150+ button .setChipIcon (button .getContext ().getResources ().getDrawable (icon ));
151+ button .setText ("Uninstall" );
138152 }
139153
140154 @ Override
141- public void doAction (ImageButton button , ModuleHolder moduleHolder ) {
155+ public void doAction (Chip button , ModuleHolder moduleHolder ) {
142156 if (!moduleHolder .hasFlag (ModuleInfo .FLAGS_MODULE_ACTIVE |
143157 ModuleInfo .FLAG_MODULE_UNINSTALLING ) &&
144158 moduleHolder .hasFlag (ModuleInfo .FLAG_MODULE_UPDATING )) {
@@ -153,7 +167,7 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
153167 }
154168
155169 @ Override
156- public boolean doActionLong (ImageButton button , ModuleHolder moduleHolder ) {
170+ public boolean doActionLong (Chip button , ModuleHolder moduleHolder ) {
157171 // We can't trust active flag on first boot
158172 if (moduleHolder .moduleInfo .hasFlag (ModuleInfo .FLAGS_MODULE_ACTIVE )) return false ;
159173 new AlertDialog .Builder (button .getContext ()).setTitle (R .string .master_delete )
@@ -165,13 +179,20 @@ public boolean doActionLong(ImageButton button, ModuleHolder moduleHolder) {
165179 moduleHolder .moduleInfo = null ;
166180 CompatActivity .getCompatActivity (button ).refreshUI ();
167181 }
168- }).setNegativeButton (R .string .master_delete_no , (v , i ) -> {}).create ().show ();
182+ }).setNegativeButton (R .string .master_delete_no , (v , i ) -> {
183+ }).create ().show ();
169184 return true ;
170185 }
171186 },
172- CONFIG (R .drawable .ic_baseline_app_settings_alt_24 ) {
187+ CONFIG () {
188+ @ Override
189+ public void update (Chip button , ModuleHolder moduleHolder ) {
190+ button .setChipIcon (button .getContext ().getResources ().getDrawable (R .drawable .ic_baseline_app_settings_alt_24 ));
191+ button .setText ("Config" );
192+ }
193+
173194 @ Override
174- public void doAction (ImageButton button , ModuleHolder moduleHolder ) {
195+ public void doAction (Chip button , ModuleHolder moduleHolder ) {
175196 String config = moduleHolder .getMainModuleConfig ();
176197 if (config == null ) return ;
177198 if (AndroidacyUtil .isAndroidacyLink (config )) {
@@ -183,31 +204,33 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
183204 },
184205 SUPPORT () {
185206 @ Override
186- public void update (ImageButton button , ModuleHolder moduleHolder ) {
207+ public void update (Chip button , ModuleHolder moduleHolder ) {
187208 ModuleInfo moduleInfo = moduleHolder .getMainModuleInfo ();
188- button .setImageResource (supportIconForUrl (moduleInfo .support ));
209+ button .setChipIcon (button .getContext ().getResources ().getDrawable (supportIconForUrl (moduleInfo .support )));
210+ button .setText ("Support" );
189211 }
190212
191213 @ Override
192- public void doAction (ImageButton button , ModuleHolder moduleHolder ) {
214+ public void doAction (Chip button , ModuleHolder moduleHolder ) {
193215 IntentHelper .openUrl (button .getContext (), moduleHolder .getMainModuleInfo ().support );
194216 }
195217 },
196218 DONATE () {
197219 @ Override
198- public void update (ImageButton button , ModuleHolder moduleHolder ) {
220+ public void update (Chip button , ModuleHolder moduleHolder ) {
199221 ModuleInfo moduleInfo = moduleHolder .getMainModuleInfo ();
200222 int icon = R .drawable .ic_baseline_monetization_on_24 ;
201223 if (moduleInfo .donate .startsWith ("https://www.paypal.me/" )) {
202224 icon = R .drawable .ic_baseline_paypal_24 ;
203225 } else if (moduleInfo .donate .startsWith ("https://www.patreon.com/" )) {
204226 icon = R .drawable .ic_patreon ;
205227 }
206- button .setImageResource (icon );
228+ button .setChipIcon (button .getContext ().getResources ().getDrawable (icon ));
229+ button .setText ("Donate" );
207230 }
208231
209232 @ Override
210- public void doAction (ImageButton button , ModuleHolder moduleHolder ) {
233+ public void doAction (Chip button , ModuleHolder moduleHolder ) {
211234 IntentHelper .openUrl (button .getContext (), moduleHolder .getMainModuleInfo ().donate );
212235 }
213236 };
@@ -239,13 +262,13 @@ public static int supportIconForUrl(String url) {
239262 this .iconId = iconId ;
240263 }
241264
242- public void update (ImageButton button , ModuleHolder moduleHolder ) {
243- button .setImageResource ( this .iconId );
265+ public void update (Chip button , ModuleHolder moduleHolder ) {
266+ button .setChipIcon ( button . getContext (). getResources (). getDrawable ( this .iconId ) );
244267 }
245268
246- public abstract void doAction (ImageButton button , ModuleHolder moduleHolder );
269+ public abstract void doAction (Chip button , ModuleHolder moduleHolder );
247270
248- public boolean doActionLong (ImageButton button , ModuleHolder moduleHolder ) {
271+ public boolean doActionLong (Chip button , ModuleHolder moduleHolder ) {
249272 return false ;
250273 }
251274}
0 commit comments