Skip to content

Commit

Permalink
Merge pull request #63 from joker-fu/master
Browse files Browse the repository at this point in the history
功能增强
  • Loading branch information
HuanTanSheng authored Apr 8, 2019
2 parents 4837ed6 + f9833f6 commit bb5adcf
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.huantansheng.easyphotos.EasyPhotos;
import com.huantansheng.easyphotos.models.album.entity.Photo;
import com.huantansheng.easyphotos.setting.Setting;

import java.util.ArrayList;

Expand Down Expand Up @@ -182,6 +183,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
EasyPhotos.createAlbum(this, true, GlideEngine.getInstance())
.setFileProviderAuthority("com.huantansheng.easyphotos.demo.fileprovider")
.setCount(9)
.setCameraLocation(Setting.LIST_FIRST)
.setAdView(photosAdView, photosAdLoaded, albumItemsAdView, albumItemsAdLoaded)
.start(101);

Expand Down Expand Up @@ -234,6 +236,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
EasyPhotos.createAlbum(this, true, GlideEngine.getInstance())
.setFileProviderAuthority("com.huantansheng.easyphotos.demo.fileprovider")
.setCount(9)
.setVideoMinSecond(10)
.onlyVideo(true)
.start(101);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,39 @@ public AlbumBuilder setCount(int selectorMaxCount) {
return AlbumBuilder.this;
}

/**
* 设置选择图片数(设置此参数后setCount失效)
*
* @param selectorMaxCount 最大选择数
* @return AlbumBuilder
*/
public AlbumBuilder setPictureCount(int selectorMaxCount) {
Setting.pictureCount = selectorMaxCount;
return AlbumBuilder.this;
}

/**
* 设置选择视频数(设置此参数后setCount失效)
*
* @param selectorMaxCount 最大选择数
* @return AlbumBuilder
*/
public AlbumBuilder setVideoCount(int selectorMaxCount) {
Setting.videoCount = selectorMaxCount;
return AlbumBuilder.this;
}

/**
* 设置相机按钮风格 默认true
*
* @param cLocation 使用Material Design风格相机按钮 默认 BOTTOM_RIGHT
* @return AlbumBuilder
*/
public AlbumBuilder setCameraLocation(@Setting.Location int cLocation) {
Setting.cameraLocation = cLocation;
return AlbumBuilder.this;
}

/**
* 设置显示照片的最小文件大小
*
Expand Down Expand Up @@ -288,6 +321,28 @@ public AlbumBuilder setVideo(boolean shouldShow) {
return AlbumBuilder.this;
}

/**
* 显示最少多少秒的视频
*
* @param second 秒
* @return @return AlbumBuilder
*/
public AlbumBuilder setVideoMinSecond(int second) {
Setting.videoMinSecond = second * 1000;
return AlbumBuilder.this;
}

/**
* 显示最多多少秒的视频
*
* @param second 秒
* @return @return AlbumBuilder
*/
public AlbumBuilder setVideoMaxSecond(int second) {
Setting.videoMaxSecond = second * 1000;
return AlbumBuilder.this;
}

/**
* 相册选择页是否显示清空按钮
*
Expand Down Expand Up @@ -325,6 +380,9 @@ public void start(int requestCode) {
Setting.showGif = false;
Setting.showVideo = true;
}
if (Setting.pictureCount != -1 || Setting.videoCount != -1) {
Setting.count = Setting.pictureCount + Setting.videoCount;
}
launchEasyPhotosActivity(requestCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void initAlbum(Context context) {
if (size < Setting.minSize) {
continue;
}
if (isVideo && duration <= 0) {
if (isVideo && (duration <= Setting.videoMinSecond || duration >= Setting.videoMaxSecond)) {
continue;
}
if (!isVideo && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.BitmapFactory;
import android.os.Build;

import com.huantansheng.easyphotos.constant.Type;
import com.huantansheng.easyphotos.models.album.entity.Photo;
import com.huantansheng.easyphotos.setting.Setting;

Expand All @@ -16,9 +17,23 @@
public class Result {
public static ArrayList<Photo> photos = new ArrayList<>();

public static void addPhoto(Photo photo) {
/**
* @return 0:添加成功 -2:超过视频选择数 -1:超过图片选择数
*/
public static int addPhoto(Photo photo) {
if (Setting.videoCount != -1 || Setting.pictureCount != -1) {
int number = getVideoNumber();
if (photo.type.contains(Type.video) && number >= Setting.videoCount) {
return -2;
}
number = photos.size() - number;
if ((!photo.type.contains(Type.video)) && number >= Setting.pictureCount) {
return -1;
}
}
photo.selected = true;
photos.add(photo);
return 0;
}

public static void removePhoto(Photo photo) {
Expand All @@ -37,6 +52,16 @@ public static void removeAll() {
}
}

private static int getVideoNumber() {
int count = 0;
for (Photo p : photos) {
if (p.type.contains(Type.video)) {
count += 1;
}
}
return count;
}

public static void processOriginal() {
boolean isIceApi = Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
if (Setting.showOriginalMenu) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.huantansheng.easyphotos.setting;

import android.support.annotation.IntDef;
import android.view.View;

import com.huantansheng.easyphotos.engine.ImageEngine;
import com.huantansheng.easyphotos.models.album.entity.Photo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;

Expand All @@ -18,6 +21,8 @@ public class Setting {
public static int minHeight = 1;
public static long minSize = 1;
public static int count = 1;
public static int pictureCount = -1;
public static int videoCount = -1;
public static WeakReference<View> photosAdView = null;
public static WeakReference<View> albumItemsAdView = null;
public static boolean photoAdIsOk = false;
Expand All @@ -29,20 +34,32 @@ public class Setting {
public static boolean selectedOriginal = false;
public static String fileProviderAuthority = null;
public static boolean isShowCamera = false;
public static int cameraLocation = 1;
public static boolean onlyStartCamera = false;
public static boolean showPuzzleMenu = true;
public static boolean onlyVideo = false;
public static boolean showGif = false;
public static boolean showVideo = false;
public static boolean showCleanMenu = true;
public static long videoMinSecond = 0L;
public static long videoMaxSecond = Long.MAX_VALUE;
public static ImageEngine imageEngine = null;

public static final int LIST_FIRST = 0;
public static final int BOTTOM_RIGHT = 1;

@Retention(RetentionPolicy.SOURCE)
@IntDef(value = {LIST_FIRST, BOTTOM_RIGHT})
public @interface Location {
}

public static void clear() {
minWidth = 1;
minHeight = 1;
minSize = 1;
count = 1;
pictureCount = -1;
videoCount = -1;
photosAdView = null;
albumItemsAdView = null;
photoAdIsOk = false;
Expand All @@ -52,13 +69,16 @@ public static void clear() {
originalMenuUsable = false;
originalMenuUnusableHint = "";
selectedOriginal = false;
cameraLocation = BOTTOM_RIGHT;
isShowCamera = false;
onlyStartCamera = false;
showPuzzleMenu = true;
onlyVideo = false;
showGif = false;
showVideo = false;
showCleanMenu = true;
videoMinSecond = 0L;
videoMaxSecond = Long.MAX_VALUE;
}

public static boolean hasPhotosAd() {
Expand All @@ -68,4 +88,8 @@ public static boolean hasPhotosAd() {
public static boolean hasAlbumItemsAd() {
return albumItemsAdView != null && albumItemsAdView.get() != null;
}

public static boolean isBottomRightCamera() {
return cameraLocation == BOTTOM_RIGHT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.provider.MediaStore;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.ActionBar;
Expand Down Expand Up @@ -64,6 +65,8 @@
import java.util.Date;
import java.util.Locale;

import static com.huantansheng.easyphotos.setting.Setting.isBottomRightCamera;

public class EasyPhotosActivity extends AppCompatActivity implements AlbumItemsAdapter
.OnClickListener, PhotosAdapter.OnClickListener, AdListener, View.OnClickListener {

Expand Down Expand Up @@ -405,14 +408,14 @@ private void addNewPhoto(Photo photo) {

if (Setting.count == 1) {
Result.clear();
Result.addPhoto(photo);
int res = Result.addPhoto(photo);
onSelectorOutOfMax(res);
} else {
if (Result.count() >= Setting.count) {
Toast.makeText(this, getString(R.string
.selector_reach_max_image_hint_easy_photos, Setting.count), Toast
.LENGTH_SHORT).show();
onSelectorOutOfMax(null);
} else {
Result.addPhoto(photo);
int res = Result.addPhoto(photo);
onSelectorOutOfMax(res);
}
}
rvAlbumItems.scrollToPosition(0);
Expand Down Expand Up @@ -483,7 +486,7 @@ private void initView() {
findViewById(R.id.m_tool_bar_bottom_line).setVisibility(View.GONE);
}
ivCamera = (ImageView) findViewById(R.id.fab_camera);
if (Setting.isShowCamera) {
if (Setting.isShowCamera && isBottomRightCamera()) {
ivCamera.setVisibility(View.VISIBLE);
}
if (!Setting.showPuzzleMenu) {
Expand All @@ -499,8 +502,13 @@ private void initView() {
//去除item更新的闪光
photoList.clear();
photoList.addAll(albumModel.getCurrAlbumItemPhotos(0));
int index = 0;
if (Setting.hasPhotosAd()) {
photoList.add(0, Setting.photosAdView);
photoList.add(index, Setting.photosAdView);
}
if (Setting.isShowCamera && !isBottomRightCamera()) {
if (Setting.hasPhotosAd()) index = 1;
photoList.add(index, null);
}
photosAdapter = new PhotosAdapter(this, photoList, this);

Expand Down Expand Up @@ -699,8 +707,13 @@ private void updatePhotos(int currAlbumItemIndex) {
this.currAlbumItemIndex = currAlbumItemIndex;
photoList.clear();
photoList.addAll(albumModel.getCurrAlbumItemPhotos(currAlbumItemIndex));
int index = 0;
if (Setting.hasPhotosAd()) {
photoList.add(0, Setting.photosAdView);
photoList.add(index, Setting.photosAdView);
}
if (Setting.isShowCamera && !isBottomRightCamera()) {
if (Setting.hasPhotosAd()) index = 1;
photoList.add(index, null);
}
photosAdapter.change();
rvPhotos.scrollToPosition(0);
Expand Down Expand Up @@ -728,16 +741,30 @@ private void shouldShowMenuDone() {
Setting.count));
}

@Override
public void onCameraClick() {
launchCamera(Code.REQUEST_CAMERA);
}

@Override
public void onPhotoClick(int position, int realPosition) {
PreviewActivity.start(EasyPhotosActivity.this, currAlbumItemIndex, realPosition);

}

@Override
public void onSelectorOutOfMax() {
Toast.makeText(this, getString(R.string.selector_reach_max_image_hint_easy_photos,
Setting.count), Toast.LENGTH_SHORT).show();
public void onSelectorOutOfMax(@Nullable Integer result) {
if (result == null) {
Toast.makeText(this, getString(R.string.selector_reach_max_hint_easy_photos, Setting.count), Toast.LENGTH_SHORT).show();
return;
}
switch (result) {
case -1:
Toast.makeText(this, getString(R.string.selector_reach_max_image_hint_easy_photos, Setting.pictureCount), Toast.LENGTH_SHORT).show();
break;
case -2:
Toast.makeText(this, getString(R.string.selector_reach_max_video_hint_easy_photos, Setting.videoCount), Toast.LENGTH_SHORT).show();
break;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
if (holder.ivPhoto.getScale() != 1f) {
holder.ivPhoto.setScale(1f, true);


}
}
});
Expand Down Expand Up @@ -369,12 +369,24 @@ private void updateSelector() {
toggleSelector();
return;
}
Toast.makeText(this, getString(R.string.selector_reach_max_image_hint_easy_photos, Setting.count), Toast.LENGTH_SHORT).show();
Toast.makeText(this, getString(R.string.selector_reach_max_hint_easy_photos, Setting.count), Toast.LENGTH_SHORT).show();
return;
}
item.selected = !item.selected;
if (item.selected) {
Result.addPhoto(item);
int res = Result.addPhoto(item);
if (res != 0) {
item.selected = false;
switch (res) {
case -1:
Toast.makeText(this, getString(R.string.selector_reach_max_image_hint_easy_photos, Setting.pictureCount), Toast.LENGTH_SHORT).show();
break;
case -2:
Toast.makeText(this, getString(R.string.selector_reach_max_video_hint_easy_photos, Setting.videoCount), Toast.LENGTH_SHORT).show();
break;
}
return;
}
if (Result.count() == Setting.count) {
unable = true;
}
Expand Down
Loading

0 comments on commit bb5adcf

Please sign in to comment.