bug: bottom dialog fragment attached not attached to activity (#117)

* Remove onClickListener from peersBtn

When HomeFragment is destroyed

* Remove unused imports

* Check if BottomDialogFragment is attached to Activity

When setting its onShowListener
This commit is contained in:
Diego Romar
2025-12-01 16:41:22 -03:00
committed by GitHub
parent f9376e3991
commit bf4ece69cd
2 changed files with 7 additions and 2 deletions
@@ -45,6 +45,11 @@ public class BottomDialogFragment extends com.google.android.material.bottomshee
// Apply transparent background theme to the dialog
BottomSheetDialog dialog = new BottomSheetDialog(requireContext(), R.style.BottomSheetDialogTheme);
dialog.setOnShowListener(dialogInterface -> {
// Check if the fragment is still attached to avoid IllegalStateException
if (getActivity() == null || !isAdded()) {
return;
}
FrameLayout bottomSheet = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
if (bottomSheet != null) {
// Set the bottom sheet to be full screen
@@ -11,7 +11,6 @@ import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import com.airbnb.lottie.LottieAnimationView;
@@ -22,7 +21,6 @@ import io.netbird.client.ServiceAccessor;
import io.netbird.client.StateListener;
import io.netbird.client.StateListenerRegistry;
import io.netbird.client.databinding.FragmentHomeBinding;
import io.netbird.client.ui.PreferenceUI;
import io.netbird.gomobile.android.PeerInfo;
import io.netbird.gomobile.android.PeerInfoArray;
@@ -126,6 +124,8 @@ public class HomeFragment extends Fragment implements StateListener {
super.onDestroyView();
buttonAnimation.destroy();
stateListenerRegistry.unregisterServiceStateListener(this);
FrameLayout openPanelCardView = binding.peersBtn;
openPanelCardView.setOnClickListener(null);
binding = null;
}