diff options
author | 2025-03-09 16:01:56 -0700 | |
---|---|---|
committer | 2025-03-09 16:01:56 -0700 | |
commit | 11966310fbb7fe63cfc272e40d9d556c5501e45e (patch) | |
tree | 9fb6a405e48b17da1e2d973c29ea07f60bde0b61 /src | |
parent | 3123137c7c2134d966980beda5735229f1d8aca9 (diff) | |
parent | e599ddbd61fcb513c118633d2ecd4235cf2cf1e6 (diff) |
Merge "[DocsUI M3] Fix the 3-section layout on compact screen" into main
Diffstat (limited to 'src')
4 files changed, 52 insertions, 15 deletions
diff --git a/src/com/android/documentsui/HorizontalBreadcrumb.java b/src/com/android/documentsui/HorizontalBreadcrumb.java index 94f0e13f9..cb25479b3 100644 --- a/src/com/android/documentsui/HorizontalBreadcrumb.java +++ b/src/com/android/documentsui/HorizontalBreadcrumb.java @@ -25,6 +25,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -45,6 +46,9 @@ public final class HorizontalBreadcrumb extends RecyclerView implements Breadcru private LinearLayoutManager mLayoutManager; private BreadcrumbAdapter mAdapter; private IntConsumer mClickListener; + // Represents the top divider (border) of the breadcrumb on the compact size screen. + // It will be null on other screen sizes, or when the use_material3 flag is OFF. + private @Nullable View mTopDividerView; public HorizontalBreadcrumb(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); @@ -61,12 +65,14 @@ public final class HorizontalBreadcrumb extends RecyclerView implements Breadcru @Override public void setup(Environment env, com.android.documentsui.base.State state, - IntConsumer listener) { + IntConsumer listener, + @Nullable View topDivider) { mClickListener = listener; mLayoutManager = new HorizontalBreadcrumbLinearLayoutManager( getContext(), LinearLayoutManager.HORIZONTAL, false); mAdapter = new BreadcrumbAdapter(state, env, this::onKey); + mTopDividerView = topDivider; // Since we are using GestureDetector to detect click events, a11y services don't know which // views are clickable because we aren't using View.OnClickListener. Thus, we need to use a // custom accessibility delegate to route click events correctly. @@ -109,6 +115,9 @@ public final class HorizontalBreadcrumb extends RecyclerView implements Breadcru setVisibility(GONE); setAdapter(null); } + if (mTopDividerView != null) { + mTopDividerView.setVisibility(visibility ? VISIBLE : GONE); + } mAdapter.updateLastItemSize(); } diff --git a/src/com/android/documentsui/NavigationViewManager.java b/src/com/android/documentsui/NavigationViewManager.java index 86b5e517f..12afbd69b 100644 --- a/src/com/android/documentsui/NavigationViewManager.java +++ b/src/com/android/documentsui/NavigationViewManager.java @@ -27,10 +27,10 @@ import android.graphics.drawable.Drawable; import android.util.Log; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.view.Window; import android.view.WindowManager; -import android.widget.FrameLayout; import androidx.annotation.ColorRes; import androidx.annotation.Nullable; @@ -144,7 +144,13 @@ public class NavigationViewManager extends SelectionTracker.SelectionObserver<St mState = state; mEnv = env; mBreadcrumb = breadcrumb; - mBreadcrumb.setup(env, state, this::onNavigationItemSelected); + mBreadcrumb.setup( + env, + state, + this::onNavigationItemSelected, + isUseMaterial3FlagEnabled() + ? activity.findViewById(R.id.breadcrumb_top_divider) + : null); mConfigStore = configStore; mInjector = injector; mProfileTabs = @@ -297,7 +303,10 @@ public class NavigationViewManager extends SelectionTracker.SelectionObserver<St } public void update() { - updateScrollFlag(); + // If use_material3 flag is ON, we don't want any scroll behavior, thus skipping this logic. + if (!isUseMaterial3FlagEnabled()) { + updateScrollFlag(); + } updateToolbar(); mProfileTabs.updateView(); @@ -467,8 +476,11 @@ public class NavigationViewManager extends SelectionTracker.SelectionObserver<St } if (!mIsActionModeActivated) { - FrameLayout.LayoutParams headerLayoutParams = - (FrameLayout.LayoutParams) mHeader.getLayoutParams(); + // This could be either FrameLayout.LayoutParams (when use_material3 flag is OFF) or + // LinearLayout.LayoutParams (when use_material3 flag is ON), so use the common parent + // class instead to make it work for both scenarios. + ViewGroup.MarginLayoutParams headerLayoutParams = + (ViewGroup.MarginLayoutParams) mHeader.getLayoutParams(); headerLayoutParams.setMargins(0, /* top= */ headerTopOffset, 0, 0); mHeader.setLayoutParams(headerLayoutParams); } @@ -498,7 +510,7 @@ public class NavigationViewManager extends SelectionTracker.SelectionObserver<St } interface Breadcrumb { - void setup(Environment env, State state, IntConsumer listener); + void setup(Environment env, State state, IntConsumer listener, @Nullable View topDivider); void show(boolean visibility); diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java index 855a8273d..6de42db59 100644 --- a/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -827,6 +827,13 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On } private int getSaveLayoutHeight() { + // When use_material3 flag is on, the bottom section not only includes the container_save, + // but also includes the breadcrumb and the divider, so we need to use the total height + // for their parent container. + if (isUseMaterial3FlagEnabled()) { + View bottomSection = getActivity().findViewById(R.id.bottom_container); + return bottomSection == null ? 0 : bottomSection.getHeight(); + } View containerSave = getActivity().findViewById(R.id.container_save); return containerSave == null ? 0 : containerSave.getHeight(); } diff --git a/src/com/android/documentsui/sorting/TableHeaderController.java b/src/com/android/documentsui/sorting/TableHeaderController.java index cb72ac916..fda7b2713 100644 --- a/src/com/android/documentsui/sorting/TableHeaderController.java +++ b/src/com/android/documentsui/sorting/TableHeaderController.java @@ -28,10 +28,11 @@ import javax.annotation.Nullable; /** View controller for table header that associates header cells in table header and columns. */ public final class TableHeaderController implements SortController.WidgetController { private final HeaderCell mTitleCell; - private final HeaderCell mSummaryCell; - private final HeaderCell mSizeCell; - private final HeaderCell mFileTypeCell; - private final HeaderCell mDateCell; + // The 4 cells below will be null in compact/medium screen sizes when use_material3 flag is ON. + private final @Nullable HeaderCell mSummaryCell; + private final @Nullable HeaderCell mSizeCell; + private final @Nullable HeaderCell mFileTypeCell; + private final @Nullable HeaderCell mDateCell; private final SortModel mModel; // We assign this here porque each method reference creates a new object // instance (which is wasteful). @@ -66,10 +67,18 @@ public final class TableHeaderController implements SortController.WidgetControl private void onModelUpdate(SortModel model, int updateTypeUnspecified) { bindCell(mTitleCell, SortModel.SORT_DIMENSION_ID_TITLE); - bindCell(mSummaryCell, SortModel.SORT_DIMENSION_ID_SUMMARY); - bindCell(mSizeCell, SortModel.SORT_DIMENSION_ID_SIZE); - bindCell(mFileTypeCell, SortModel.SORT_DIMENSION_ID_FILE_TYPE); - bindCell(mDateCell, SortModel.SORT_DIMENSION_ID_DATE); + if (mSummaryCell != null) { + bindCell(mSummaryCell, SortModel.SORT_DIMENSION_ID_SUMMARY); + } + if (mSizeCell != null) { + bindCell(mSizeCell, SortModel.SORT_DIMENSION_ID_SIZE); + } + if (mFileTypeCell != null) { + bindCell(mFileTypeCell, SortModel.SORT_DIMENSION_ID_FILE_TYPE); + } + if (mDateCell != null) { + bindCell(mDateCell, SortModel.SORT_DIMENSION_ID_DATE); + } } @Override |