From fdf0fb2f8a5ac7736121b680704489a4476e2129 Mon Sep 17 00:00:00 2001 From: Deep Date: Sun, 30 Aug 2020 18:29:40 -0400 Subject: [PATCH] Update bottomsheet behaviour --- .../BraveStatsBottomSheetDialogFragment.java | 32 ++++++++++--------- .../res/layout/brave_stats_pager_layout.xml | 4 +-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java b/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java index 1454b3bcd4d..cdda4a873a6 100644 --- a/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java +++ b/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java @@ -99,16 +99,20 @@ public class BraveStatsBottomSheetDialogFragment extends BottomSheetDialogFragme public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); - View view = LayoutInflater.from(getContext()).inflate(R.layout.brave_stats_bottom_sheet, null); + final View view = LayoutInflater.from(getContext()).inflate(R.layout.brave_stats_bottom_sheet, null); emptyDataLayout = view.findViewById(R.id.brave_stats_empty_layout); - getDialog().setOnShowListener(new DialogInterface.OnShowListener() { + getDialog().setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { BottomSheetDialog d = (BottomSheetDialog) dialog; - View bottomSheetInternal = d.findViewById(com.google.android.material.R.id.design_bottom_sheet); - bottomSheetInternal.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; + View bottomSheetInternal = (View)view.getParent(); + boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity()); + if (!isTablet) { + bottomSheetInternal.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; + } + bottomSheetInternal.requestLayout(); } }); @@ -166,27 +170,25 @@ public class BraveStatsBottomSheetDialogFragment extends BottomSheetDialogFragme dialog.setContentView(view); } - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - + private void setWidthForDialog() { boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity()); - if (isTablet || (!isTablet && newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)) { + if (isTablet) { getDialog().getWindow().setLayout(dpToPx(getActivity(), 400), -1); } else { getDialog().getWindow().setLayout(-1, -1); } } + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + setWidthForDialog(); + } + @Override public void onResume() { super.onResume(); - boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity()); - if (isTablet || (!isTablet && ConfigurationUtils.isLandscape(getActivity()))) { - getDialog().getWindow().setLayout(dpToPx(getActivity(), 400), -1); - } else { - getDialog().getWindow().setLayout(-1, -1); - } + setWidthForDialog(); } @Override diff --git a/android/java/res/layout/brave_stats_pager_layout.xml b/android/java/res/layout/brave_stats_pager_layout.xml index 00aa55731a7..9f11764baeb 100644 --- a/android/java/res/layout/brave_stats_pager_layout.xml +++ b/android/java/res/layout/brave_stats_pager_layout.xml @@ -3,7 +3,7 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - - \ No newline at end of file + \ No newline at end of file