Search in sources :

Example 1 with PhotoFolderInfo

use of cn.finalteam.galleryfinal.model.PhotoFolderInfo in project GalleryFinal by pengjianbo.

the class FolderListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(FolderViewHolder holder, int position) {
    PhotoFolderInfo photoFolderInfo = getDatas().get(position);
    String path = "";
    PhotoInfo photoInfo = photoFolderInfo.getCoverPhoto();
    if (photoInfo != null) {
        path = photoInfo.getPhotoPath();
    }
    holder.mIvCover.setImageResource(R.drawable.ic_gf_default_photo);
    Drawable defaultDrawable = mActivity.getResources().getDrawable(R.drawable.ic_gf_default_photo);
    GalleryFinal.getCoreConfig().getImageLoader().displayImage(mActivity, path, holder.mIvCover, defaultDrawable, 200, 200);
    holder.mTvFolderName.setText(photoFolderInfo.getFolderName());
    int size = 0;
    if (photoFolderInfo.getPhotoList() != null) {
        size = photoFolderInfo.getPhotoList().size();
    }
    holder.mTvPhotoCount.setText(mActivity.getString(R.string.folder_photo_size, size));
    if (GalleryFinal.getCoreConfig().getAnimation() > 0) {
        holder.mView.startAnimation(AnimationUtils.loadAnimation(mActivity, GalleryFinal.getCoreConfig().getAnimation()));
    }
    holder.mIvFolderCheck.setImageResource(GalleryFinal.getGalleryTheme().getIconCheck());
    if (mSelectFolder == photoFolderInfo || (mSelectFolder == null && position == 0)) {
        holder.mIvFolderCheck.setVisibility(View.VISIBLE);
        holder.mIvFolderCheck.setColorFilter(GalleryFinal.getGalleryTheme().getCheckSelectedColor());
    } else {
        holder.mIvFolderCheck.setVisibility(View.GONE);
    }
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) Drawable(android.graphics.drawable.Drawable) PhotoFolderInfo(cn.finalteam.galleryfinal.model.PhotoFolderInfo)

Example 2 with PhotoFolderInfo

use of cn.finalteam.galleryfinal.model.PhotoFolderInfo in project GalleryFinal by pengjianbo.

the class PhotoTools method getAllPhotoFolder.

/**
     * 获取所有图片
     * @param context
     * @return
     */
public static List<PhotoFolderInfo> getAllPhotoFolder(Context context, List<PhotoInfo> selectPhotoMap) {
    List<PhotoFolderInfo> allFolderList = new ArrayList<>();
    final String[] projectionPhotos = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.ORIENTATION, MediaStore.Images.Thumbnails.DATA };
    final ArrayList<PhotoFolderInfo> allPhotoFolderList = new ArrayList<>();
    HashMap<Integer, PhotoFolderInfo> bucketMap = new HashMap<>();
    Cursor cursor = null;
    //所有图片
    PhotoFolderInfo allPhotoFolderInfo = new PhotoFolderInfo();
    allPhotoFolderInfo.setFolderId(0);
    allPhotoFolderInfo.setFolderName(context.getResources().getString(R.string.all_photo));
    allPhotoFolderInfo.setPhotoList(new ArrayList<PhotoInfo>());
    allPhotoFolderList.add(0, allPhotoFolderInfo);
    List<String> selectedList = GalleryFinal.getFunctionConfig().getSelectedList();
    List<String> filterList = GalleryFinal.getFunctionConfig().getFilterList();
    try {
        cursor = MediaStore.Images.Media.query(context.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
        if (cursor != null) {
            int bucketNameColumn = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
            final int bucketIdColumn = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
            while (cursor.moveToNext()) {
                int bucketId = cursor.getInt(bucketIdColumn);
                String bucketName = cursor.getString(bucketNameColumn);
                final int dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
                final int imageIdColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
                //int thumbImageColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
                final int imageId = cursor.getInt(imageIdColumn);
                final String path = cursor.getString(dataColumn);
                //final String thumb = cursor.getString(thumbImageColumn);
                File file = new File(path);
                if ((filterList == null || !filterList.contains(path)) && file.exists() && file.length() > 0) {
                    final PhotoInfo photoInfo = new PhotoInfo();
                    photoInfo.setPhotoId(imageId);
                    photoInfo.setPhotoPath(path);
                    //photoInfo.setThumbPath(thumb);
                    if (allPhotoFolderInfo.getCoverPhoto() == null) {
                        allPhotoFolderInfo.setCoverPhoto(photoInfo);
                    }
                    //添加到所有图片
                    allPhotoFolderInfo.getPhotoList().add(photoInfo);
                    //通过bucketId获取文件夹
                    PhotoFolderInfo photoFolderInfo = bucketMap.get(bucketId);
                    if (photoFolderInfo == null) {
                        photoFolderInfo = new PhotoFolderInfo();
                        photoFolderInfo.setPhotoList(new ArrayList<PhotoInfo>());
                        photoFolderInfo.setFolderId(bucketId);
                        photoFolderInfo.setFolderName(bucketName);
                        photoFolderInfo.setCoverPhoto(photoInfo);
                        bucketMap.put(bucketId, photoFolderInfo);
                        allPhotoFolderList.add(photoFolderInfo);
                    }
                    photoFolderInfo.getPhotoList().add(photoInfo);
                    if (selectedList != null && selectedList.size() > 0 && selectedList.contains(path)) {
                        selectPhotoMap.add(photoInfo);
                    }
                }
            }
        }
    } catch (Exception ex) {
        ILogger.e(ex);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    allFolderList.addAll(allPhotoFolderList);
    if (selectedList != null) {
        selectedList.clear();
    }
    return allFolderList;
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) PhotoFolderInfo(cn.finalteam.galleryfinal.model.PhotoFolderInfo) File(java.io.File)

Example 3 with PhotoFolderInfo

use of cn.finalteam.galleryfinal.model.PhotoFolderInfo in project GalleryFinal by pengjianbo.

the class PhotoSelectActivity method takeRefreshGallery.

/**
     * 解决在5.0手机上刷新Gallery问题,从startActivityForResult回到Activity把数据添加到集合中然后理解跳转到下一个页面,
     * adapter的getCount与list.size不一致,所以我这里用了延迟刷新数据
     * @param photoInfo
     */
private void takeRefreshGallery(PhotoInfo photoInfo) {
    mCurPhotoList.add(0, photoInfo);
    mPhotoListAdapter.notifyDataSetChanged();
    //添加到集合中
    List<PhotoInfo> photoInfoList = mAllPhotoFolderList.get(0).getPhotoList();
    if (photoInfoList == null) {
        photoInfoList = new ArrayList<>();
    }
    photoInfoList.add(0, photoInfo);
    mAllPhotoFolderList.get(0).setPhotoList(photoInfoList);
    if (mFolderListAdapter.getSelectFolder() != null) {
        PhotoFolderInfo photoFolderInfo = mFolderListAdapter.getSelectFolder();
        List<PhotoInfo> list = photoFolderInfo.getPhotoList();
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(0, photoInfo);
        if (list.size() == 1) {
            photoFolderInfo.setCoverPhoto(photoInfo);
        }
        mFolderListAdapter.getSelectFolder().setPhotoList(list);
    } else {
        String folderA = new File(photoInfo.getPhotoPath()).getParent();
        for (int i = 1; i < mAllPhotoFolderList.size(); i++) {
            PhotoFolderInfo folderInfo = mAllPhotoFolderList.get(i);
            String folderB = null;
            if (!StringUtils.isEmpty(photoInfo.getPhotoPath())) {
                folderB = new File(photoInfo.getPhotoPath()).getParent();
            }
            if (TextUtils.equals(folderA, folderB)) {
                List<PhotoInfo> list = folderInfo.getPhotoList();
                if (list == null) {
                    list = new ArrayList<>();
                }
                list.add(0, photoInfo);
                folderInfo.setPhotoList(list);
                if (list.size() == 1) {
                    folderInfo.setCoverPhoto(photoInfo);
                }
            }
        }
    }
    mFolderListAdapter.notifyDataSetChanged();
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) PhotoFolderInfo(cn.finalteam.galleryfinal.model.PhotoFolderInfo) File(java.io.File)

Example 4 with PhotoFolderInfo

use of cn.finalteam.galleryfinal.model.PhotoFolderInfo in project GalleryFinal by pengjianbo.

the class PhotoSelectActivity method folderItemClick.

private void folderItemClick(int position) {
    mLlFolderPanel.setVisibility(View.GONE);
    mCurPhotoList.clear();
    PhotoFolderInfo photoFolderInfo = mAllPhotoFolderList.get(position);
    if (photoFolderInfo.getPhotoList() != null) {
        mCurPhotoList.addAll(photoFolderInfo.getPhotoList());
    }
    mPhotoListAdapter.notifyDataSetChanged();
    if (position == 0) {
        mPhotoTargetFolder = null;
    } else {
        PhotoInfo photoInfo = photoFolderInfo.getCoverPhoto();
        if (photoInfo != null && !StringUtils.isEmpty(photoInfo.getPhotoPath())) {
            mPhotoTargetFolder = new File(photoInfo.getPhotoPath()).getParent();
        } else {
            mPhotoTargetFolder = null;
        }
    }
    mTvSubTitle.setText(photoFolderInfo.getFolderName());
    mFolderListAdapter.setSelectFolder(photoFolderInfo);
    mFolderListAdapter.notifyDataSetChanged();
    if (mCurPhotoList.size() == 0) {
        mTvEmptyView.setText(R.string.no_photo);
    }
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) PhotoFolderInfo(cn.finalteam.galleryfinal.model.PhotoFolderInfo) File(java.io.File)

Aggregations

PhotoFolderInfo (cn.finalteam.galleryfinal.model.PhotoFolderInfo)4 PhotoInfo (cn.finalteam.galleryfinal.model.PhotoInfo)4 File (java.io.File)3 Cursor (android.database.Cursor)1 Drawable (android.graphics.drawable.Drawable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1