Skip to content

Commit

Permalink
fix SGLM reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
codeestX committed Aug 25, 2016
1 parent ac018bf commit 788b0e2
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 27 deletions.
7 changes: 6 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public class GankItemBean {
private String url;
private boolean used;
private String who;
private int height;

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public String get_id() {
return _id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.codeest.geeknews.ui.gank.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.codeest.geeknews.R;
import com.codeest.geeknews.component.ImageLoader;
import com.codeest.geeknews.app.App;
import com.codeest.geeknews.model.bean.GankItemBean;

import java.util.ArrayList;
Expand Down Expand Up @@ -36,20 +41,47 @@ public GirlAdapter(Context mContext,List<GankItemBean> mList) {
mHeights = new ArrayList<>();
}

/**
* https://github.com/oxoooo/mr-mantou-android/blob/master/app/src/main/java/ooo/oxo/mr/MainAdapter.java
* 重写getItemViewType可以防止StaggeredGridLayoutManager快速滑动时重新排列的问题,原因目前未知
* @param position
* @return
*/
@Override
public int getItemViewType(int position) {
return Math.round((float) App.SCREEN_WIDTH / (float) mList.get(position).getHeight() * 10f);
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(inflater.inflate(R.layout.item_girl, parent, false));
}

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
if (mHeights.size() <= position) {
mHeights.add((int) (420 + Math.random() * 220));
//存在记录的高度时先Layout再异步加载图片
if (mList.get(holder.getAdapterPosition()).getHeight() > 0) {
ViewGroup.LayoutParams layoutParams = holder.ivGirl.getLayoutParams();
layoutParams.height = mList.get(holder.getAdapterPosition()).getHeight();
}
ViewGroup.LayoutParams lp = holder.ivGirl.getLayoutParams();
lp.height = mHeights.get(position);
holder.ivGirl.setLayoutParams(lp);
ImageLoader.load(mContext, mList.get(position).getUrl(),holder.ivGirl);

Glide.with(mContext).load(mList.get(position).getUrl()).asBitmap().placeholder(R.mipmap.bg_drawable).diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>(App.SCREEN_WIDTH / 2, App.SCREEN_WIDTH / 2) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
if(holder.getAdapterPosition() != RecyclerView.NO_POSITION) {
if (mList.get(holder.getAdapterPosition()).getHeight() <= 0) {
int width = resource.getWidth();
int height = resource.getHeight();
int realHeight = (App.SCREEN_WIDTH / 2) * height / width;
mList.get(holder.getAdapterPosition()).setHeight(realHeight);
ViewGroup.LayoutParams lp = holder.ivGirl.getLayoutParams();
lp.height = realHeight;
}
holder.ivGirl.setImageBitmap(resource);
}
}
});
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class GirlFragment extends BaseFragment<GirlPresenter> implements GirlCon

GirlAdapter mAdapter;
List<GankItemBean> mList;
StaggeredGridLayoutManager mStaggeredGridLayoutManager;

private boolean isLoadingMore = false;

Expand All @@ -56,8 +57,16 @@ protected int getLayoutId() {
protected void initEventAndData() {
mList = new ArrayList<>();
mAdapter = new GirlAdapter(mContext, mList);
rvGirlContent.setLayoutManager(new StaggeredGridLayoutManager(SPAN_COUNT,StaggeredGridLayoutManager.VERTICAL));
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(SPAN_COUNT,StaggeredGridLayoutManager.VERTICAL);
mStaggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
rvGirlContent.setLayoutManager(mStaggeredGridLayoutManager);
rvGirlContent.setAdapter(mAdapter);

// rvGirlContent.setHasFixedSize(true);
// rvGirlContent.setItemViewCacheSize(20);
// rvGirlContent.setDrawingCacheEnabled(true);
// rvGirlContent.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Expand All @@ -68,7 +77,7 @@ public void onRefresh() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int[] visibleItems = ((StaggeredGridLayoutManager)rvGirlContent.getLayoutManager()).findLastVisibleItemPositions(null);
int[] visibleItems = mStaggeredGridLayoutManager.findLastVisibleItemPositions(null);
int lastItem = Math.max(visibleItems[0],visibleItems[1]);
if (lastItem > mAdapter.getItemCount() - 5 && !isLoadingMore && dy > 0 ) {
isLoadingMore = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
package com.codeest.geeknews.ui.main.fragment;

import android.support.v7.widget.AppCompatCheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.codeest.geeknews.R;
import com.codeest.geeknews.base.SimpleFragment;

import butterknife.BindView;
import butterknife.OnClick;

/**
* Created by codeest on 16/8/23.
*/

public class SettingFragment extends SimpleFragment {
public class SettingFragment extends SimpleFragment implements CompoundButton.OnCheckedChangeListener{

@BindView(R.id.cb_setting_cache)
AppCompatCheckBox cbSettingCache;
@BindView(R.id.cb_setting_image)
AppCompatCheckBox cbSettingImage;
@BindView(R.id.cb_setting_night)
AppCompatCheckBox cbSettingNight;
@BindView(R.id.ll_setting_feedback)
LinearLayout llSettingFeedback;
@BindView(R.id.tv_setting_clear)
TextView tvSettingClear;
@BindView(R.id.ll_setting_clear)
LinearLayout llSettingClear;
@BindView(R.id.tv_setting_update)
TextView tvSettingUpdate;
@BindView(R.id.ll_setting_update)
LinearLayout llSettingUpdate;

@Override
protected int getLayoutId() {
Expand All @@ -16,7 +41,28 @@ protected int getLayoutId() {

@Override
protected void initEventAndData() {
cbSettingCache.setOnCheckedChangeListener(this);
cbSettingImage.setOnCheckedChangeListener(this);
cbSettingNight.setOnCheckedChangeListener(this);
}

@OnClick(R.id.ll_setting_feedback)
void doFeedBack() {

}

@OnClick(R.id.ll_setting_clear)
void doClear() {

}

@OnClick(R.id.ll_setting_update)
void doUpdate() {

}

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void showContent(ThemeListBean themeListBean) {
rvThemeList.setVisibility(View.VISIBLE);
mList.clear();
mList.addAll(themeListBean.getOthers());
mAdapter.notifyDataSetChanged();
}

@Override
Expand Down
Loading

0 comments on commit 788b0e2

Please sign in to comment.