Skip to content

Commit

Permalink
修改空格图片上传view
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwfqin committed Jul 30, 2020
1 parent cffa3d4 commit 702f770
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
# 导入指南
``` groovy
def quicklib = "4.2.0"
def quicklib = "4.4.0"
// quicklib(Base)
implementation "com.sdwfqin.quicklib:quicklib:$quicklib"
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/sdwfqin/quickseed/model/PictureModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import android.net.Uri;

import com.sdwfqin.widget.pictureupload.PictureUpModel;
import com.sdwfqin.widget.pictureupload.PictureUploadModel;

/**
* 描述:
*
* @author zhangqin
* @date 2018/5/31
* @date 2018/5/3,1
*/
public class PictureModel extends PictureUpModel {
public class PictureModel implements PictureUploadModel {

private Uri imgPath;

public PictureModel(Uri imgPath) {
super(imgPath);
this.imgPath = imgPath;
}

Expand All @@ -31,7 +30,12 @@ public void setImgPath(Uri imgPath) {
public String toString() {
return "PictureModel{" +
"imgPath='" + imgPath + '\'' +
", image=" + image +
", image=" + imgPath +
'}';
}

@Override
public Object getPictureImage() {
return imgPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class PictureUploadActivity extends SampleBaseActivity<ActivityPictureUpl

public static final int RESULT_PHOTO_SELECT = 101;

// PictureUploadView<PictureModel> mPic;

@Override
protected ActivityPictureUploadBinding getViewBinding() {
return ActivityPictureUploadBinding.inflate(getLayoutInflater());
Expand All @@ -39,9 +37,8 @@ protected void initEventAndData() {
mTopBar.addLeftBackImageButton()
.setOnClickListener(v -> finish());

// mPic = mBinding.pic;

mBinding.pic.setMaxColumn(3);
mBinding.pic.setMaxSize(12);
mBinding.pic.setPicUploadCallback(new PictureUploadCallback<PictureModel>() {
@Override
public void click(int position, PictureModel pictureModel, List<PictureModel> list) {
Expand Down Expand Up @@ -76,7 +73,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
for (int i = 0; i < selectList.size(); i++) {
models.add(new PictureModel(selectList.get(i)));
}
mBinding.pic.setAddData(models);
mBinding.pic.addData(models);

// 刷新相册图片
if (selectList.size() == 1) {
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {

versionCode = 202007231
versionName = "4.3.0"
versionCode = 202007301
versionName = "4.4.0"

qmui = "2.0.0-alpha10"
okhttp = "4.7.2"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author zhangqin
* @date 2018/5/31
*/
public class PictureUploadAdapter<T extends PictureUpModel> extends BaseQuickAdapter<T, BaseViewHolder> {
public class PictureUploadAdapter<T extends PictureUploadModel> extends BaseQuickAdapter<T, BaseViewHolder> {

public PictureUploadAdapter(int layoutResId, @Nullable List<T> data) {
super(layoutResId, data);
Expand All @@ -30,7 +30,7 @@ protected void convert(BaseViewHolder helper, T item) {

if (item != null) {
ImageLoader imageLoader = new ImageLoader.Builder()
.setImagePath(item.getImage())
.setImagePath(item.getPictureImage())
.setPlaceholder(R.mipmap.image_loading)
.setErrorImage(R.mipmap.image_load_err)
.build(iiImg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author zhangqin
* @date 2018/5/31
*/
public interface PictureUploadCallback<T extends PictureUpModel> {
public interface PictureUploadCallback<T extends PictureUploadModel> {

/**
* 移除某个图片
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sdwfqin.widget.pictureupload;

/**
* 描述:
*
* @author zhangqin
* @date 2018/5/31
*/
public interface PictureUploadModel {

/**
* 获取图像文件
*/
Object getPictureImage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.FrameLayout;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.LogUtils;
import com.sdwfqin.widget.R;

import java.util.ArrayList;
Expand All @@ -25,7 +24,7 @@
* @author zhangqin
* @date 2018/5/31
*/
public class PictureUploadView<T extends PictureUpModel> extends RelativeLayout {
public class PictureUploadView<T extends PictureUploadModel> extends FrameLayout {

private Context mContext;

Expand Down Expand Up @@ -61,6 +60,7 @@ public PictureUploadView(Context context, @Nullable AttributeSet attrs) {
mContext = context;
LayoutInflater.from(context).inflate(R.layout.quick_picture_upload_view, this);
mRecyclerView = findViewById(R.id.rv);
mRecyclerView.setNestedScrollingEnabled(false);

mDataList.add(null);
initList();
Expand Down Expand Up @@ -110,12 +110,11 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle

} else if (i == R.id.ii_del) {
if (mDataList.size() == mMaxSize && mDataList.get(mDataList.size() - 1) != null) {
mUploadAdapter.remove(position);
mUploadAdapter.removeAt(position);
mDataList.add(null);
mUploadAdapter.setNewData(mDataList);
mUploadAdapter.setList(mDataList);
} else {
mUploadAdapter.remove(position);
mUploadAdapter.notifyDataSetChanged();
mUploadAdapter.removeAt(position);
}
if (mCallback == null) {
return;
Expand Down Expand Up @@ -165,20 +164,28 @@ public List<T> getData() {
*/
public void setNewData(List<T> data) {
mDataList.clear();
mDataList = data == null ? new ArrayList<>() : data;
int size = mDataList.size();
if (size < mMaxSize && mDataList.get(size - 1) != null) {
// 如果数量小于最大值,添加一个null作为占位符
mDataList.add(null);
}
mDataList = data;
mUploadAdapter.notifyDataSetChanged();
// mUploadAdapter.setNewData(mDataList);
mUploadAdapter.setList(mDataList);
}

/**
* 添加图片
*/
public void setAddData(List<T> data) {
public void addData(T data) {
List<T> list = new ArrayList<>();
list.add(data);
addData(list);
}

/**
* 添加图片
*/
public void addData(List<T> data) {
int size = mDataList.size();
if (size <= mMaxSize && mDataList.get(size - 1) == null) {
mDataList.remove(mDataList.size() - 1);
Expand All @@ -188,17 +195,14 @@ public void setAddData(List<T> data) {
// 如果数量小于最大值,添加一个null作为占位符
mDataList.add(null);
}
LogUtils.e(mDataList);
// fixme brvah3
mUploadAdapter.notifyDataSetChanged();
// mUploadAdapter.setNewData(mDataList);
mUploadAdapter.setList(mDataList);
}

/**
* 移除全部图片
*/
public void removeAll() {
mUploadAdapter.setNewData(null);
mUploadAdapter.setList(null);
mDataList.clear();
}

Expand Down

0 comments on commit 702f770

Please sign in to comment.