Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
longerian committed May 14, 2017
2 parents 0859377 + d5c4e64 commit 8d26b1b
Show file tree
Hide file tree
Showing 23 changed files with 1,971 additions and 129 deletions.
7 changes: 5 additions & 2 deletions README-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ recycler.setAdapter(myAdapter);

```
-keepattributes InnerClasses
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx {
*;
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx { *; }
-keep class android.support.v7.widget.RecyclerView$LayoutParams { *; }
-keep class android.support.v7.widget.RecyclerView$ViewHolder { *; }
-keep class android.support.v7.widget.ChildHelper { *; }
-keep class android.support.v7.widget.RecyclerView$LayoutManager { *; }
```

# Demo
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ Add following configs in your proguard file if your app is released with proguar

```
-keepattributes InnerClasses
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx {
*;
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx { *; }
-keep class android.support.v7.widget.RecyclerView$LayoutParams { *; }
-keep class android.support.v7.widget.RecyclerView$ViewHolder { *; }
-keep class android.support.v7.widget.ChildHelper { *; }
-keep class android.support.v7.widget.RecyclerView$LayoutManager { *; }
```

# Demo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.alibaba.android.vlayout.example;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.DelegateAdapter.Adapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.RecyclablePagerAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
Expand All @@ -36,6 +35,8 @@
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper;
import com.alibaba.android.vlayout.layout.RangeGridLayoutHelper;
import com.alibaba.android.vlayout.layout.RangeGridLayoutHelper.GridRangeStyle;
import com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;
import com.alibaba.android.vlayout.layout.StaggeredGridLayoutHelper;
Expand All @@ -53,18 +54,13 @@
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -264,6 +260,36 @@ public void onBindViewHolder(MainViewHolder holder, int position) {
adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
}

{
RangeGridLayoutHelper layoutHelper = new RangeGridLayoutHelper(4);
layoutHelper.setBgColor(Color.GREEN);
layoutHelper.setWeights(new float[]{20f, 26.665f});
layoutHelper.setPadding(15, 15, 15, 15);
layoutHelper.setMargin(15, 15, 15, 15);
layoutHelper.setHGap(10);
layoutHelper.setVGap(10);
GridRangeStyle rangeStyle = new GridRangeStyle();
rangeStyle.setBgColor(Color.RED);
rangeStyle.setSpanCount(2);
rangeStyle.setWeights(new float[]{46.665f});
rangeStyle.setPadding(15, 15, 15, 15);
rangeStyle.setMargin(15, 15, 15, 15);
rangeStyle.setHGap(5);
rangeStyle.setVGap(5);
layoutHelper.addRangeStyle(4, 7, rangeStyle);
GridRangeStyle rangeStyle1 = new GridRangeStyle();
rangeStyle1.setBgColor(Color.YELLOW);
rangeStyle1.setSpanCount(2);
rangeStyle1.setWeights(new float[]{46.665f});
rangeStyle1.setPadding(15, 15, 15, 15);
rangeStyle1.setMargin(15, 15, 15, 15);
rangeStyle1.setHGap(5);
rangeStyle1.setVGap(5);
layoutHelper.addRangeStyle(8, 11, rangeStyle1);
adapters.add(new SubAdapter(this, layoutHelper, 16));

}

if (SINGLE_LAYOUT) {
SingleLayoutHelper layoutHelper = new SingleLayoutHelper();
layoutHelper.setBgColor(Color.rgb(135, 225, 90));
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
GROUP=com.alibaba.android
ARTIFACT=vlayout
VERSION=1
VERSION_NAME=1.0.5
VERSION_NAME=1.0.6
PACKAGING_TYPE=aar
systemProp.compileSdkVersion=23
systemProp.targetSdkVersion=23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class DelegateAdapter extends VirtualLayoutAdapter<RecyclerView.ViewHolde

private int mTotal = 0;

private final SparseArray<Pair<AdapterDataObserver, Adapter>> mIndexAry = new SparseArray<>();

/**
* Delegate Adapter merge multi sub adapters, default is thread-unsafe
*
Expand Down Expand Up @@ -117,14 +119,12 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
int index = viewType - t;
int subItemType = w - index;

int idx = findAdapterPositionByIndex(index);
if (idx < 0) {
Adapter adapter = findAdapterByIndex(index);
if (adapter == null) {
return null;
}

Pair<AdapterDataObserver, Adapter> p = mAdapters.get(idx);

return p.second.onCreateViewHolder(parent, subItemType);
return adapter.onCreateViewHolder(parent, subItemType);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -265,6 +265,8 @@ public void setAdapters(@Nullable List<Adapter> adapters) {

boolean hasStableIds = true;
mTotal = 0;

Pair<AdapterDataObserver, Adapter> pair;
for (Adapter adapter : adapters) {
// every adapter has an unique index id
AdapterDataObserver observer = new AdapterDataObserver(mTotal, mIndexGen == null ? mIndex++ : mIndexGen.incrementAndGet());
Expand All @@ -275,7 +277,9 @@ public void setAdapters(@Nullable List<Adapter> adapters) {
helper.setItemCount(adapter.getItemCount());
mTotal += helper.getItemCount();
helpers.add(helper);
mAdapters.add(Pair.create(observer, adapter));
pair = Pair.create(observer, adapter);
mIndexAry.put(observer.mIndex, pair);
mAdapters.add(pair);
}

if (!hasObservers()) {
Expand Down Expand Up @@ -307,6 +311,8 @@ public void addAdapters(int position, @Nullable List<Adapter> adapters) {

List<LayoutHelper> helpers = new LinkedList<>(super.getLayoutHelpers());

Pair<AdapterDataObserver, Adapter> pair;

for (Adapter adapter : adapters) {
// every adapter has an unique index id
AdapterDataObserver observer = new AdapterDataObserver(mTotal, mIndexGen == null ? mIndex++ : mIndexGen.incrementAndGet());
Expand All @@ -318,7 +324,11 @@ public void addAdapters(int position, @Nullable List<Adapter> adapters) {
mTotal += helper.getItemCount();

helpers.add(position, helper);
mAdapters.add(position, Pair.create(observer, adapter));

pair = Pair.create(observer, adapter);

mIndexAry.put(observer.mIndex, pair);
mAdapters.add(position, pair);
position++;
}

Expand Down Expand Up @@ -436,11 +446,12 @@ public void clear() {

mItemTypeAry.clear();
mAdapters.clear();
mIndexAry.clear();
}


@Nullable
protected Pair<AdapterDataObserver, Adapter> findAdapterByPosition(int position) {
public Pair<AdapterDataObserver, Adapter> findAdapterByPosition(int position) {
final int count = mAdapters.size();
if (count == 0) {
return null;
Expand Down Expand Up @@ -470,33 +481,18 @@ protected Pair<AdapterDataObserver, Adapter> findAdapterByPosition(int position)
}


protected int findAdapterPositionByIndex(int index) {
final int count = mAdapters.size();
if (count == 0) {
return -1;
}

int s = 0, e = count - 1, m = -1;
Pair<AdapterDataObserver, Adapter> rs = null;
public int findAdapterPositionByIndex(int index) {
Pair<AdapterDataObserver, Adapter> rs = mIndexAry.get(index);

// binary search range
while (s <= e) {
m = (s + e) / 2;
rs = mAdapters.get(m);
if (rs.first.mIndex > index) {
e = m - 1;
} else if (rs.first.mIndex < index) {
s = m + 1;
} else if (rs.first.mIndex == index) {
break;
}
rs = null;
}
return rs == null ? -1 : mAdapters.indexOf(rs);
}

return rs == null ? -1 : m;
public Adapter findAdapterByIndex(int index) {
Pair<AdapterDataObserver, Adapter> rs = mIndexAry.get(index);
return rs.second;
}

private class AdapterDataObserver extends RecyclerView.AdapterDataObserver {
protected class AdapterDataObserver extends RecyclerView.AdapterDataObserver {
int mStartPosition;

int mIndex = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1906,8 +1906,10 @@ void ensureChildHelper() {
void hide(View view) {
try {
ensureChildHelper();
args[0] = view;
mHideMethod.invoke(mInnerChildHelper, args);
if (mInnerHiddenView.indexOf(view) < 0) {
args[0] = view;
mHideMethod.invoke(mInnerChildHelper, args);
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public interface LayoutManagerHelper {
*/
void addOffFlowView(View view, boolean head);

/**
* Add view out of normal flow, which means it won't be ignored in getChildAt, but still be able to scrolled with content
* But it's can be find by position via {@link #findViewByPosition(int)}.
* The differece between with {@link #addOffFlowView(View, boolean)} is that this method does not hide the view, it is used to add background view with overlapping.
* @param view View will be added
* @param head Whether added to the head or tail
*/
void addBackgroundView(View view, boolean head);

/**
* Add view to fixed layer, which overlays on the normal layer.
* It won't be found by getChildAt and also scrolled with content.
Expand Down Expand Up @@ -179,7 +188,7 @@ public interface LayoutManagerHelper {
OrientationHelper getSecondaryOrientationHelper();

/**
* Measure children views with margins and decorations, use this to measure children
* Measure children views with decorations, use this to measure children
*
* @param view
* @param widthSpec
Expand All @@ -188,14 +197,24 @@ public interface LayoutManagerHelper {
void measureChild(View view, int widthSpec, int heightSpec);

/**
* Layout children views with margins and decorations.
* Measure children views with margins and decorations, use this to measure children
*
* @param view
* @param left
* @param top
* @param right
* @param bottom
* @param child
* @param widthUsed
* @param heightUsed
*/
void measureChildWithMargins(View child, int widthUsed, int heightUsed);


/**
* Layout children views with margins and decorations.
*
* @param view
* @param left
* @param top
* @param right
* @param bottom
*/
void layoutChild(View view, int left, int top, int right, int bottom);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ public void addChildView(View view, int index) {
}


@Override
public void moveView(int fromIndex, int toIndex) {
super.moveView(fromIndex, toIndex);
}
Expand Down Expand Up @@ -1084,6 +1085,12 @@ public void addOffFlowView(View view, boolean head) {

}

@Override
public void addBackgroundView(View view, boolean head) {
showView(view);
int index = head ? 0 : -1;
addView(view, index);
}

@Override
public void addFixedView(View view) {
Expand Down Expand Up @@ -1142,7 +1149,12 @@ public OrientationHelper getSecondaryOrientationHelper() {

@Override
public void measureChild(View child, int widthSpec, int heightSpec) {
measureChildWithDecorationsAndMargin(child, widthSpec, heightSpec);
measureChildWithDecorations(child, widthSpec, heightSpec);
}

@Override
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) {
measureChildWithDecorationsAndMargin(child, widthUsed, heightUsed);
}

@Override
Expand Down Expand Up @@ -1279,6 +1291,13 @@ public boolean isDoLayoutRTL() {

private Rect mDecorInsets = new Rect();

private void measureChildWithDecorations(View child, int widthSpec, int heightSpec) {
calculateItemDecorationsForChild(child, mDecorInsets);
widthSpec = updateSpecWithExtra(widthSpec, mDecorInsets.left, mDecorInsets.right);
heightSpec = updateSpecWithExtra(heightSpec, mDecorInsets.top, mDecorInsets.bottom);
child.measure(widthSpec, heightSpec);
}

private void measureChildWithDecorationsAndMargin(View child, int widthSpec, int heightSpec) {
calculateItemDecorationsForChild(child, mDecorInsets);
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
Expand Down
Loading

0 comments on commit 8d26b1b

Please sign in to comment.