package com.simperium.android;

import android.app.Dialog;
import android.os.Bundle;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.simperium.R;

public class SimperiumBottomSheetDialogFragment extends BottomSheetDialogFragment {
    @Override
    public int getTheme() {
        return R.style.BottomSheetDialogTheme;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        setRetainInstance(true);
        return new BottomSheetDialog(requireContext(), getTheme());
    }

    @Override
    public void onResume() {
        super.onResume();

        if (getDialog() != null) {
            // Limit width of bottom sheet on wide screens; non-zero width defined only for large qualifier.
            int dp = (int) getDialog().getContext().getResources().getDimension(R.dimen.width_layout);

            if (dp > 0) {
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                layoutParams.copyFrom(getDialog().getWindow() != null ? getDialog().getWindow().getAttributes() : null);
                layoutParams.width = dp;
                layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
                getDialog().getWindow().setAttributes(layoutParams);
            }
        }
    }
}

@@ -102,58 +102,179 @@
 iew.
-WindowManager;%0A%0Aimport androidx.annotation.NonNull
+Gravity;%0Aimport android.view.ViewParent;%0Aimport android.widget.FrameLayout;%0A%0Aimport androidx.annotation.NonNull;%0Aimport androidx.coordinatorlayout.widget.CoordinatorLayout
 ;%0A%0Ai
@@ -1178,101 +1178,370 @@
     
-WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();%0A                l
+FrameLayout bottomSheetLayout = getDialog().findViewById(com.google.android.material.R.id.design_bottom_sheet);%0A%0A                if (bottomSheetLayout != null) %7B%0A                    ViewParent bottomSheetParent = bottomSheetLayout.getParent();%0A%0A                    if (bottomSheetParent instanceof CoordinatorLayout) %7B%0A                        CoordinatorLayout.L
 ayou
@@ -1551,101 +1551,113 @@
 rams
-.copyFrom(getDialog().getWindow() != null ? getDialog().getWindow().getAttributes() : null);%0A
+ coordinatorLayoutParams = (CoordinatorLayout.LayoutParams) bottomSheetLayout.getLayoutParams();%0A        
     
@@ -1660,33 +1660,44 @@
                 
-l
+coordinatorL
 ayoutParams.widt
@@ -1724,139 +1724,492 @@
     
-layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;%0A                getDialog().getWindow().setAttributes(layoutParams);
+        bottomSheetLayout.setLayoutParams(coordinatorLayoutParams);%0A%0A                        CoordinatorLayout coordinatorLayout = (CoordinatorLayout) bottomSheetParent;%0A                        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) coordinatorLayout.getLayoutParams();%0A                        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;%0A                        coordinatorLayout.setLayoutParams(layoutParams);%0A                    %7D%0A                %7D
 %0A   

Update layout parameter assignment in simperium bottom sheet dialog fragment