1
This commit is contained in:
@@ -20,7 +20,7 @@ import entity.DiscoveryListEntity;
|
||||
|
||||
|
||||
public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends RecyclerView.Adapter<BaseRecycleViewAdapter.BaseViewHolder> {
|
||||
private ArrayList<T1> list;
|
||||
private ArrayList<T1> list=new ArrayList<>();
|
||||
private LayoutInflater inflater;
|
||||
private Context context;
|
||||
private AdapterView.OnItemClickListener itemClickListener;
|
||||
@@ -41,7 +41,6 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
|
||||
public void setData(ArrayList<T1> list) {
|
||||
this.list.clear();
|
||||
this.list = new ArrayList<>();
|
||||
this.list.addAll(list);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
private String mParam2;
|
||||
BaseActivity baseActivity;
|
||||
private ProgressDialog progressDialog;
|
||||
private ArrayList<DiscoveryListEntity> discoveryListEntities;
|
||||
private ArrayList<DiscoveryListEntity> discoveryListEntities = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -485,7 +485,7 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
|
||||
Log.e("pic", discoveryListEntity.getPic().get(0));
|
||||
for (int i = 0; i < discoveryListEntity.getPic().size(); i++) {
|
||||
if (discoveryListEntity.getPic().get(i).endsWith(".mp4")) {
|
||||
if (discoveryListEntity.getPic().get(i).endsWith(".mp4") || discoveryListEntity.getPic().get(i).endsWith(".avi")) {
|
||||
ImageInfo imageInfo = new ImageInfo();
|
||||
imageInfo.setType(2);
|
||||
imageInfo.setBigImageUrl(discoveryListEntity.getPic().get(i));
|
||||
@@ -501,7 +501,7 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
} else {
|
||||
ImageInfo imageInfo = new ImageInfo();
|
||||
imageInfo.setType(1);
|
||||
imageInfo.setBigImageUrl(discoveryListEntity.getThumb());
|
||||
@@ -520,7 +520,10 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
private void getGankList(String myurl, Map<String, String> map, String msg, final int requstecode) {
|
||||
progressDialog.setMessage(msg);
|
||||
progressDialog.setCancelable(false);
|
||||
// progressDialog.show();
|
||||
// if (page>1){
|
||||
// progressDialog.show();
|
||||
// }
|
||||
|
||||
|
||||
mGankLoader = new Loader();
|
||||
Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
||||
@@ -536,7 +539,7 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
baseActivity.setToast(1, resultcode.msg);
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
intRecycleView();
|
||||
// intRecycleView();
|
||||
Gson gs = new Gson();
|
||||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
@@ -555,7 +558,9 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
.placeholder(R.mipmap.icon_default_rectangle)
|
||||
.transform(new PicassoRoundTransform())
|
||||
.into(mDataBinding.head);
|
||||
discoveryListEntities = new Gson().fromJson(array.toString(), type);
|
||||
ArrayList<DiscoveryListEntity> o = new Gson().fromJson(array.toString(), type);
|
||||
discoveryListEntities.clear();
|
||||
discoveryListEntities.addAll(o);
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||||
page++;
|
||||
@@ -565,10 +570,12 @@ public class DiscoveryFragment extends BaseFragment<FragmentDiscoveryBinding> im
|
||||
|
||||
BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter();
|
||||
baseRecycleViewAdapter.setData(discoveryListEntities);
|
||||
int count = jsonObject.getInt("count");
|
||||
if (discoveryListEntities.size() == count || o.isEmpty()) {
|
||||
Log.e("sizi", discoveryListEntities.size() + "");
|
||||
// int count = jsonObject.getInt("count");
|
||||
if (o.isEmpty()) {
|
||||
mDataBinding.dw.finishLoadMoreWithNoMoreData();
|
||||
} else {
|
||||
|
||||
page++;
|
||||
|
||||
}
|
||||
|
||||
@@ -54,8 +54,12 @@
|
||||
android:layout_weight="1"
|
||||
android:background="@color/white"
|
||||
app:srlEnableLoadMore="true"
|
||||
app:srlEnableLoadMoreWhenContentNotFull="true">
|
||||
app:srlDisableContentWhenLoading="true"
|
||||
|
||||
>
|
||||
<com.scwang.smartrefresh.layout.header.ClassicsHeader
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<ScrollView
|
||||
android:id="@+id/sv"
|
||||
android:layout_width="match_parent"
|
||||
@@ -105,6 +109,9 @@
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.lzy.ninegrid;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -11,7 +14,7 @@ import java.io.Serializable;
|
||||
* 修订历史:
|
||||
* ================================================
|
||||
*/
|
||||
public class ImageInfo implements Serializable {
|
||||
public class ImageInfo implements Serializable, Parcelable {
|
||||
public String thumbnailUrl;
|
||||
public String bigImageUrl;
|
||||
public int imageViewHeight;
|
||||
@@ -19,6 +22,7 @@ public class ImageInfo implements Serializable {
|
||||
public int imageViewX;
|
||||
public int imageViewY;
|
||||
public int type;
|
||||
public String videoUrl;
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
@@ -86,6 +90,50 @@ public class ImageInfo implements Serializable {
|
||||
", imageViewX=" + imageViewX +
|
||||
", imageViewY=" + imageViewY +
|
||||
", type=" + type +
|
||||
", videoUrl='" + videoUrl + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(this.thumbnailUrl);
|
||||
dest.writeString(this.bigImageUrl);
|
||||
dest.writeInt(this.imageViewHeight);
|
||||
dest.writeInt(this.imageViewWidth);
|
||||
dest.writeInt(this.imageViewX);
|
||||
dest.writeInt(this.imageViewY);
|
||||
dest.writeInt(this.type);
|
||||
dest.writeString(this.videoUrl);
|
||||
}
|
||||
|
||||
public ImageInfo() {
|
||||
}
|
||||
|
||||
protected ImageInfo(Parcel in) {
|
||||
this.thumbnailUrl = in.readString();
|
||||
this.bigImageUrl = in.readString();
|
||||
this.imageViewHeight = in.readInt();
|
||||
this.imageViewWidth = in.readInt();
|
||||
this.imageViewX = in.readInt();
|
||||
this.imageViewY = in.readInt();
|
||||
this.type = in.readInt();
|
||||
this.videoUrl = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<ImageInfo> CREATOR = new Creator<ImageInfo>() {
|
||||
@Override
|
||||
public ImageInfo createFromParcel(Parcel source) {
|
||||
return new ImageInfo(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageInfo[] newArray(int size) {
|
||||
return new ImageInfo[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -32,7 +33,7 @@ public class NineGridView extends ViewGroup {
|
||||
private int gridWidth; // 宫格宽度
|
||||
private int gridHeight; // 宫格高度
|
||||
|
||||
private List<ImageView> imageViews;
|
||||
private List<NineGridViewWrapper> imageViews;
|
||||
private List<ImageInfo> mImageInfo;
|
||||
private NineGridViewAdapter mAdapter;
|
||||
|
||||
@@ -94,7 +95,7 @@ public class NineGridView extends ViewGroup {
|
||||
if (mImageInfo == null) return;
|
||||
int childrenCount = mImageInfo.size();
|
||||
for (int i = 0; i < childrenCount; i++) {
|
||||
ImageView childrenView = (ImageView) getChildAt(i);
|
||||
NineGridViewWrapper childrenView = (NineGridViewWrapper) getChildAt(i);
|
||||
|
||||
int rowNum = i / columnCount;
|
||||
int columnNum = i % columnCount;
|
||||
@@ -105,12 +106,15 @@ public class NineGridView extends ViewGroup {
|
||||
childrenView.layout(left, top, right, bottom);
|
||||
|
||||
if (mImageLoader != null) {
|
||||
childrenView.setType(mImageInfo.get(i).type);
|
||||
mImageLoader.onDisplayImage(getContext(), childrenView, mImageInfo.get(i).thumbnailUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置适配器 */
|
||||
/**
|
||||
* 设置适配器
|
||||
*/
|
||||
public void setAdapter(@NonNull NineGridViewAdapter adapter) {
|
||||
mAdapter = adapter;
|
||||
List<ImageInfo> imageInfo = adapter.getImageInfo();
|
||||
@@ -160,24 +164,27 @@ public class NineGridView extends ViewGroup {
|
||||
}
|
||||
}
|
||||
//修改最后一个条目,决定是否显示更多
|
||||
if (adapter.getImageInfo().size() > maxImageSize) {
|
||||
View child = getChildAt(maxImageSize - 1);
|
||||
if (child instanceof NineGridViewWrapper) {
|
||||
NineGridViewWrapper imageView = (NineGridViewWrapper) child;
|
||||
imageView.setMoreNum(adapter.getImageInfo().size() - maxImageSize);
|
||||
}
|
||||
}
|
||||
// if (adapter.getImageInfo().size() > maxImageSize) {
|
||||
// View child = getChildAt(maxImageSize - 1);
|
||||
// if (child instanceof NineGridViewWrapper) {
|
||||
// NineGridViewWrapper imageView = (NineGridViewWrapper) child;
|
||||
// imageView.setMoreNum(adapter.getImageInfo().size() - maxImageSize);
|
||||
// }
|
||||
// }
|
||||
|
||||
mImageInfo = imageInfo;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
/** 获得 ImageView 保证了 ImageView 的重用 */
|
||||
private ImageView getImageView(final int position) {
|
||||
ImageView imageView;
|
||||
/**
|
||||
* 获得 ImageView 保证了 ImageView 的重用
|
||||
*/
|
||||
private NineGridViewWrapper getImageView(final int position) {
|
||||
NineGridViewWrapper imageView;
|
||||
if (position < imageViews.size()) {
|
||||
imageView = imageViews.get(position);
|
||||
} else {
|
||||
imageView = mAdapter.generateImageView(getContext());
|
||||
imageView = mAdapter.generateImageView(getContext(), mAdapter.getImageInfo().get(position).getType());
|
||||
imageView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -189,22 +196,30 @@ public class NineGridView extends ViewGroup {
|
||||
return imageView;
|
||||
}
|
||||
|
||||
/** 设置宫格间距 */
|
||||
/**
|
||||
* 设置宫格间距
|
||||
*/
|
||||
public void setGridSpacing(int spacing) {
|
||||
gridSpacing = spacing;
|
||||
}
|
||||
|
||||
/** 设置只有一张图片时的宽 */
|
||||
/**
|
||||
* 设置只有一张图片时的宽
|
||||
*/
|
||||
public void setSingleImageSize(int maxImageSize) {
|
||||
singleImageSize = maxImageSize;
|
||||
}
|
||||
|
||||
/** 设置只有一张图片时的宽高比 */
|
||||
/**
|
||||
* 设置只有一张图片时的宽高比
|
||||
*/
|
||||
public void setSingleImageRatio(float ratio) {
|
||||
singleImageRatio = ratio;
|
||||
}
|
||||
|
||||
/** 设置最大图片数 */
|
||||
/**
|
||||
* 设置最大图片数
|
||||
*/
|
||||
public void setMaxSize(int maxSize) {
|
||||
maxImageSize = maxSize;
|
||||
}
|
||||
|
||||
@@ -32,11 +32,13 @@ public abstract class NineGridViewAdapter implements Serializable {
|
||||
* 如果需要自定义图片展示效果,重写此方法即可
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param type
|
||||
* @return 生成的 ImageView
|
||||
*/
|
||||
protected ImageView generateImageView(Context context) {
|
||||
protected NineGridViewWrapper generateImageView(Context context, int type) {
|
||||
NineGridViewWrapper imageView = new NineGridViewWrapper(context);
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
imageView.setType(type);
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
imageView.setImageResource(R.drawable.ic_default_color);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.lzy.ninegrid;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
@@ -13,6 +15,7 @@ import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.ImageView;
|
||||
|
||||
|
||||
public class NineGridViewWrapper extends ImageView {
|
||||
|
||||
private int moreNum = 0; //显示更多的数量
|
||||
@@ -21,7 +24,8 @@ public class NineGridViewWrapper extends ImageView {
|
||||
private int textColor = 0xFFFFFFFF; //显示文字的颜色
|
||||
|
||||
private TextPaint textPaint; //文字的画笔
|
||||
private String msg = ""; //要绘制的文字
|
||||
private String msg = "哈哈哈啊"; //要绘制的文字
|
||||
private int mType;
|
||||
|
||||
public NineGridViewWrapper(Context context) {
|
||||
this(context, null);
|
||||
@@ -44,14 +48,28 @@ public class NineGridViewWrapper extends ImageView {
|
||||
textPaint.setColor(textColor); //设置文字颜色
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
mType = type;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (moreNum > 0) {
|
||||
canvas.drawColor(maskColor);
|
||||
float baseY = getHeight() / 2 - (textPaint.ascent() + textPaint.descent()) / 2;
|
||||
canvas.drawText(msg, getWidth() / 2, baseY, textPaint);
|
||||
}
|
||||
if (mType == 2) {
|
||||
// canvas.drawColor(maskColor);
|
||||
// float baseY = getHeight() / 2 - (textPaint.ascent() + textPaint.descent()) / 2;
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_image);
|
||||
canvas.translate(getWidth() / 2, getHeight() / 2);
|
||||
canvas.drawBitmap(bitmap, -50, -50, null);
|
||||
}
|
||||
// if (mType == 2) {
|
||||
// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.phone);
|
||||
// // canvas.translate(getWidth() / 2, getHeight() / 2);
|
||||
// canvas.drawBitmap(bitmap, 0, 0, null);
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
BIN
ninegridview/src/main/res/drawable/icon_image.png
Normal file
BIN
ninegridview/src/main/res/drawable/icon_image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Reference in New Issue
Block a user