Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a47a04b3 authored by Wesley.CW Wang's avatar Wesley.CW Wang Committed by Michael W
Browse files

Fix recyclerview items setup wrong description

 - Adjust the recyclerview setLayoutManager() timing, since we set it twice when using gird layout, it will mis-trigger our setContentDescription() method randomly and make some options setup wrong content description
 video: https://drive.google.com/file/d/1xGjw9zacgeQsPtQA7DkWo3d-TvzPUYIi/view?usp=sharing

 Fixes: 160761967
 Test: manually

Change-Id: I52eec0f40e5c65c5e520abe32a08611959ce5d13
parent 4a3a1d6c
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -222,9 +222,15 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
            }
        };

        Resources res = mContainer.getContext().getResources();
        if (mUseGrid) {
            mContainer.setLayoutManager(new GridLayoutManager(mContainer.getContext(),
                    res.getInteger(R.integer.options_grid_num_columns)));
        } else {
            mContainer.setLayoutManager(new LinearLayoutManager(mContainer.getContext(),
                    LinearLayoutManager.HORIZONTAL, false));
        Resources res = mContainer.getContext().getResources();
        }

        mContainer.setAdapter(mAdapter);

        // Measure RecyclerView to get to the total amount of space used by all options.
@@ -243,14 +249,18 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {

        if (mUseGrid) {
            int numColumns = res.getInteger(R.integer.options_grid_num_columns);
            int widthPerItem = totalWidth / mAdapter.getItemCount();
            int widthPerItem = res.getDimensionPixelOffset(R.dimen.option_tile_width);
            int extraSpace = availableWidth - widthPerItem * numColumns;
            while (extraSpace < 0) {
                numColumns -= 1;
                extraSpace = availableWidth - widthPerItem * numColumns;
            }
            int containerSidePadding = extraSpace / (numColumns + 1);
            mContainer.setLayoutManager(new GridLayoutManager(mContainer.getContext(), numColumns));

            if (mContainer.getLayoutManager() != null) {
                ((GridLayoutManager) mContainer.getLayoutManager()).setSpanCount(numColumns);
            }

            int containerSidePadding = (extraSpace / (numColumns + 1)) / 2;
            mContainer.setPaddingRelative(containerSidePadding, 0, containerSidePadding, 0);
            mContainer.setOverScrollMode(View.OVER_SCROLL_NEVER);
            return;