Loading src/com/android/settings/homepage/HomepageAdapter.java +19 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; Loading @@ -28,14 +29,16 @@ import java.util.List; public class HomepageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements HomepageCardUpdateListener { static final int SPAN_COUNT = 2; private static final String TAG = "HomepageAdapter"; private static final int HALF_WIDTH = 1; private static final int FULL_WIDTH = 2; private final Context mContext; private final ControllerRendererPool mControllerRendererPool; private List<HomepageCard> mHomepageCards; private RecyclerView mRecyclerView; public HomepageAdapter(Context context, HomepageManager manager) { mContext = context; Loading Loading @@ -81,7 +84,21 @@ public class HomepageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); mRecyclerView = recyclerView; final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { final HomepageCard card = mHomepageCards.get(position); //TODO(b/114009676): may use another field to make decision. still under review. if (card.isHalfWidth()) { return HALF_WIDTH; } return FULL_WIDTH; } }); } } @Override Loading src/com/android/settings/homepage/PersonalSettingsFragment.java +6 −3 Original line number Diff line number Diff line Loading @@ -16,11 +16,14 @@ package com.android.settings.homepage; import static com.android.settings.homepage.HomepageAdapter.SPAN_COUNT; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; Loading @@ -35,7 +38,7 @@ public class PersonalSettingsFragment extends InstrumentedFragment { private RecyclerView mCardsContainer; //TODO(b/113966426): rename private HomepageAdapter mHomepageAdapter; private LinearLayoutManager mLayoutManager; private GridLayoutManager mLayoutManager; //TODO(b/113966426): rename private HomepageManager mHomepageManager; Loading @@ -52,8 +55,8 @@ public class PersonalSettingsFragment extends InstrumentedFragment { final View rootView = inflater.inflate(R.layout.settings_homepage, container, false); mCardsContainer = (RecyclerView) rootView.findViewById(R.id.card_container); //TODO(b/111822407): May have to swap to GridLayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, LinearLayoutManager.VERTICAL, false /* reverseLayout */); mCardsContainer.setLayoutManager(mLayoutManager); mHomepageAdapter = new HomepageAdapter(getContext(), mHomepageManager); mCardsContainer.setAdapter(mHomepageAdapter); Loading Loading
src/com/android/settings/homepage/HomepageAdapter.java +19 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; Loading @@ -28,14 +29,16 @@ import java.util.List; public class HomepageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements HomepageCardUpdateListener { static final int SPAN_COUNT = 2; private static final String TAG = "HomepageAdapter"; private static final int HALF_WIDTH = 1; private static final int FULL_WIDTH = 2; private final Context mContext; private final ControllerRendererPool mControllerRendererPool; private List<HomepageCard> mHomepageCards; private RecyclerView mRecyclerView; public HomepageAdapter(Context context, HomepageManager manager) { mContext = context; Loading Loading @@ -81,7 +84,21 @@ public class HomepageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); mRecyclerView = recyclerView; final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { final HomepageCard card = mHomepageCards.get(position); //TODO(b/114009676): may use another field to make decision. still under review. if (card.isHalfWidth()) { return HALF_WIDTH; } return FULL_WIDTH; } }); } } @Override Loading
src/com/android/settings/homepage/PersonalSettingsFragment.java +6 −3 Original line number Diff line number Diff line Loading @@ -16,11 +16,14 @@ package com.android.settings.homepage; import static com.android.settings.homepage.HomepageAdapter.SPAN_COUNT; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; Loading @@ -35,7 +38,7 @@ public class PersonalSettingsFragment extends InstrumentedFragment { private RecyclerView mCardsContainer; //TODO(b/113966426): rename private HomepageAdapter mHomepageAdapter; private LinearLayoutManager mLayoutManager; private GridLayoutManager mLayoutManager; //TODO(b/113966426): rename private HomepageManager mHomepageManager; Loading @@ -52,8 +55,8 @@ public class PersonalSettingsFragment extends InstrumentedFragment { final View rootView = inflater.inflate(R.layout.settings_homepage, container, false); mCardsContainer = (RecyclerView) rootView.findViewById(R.id.card_container); //TODO(b/111822407): May have to swap to GridLayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, LinearLayoutManager.VERTICAL, false /* reverseLayout */); mCardsContainer.setLayoutManager(mLayoutManager); mHomepageAdapter = new HomepageAdapter(getContext(), mHomepageManager); mCardsContainer.setAdapter(mHomepageAdapter); Loading