55import android .view .LayoutInflater ;
66import android .view .View ;
77import android .view .ViewGroup ;
8+ import android .widget .EditText ;
89import android .widget .ImageView ;
910import android .widget .TextView ;
1011import android .widget .Toast ;
1112
1213import androidx .annotation .NonNull ;
14+ import androidx .appcompat .app .AlertDialog ;
1315import androidx .constraintlayout .widget .ConstraintLayout ;
1416import androidx .core .content .ContextCompat ;
1517import androidx .fragment .app .Fragment ;
1921import androidx .recyclerview .widget .RecyclerView ;
2022
2123import com .google .android .material .floatingactionbutton .FloatingActionButton ;
24+ import com .topjohnwu .superuser .Shell ;
2225import com .topjohnwu .superuser .io .SuFile ;
2326
2427import org .androidbootmanager .app .R ;
2730import org .androidbootmanager .app .ui .wizard .WizardActivity ;
2831import org .androidbootmanager .app .util .ActionAbortedCleanlyError ;
2932import org .androidbootmanager .app .util .ConfigFile ;
33+ import org .androidbootmanager .app .util .ConfigTextWatcher ;
34+ import org .androidbootmanager .app .util .MiscUtils ;
3035
3136import java .util .ArrayList ;
3237import java .util .List ;
@@ -111,8 +116,58 @@ public ViewHolder(View view) {
111116 pic = view .findViewById (R .id .entry_pic );
112117 name = view .findViewById (R .id .entry_name );
113118 container .setOnClickListener ((v ) -> {
114- // TODO
115- updateEntries ();
119+ assert e != null ;
120+ ConfigFile proposed_ ;
121+ try {
122+ proposed_ = ConfigFile .importFromFile (e .file );
123+ } catch (ActionAbortedCleanlyError actionAbortedCleanlyError ) {
124+ actionAbortedCleanlyError .printStackTrace ();
125+ Toast .makeText (requireContext (),"Loading configuration file: Error. Action aborted cleanly. Creating new." ,Toast .LENGTH_LONG ).show ();
126+ proposed_ = new ConfigFile ();
127+ }
128+ final ConfigFile proposed = proposed_ ;
129+ View dialog = LayoutInflater .from (requireContext ()).inflate (R .layout .edit_entry ,null );
130+ ((EditText ) dialog .findViewById (R .id .editentryTitle )).setText (e .config .get ("title" ));
131+ ((EditText ) dialog .findViewById (R .id .editentryTitle )).addTextChangedListener (new ConfigTextWatcher (proposed , "title" ));
132+ ((EditText ) dialog .findViewById (R .id .editentryKernel )).setText (e .config .get ("linux" ));
133+ ((EditText ) dialog .findViewById (R .id .editentryKernel )).addTextChangedListener (new ConfigTextWatcher (proposed , "linux" ));
134+ ((EditText ) dialog .findViewById (R .id .editentryDtb )).setText (e .config .get ("dtb" ));
135+ ((EditText ) dialog .findViewById (R .id .editentryDtb )).addTextChangedListener (new ConfigTextWatcher (proposed , "dtb" ));
136+ ((EditText ) dialog .findViewById (R .id .editentryInitrd )).setText (e .config .get ("initrd" ));
137+ ((EditText ) dialog .findViewById (R .id .editentryInitrd )).addTextChangedListener (new ConfigTextWatcher (proposed , "initrd" ));
138+ ((EditText ) dialog .findViewById (R .id .editentryCmdline )).setText (e .config .get ("options" ));
139+ ((EditText ) dialog .findViewById (R .id .editentryCmdline )).addTextChangedListener (new ConfigTextWatcher (proposed , "options" ));
140+ ((EditText ) dialog .findViewById (R .id .editentryDataPart )).setText (e .config .get ("xdata" ));
141+ dialog .findViewById (R .id .editentryDataPart ).setEnabled (false );
142+ ((EditText ) dialog .findViewById (R .id .editentrySysPart )).setText (e .config .get ("xsystem" ));
143+ dialog .findViewById (R .id .editentrySysPart ).setEnabled (false );
144+ new AlertDialog .Builder (requireContext ())
145+ .setCancelable (true )
146+ .setNeutralButton (R .string .cancel , (p1 , p2 ) -> p1 .dismiss ())
147+ .setNegativeButton (R .string .delete , (p1 , p2 ) -> MiscUtils .sure (requireContext (), p1 , getString (R .string .delete_msg_2 , e .config .get ("title" )), (p112 , p212 ) -> {
148+ if (e .config .get ("xsystem" ) != null && e .config .get ("xdata" ) != null ) {
149+ if (e .config .get ("xsystem" ).equals ("real" ) || e .config .get ("xdata" ).equals ("real" ))
150+ new AlertDialog .Builder (requireContext ())
151+ .setTitle (R .string .failed )
152+ .setMessage (R .string .delete_real_rom )
153+ .setCancelable (true )
154+ .setNegativeButton (R .string .ok , (d , p ) -> d .dismiss ())
155+ .show ();
156+ } else {
157+ if (!SuFile .open (e .file ).delete ())
158+ Toast .makeText (requireContext (),"Deleting configuration file: Error." ,Toast .LENGTH_LONG ).show ();
159+ Shell .su ("rm -rf /data/abm/bootset/" + e .file .replace ("/data/abm/bootset/lk2nd/entries/" ,"" ).replace (".conf" ,"" )).submit ();
160+ updateEntries ();
161+ }
162+ }))
163+ .setPositiveButton (R .string .save , (p1 , p2 ) -> {
164+ e .config = proposed ;
165+ e .save ();
166+ updateEntries ();
167+ })
168+ .setTitle (R .string .edit_entry )
169+ .setView (dialog )
170+ .show ();
116171 });
117172 }
118173
@@ -148,6 +203,7 @@ public void updateEntries() {
148203 Toast .makeText (requireContext (), "Loading entry: Error. Action aborted cleanly." , Toast .LENGTH_LONG ).show ();
149204 }
150205 }
151- if (adapter != null ) adapter .notifyDataSetChanged ();
206+ adapter = new ROMRecyclerViewAdapter (entries );
207+ recyclerView .setAdapter (adapter );
152208 }
153209}
0 commit comments