-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chenli
committed
Dec 2, 2019
1 parent
95db0c0
commit 530a685
Showing
30 changed files
with
639 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,33 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
|
||
android { | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
compileSdkVersion 28 | ||
compileSdkVersion 29 | ||
defaultConfig { | ||
applicationId "com.cl.picure" | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
androidTestImplementation 'androidx.test:runner:1.2.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
|
||
implementation 'com.github.bumptech.glide:glide:4.9.0' | ||
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' | ||
|
||
implementation project(':picture_selector') | ||
|
||
|
||
implementation 'androidx.recyclerview:recyclerview:1.1.0' | ||
} |
147 changes: 147 additions & 0 deletions
147
app/src/main/java/com/cl/picure/GoodsMainFigureAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package com.cl.picure; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
|
||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.cl.picure.MainActivity.TAG_NEGATIVE; | ||
|
||
/** | ||
* 项目:hbtGit | ||
* 版权:蒲公英公司 版权所有 | ||
* 作者:Arry | ||
* 版本:1.0 | ||
* 创建日期:2019-11-08 | ||
* 描述: | ||
* 修订历史: | ||
*/ | ||
public class GoodsMainFigureAdapter extends RecyclerView.Adapter<GoodsMainFigureAdapter.SelectedPicViewHolder>{ | ||
|
||
private int maxImgCount; | ||
private Context mContext; | ||
private List<String> mData = new ArrayList<>(); | ||
|
||
private LayoutInflater mInflater; | ||
private OnRecyclerViewItemClickListener listener; | ||
private boolean isAdded; //是否额外添加了最后一个图片 | ||
|
||
public interface OnRecyclerViewItemClickListener { | ||
void onItemClick(View view, int position); | ||
} | ||
|
||
public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) { | ||
this.listener = listener; | ||
} | ||
|
||
public void setImages(List<String> data) { | ||
mData = new ArrayList<>(data); | ||
if (getItemCount() < maxImgCount) { | ||
mData.add(new String()); | ||
isAdded = true; | ||
} else { | ||
isAdded = false; | ||
} | ||
notifyDataSetChanged(); | ||
} | ||
|
||
public List<String> getImages() { | ||
//由于图片未选满时,最后一张显示添加图片,因此这个方法返回真正的已选图片 | ||
if (isAdded) return new ArrayList<>(mData.subList(0, mData.size() - 1)); | ||
else return mData; | ||
} | ||
|
||
public GoodsMainFigureAdapter(Context mContext, List<String> data, int maxImgCount) { | ||
this.mContext = mContext; | ||
this.maxImgCount = maxImgCount; | ||
this.mInflater = LayoutInflater.from(mContext); | ||
setImages(data); | ||
} | ||
|
||
@Override | ||
public SelectedPicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new SelectedPicViewHolder(mInflater.inflate(R.layout.item_list_image, parent, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(SelectedPicViewHolder holder, int position) { | ||
holder.bind(position); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mData.size(); | ||
} | ||
|
||
public class SelectedPicViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
|
||
private final ImageView mIvDelete; | ||
private ImageView iv_img; | ||
private int clickPosition; | ||
|
||
public SelectedPicViewHolder(View itemView) { | ||
super(itemView); | ||
iv_img = (ImageView) itemView.findViewById(R.id.iv_img); | ||
mIvDelete = (ImageView) itemView.findViewById(R.id.iv_delete); | ||
} | ||
|
||
public void bind(final int position) { | ||
//设置条目的点击事件 | ||
itemView.setOnClickListener(this); | ||
//根据条目位置设置图片 | ||
String item = mData.get(position); | ||
if (isAdded && position == getItemCount() - 1) { | ||
iv_img.setImageResource(R.mipmap.ic_add_pic); | ||
clickPosition = TAG_NEGATIVE; | ||
mIvDelete.setVisibility(View.GONE); | ||
} else { | ||
Glide.with(mContext).load(item).into(iv_img); | ||
clickPosition = position; | ||
mIvDelete.setVisibility(View.VISIBLE); | ||
} | ||
mIvDelete.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
// if(mData!=null){ | ||
// remove(position); | ||
// } | ||
if (onImage != null) { | ||
onImage.OnItemImg(position); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
if (listener != null) listener.onItemClick(v, clickPosition); | ||
} | ||
} | ||
|
||
public void remove(int position) { | ||
mData.remove(position); | ||
notifyItemRemoved(position); | ||
} | ||
|
||
/** | ||
* 监听器 | ||
*/ | ||
public interface OnImage { | ||
public void OnItemImg(int position); | ||
} | ||
|
||
public OnImage onImage; | ||
|
||
public void setOnImage(OnImage onImage) { | ||
this.onImage = onImage; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.