From 20d74b866f5cb9f5d6db8a4617a85bf4f3416fa9 Mon Sep 17 00:00:00 2001 From: Neel Doshi Date: Wed, 12 Jun 2024 06:04:34 +0530 Subject: [PATCH 1/3] Migrate `CollapseFullScreenDialogFragment` to ViewBinding --- .../ui/CollapseFullScreenDialogFragment.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java index 795801d2a42d..4e7a9bb6707c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java @@ -22,7 +22,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.content.res.AppCompatResources; -import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.core.view.MenuItemCompat; @@ -36,6 +35,7 @@ import com.google.android.material.elevation.ElevationOverlayProvider; import org.wordpress.android.R; +import org.wordpress.android.databinding.CollapseFullScreenDialogFragmentBinding; /** * A {@link DialogFragment} implementing the full-screen dialog pattern defined in the @@ -56,6 +56,7 @@ public class CollapseFullScreenDialogFragment extends DialogFragment { private static final String ARG_HIDE_ACTIVITY_BAR = "ARG_HIDE_ACTIVITY_BAR"; private static final String ARG_TITLE = "ARG_TITLE"; private static final int ID_ACTION = 1; + private CollapseFullScreenDialogFragmentBinding mBinding; public static final String TAG = CollapseFullScreenDialogFragment.class.getSimpleName(); @@ -120,7 +121,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { - mFragment = getChildFragmentManager().findFragmentById(R.id.full_screen_dialog_fragment_content); + mFragment = getChildFragmentManager().findFragmentById(mBinding.fullScreenDialogFragmentContent.getId()); } mController = new CollapseFullScreenDialogController() { @@ -171,7 +172,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c hideActivityBar(); } - ViewGroup view = (ViewGroup) inflater.inflate(R.layout.collapse_full_screen_dialog_fragment, container, false); + mBinding = CollapseFullScreenDialogFragmentBinding.inflate(inflater, container, false); + ViewGroup view = mBinding.getRoot(); initToolbar(view); setThemeBackground(view); view.setFocusableInTouchMode(true); @@ -270,20 +272,19 @@ private void initBuilderArguments() { * @param view {@link View} */ private void initToolbar(View view) { - Toolbar toolbar = view.findViewById(R.id.full_screen_dialog_fragment_toolbar); - ElevationOverlayProvider elevationOverlayProvider = new ElevationOverlayProvider(view.getContext()); float appbarElevation = getResources().getDimension(R.dimen.appbar_elevation); int elevatedColor = elevationOverlayProvider.compositeOverlayWithThemeSurfaceColorIfNeeded(appbarElevation); - toolbar.setBackgroundColor(elevatedColor); + mBinding.fullScreenDialogFragmentToolbar.setBackgroundColor(elevatedColor); - toolbar.setTitle(mTitle); - toolbar.setNavigationContentDescription(R.string.description_collapse); - toolbar.setNavigationIcon(ContextCompat.getDrawable(view.getContext(), R.drawable.ic_chevron_down_white_24dp)); - toolbar.setNavigationOnClickListener(v -> onCollapseClicked()); + mBinding.fullScreenDialogFragmentToolbar.setTitle(mTitle); + mBinding.fullScreenDialogFragmentToolbar.setNavigationContentDescription(R.string.description_collapse); + mBinding.fullScreenDialogFragmentToolbar.setNavigationIcon(ContextCompat.getDrawable(view.getContext(), + R.drawable.ic_chevron_down_white_24dp)); + mBinding.fullScreenDialogFragmentToolbar.setNavigationOnClickListener(v -> onCollapseClicked()); if (!mAction.isEmpty()) { - Menu menu = toolbar.getMenu(); + Menu menu = mBinding.fullScreenDialogFragmentToolbar.getMenu(); mMenuAction = menu.add(0, ID_ACTION, 0, this.mAction); mMenuAction.setIcon(R.drawable.ic_send_white_24dp); MenuItemCompat.setIconTintList(mMenuAction, From 72f4cc2218522eafbf5410f9be50c43b5c87e179 Mon Sep 17 00:00:00 2001 From: Neel Doshi Date: Thu, 13 Jun 2024 16:22:27 +0530 Subject: [PATCH 2/3] Binding Reference to be null on Fragment Destroy --- .../android/ui/CollapseFullScreenDialogFragment.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java index 4e7a9bb6707c..b68a5a63a072 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java @@ -521,4 +521,10 @@ public Builder setTitle(@StringRes int textId) { return this; } } + + @Override + public void onDestroy() { + super.onDestroy(); + mBinding = null + } } From 34b172b5aaebf79252d20c40651b753bb7fe0646 Mon Sep 17 00:00:00 2001 From: Neel Doshi Date: Sat, 22 Jun 2024 14:04:05 +0530 Subject: [PATCH 3/3] Added : semicolon ; --- .../wordpress/android/ui/CollapseFullScreenDialogFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java index b68a5a63a072..f57910c7cb0e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java @@ -525,6 +525,6 @@ public Builder setTitle(@StringRes int textId) { @Override public void onDestroy() { super.onDestroy(); - mBinding = null + mBinding = null; } }