@@ -378,19 +378,6 @@ public static OpeningHoursFragment newInstanceForFragment(@NonNull ValueWithDesc
378
378
return f ;
379
379
}
380
380
381
- @ Override
382
- public void onAttach (Context context ) {
383
- super .onAttach (context );
384
- Log .d (DEBUG_TAG , "onAttach" );
385
- if (!useFragmentCallback ) {
386
- try {
387
- saveListener = (OnSaveListener ) context ;
388
- } catch (ClassCastException e ) {
389
- throw new ClassCastException (context .toString () + " must implement OnSaveListener" );
390
- }
391
- }
392
- }
393
-
394
381
@ Override
395
382
public void onCreate (Bundle savedInstanceState ) {
396
383
super .onCreate (savedInstanceState );
@@ -412,6 +399,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
412
399
@ SuppressLint ("InflateParams" )
413
400
@ Override
414
401
public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
402
+ Log .d (DEBUG_TAG , "onCreateView" );
415
403
int initialRule = -1 ;
416
404
if (savedInstanceState != null ) {
417
405
Log .d (DEBUG_TAG , "Restoring from saved state" );
@@ -506,13 +494,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
506
494
AppCompatButton cancel = (AppCompatButton ) openingHoursLayout .findViewById (R .id .cancel );
507
495
cancel .setOnClickListener (v -> dismiss ());
508
496
509
- if (useFragmentCallback ) {
510
- Fragment fragment = getParentFragment ();
511
- // we may be nested one or two levels deep
512
- if (!(fragment instanceof OnSaveListener )) {
513
- fragment = fragment .getParentFragment ();
497
+ Object listener = null ;
498
+ try {
499
+ if (useFragmentCallback ) {
500
+ listener = getParentFragment ();
501
+ // we may be nested one or two levels deep
502
+ if (!(listener instanceof OnSaveListener )) {
503
+ listener = ((Fragment ) listener ).getParentFragment ();
504
+ }
505
+ } else {
506
+ listener = getContext ();
514
507
}
515
- saveListener = (OnSaveListener ) fragment ;
508
+ saveListener = (OnSaveListener ) listener ;
509
+ } catch (ClassCastException e ) {
510
+ throw new ClassCastException (listener != null ? listener .getClass ().getCanonicalName () + " must implement OnSaveListener" : "OnSaveListener is null" );
516
511
}
517
512
518
513
saveButton = (AppCompatButton ) openingHoursLayout .findViewById (R .id .save );
0 commit comments