55import android .os .Handler ;
66
77import androidx .appcompat .app .AppCompatActivity ;
8+ import androidx .core .view .ViewCompat ;
9+ import androidx .core .view .WindowInsetsCompat ;
810
911import android .util .Log ;
1012import android .view .View ;
1113import android .widget .Button ;
14+ import android .widget .LinearLayout ;
1215import android .widget .RadioButton ;
1316import android .widget .RadioGroup ;
1417import android .widget .TextView ;
@@ -38,6 +41,7 @@ public class EditEventActivity extends AppCompatActivity {
3841 private String mEventTypeStr = null ;
3942 private String mEventSubTypeStr = null ;
4043 private String mEventId ;
44+ private ArrayList <String > mEventIds ; // For group editing
4145 private String mEventNotes = "" ;
4246 //private Date mEventDateTime;
4347 private RadioGroup mEventTypeRg ;
@@ -52,6 +56,22 @@ protected void onCreate(Bundle savedInstanceState) {
5256 Log .v (TAG , "onCreate()" );
5357 super .onCreate (savedInstanceState );
5458 setContentView (R .layout .activity_edit_event );
59+ // Handle system window insets for all API levels
60+ View rootView = findViewById (R .id .root_layout_edit_event );
61+ ViewCompat .setOnApplyWindowInsetsListener (rootView , (v , insets ) -> {
62+ // Get the system bar insets
63+ int top = insets .getInsets (WindowInsetsCompat .Type .systemBars ()).top ;
64+ int bottom = insets .getInsets (WindowInsetsCompat .Type .systemBars ()).bottom ;
65+
66+ // Apply padding to your main content view
67+ LinearLayout content = findViewById (R .id .edit_event_content_layout );
68+ content .setPadding (0 , top , 0 , bottom );
69+
70+ // Return the insets so they keep propagating
71+ return WindowInsetsCompat .CONSUMED ;
72+ });
73+
74+
5575 mUtil = new OsdUtil (getApplicationContext (), serverStatusHandler );
5676 mConnection = new SdServiceConnection (getApplicationContext ());
5777
@@ -61,8 +81,15 @@ protected void onCreate(Bundle savedInstanceState) {
6181
6282 Bundle extras = getIntent ().getExtras ();
6383 if (extras != null ) {
64- String eventId = extras .getString ("eventId" );
65- mEventId = eventId ;
84+ mEventIds = extras .getStringArrayList ("eventIds" );
85+ if (mEventIds != null && !mEventIds .isEmpty ()) {
86+ Log .v (TAG , "onCreate - Group Edit - eventIds=" + mEventIds .toString ());
87+ mEventId = mEventIds .get (0 );
88+ } else {
89+ Log .v (TAG , "onCreate - Single Edit - eventId=" + extras .getString ("eventId" ));
90+ mEventId = extras .getString ("eventId" );
91+ mEventIds = null ;
92+ }
6693 Log .v (TAG , "onCreate - mEventId=" + mEventId );
6794 }
6895
@@ -297,6 +324,7 @@ public void onClick(View view) {
297324 }
298325 Log .v (TAG , "onOK() - eventObj=" + mEventObj .toString ());
299326
327+ // First we just save the open event, irrespective of whether it is a group edit or not.
300328 try {
301329 mWac .updateEvent (mEventObj , new WebApiConnection .JSONObjectCallback () {
302330 @ Override
@@ -320,9 +348,58 @@ public void accept(JSONObject eventObj) {
320348 mUtil .showToast ("Error Updating Event" );
321349 updateUi ();
322350 }
351+
352+ // If this is a group edit, we need to update the other events in the group.
353+ if (mEventIds != null && mEventIds .size () > 1 ) {
354+ Log .v (TAG , "onOK() - Group Edit - updating other events in group" );
355+ updateGroupEventsSequentially (0 );
356+ }
323357 }
358+
324359 };
325360
361+ private void updateGroupEventsSequentially (final int index ) {
362+ if (mEventIds == null || index >= mEventIds .size ()) {
363+ Log .v (TAG , "updateGroupEventsSequentially - All events updated" );
364+ return ;
365+ }
366+ final String eventId = mEventIds .get (index );
367+ mWac .getEvent (eventId , new WebApiConnection .JSONObjectCallback () {
368+ @ Override
369+ public void accept (JSONObject eventObj ) {
370+ if (eventObj == null ) {
371+ Log .e (TAG , "updateGroupEventsSequentially - ERROR: could not retrieve event " + eventId );
372+ mUtil .showToast ("Error Retrieving Event " + eventId );
373+ updateGroupEventsSequentially (index + 1 );
374+ return ;
375+ }
376+ try {
377+ eventObj .put ("id" , eventId );
378+ eventObj .put ("type" , mEventObj .getString ("type" ));
379+ eventObj .put ("subType" , mEventObj .getString ("subType" ));
380+ eventObj .put ("desc" , mEventObj .getString ("desc" ));
381+ } catch (JSONException e ) {
382+ Log .e (TAG , "updateGroupEventsSequentially - ERROR: " + e .getMessage ());
383+ updateGroupEventsSequentially (index + 1 );
384+ return ;
385+ }
386+ mWac .updateEvent (eventObj , new WebApiConnection .JSONObjectCallback () {
387+ @ Override
388+ public void accept (JSONObject updatedObj ) {
389+ if (updatedObj == null ) {
390+ Log .e (TAG , "updateGroupEventsSequentially - ERROR: update failed for " + eventId );
391+ mUtil .showToast ("Error Updating Event " + eventId );
392+ } else {
393+ Log .v (TAG , "updateGroupEventsSequentially - Updated event " + eventId + " OK" );
394+ mUtil .showToast ("Event " + eventId + " Updated OK" );
395+ }
396+ updateGroupEventsSequentially (index + 1 );
397+ }
398+ });
399+ }
400+ });
401+ }
402+
326403
327404 RadioGroup .OnCheckedChangeListener onEventTypeChange =
328405 new RadioGroup .OnCheckedChangeListener () {
0 commit comments