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

Commit 49d153e4 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing unnecessary abstraction of AdapterProvider

Bug: 266605714
Test: Presubmit
Change-Id: Ib5ccecc33e66e61cb27d083591c8fb7c13a96698
Merged-In: Ib5ccecc33e66e61cb27d083591c8fb7c13a96698
parent dbc5e56e
Loading
Loading
Loading
Loading
+13 −20
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
    private boolean mRebindAdaptersAfterSearchAnimation;
    private int mNavBarScrimHeight = 0;
    private SearchRecyclerView mSearchRecyclerView;
    private SearchAdapterProvider<?> mMainAdapterProvider;
    protected SearchAdapterProvider<?> mMainAdapterProvider;
    private View mBottomSheetHandleArea;
    private boolean mHasWorkApps;
    private float[] mBottomSheetCornerRadii;
@@ -202,9 +202,12 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
    protected void initContent() {
        mMainAdapterProvider = createMainAdapterProvider();

        mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN));
        mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK));
        mAH.set(SEARCH, new AdapterHolder(SEARCH));
        mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN,
                new AlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null)));
        mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK,
                new AlphabeticalAppsList<>(mActivityContext, mAllAppsStore, mWorkManager)));
        mAH.set(SEARCH, new AdapterHolder(SEARCH,
                new AlphabeticalAppsList<>(mActivityContext, null, null)));

        getLayoutInflater().inflate(R.layout.all_apps_content, this);
        mHeader = findViewById(R.id.all_apps_header);
@@ -344,7 +347,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
                mAH.get(i).mRecyclerView.scrollToTop();
            }
        }
        if (isHeaderVisible()) {
        if (mHeader != null && mHeader.getVisibility() == VISIBLE) {
            mHeader.reset(animate);
        }
        // Reset the base recycler view after transitioning home.
@@ -625,10 +628,9 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
    }

    protected BaseAllAppsAdapter<T> createAdapter(AlphabeticalAppsList<T> appsList,
            BaseAdapterProvider[] adapterProviders) {
    protected BaseAllAppsAdapter<T> createAdapter(AlphabeticalAppsList<T> appsList) {
        return new AllAppsGridAdapter<>(mActivityContext, getLayoutInflater(), appsList,
                adapterProviders);
                mMainAdapterProvider);
    }

    // TODO(b/216683257): Remove when Taskbar All Apps supports search.
@@ -999,10 +1001,6 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        return rv == null ? null : rv.getScrollbar();
    }

    public boolean isHeaderVisible() {
        return mHeader != null && mHeader.getVisibility() == View.VISIBLE;
    }

    /**
     * Adds an update listener to animator that adds springs to the animation.
     */
@@ -1153,15 +1151,10 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        final Rect mPadding = new Rect();
        AllAppsRecyclerView mRecyclerView;

        AdapterHolder(int type) {
        AdapterHolder(int type, AlphabeticalAppsList<T> appsList) {
            mType = type;
            mAppsList = new AlphabeticalAppsList<>(mActivityContext,
                    isSearch() ? null : mAllAppsStore,
                    isWork() ? mWorkManager : null);
            BaseAdapterProvider[] adapterProviders =
                    new BaseAdapterProvider[]{mMainAdapterProvider};

            mAdapter = createAdapter(mAppsList, adapterProviders);
            mAppsList = appsList;
            mAdapter = createAdapter(mAppsList);
            mAppsList.setAdapter(mAdapter);
            mLayoutManager = mAdapter.getLayoutManager();
        }
+8 −10
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.Adapter;

import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.util.ScrollableLayoutManager;
import com.android.launcher3.views.ActivityContext;

@@ -73,8 +74,8 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends


    public AllAppsGridAdapter(T activityContext, LayoutInflater inflater,
            AlphabeticalAppsList apps, BaseAdapterProvider[] adapterProviders) {
        super(activityContext, inflater, apps, adapterProviders);
            AlphabeticalAppsList apps, SearchAdapterProvider<?> adapterProvider) {
        super(activityContext, inflater, apps, adapterProvider);
        mGridLayoutMgr = new AppsGridLayoutManager(mActivityContext);
        mGridLayoutMgr.setSpanSizeLookup(new GridSpanSizer());
        setAppsPerRow(activityContext.getDeviceProfile().numShownAllAppsColumns);
@@ -195,13 +196,11 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
    public void setAppsPerRow(int appsPerRow) {
        mAppsPerRow = appsPerRow;
        int totalSpans = mAppsPerRow;
        for (BaseAdapterProvider adapterProvider : mAdapterProviders) {
            for (int itemPerRow : adapterProvider.getSupportedItemsPerRowArray()) {
        for (int itemPerRow : mAdapterProvider.getSupportedItemsPerRowArray()) {
            if (totalSpans % itemPerRow != 0) {
                totalSpans *= itemPerRow;
            }
        }
        }
        mGridLayoutMgr.setSpanCount(totalSpans);
    }

@@ -226,9 +225,8 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
            if (isIconViewType(viewType)) {
                return totalSpans / mAppsPerRow;
            } else {
                BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
                if (adapterProvider != null) {
                    return totalSpans / adapterProvider.getItemsPerRow(viewType, mAppsPerRow);
                if (mAdapterProvider.isViewSupported(viewType)) {
                    return totalSpans / mAdapterProvider.getItemsPerRow(viewType, mAppsPerRow);
                }

                // Section breaks span the full width
+0 −56
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.allapps;

import android.view.LayoutInflater;
import android.view.ViewGroup;

/**
 * A UI expansion wrapper providing for providing dynamic recyclerview items
 */
public abstract class BaseAdapterProvider {

    /**
     * Returns whether or not viewType can be handled by searchProvider
     */
    public abstract boolean isViewSupported(int viewType);

    /**
     * Called from RecyclerView.Adapter#onBindViewHolder
     */
    public abstract void onBindView(AllAppsGridAdapter.ViewHolder holder, int position);

    /**
     * Called from RecyclerView.Adapter#onCreateViewHolder
     */
    public abstract AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater,
            ViewGroup parent, int viewType);

    /**
     * Returns supported item per row combinations supported
     */
    public int[] getSupportedItemsPerRowArray() {
        return new int[]{};
    }

    /**
     * Returns how many cells a view should span
     */
    public int getItemsPerRow(int viewType, int appsPerRow) {
        return appsPerRow;
    }

}
+8 −24
Original line number Diff line number Diff line
@@ -27,18 +27,16 @@ import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.views.ActivityContext;

import java.util.Arrays;

/**
 * Adapter for all the apps.
 *
@@ -65,8 +63,7 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
    public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
    public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;


    protected final BaseAdapterProvider[] mAdapterProviders;
    protected final SearchAdapterProvider<?> mAdapterProvider;

    /**
     * ViewHolder for each icon.
@@ -146,7 +143,7 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
    private final int mExtraHeight;

    public BaseAllAppsAdapter(T activityContext, LayoutInflater inflater,
            AlphabeticalAppsList<T> apps, BaseAdapterProvider[] adapterProviders) {
            AlphabeticalAppsList<T> apps, SearchAdapterProvider<?> adapterProvider) {
        Resources res = activityContext.getResources();
        mActivityContext = activityContext;
        mApps = apps;
@@ -154,7 +151,7 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex

        mOnIconClickListener = mActivityContext.getItemOnClickListener();

        mAdapterProviders = adapterProviders;
        mAdapterProvider = adapterProvider;
        mExtraHeight = res.getDimensionPixelSize(R.dimen.all_apps_height_extra);
    }

@@ -216,9 +213,8 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
                return new ViewHolder(mLayoutInflater.inflate(
                        R.layout.work_apps_paused, parent, false));
            default:
                BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
                if (adapterProvider != null) {
                    return adapterProvider.onCreateViewHolder(mLayoutInflater, parent, viewType);
                if (mAdapterProvider.isViewSupported(viewType)) {
                    return mAdapterProvider.onCreateViewHolder(mLayoutInflater, parent, viewType);
                }
                throw new RuntimeException("Unexpected view type" + viewType);
        }
@@ -250,16 +246,10 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
                ((WorkEduCard) holder.itemView).setPosition(position);
                break;
            default:
                BaseAdapterProvider adapterProvider = getAdapterProvider(holder.getItemViewType());
                if (adapterProvider != null) {
                    adapterProvider.onBindView(holder, position);
                }
                if (mAdapterProvider.isViewSupported(holder.getItemViewType())) {
                    mAdapterProvider.onBindView(holder, position);
                }
        }

    @Override
    public void onViewRecycled(@NonNull ViewHolder holder) {
        super.onViewRecycled(holder);
    }

    @Override
@@ -283,10 +273,4 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
        return (viewType & viewTypeMask) != 0;
    }

    @Nullable
    protected BaseAdapterProvider getAdapterProvider(int viewType) {
        return Arrays.stream(mAdapterProviders).filter(
                adapterProvider -> adapterProvider.isViewSupported(viewType)).findFirst().orElse(
                null);
    }
}
+1 −9
Original line number Diff line number Diff line
@@ -15,12 +15,10 @@
 */
package com.android.launcher3.allapps.search;

import android.graphics.Canvas;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.android.launcher3.BubbleTextView;
@@ -38,13 +36,7 @@ public class DefaultSearchAdapterProvider extends SearchAdapterProvider<Activity

    public DefaultSearchAdapterProvider(ActivityContext launcher) {
        super(launcher);
        mDecoration = new RecyclerView.ItemDecoration() {
            @Override
            public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent,
                    @NonNull RecyclerView.State state) {
                super.onDraw(c, parent, state);
            }
        };
        mDecoration = new RecyclerView.ItemDecoration() { };
    }

    @Override
Loading