[Android] Handle insets inside DownloaderFragment

Signed-off-by: Dzmitry Strekha <mr.choo96@gmail.com>
This commit is contained in:
Dzmitry Strekha 2024-10-02 17:32:07 +03:00 committed by Viktor Havaka
parent b2906cb858
commit c7a61e922b

View file

@ -1,8 +1,15 @@
package app.organicmaps.downloader;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.OnApplyWindowInsetsListener;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import app.organicmaps.util.WindowInsetUtils;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import app.organicmaps.R;
import app.organicmaps.util.StringUtils;
@ -55,6 +62,30 @@ class BottomPanel
});
mButton = frame.findViewById(R.id.action);
ViewCompat.setOnApplyWindowInsetsListener(frame, new OnApplyWindowInsetsListener()
{
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets)
{
Insets safeInsets = insets.getInsets(WindowInsetUtils.TYPE_SAFE_DRAWING);
int baseMargin = UiUtils.dimen(v.getContext(), R.dimen.margin_base);
ViewGroup.MarginLayoutParams fabParams = (ViewGroup.MarginLayoutParams) mFab.getLayoutParams();
ViewGroup.MarginLayoutParams buttonParams = (ViewGroup.MarginLayoutParams) mButton.getLayoutParams();
buttonParams.bottomMargin = safeInsets.bottom;
mButton.setPadding(safeInsets.left, mButton.getPaddingTop(), safeInsets.right, mButton.getPaddingBottom());
fabParams.rightMargin = safeInsets.right + baseMargin;
mFab.requestLayout();
mButton.requestLayout();
return insets;
}
});
}
private void setUpdateAllState(UpdateInfo info)