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

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
longerian committed May 6, 2017
2 parents 45d74c4 + 7e1036e commit b53be73
Show file tree
Hide file tree
Showing 8 changed files with 1,041 additions and 916 deletions.
15 changes: 13 additions & 2 deletions README-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ recyclerView.setLayoutManager(layoutManager);
RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
recyclerView.setRecycledViewPool(viewPool);
viewPool.setMaxRecycledViews(0, 10);

```

**注意:上述示例代码里只针对type=0的item设置了复用池的大小,如果你的页面有多种type,需要为每一种类型的分别调整复用池大小参数。**

加载数据时有两种方式:

* 一种是使用 ```DelegateAdapter```, 可以像平常一样写继承自```DelegateAdapter.Adapter```的Adapter, 只比之前的Adapter需要多重载```onCreateLayoutHelper```方法。
其他的和默认Adapter一样。

``` java
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasStableItemType);
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasConsistItemType);
recycler.setAdapter(delegateAdapter);

// 之后可以通过 setAdapters 或 addAdapter方法添加DelegateAdapter.Adapter
Expand All @@ -84,6 +87,8 @@ delegateAdapter.addAdapter(adapter);
// 如果数据有变化,调用自定义 adapter 的 notifyDataSetChanged()
adapter.notifyDataSetChanged();
```
**注意:当hasConsistItemType=true的时候,不论是不是属于同一个子adapter,相同类型的item都能复用。表示它们共享一个类型。
当hasConsistItemType=false的时候,不同子adapter之间的类型不共享**

* 另一种是当业务有自定义的复杂需求的时候, 可以继承自```VirtualLayoutAdapter```, 实现自己的Adapter

Expand Down Expand Up @@ -114,7 +119,13 @@ recycler.setAdapter(myAdapter);

在这种情况下,需要使用者注意在当```LayoutHelpers```的结构或者数据数量等会影响到布局的元素变化时,需要主动调用```setLayoutHepers```去更新布局模式。

另外如果你的应用有混淆配置,请为vlayout添加一下防混淆配置:

```
-keepattributes InnerClasses
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx {
*;
```

# Demo

Expand All @@ -132,4 +143,4 @@ recycler.setAdapter(myAdapter);

# 开源许可证

vlayout遵循MIT开源许可证协议。
vlayout遵循MIT开源许可证协议。
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ recyclerView.setRecycledViewPool(viewPool);
viewPool.setMaxRecycledViews(0, 10);
```

**Attention: the demo code above only modify the recycle pool size of item with type = 0, it you has more than one type in your adapter, you should update recycle pool size for each type.**

### Set Adapters

* You can use `DelegateAdapter` for as a root adapter to make combination of your own adapters. Just make it extend ```DelegateAdapter.Adapter``` and overrides ```onCreateLayoutHelper``` method.

``` java
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasStableItemType);
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasConsistItemType);
recycler.setAdapter(delegateAdapter);

// Then you can set sub- adapters
Expand All @@ -85,6 +87,8 @@ adapter.notifyDataSetChanged();

```

**Attention: When `hasConsistItemType = true`, items with same type value in different sub-adapters share the same type, their view would be reused during scroll. When `hasConsistItemType = false`, items with same type value in different sub-adapters do not share the same type internally.**

* The other way to set adapter is extending ```VirtualLayoutAdapter``` and implementing it to make deep combination to your business code.

``` java
Expand Down Expand Up @@ -114,6 +118,16 @@ recycler.setAdapter(myAdapter);

In this way, one thing you should note is that you should call ```setLayoutHelpers``` when the data of Adapter changes.

### Config proguard

Add following configs in your proguard file if your app is released with proguard.

```
-keepattributes InnerClasses
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx {
*;
```

# Demo

![](http://img3.tbcdn.cn/L1/461/1/1b9bfb42009047f75cee08ae741505de2c74ac0a)
Expand All @@ -130,4 +144,4 @@ Before you open an issue or create a pull request, please read [Contributing Gui

# LICENSE

Vlayout is available under the MIT license.
Vlayout is available under the MIT license.
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
buildToolsVersion System.properties['buildToolsVersion']

defaultConfig {
applicationId "com.alibab.android.vlayout.example"
applicationId "com.alibaba.android.vlayout.example"
minSdkVersion 14
targetSdkVersion Integer.parseInt(System.properties['targetSdkVersion'])
versionCode 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@
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;
Expand Down Expand Up @@ -173,7 +176,6 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle

final List<DelegateAdapter.Adapter> adapters = new LinkedList<>();


if (BANNER_LAYOUT) {
adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

Expand Down Expand Up @@ -482,6 +484,30 @@ public void run() {


mainHandler.postDelayed(trigger, 1000);
setListenerToRootView();
}

boolean isOpened = false;

public void setListenerToRootView() {
final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {

int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
if (isOpened == false) {
//Do two things, make the view top visible and the editText smaller
}
isOpened = true;
} else if (isOpened == true) {
isOpened = false;
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
recyclerView.getAdapter().notifyDataSetChanged();
}
}
});
}

// RecyclableViewPager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ public class GridLayoutHelper extends BaseLayoutHelper {

private View[] mSet;

/**
* store index of each span
*/
private int[] mSpanIndices;

/**
* store size of each span when {@link #mWeights} is not empty
*/
private int[] mSpanCols;


Expand Down Expand Up @@ -126,7 +132,6 @@ public void setWeights(float[] weights) {
}
}


public void setSpanSizeLookup(SpanSizeLookup spanSizeLookup) {
if (spanSizeLookup != null) {
// TODO: handle reverse layout?
Expand Down Expand Up @@ -343,7 +348,8 @@ public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state
// we should assign spans before item decor offsets are calculated
assignSpans(recycler, state, count, consumedSpanCount, layingOutInPrimaryDirection, helper);

if (remainingSpan > 0 && mIsAutoExpand) {
if (remainingSpan > 0 && (count == consumedSpanCount) && mIsAutoExpand) {
//autoExpand only support when each cell occupy one span.
if (layoutInVertical) {
mSizePerSpan = (helper.getContentWidth() - helper.getPaddingRight() - getHorizontalMargin() - getHorizontalPadding() -
helper.getPaddingLeft() - (count - 1) * mHGap) / count;
Expand Down
Loading

0 comments on commit b53be73

Please sign in to comment.