Skip to content

Commit

Permalink
Merge branch 'release/v0.11.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sangcomz committed Apr 2, 2020
2 parents 3a537c9 + f93fc83 commit f83d6fd
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 114 deletions.
2 changes: 2 additions & 0 deletions FishBun/src/main/java/com/sangcomz/fishbun/BaseProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ interface BaseProperty {

fun exceptGif(isExcept: Boolean): FishBunCreator

fun exceptMimeType(exceptMimeTypeList: List<MimeType>): FishBunCreator

fun startAlbum()
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ interface CustomizationProperty {
fun setSelectCircleStrokeColor(strokeColor: Int): FishBunCreator

fun isStartInAllView(isStartInAllView: Boolean): FishBunCreator

fun setSpecifyFolderList(specifyFolderList: List<String>): FishBunCreator
}
20 changes: 19 additions & 1 deletion FishBun/src/main/java/com/sangcomz/fishbun/FishBunCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.sangcomz.fishbun.define.Define
import com.sangcomz.fishbun.ui.album.AlbumActivity
import com.sangcomz.fishbun.ui.picker.PickerActivity
import java.util.*
import kotlin.collections.ArrayList

/**
* Created by sangcomz on 17/05/2017.
Expand Down Expand Up @@ -131,8 +132,13 @@ class FishBunCreator(private val fishBun: FishBun, private val fishton: Fishton)
fishton.isUseAllDoneButton = isUse
}

@Deprecated("instead setMaxCount(count)", ReplaceWith("exceptMimeType(mimeType)"))
override fun exceptGif(isExcept: Boolean): FishBunCreator = this.apply {
fishton.isExceptGif = isExcept
fishton.exceptMimeTypeList = arrayListOf(MimeType.GIF)
}

override fun exceptMimeType(exceptMimeTypeList: List<MimeType>) = this.apply {
fishton.exceptMimeTypeList = exceptMimeTypeList
}

override fun setMenuDoneText(text: String?): FishBunCreator = this.apply {
Expand Down Expand Up @@ -163,11 +169,16 @@ class FishBunCreator(private val fishBun: FishBun, private val fishton: Fishton)
fishton.isStartInAllView = isStartInAllView
}

override fun setSpecifyFolderList(specifyFolderList: List<String>) = this.apply {
fishton.specifyFolderList = specifyFolderList
}

override fun startAlbum() {
val fishBunContext = fishBun.fishBunContext
val context = fishBunContext.getContext()

exceptionHandling()

if (fishton.imageAdapter == null) throw NullPointerException("ImageAdapter is Null")

with(fishton) {
Expand All @@ -191,5 +202,12 @@ class FishBunCreator(private val fishBun: FishBun, private val fishton: Fishton)

fishBunContext.startActivityForResult(intent, requestCode)
}

private fun exceptionHandling() {
//TODO support camera
if (fishton.isCamera) {
fishton.isCamera = fishton.specifyFolderList.isEmpty()
}
}
}

8 changes: 5 additions & 3 deletions FishBun/src/main/java/com/sangcomz/fishbun/Fishton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import java.util.ArrayList
*/
class Fishton {
var imageAdapter: ImageAdapter? = null
var pickerImages: Array<Uri>? = null
var pickerImages: List<Uri>? = null

//BaseParams
var maxCount: Int = 0
var minCount: Int = 0
var isExceptGif: Boolean = false
var exceptMimeTypeList = emptyList<MimeType>()
var selectedImages = ArrayList<Uri>()

//CustomizationParams
var specifyFolderList = emptyList<String>()
var photoSpanCount: Int = 0
var albumPortraitSpanCount: Int = 0
var albumLandscapeSpanCount: Int = 0
Expand Down Expand Up @@ -74,10 +75,11 @@ class Fishton {
//BaseParams
maxCount = 10
minCount = 1
isExceptGif = true
exceptMimeTypeList = emptyList()
selectedImages = ArrayList()

//CustomizationParams
specifyFolderList = emptyList()
photoSpanCount = 3
albumPortraitSpanCount = 1
albumLandscapeSpanCount = 2
Expand Down
9 changes: 9 additions & 0 deletions FishBun/src/main/java/com/sangcomz/fishbun/MimeType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sangcomz.fishbun

enum class MimeType(val type: String) {
GIF("image/gif"),
PNG("image/png"),
JPEG("image/jpeg"),
BMP("image/bmp"),
WEBP("image/webp");
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlinx.android.synthetic.main.detail_item.view.*
* Created by sangcomz on 15/06/2017.
*/

class DetailViewPagerAdapter(private val inflater: LayoutInflater, private val images: Array<Uri>) : PagerAdapter() {
class DetailViewPagerAdapter(private val inflater: LayoutInflater, private val images: List<Uri>) : PagerAdapter() {
private val fishton = Fishton.getInstance()

override fun instantiateItem(container: ViewGroup, position: Int): Any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.google.android.material.snackbar.Snackbar;

import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.snackbar.Snackbar;
import com.sangcomz.fishbun.Fishton;
import com.sangcomz.fishbun.R;
import com.sangcomz.fishbun.define.Define;
Expand All @@ -26,7 +24,6 @@
import com.sangcomz.fishbun.util.RadioWithTextButton;

import java.util.ArrayList;
import java.util.Collections;


public class PickerGridAdapter
Expand Down Expand Up @@ -83,7 +80,7 @@ public void onClick(View v) {
else imagePos = position;

final ViewHolderImage vh = (ViewHolderImage) holder;
final Uri image = fishton.getPickerImages()[imagePos];
final Uri image = fishton.getPickerImages().get(imagePos);
final Context context = vh.item.getContext();
vh.item.setTag(image);
vh.btnThumbCount.unselect();
Expand Down Expand Up @@ -214,7 +211,7 @@ public void run() {
public int getItemCount() {
int count;
if (fishton.getPickerImages() == null) count = 0;
else count = fishton.getPickerImages().length;
else count = fishton.getPickerImages().size();

if (fishton.isCamera())
return count + 1;
Expand All @@ -234,9 +231,11 @@ public int getItemViewType(int position) {

public void addImage(Uri path) {
ArrayList<Uri> al = new ArrayList<>();
Collections.addAll(al, fishton.getPickerImages());
if (fishton.getPickerImages() != null){
al.addAll(fishton.getPickerImages());
}
al.add(0, path);
fishton.setPickerImages(al.toArray(new Uri[al.size()]));
fishton.setPickerImages(al);

notifyDataSetChanged();

Expand Down
7 changes: 7 additions & 0 deletions FishBun/src/main/java/com/sangcomz/fishbun/ext/MimeTypeExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:JvmName("MimeTypeExt")

package com.sangcomz.fishbun.ext

import com.sangcomz.fishbun.MimeType

fun MimeType.equalsMimeType(mimeType: String) = this.type == mimeType
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;

public class AlbumActivity extends BaseActivity {
private AlbumController albumController;
private ArrayList<Album> albumList = new ArrayList<>();
private List<Album> albumList = Collections.emptyList();

private RecyclerView recyclerAlbumList;
private RelativeLayout relAlbumEmpty;
Expand Down Expand Up @@ -76,7 +77,9 @@ public void onCreate(Bundle savedInstanceState) {
initView();
initController();
if (albumController.checkPermission())
albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif());
albumController.getAlbumList(fishton.getTitleAlbumAllView(),
fishton.getExceptMimeTypeList(),
fishton.getSpecifyFolderList());
}

@Override
Expand Down Expand Up @@ -163,7 +166,7 @@ private void setAlbumListAdapter() {
changeToolbarTitle();
}

protected void setAlbumList(ArrayList<Album> albumList) {
protected void setAlbumList(List<Album> albumList) {
this.albumList = albumList;
if (albumList.size() > 0) {
relAlbumEmpty.setVisibility(View.GONE);
Expand All @@ -178,7 +181,7 @@ protected void setAlbumList(ArrayList<Album> albumList) {
private void refreshList(int position, ArrayList<Uri> imagePath) {
if (imagePath.size() > 0) {
if (position == 0) {
albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif());
albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.getExceptMimeTypeList(), fishton.getSpecifyFolderList());
} else {
albumList.get(0).counter += imagePath.size();
albumList.get(position).counter += imagePath.size();
Expand Down Expand Up @@ -264,7 +267,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
new SingleMediaScanner(this, new File(albumController.getSavePath()), new Function0<Unit>() {
@Override
public Unit invoke() {
albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif());
albumController.getAlbumList(fishton.getTitleAlbumAllView(),
fishton.getExceptMimeTypeList(),
fishton.getSpecifyFolderList());
return Unit.INSTANCE;
}
});
Expand All @@ -285,7 +290,9 @@ public void onRequestPermissionsResult(int requestCode,
if (grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay!
albumController.getAlbumList(fishton.getTitleAlbumAllView(), fishton.isExceptGif());
albumController.getAlbumList(fishton.getTitleAlbumAllView(),
fishton.getExceptMimeTypeList(),
fishton.getSpecifyFolderList());
} else {
new PermissionCheck(this).showPermissionDialog();
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import android.os.Environment;
import android.provider.MediaStore;

import com.sangcomz.fishbun.MimeType;
import com.sangcomz.fishbun.bean.Album;
import com.sangcomz.fishbun.ext.MimeTypeExt;
import com.sangcomz.fishbun.permission.PermissionCheck;
import com.sangcomz.fishbun.util.CameraUtil;
import com.sangcomz.fishbun.util.RegexUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

class AlbumController {

Expand Down Expand Up @@ -51,30 +53,33 @@ boolean checkCameraPermission() {
}

void getAlbumList(String allViewTitle,
Boolean exceptGif) {
new LoadAlbumList(allViewTitle, exceptGif).execute();
List<MimeType> exceptMimeTypeList,
List<String> specifyFolderList) {
new LoadAlbumList(allViewTitle, exceptMimeTypeList, specifyFolderList).execute();
}

private class LoadAlbumList extends AsyncTask<Void, Void, ArrayList<Album>> {
private class LoadAlbumList extends AsyncTask<Void, Void, List<Album>> {

String allViewTitle;
Boolean exceptGif;
List<MimeType> exceptMimeTypeList;
List<String> specifyFolderList;

LoadAlbumList(String allViewTitle,
Boolean exceptGif) {
List<MimeType> exceptMimeTypeList,
List<String> specifyFolderList) {
this.allViewTitle = allViewTitle;
this.exceptGif = exceptGif;

this.exceptMimeTypeList = exceptMimeTypeList;
this.specifyFolderList = specifyFolderList;
}

@Override
protected ArrayList<Album> doInBackground(Void... params) {
protected List<Album> doInBackground(Void... params) {
HashMap<Long, Album> albumHashMap = new HashMap<>();
final String orderBy = MediaStore.Images.Media._ID + " DESC";
String[] projection = new String[]{
MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.MIME_TYPE,
MediaStore.Images.Media.BUCKET_ID};

Cursor c = resolver.query(
Expand All @@ -83,29 +88,34 @@ protected ArrayList<Album> doInBackground(Void... params) {

int totalCounter = 0;
if (c != null) {
int bucketData = c
.getColumnIndex(MediaStore.Images.Media.DATA);
int bucketMimeType = c.getColumnIndex(MediaStore.Images.Media.MIME_TYPE);
int bucketColumn = c
.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
int bucketColumnId = c
.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);

albumHashMap.put((long) 0, new Album(0, allViewTitle, null, 0));
if (!isNotContainsSpecifyFolderList(specifyFolderList, allViewTitle)) {
albumHashMap.put((long) 0, new Album(0, allViewTitle, null, 0));
}

while (c.moveToNext()) {
if (exceptGif && RegexUtil.checkGif(c.getString(bucketData))) continue;
String mimeType = c.getString(bucketMimeType);
String folderName = c.getString(bucketColumn);

if (isExceptMemeType(exceptMimeTypeList, mimeType)
|| isNotContainsSpecifyFolderList(specifyFolderList, folderName))
continue;

totalCounter++;
long bucketId = c.getInt(bucketColumnId);
Album album = albumHashMap.get(bucketId);
if (album == null) {
int imgId = c.getInt(c.getColumnIndex(MediaStore.MediaColumns._ID));
Uri path = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imgId);
albumHashMap.put(bucketId,
new Album(bucketId,
c.getString(bucketColumn),
path.toString(), 1));
if (albumHashMap.get((long) 0).thumbnailPath == null)
albumHashMap.get((long) 0).thumbnailPath = path.toString();
albumHashMap.put(bucketId, new Album(bucketId, folderName, path.toString(), 1));
if (albumHashMap.get(0L) != null
&& albumHashMap.get(0L).thumbnailPath == null)
albumHashMap.get(0L).thumbnailPath = path.toString();
} else {
album.counter++;
}
Expand All @@ -131,7 +141,7 @@ protected ArrayList<Album> doInBackground(Void... params) {
}

@Override
protected void onPostExecute(ArrayList<Album> albumList) {
protected void onPostExecute(List<Album> albumList) {
super.onPostExecute(albumList);
albumActivity.setAlbumList(albumList);
}
Expand All @@ -150,4 +160,17 @@ String getPathDir() {
return Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM + "/Camera").getAbsolutePath();
}

private boolean isExceptMemeType(List<MimeType> mimeTypes, String mimeType) {
for (MimeType type : mimeTypes) {
if (MimeTypeExt.equalsMimeType(type, mimeType))
return true;
}
return false;
}

private boolean isNotContainsSpecifyFolderList(List<String> specifyFolderList, String displayBundleName) {
if (specifyFolderList.isEmpty()) return false;
return !specifyFolderList.contains(displayBundleName);
}
}
Loading

0 comments on commit f83d6fd

Please sign in to comment.