Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: 视频选择和图片选择不再共用一个字段 #1241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/src/main/java/com/luck/pictureselector/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,10 @@ public void onAddPicClick() {
.setPictureCropStyle(mCropParameterStyle)// 动态自定义裁剪主题
.setPictureWindowAnimationStyle(mWindowAnimationStyle)// 自定义相册启动退出动画
.isWithVideoImage(true)// 图片和视频是否可以同选,只在ofAll模式下有效
.maxSelectNum(maxSelectNum)// 最大图片选择数量
.minSelectNum(1)// 最小选择数量
.maxVideoSelectNum(1) // 视频最大选择数量,如果没有单独设置的需求则可以不设置,同用maxSelectNum字段
.maxSelectNum(maxSelectNum)// 最大选择数量
.maxPictureSelectNum(maxSelectNum)// 最大图片选择数量
.minPictureSelectNum(1)// 最小图片选择数量
.maxVideoSelectNum(maxSelectNum) // 视频最大选择数量,如果没有单独设置的需求则可以不设置
//.minVideoSelectNum(1)// 视频最小选择数量,如果没有单独设置的需求则可以不设置,同用minSelectNum字段
.imageSpanCount(4)// 每行显示个数
.isReturnEmpty(false)// 未选择数据时点击按钮是否可以返回
Expand Down Expand Up @@ -518,9 +519,9 @@ public void onCancel() {
.setPictureStyle(mPictureParameterStyle)// 动态自定义相册主题
.setPictureCropStyle(mCropParameterStyle)// 动态自定义裁剪主题
.setPictureWindowAnimationStyle(mWindowAnimationStyle)// 自定义相册启动退出动画
.maxSelectNum(maxSelectNum)// 最大图片选择数量
.maxPictureSelectNum(maxSelectNum)// 最大图片选择数量
.isUseCustomCamera(cb_custom_camera.isChecked())// 是否使用自定义相机
.minSelectNum(1)// 最小选择数量
.minPictureSelectNum(1)// 最小选择数量
//.querySpecifiedFormatSuffix(PictureMimeType.ofPNG())// 查询指定后缀格式资源
.selectionMode(cb_choose_mode.isChecked() ?
PictureConfig.MULTIPLE : PictureConfig.SINGLE)// 多选 or 单选
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/luck/pictureselector/PhotoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ public void onAddPicClick() {
.setPictureCropStyle(mCropParameterStyle)// 动态自定义裁剪主题
.setPictureWindowAnimationStyle(mWindowAnimationStyle)// 自定义相册启动退出动画
.isWithVideoImage(true)// 图片和视频是否可以同选
.maxSelectNum(maxSelectNum)// 最大图片选择数量
//.minSelectNum(1)// 最小选择数量
.maxPictureSelectNum(maxSelectNum)// 最大图片选择数量
//.minPictureSelectNum(1)// 最小选择数量
//.minVideoSelectNum(1)// 视频最小选择数量,如果没有单独设置的需求则可以不设置,同用minSelectNum字段
.maxVideoSelectNum(1) // 视频最大选择数量,如果没有单独设置的需求则可以不设置,同用maxSelectNum字段
.imageSpanCount(4)// 每行显示个数
Expand Down Expand Up @@ -515,8 +515,8 @@ public void onCancel() {
.setPictureStyle(mPictureParameterStyle)// 动态自定义相册主题
.setPictureCropStyle(mCropParameterStyle)// 动态自定义裁剪主题
.setPictureWindowAnimationStyle(mWindowAnimationStyle)// 自定义相册启动退出动画
.maxSelectNum(maxSelectNum)// 最大图片选择数量
.minSelectNum(1)// 最小选择数量
.maxPictureSelectNum(maxSelectNum)// 最大图片选择数量
.minPictureSelectNum(1)// 最小选择数量
.isUseCustomCamera(cb_custom_camera.isChecked())// 是否使用自定义相机
//.querySpecifiedFormatSuffix(PictureMimeType.ofPNG())// 查询指定后缀格式资源
.selectionMode(cb_choose_mode.isChecked() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ protected void initCompleteText(int startCount) {
// 未选择任何图片
mTvPictureOk.setText(isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureUnCompleteText)
? config.style.pictureUnCompleteText : getString(R.string.picture_done_front_num,
startCount, config.maxVideoSelectNum + config.maxSelectNum));
startCount, config.maxVideoSelectNum + config.maxPictureSelectNum));
} else {
// 已选择
if (isCompleteReplaceNum && isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureCompleteText)) {
mTvPictureOk.setText(String.format(config.style.pictureCompleteText, startCount, config.maxVideoSelectNum + config.maxSelectNum));
mTvPictureOk.setText(String.format(config.style.pictureCompleteText, startCount, config.maxVideoSelectNum + config.maxPictureSelectNum));
} else {
mTvPictureOk.setText(getString(R.string.picture_done_front_num,
startCount, config.maxVideoSelectNum + config.maxSelectNum));
startCount, config.maxVideoSelectNum + config.maxPictureSelectNum));
}
}
}
Expand Down Expand Up @@ -496,8 +496,8 @@ protected void onCheckedComplete() {
return;
}
}
if (PictureMimeType.eqImage(image.getMimeType()) && imageSize >= config.maxSelectNum && !check.isSelected()) {
ToastUtils.s(getContext(), StringUtils.getMsg(getContext(), image.getMimeType(), config.maxSelectNum));
if (PictureMimeType.eqImage(image.getMimeType()) && imageSize >= config.maxPictureSelectNum && !check.isSelected()) {
ToastUtils.s(getContext(), StringUtils.getMsg(getContext(), image.getMimeType(), config.maxPictureSelectNum));
return;
}
} else {
Expand Down Expand Up @@ -530,8 +530,8 @@ protected void onCheckedComplete() {
return;
}
} else {
if (currentSize >= config.maxSelectNum && !check.isSelected()) {
ToastUtils.s(getContext(), StringUtils.getMsg(getContext(), mimeType, config.maxSelectNum));
if (currentSize >= config.maxPictureSelectNum && !check.isSelected()) {
ToastUtils.s(getContext(), StringUtils.getMsg(getContext(), mimeType, config.maxPictureSelectNum));
return;
}
if (PictureMimeType.eqVideo(image.getMimeType())) {
Expand Down Expand Up @@ -623,9 +623,9 @@ protected void onComplete() {
}
}
if (config.selectionMode == PictureConfig.MULTIPLE) {
if (config.minSelectNum > 0) {
if (imageSize < config.minSelectNum) {
ToastUtils.s(getContext(), getString(R.string.picture_min_img_num, config.minSelectNum));
if (config.minPictureSelectNum > 0) {
if (imageSize < config.minPictureSelectNum) {
ToastUtils.s(getContext(), getString(R.string.picture_min_img_num, config.minPictureSelectNum));
return;
}
}
Expand All @@ -639,8 +639,8 @@ protected void onComplete() {
} else {
// 单选模式(同类型)
if (config.selectionMode == PictureConfig.MULTIPLE) {
if (PictureMimeType.eqImage(mimeType) && config.minSelectNum > 0 && size < config.minSelectNum) {
String str = getString(R.string.picture_min_img_num, config.minSelectNum);
if (PictureMimeType.eqImage(mimeType) && config.minPictureSelectNum > 0 && size < config.minPictureSelectNum) {
String str = getString(R.string.picture_min_img_num, config.minPictureSelectNum);
ToastUtils.s(getContext(), str);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public PictureSelectionModel isWithVideoImage(boolean isWithVideoImage) {
}

/**
* @param maxSelectNum PictureSelector max selection
* @param maxSelectNum Selector max selection
* @return
*/
public PictureSelectionModel maxSelectNum(int maxSelectNum) {
Expand All @@ -298,14 +298,32 @@ public PictureSelectionModel maxSelectNum(int maxSelectNum) {
}

/**
* @param minSelectNum PictureSelector min selection
* @param minSelectNum Selector min selection
* @return
*/
public PictureSelectionModel minSelectNum(int minSelectNum) {
selectionConfig.minSelectNum = minSelectNum;
return this;
}

/**
* @param maxSelectNum PictureSelector max selection
* @return
*/
public PictureSelectionModel maxPictureSelectNum(int maxSelectNum) {
selectionConfig.maxPictureSelectNum = maxSelectNum;
return this;
}

/**
* @param minSelectNum PictureSelector min selection
* @return
*/
public PictureSelectionModel minPictureSelectNum(int minSelectNum) {
selectionConfig.minPictureSelectNum = minSelectNum;
return this;
}

/**
* @param maxVideoSelectNum PictureSelector video max selection
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@ protected void initCompleteText(int startCount) {
// 未选择任何图片
mTvPictureOk.setText(isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureUnCompleteText)
? config.style.pictureUnCompleteText : getString(R.string.picture_done_front_num,
startCount, config.maxVideoSelectNum + config.maxSelectNum));
startCount, config.maxVideoSelectNum + config.maxPictureSelectNum));
} else {
// 已选择
if (isCompleteReplaceNum && isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureCompleteText)) {
mTvPictureOk.setText(String.format(config.style.pictureCompleteText, startCount, config.maxVideoSelectNum + config.maxSelectNum));
mTvPictureOk.setText(String.format(config.style.pictureCompleteText, startCount, config.maxVideoSelectNum + config.maxPictureSelectNum));
} else {
mTvPictureOk.setText(getString(R.string.picture_done_front_num,
startCount, config.maxVideoSelectNum + config.maxSelectNum));
startCount, config.maxVideoSelectNum + config.maxPictureSelectNum));
}
}
}
Expand Down Expand Up @@ -580,9 +580,9 @@ private void onComplete() {
}
}
if (config.selectionMode == PictureConfig.MULTIPLE) {
if (config.minSelectNum > 0) {
if (imageSize < config.minSelectNum) {
ToastUtils.s(getContext(), getString(R.string.picture_min_img_num, config.minSelectNum));
if (config.minPictureSelectNum > 0) {
if (imageSize < config.minPictureSelectNum) {
ToastUtils.s(getContext(), getString(R.string.picture_min_img_num, config.minPictureSelectNum));
return;
}
}
Expand All @@ -595,8 +595,8 @@ private void onComplete() {
}
} else {
if (config.selectionMode == PictureConfig.MULTIPLE) {
if (PictureMimeType.eqImage(mimeType) && config.minSelectNum > 0 && size < config.minSelectNum) {
String str = getString(R.string.picture_min_img_num, config.minSelectNum);
if (PictureMimeType.eqImage(mimeType) && config.minPictureSelectNum > 0 && size < config.minPictureSelectNum) {
String str = getString(R.string.picture_min_img_num, config.minPictureSelectNum);
ToastUtils.s(getContext(), str);
return;
}
Expand All @@ -611,8 +611,8 @@ private void onComplete() {
// 如果没选并且设置了可以空返回则直接回到结果页
if (config.returnEmpty && size == 0) {
if (config.selectionMode == PictureConfig.MULTIPLE) {
if (config.minSelectNum > 0 && size < config.minSelectNum) {
String str = getString(R.string.picture_min_img_num, config.minSelectNum);
if (config.minPictureSelectNum > 0 && size < config.minPictureSelectNum) {
String str = getString(R.string.picture_min_img_num, config.minPictureSelectNum);
ToastUtils.s(getContext(), str);
return;
}
Expand Down Expand Up @@ -1375,12 +1375,12 @@ private void requestCamera(Intent data) {
}
} else {
// 图片还可选
if (imageSize < config.maxSelectNum) {
if (imageSize < config.maxPictureSelectNum) {
selectedImages.add(media);
mAdapter.bindSelectImages(selectedImages);
} else {
ToastUtils.s(getContext(), StringUtils.getMsg(getContext(), media.getMimeType(),
config.maxSelectNum));
config.maxPictureSelectNum));
}
}

Expand All @@ -1400,17 +1400,17 @@ private void requestCamera(Intent data) {
}
} else {
// 没有到最大选择量 才做默认选中刚拍好的
if (count < config.maxSelectNum) {
if (count < config.maxPictureSelectNum) {
// 类型相同或还没有选中才加进选中集合中
if (mimeTypeSame || count == 0) {
if (count < config.maxSelectNum) {
if (count < config.maxPictureSelectNum) {
selectedImages.add(media);
mAdapter.bindSelectImages(selectedImages);
}
}
} else {
ToastUtils.s(getContext(), StringUtils.getMsg(getContext(), mimeType,
config.maxSelectNum));
config.maxPictureSelectNum));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ protected void initCompleteText(int startCount) {
boolean isCompleteReplaceNum = isNotEmptyStyle && config.style.isCompleteReplaceNum;
if (isCompleteReplaceNum && isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureCompleteText)) {
mPictureSendView.setText(String.format(config.style.pictureCompleteText,
selectImages.size(), config.maxVideoSelectNum + config.maxSelectNum));
selectImages.size(), config.maxVideoSelectNum + config.maxPictureSelectNum));
} else {
mPictureSendView.setText(isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureUnCompleteText)
? config.style.pictureUnCompleteText : getString(R.string.picture_send_num, selectImages.size(),
config.maxVideoSelectNum + config.maxSelectNum));
config.maxVideoSelectNum + config.maxPictureSelectNum));
}
}
} else {
String mimeType = selectImages.get(0).getMimeType();
int maxSize = PictureMimeType.eqVideo(mimeType) ? config.maxVideoSelectNum : config.maxSelectNum;
int maxSize = PictureMimeType.eqVideo(mimeType) ? config.maxVideoSelectNum : config.maxPictureSelectNum;
if (config.selectionMode == PictureConfig.SINGLE) {
if (startCount <= 0) {
mPictureSendView.setText(isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureUnCompleteText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ protected void initCompleteText(List<LocalMedia> list) {
} else {
boolean isCompleteReplaceNum = isNotEmptyStyle && config.style.isCompleteReplaceNum;
if (isCompleteReplaceNum && isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureCompleteText)) {
mPictureSendView.setText(String.format(config.style.pictureCompleteText, size, config.maxVideoSelectNum + config.maxSelectNum));
mPictureSendView.setText(String.format(config.style.pictureCompleteText, size, config.maxVideoSelectNum + config.maxPictureSelectNum));
} else {
mPictureSendView.setText(isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureUnCompleteText)
? config.style.pictureUnCompleteText : getString(R.string.picture_send_num, size, config.maxVideoSelectNum + config.maxSelectNum));
? config.style.pictureUnCompleteText : getString(R.string.picture_send_num, size, config.maxVideoSelectNum + config.maxPictureSelectNum));
}
}
} else {
String mimeType = list.get(0).getMimeType();
int maxSize = PictureMimeType.eqVideo(mimeType) ? config.maxVideoSelectNum : config.maxSelectNum;
int maxSize = PictureMimeType.eqVideo(mimeType) ? config.maxVideoSelectNum : config.maxPictureSelectNum;
if (config.selectionMode == PictureConfig.SINGLE) {
if (size <= 0) {
mPictureSendView.setText(isNotEmptyStyle && !TextUtils.isEmpty(config.style.pictureUnCompleteText)
Expand Down
Loading