Skip to content

Commit

Permalink
Optimize sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyge committed Nov 18, 2016
1 parent da12635 commit 04d2567
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 35 deletions.
Binary file modified sample/libs/assemblyadapter-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.xiaopan.sketchsample.adapter.itemfactory;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.TextView;

Expand All @@ -12,11 +10,6 @@
import me.xiaopan.sketchsample.adapter.BindAssemblyRecyclerItem;

public class ItemTitleItemFactory extends AssemblyRecyclerItemFactory<ItemTitleItemFactory.ItemTitleItem> {
private RecyclerView recyclerView;

public ItemTitleItemFactory(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
}

@Override
public boolean isTarget(Object o) {
Expand All @@ -28,20 +21,6 @@ public ItemTitleItem createAssemblyItem(ViewGroup viewGroup) {
return new ItemTitleItem(R.layout.list_item_title, viewGroup);
}

@Override
public int getSpanSize() {
if (recyclerView == null) {
return 1;
}
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager == null || !(layoutManager instanceof GridLayoutManager)) {
return 1;
}

GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
return gridLayoutManager.getSpanCount();
}

public class ItemTitleItem extends BindAssemblyRecyclerItem<String> {
@BindView(R.id.text_titleItem)
TextView textView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class StarHeaderItem extends BindAssemblyRecyclerItem<String> {

public StarHeaderItem(int itemLayoutId, ViewGroup parent) {
super(itemLayoutId, parent);
fullSpanInStaggeredGrid();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void run() {
adapter.addItemFactory(new HotStarThreeLeftItemFactory(HotStarFragment.this));
adapter.addItemFactory(new HotStarThreeRightItemFactory(HotStarFragment.this));
adapter.addItemFactory(new HotStarTwoItemFactory(HotStarFragment.this));
adapter.addItemFactory(new ItemTitleItemFactory(null));
adapter.addItemFactory(new ItemTitleItemFactory());
boolean result = false;
if (hotStarList.size() > 0 && hotStarList.get(0).getStarList().size() > 0) {
changeBackground(hotStarList.get(0).getStarList().get(0).getHeightImage().getUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class StarCatalogFragment extends MyFragment implements PullRefreshLayout
@InjectView(R.id.hint_starCatalog)
private HintView hintView;
@InjectView(R.id.recyclerView_starCatalog_content)
private RecyclerView contentRecyclerView;
private RecyclerView recyclerView;

private HttpRequestFuture httpRequestFuture;
private AssemblyRecyclerAdapter adapter;
Expand All @@ -70,19 +70,19 @@ public int getSpanSize(int position) {
return adapter != null ? adapter.getSpanSize(position) : 1;
}
});
contentRecyclerView.setLayoutManager(gridLayoutManager);
contentRecyclerView.setOnScrollListener(new ScrollingPauseLoadManager(view.getContext()));
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setOnScrollListener(new ScrollingPauseLoadManager(view.getContext()));
int padding = (int) getResources().getDimension(R.dimen.home_category_margin_border);
contentRecyclerView.setPadding(padding, padding, padding, padding);
contentRecyclerView.setClipToPadding(false);
recyclerView.setPadding(padding, padding, padding, padding);
recyclerView.setClipToPadding(false);

refreshLayout.setOnRefreshListener(this);

if (adapter == null) {
refreshLayout.startRefresh();
} else {
contentRecyclerView.setAdapter(adapter);
contentRecyclerView.scheduleLayoutAnimation();
recyclerView.setAdapter(adapter);
recyclerView.scheduleLayoutAnimation();
}
}

Expand Down Expand Up @@ -121,8 +121,8 @@ public void onStarted(HttpRequest httpRequest) {
public void onCompleted(HttpRequest httpRequest, HttpResponse httpResponse, StarCatalogRequest.Result result, boolean b, boolean b2) {
if (last) {
append(adapter, result);
contentRecyclerView.setAdapter(adapter);
contentRecyclerView.scheduleLayoutAnimation();
recyclerView.setAdapter(adapter);
recyclerView.scheduleLayoutAnimation();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Expand All @@ -133,7 +133,7 @@ public void run() {
adapter = new AssemblyRecyclerAdapter(new ArrayList());
append(adapter, result);
adapter.addItemFactory(new StarCatalogItemFactory(StarCatalogFragment.this));
adapter.addItemFactory(new ItemTitleItemFactory(contentRecyclerView));
adapter.addItemFactory(new ItemTitleItemFactory().fullSpan(recyclerView));
load(true, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ public void onCompleted(HttpRequest httpRequest, HttpResponse httpResponse, Star

AssemblyRecyclerAdapter adapter = new AssemblyRecyclerAdapter(responseObject.getImages());
if (backgroundImageUrl != null) {
adapter.addHeaderItem(new StarHeaderItemFactory(), backgroundImageUrl);
adapter.addHeaderItem(new StarHeaderItemFactory().fullSpan(recyclerView), backgroundImageUrl);
}
adapter.addItemFactory(new StaggeredImageItemFactory(StarHomeFragment.this));
adapter.setLoadMoreItem(new LoadMoreItemFactory(StarHomeFragment.this));
adapter.setLoadMoreItem(new LoadMoreItemFactory(StarHomeFragment.this).fullSpan(recyclerView));

setAdapter(adapter);

Expand Down

0 comments on commit 04d2567

Please sign in to comment.