Commit 5412eba44e6f74c3bf72749e2f92d32199a8a563
1 parent
8df30b8d
处理默认
Showing
10 changed files
with
41 additions
and
33 deletions
app/src/main/java/com/cnlive/strike/debug/MainActivity.java
| ... | ... | @@ -15,7 +15,6 @@ import com.cnlive.media.PickerConfig; |
| 15 | 15 | import com.cnlive.media.media.entity.Media; |
| 16 | 16 | import com.cnlive.media.utils.AndroidQUtil; |
| 17 | 17 | import com.cnlive.media.utils.GlideCacheUtil; |
| 18 | -import com.cnlive.strike.debug.R; | |
| 19 | 18 | import com.cnlive.strike.debug.databinding.ActivityMainBinding; |
| 20 | 19 | |
| 21 | 20 | import java.io.File; |
| ... | ... | @@ -70,12 +69,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 70 | 69 | .maxNum(5) |
| 71 | 70 | .setSelectGif(false) |
| 72 | 71 | .maxImageSize(25 * 1024 * 1024) |
| 72 | + .maxVideoSize(100*1024*1024) | |
| 73 | 73 | .isReturnUri(AndroidQUtil.isAndroidQ()) |
| 74 | - .selectMode(PickerConfig.PICKER_ONLY_ONE_TYPE) | |
| 74 | + .selectMode(PickerConfig.PICKER_IMAGE_VIDEO) | |
| 75 | 75 | .defaultSelectList(new ArrayList<Media>()) |
| 76 | - .needCamera(true) | |
| 77 | - .cachePath(fileDir + "/strike/file/") | |
| 78 | - .setJumpCameraMode(PickerConfig.CAMERA_MODE_PIC) | |
| 76 | + .needCamera(false) | |
| 79 | 77 | .builder() |
| 80 | 78 | // .doCrop(1, 1, 900, 900) |
| 81 | 79 | .start(this, PickerConfig.PICKER_IMAGE, PickerConfig.DEFAULT_RESULT_CODE); | ... | ... |
config.gradle
lib_media/src/main/java/com/cnlive/media/PickerConfig.java
| ... | ... | @@ -10,10 +10,14 @@ public class PickerConfig { |
| 10 | 10 | //视频文件最大时长 |
| 11 | 11 | public static final String MAX_TIME = "max_time"; |
| 12 | 12 | // 默认视频时长 |
| 13 | - public static final int DEFAULT_MAX_TIME = 60 * 1000; | |
| 13 | + public static final int DEFAULT_MAX_TIME = Integer.MAX_VALUE; | |
| 14 | + //最大选择个数 | |
| 15 | + public static final int DEFAULT_MAX_NUM= Integer.MAX_VALUE; | |
| 16 | + | |
| 17 | + // 默认视频大小 | |
| 18 | + public static final int DEFAULT_MAX_VIDEO_SIZE = Integer.MAX_VALUE; | |
| 19 | + public static final int DEFAULT_MAX_IMAGE_SIZE = Integer.MAX_VALUE; | |
| 14 | 20 | |
| 15 | - // 默认视频时长 | |
| 16 | - public static final int DEFAULT_MAX_VIDEO_TIME = 600 * 1000; | |
| 17 | 21 | //界面跳转options的键值 |
| 18 | 22 | public static final String INTENT_KEY_OPTIONS = "options"; |
| 19 | 23 | //图片选择模式,默认选视频和图片 |
| ... | ... | @@ -40,6 +44,8 @@ public class PickerConfig { |
| 40 | 44 | public static final int PICKER_IMAGE_VIDEO = 101; |
| 41 | 45 | //只能选择一种类型 |
| 42 | 46 | public static final int PICKER_ONLY_ONE_TYPE = 103; |
| 47 | + //视频选一个 图片选九个 | |
| 48 | + public static final int PICKER_ONE_VIDEO_TYPE = 103; | |
| 43 | 49 | //展示图片的列数行数 |
| 44 | 50 | public static int GridSpanCount = 3; |
| 45 | 51 | public static int GridSpace = 4; | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/presenter/MediaPickerFragmentPresenter.java
| ... | ... | @@ -59,7 +59,6 @@ public class MediaPickerFragmentPresenter extends MvpBasePresenter<MediaPickerFr |
| 59 | 59 | mediaPickerActivity.maxNum = mediaPickerActivity.mOptions .getMaxNum(); |
| 60 | 60 | mediaPickerActivity.maxVideoSize = mediaPickerActivity.mOptions .getMaxVideoSize(); |
| 61 | 61 | mediaPickerActivity.selectMode = mediaPickerActivity.mOptions .getSelectMode(); |
| 62 | - mediaPickerActivity.maxTime = mediaPickerActivity.mOptions .getMaxTime(); | |
| 63 | 62 | mediaPickerActivity.isReturnUri = mediaPickerActivity.mOptions .isReturnUri(); |
| 64 | 63 | mediaPickerActivity.isFrendCircle = mediaPickerActivity.mOptions .isFriendCircle(); |
| 65 | 64 | mediaPickerActivity.needCrop = mediaPickerActivity.mOptions .isNeedCrop(); | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/presenter/MediaPresenter.java
| ... | ... | @@ -36,7 +36,6 @@ public class MediaPresenter extends MvpBasePresenter<MediaView> { |
| 36 | 36 | if (TextUtils.isEmpty(mediaPickerActivity.cachePath)) { |
| 37 | 37 | if (AndroidQUtil.isAndroidQ()) { |
| 38 | 38 | mediaPickerActivity.cachePath = mediaPickerActivity.getExternalFilesDir("").getPath() + File.separator + "MediaPickerPic"; |
| 39 | - | |
| 40 | 39 | } else { |
| 41 | 40 | mediaPickerActivity.cachePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "MediaPickerPic"; |
| 42 | 41 | } |
| ... | ... | @@ -70,7 +69,6 @@ public class MediaPresenter extends MvpBasePresenter<MediaView> { |
| 70 | 69 | mediaPickerActivity.maxNum = mediaPickerActivity.mOptions.getMaxNum(); |
| 71 | 70 | mediaPickerActivity.maxVideoSize = mediaPickerActivity.mOptions.getMaxVideoSize(); |
| 72 | 71 | mediaPickerActivity.selectMode = mediaPickerActivity.mOptions.getSelectMode(); |
| 73 | - mediaPickerActivity.maxTime = mediaPickerActivity.mOptions.getMaxTime(); | |
| 74 | 72 | mediaPickerActivity.isReturnUri = mediaPickerActivity.mOptions.isReturnUri(); |
| 75 | 73 | mediaPickerActivity.isFrendCircle = mediaPickerActivity.mOptions.isFriendCircle(); |
| 76 | 74 | mediaPickerActivity.needCrop = mediaPickerActivity.mOptions.isNeedCrop(); | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/view/MediaPickerFragmentView.java
| ... | ... | @@ -80,7 +80,14 @@ public class MediaPickerFragmentView implements MvpView { |
| 80 | 80 | @Override |
| 81 | 81 | public void itemClick(Media media) { |
| 82 | 82 | if (DoublePressed.onDoublePressed()) return; |
| 83 | - if (mActivity.mOptions.isSinglePick() || mActivity.mOptions.maxNum == 1) { | |
| 83 | + if (PickerConfig.PICKER_ONLY_ONE_TYPE == mActivity.selectMode && media.mediaType == 3) { | |
| 84 | + if (mActivity.selects.size() > 0) { | |
| 85 | + showMessage(mFragment.getResources().getString(R.string.msg_type_limit)); | |
| 86 | + } else { | |
| 87 | + MeidaResultObservable.getInstance().finishMedia(true, media); | |
| 88 | + } | |
| 89 | + | |
| 90 | + } else if (mActivity.mOptions.isSinglePick() || mActivity.mOptions.maxNum == 1) { | |
| 84 | 91 | |
| 85 | 92 | if (mActivity.mOptions.isNeedCrop()) { |
| 86 | 93 | if (media.mediaType != 1) { |
| ... | ... | @@ -160,7 +167,7 @@ public class MediaPickerFragmentView implements MvpView { |
| 160 | 167 | return false; |
| 161 | 168 | } |
| 162 | 169 | //视频时长限制 |
| 163 | - if (media.mediaType == 3 && media.duration > mActivity.maxTime) { | |
| 170 | + if (media.mediaType == 3 && media.duration > mActivity.maxVideoTime) { | |
| 164 | 171 | showMessage(mFragment.getResources().getString(R.string.media_msg_time_limit) + (MediaStringUtils.gennerMinSec(mActivity.maxVideoTime / 1000))); |
| 165 | 172 | return false; |
| 166 | 173 | } |
| ... | ... | @@ -196,7 +203,6 @@ public class MediaPickerFragmentView implements MvpView { |
| 196 | 203 | mediaActivity.allMedias.get(mediaActivity.allMedias.indexOf(select)).setSelect(true); |
| 197 | 204 | } |
| 198 | 205 | } |
| 199 | -// List<Media> listMedias = medias.get(0).getMedias(); | |
| 200 | 206 | if (mediaActivity.needCamera && medias.get(0) != null && medias.get(0).getMedias() != null |
| 201 | 207 | && medias.get(0).getMedias().get(0) != null && medias.get(0).getMedias().get(0).mediaType != 0) { |
| 202 | 208 | mediaActivity.allMedias.add(0, new Media(0)); | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/view/MediaView.java
| ... | ... | @@ -336,8 +336,8 @@ public class MediaView implements MvpView { |
| 336 | 336 | return false; |
| 337 | 337 | } |
| 338 | 338 | //视频时长限制 |
| 339 | - if (media.mediaType == 3 && media.duration > mActivity.maxTime) { | |
| 340 | - showMessage(mActivity.getResources().getString(R.string.media_msg_time_limit) + (MediaStringUtils.gennerMinSec(mActivity.maxTime / 1000))); | |
| 339 | + if (media.mediaType == 3 && media.duration > mActivity.maxVideoTime) { | |
| 340 | + showMessage(mActivity.getResources().getString(R.string.media_msg_time_limit) + (MediaStringUtils.gennerMinSec(mActivity.maxVideoTime / 1000))); | |
| 341 | 341 | return false; |
| 342 | 342 | } |
| 343 | 343 | //判断是否支持gif | ... | ... |
lib_media/src/main/java/com/cnlive/media/model/ImagePickerOptions.java
| ... | ... | @@ -17,11 +17,11 @@ public class ImagePickerOptions implements Parcelable { |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | //最大个数 |
| 20 | - public int maxNum = 40; | |
| 20 | + public int maxNum = PickerConfig.DEFAULT_MAX_NUM; | |
| 21 | 21 | //视频的最大 的大小 |
| 22 | - public long maxVideoSize = 188743680L; | |
| 22 | + public long maxVideoSize = PickerConfig.DEFAULT_MAX_VIDEO_SIZE; | |
| 23 | 23 | //图片的最大大小 |
| 24 | - public long maxImageSize = 188743680L; | |
| 24 | + public long maxImageSize = PickerConfig.DEFAULT_MAX_IMAGE_SIZE; | |
| 25 | 25 | //是否展示相机 |
| 26 | 26 | public boolean needCamera = false; |
| 27 | 27 | //选择模式 | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/activity/MediaActivity.java
| ... | ... | @@ -79,11 +79,11 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, |
| 79 | 79 | // 结果的code |
| 80 | 80 | public int resultCode; |
| 81 | 81 | //最大 |
| 82 | - public int maxNum = 40; | |
| 82 | + public int maxNum = 9; | |
| 83 | 83 | //视频的最大 的大小 |
| 84 | - public long maxVideoSize = 188743680L; | |
| 84 | + public long maxVideoSize = Integer.MAX_VALUE; | |
| 85 | 85 | //图片的最大大小 |
| 86 | - public long maxImageSize = 188743680L; | |
| 86 | + public long maxImageSize = Integer.MAX_VALUE; | |
| 87 | 87 | //是否展示相机 |
| 88 | 88 | public boolean needCamera = false; |
| 89 | 89 | //选择模式 |
| ... | ... | @@ -94,8 +94,6 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, |
| 94 | 94 | public String cachePath; |
| 95 | 95 | //剪辑视频存储路径 |
| 96 | 96 | public String videoTrimPath; |
| 97 | - //是否是朋友圈 | |
| 98 | - public boolean friendCircle = false; | |
| 99 | 97 | //裁剪的数据 |
| 100 | 98 | public ImagePickerCropParams cropParams; |
| 101 | 99 | //是否需要裁剪 |
| ... | ... | @@ -104,8 +102,7 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, |
| 104 | 102 | public boolean singlePick = false; |
| 105 | 103 | //展示时长 |
| 106 | 104 | public boolean showTime = false; |
| 107 | - public int maxTime = 60 * 60_000; | |
| 108 | - public int maxVideoTime = PickerConfig.DEFAULT_MAX_VIDEO_TIME; | |
| 105 | + public int maxVideoTime = PickerConfig.DEFAULT_MAX_TIME; | |
| 109 | 106 | //是否选择Gif |
| 110 | 107 | public boolean selectGift = true; |
| 111 | 108 | //处理返回uri地址 |
| ... | ... | @@ -162,7 +159,8 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, |
| 162 | 159 | } else if (type == PickerConfig.PICKER_ONLY_ONE_TYPE) { |
| 163 | 160 | loaderM = MediaLoader.getInstance(this, this); |
| 164 | 161 | getLoaderManager().initLoader(type, null, (MediaLoader) loaderM); |
| 165 | - } else if (type == PickerConfig.PICKER_IMAGE) { | |
| 162 | + } | |
| 163 | + else if (type == PickerConfig.PICKER_IMAGE) { | |
| 166 | 164 | loaderM = ImageLoader.getInstance(this, this); |
| 167 | 165 | getLoaderManager().initLoader(type, null, (ImageLoader) loaderM); |
| 168 | 166 | } else if (type == PickerConfig.PICKER_VIDEO) { | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/adapter/MediaAdapter.java
| ... | ... | @@ -90,6 +90,7 @@ public class MediaAdapter extends BaseRecyclerViewAdapter<Media> { |
| 90 | 90 | break; |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | + | |
| 93 | 94 | @Override |
| 94 | 95 | public int getItemViewType(int position) { |
| 95 | 96 | Media meida = getItem(position); |
| ... | ... | @@ -109,10 +110,11 @@ public class MediaAdapter extends BaseRecyclerViewAdapter<Media> { |
| 109 | 110 | |
| 110 | 111 | /** |
| 111 | 112 | * 处理图像展示的逻辑 |
| 113 | + * | |
| 112 | 114 | * @param mediaViewHolder |
| 113 | 115 | */ |
| 114 | 116 | private void showMedia(MediaViewHolder mediaViewHolder, int position) { |
| 115 | - Media mMedia=getItem(position); | |
| 117 | + Media mMedia = getItem(position); | |
| 116 | 118 | binding = (MediaImageItemBinding) mediaViewHolder.getBinding(); |
| 117 | 119 | GlideCacheUtil.intoItemImageThumbnail(mContext, mMedia, binding.mediaImage, null); |
| 118 | 120 | if (mMedia.mediaType == 1) { |
| ... | ... | @@ -122,7 +124,7 @@ public class MediaAdapter extends BaseRecyclerViewAdapter<Media> { |
| 122 | 124 | binding.textViewSize.setText(showTime ? StringUtils.gennerTime(mMedia.duration / 1000) : FileUtils.getSizeByUnit(mMedia.size)); |
| 123 | 125 | } |
| 124 | 126 | //单选 |
| 125 | - if (mOptions.singlePick||mOptions.isNeedCrop()||mOptions.maxNum==1) { | |
| 127 | + if (mOptions.singlePick || mOptions.isNeedCrop() || mOptions.maxNum == 1 || (mOptions.getSelectMode() == PickerConfig.PICKER_ONLY_ONE_TYPE && mMedia.mediaType == 3)) { | |
| 126 | 128 | binding.checkImage.setVisibility(View.GONE); |
| 127 | 129 | } else { |
| 128 | 130 | binding.checkImage.setVisibility(View.VISIBLE); |
| ... | ... | @@ -140,14 +142,17 @@ public class MediaAdapter extends BaseRecyclerViewAdapter<Media> { |
| 140 | 142 | |
| 141 | 143 | /** |
| 142 | 144 | * 处理选中的事件 |
| 145 | + * | |
| 143 | 146 | * @param binding |
| 144 | 147 | */ |
| 145 | 148 | private void progressSelectItem(MediaImageItemBinding binding, int position) { |
| 146 | - if (listener != null) listener.itemSelect(getItem(position).isSelect(), getItem(position),position); | |
| 149 | + if (listener != null) | |
| 150 | + listener.itemSelect(getItem(position).isSelect(), getItem(position), position); | |
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | /** |
| 150 | 154 | * 处理相机点击事件 |
| 155 | + * | |
| 151 | 156 | * @param mediaViewHolder |
| 152 | 157 | */ |
| 153 | 158 | private void showCamera(MediaViewHolder mediaViewHolder, int position) { |
| ... | ... | @@ -157,6 +162,4 @@ public class MediaAdapter extends BaseRecyclerViewAdapter<Media> { |
| 157 | 162 | } |
| 158 | 163 | |
| 159 | 164 | |
| 160 | - | |
| 161 | - | |
| 162 | 165 | } | ... | ... |