Search in sources :

Example 1 with MediaPhoto

use of com.yydcdut.noteplugin.bean.MediaPhoto in project PhotoNoter by yydcdut.

the class PhotoModel method findByMedia.

@NonNull
public Map<String, MediaFolder> findByMedia(@NonNull Context context) {
    WeakReference<Context> contextWeakReference = new WeakReference<>(context);
    if (mMediaCache == null) {
        mMediaCache = new HashMap<>();
        MediaFolder mediaFolder4All = new MediaFolder(MediaFolder.ALL, new ArrayList<MediaPhoto>());
        mMediaCache.put(MediaFolder.ALL, mediaFolder4All);
        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 };
        Cursor cursor = MediaStore.Images.Media.query(contextWeakReference.get().getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
        if (cursor == null) {
            return mMediaCache;
        }
        while (cursor.moveToNext()) {
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
            String thumb = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
            File file = new File(path);
            if (file.exists() && file.length() > 0) {
                MediaPhoto mediaPhoto = new MediaPhoto(path, thumb);
                String folderName = file.getParentFile().getName();
                MediaFolder mediaFolder = mMediaCache.get(folderName);
                if (mediaFolder == null) {
                    List<MediaPhoto> mediaPhotoList = new ArrayList<>();
                    mediaPhotoList.add(mediaPhoto);
                    mediaFolder = new MediaFolder(folderName, mediaPhotoList);
                    mMediaCache.put(folderName, mediaFolder);
                } else {
                    mediaFolder.getMediaPhotoList().add(mediaPhoto);
                }
                mediaFolder4All.getMediaPhotoList().add(mediaPhoto);
            }
        }
    }
    contextWeakReference.clear();
    return mMediaCache;
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) MediaFolder(com.yydcdut.noteplugin.bean.MediaFolder) Cursor(android.database.Cursor) WeakReference(java.lang.ref.WeakReference) MediaPhoto(com.yydcdut.noteplugin.bean.MediaPhoto) File(java.io.File) TreeFile(com.yydcdut.noteplugin.bean.TreeFile) NonNull(android.support.annotation.NonNull)

Example 2 with MediaPhoto

use of com.yydcdut.noteplugin.bean.MediaPhoto in project PhotoNoter by yydcdut.

the class MediaPhotoAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MediaPhotoViewHolder holder, int position) {
    MediaPhoto mediaPhoto = mMediaPhotoList.get(position);
    if (SelectPhotoModel.getInstance().contains(mediaPhoto.getPath())) {
        holder.checkBox.setCheckedWithoutCallback(true);
    } else {
        holder.checkBox.setCheckedWithoutCallback(false);
    }
    holder.imageView.setImageResource(R.drawable.ic_gf_default_photo);
    ImageLoader.getInstance().displayImage("file:/" + mediaPhoto.getThumbPath(), holder.imageView);
}
Also used : MediaPhoto(com.yydcdut.noteplugin.bean.MediaPhoto)

Example 3 with MediaPhoto

use of com.yydcdut.noteplugin.bean.MediaPhoto in project PhotoNoter by yydcdut.

the class PhotoDetailActivity method initViewPager.

private void initViewPager() {
    PhotoDetailPagerAdapter photoDetailPagerAdapter;
    if (isPreviewSelected) {
        mAdapterPathList = new ArrayList<>(SelectPhotoModel.getInstance().getCount());
        for (int i = 0; i < SelectPhotoModel.getInstance().getCount(); i++) {
            mAdapterPathList.add(SelectPhotoModel.getInstance().get(i));
        }
        photoDetailPagerAdapter = new PhotoDetailPagerAdapter(mAdapterPathList);
        mViewPager.setAdapter(photoDetailPagerAdapter);
        mPhotoCheckBox.setCheckedWithoutCallback(true);
    } else {
        int initPage = getIntent().getIntExtra(INTENT_PAGE, 0);
        String folderName = getIntent().getStringExtra(INTENT_FOLDER);
        List<MediaPhoto> mediaPhotoList = PhotoModel.getInstance().findByMedia(this).get(folderName).getMediaPhotoList();
        mAdapterPathList = new ArrayList<>(mediaPhotoList.size());
        for (MediaPhoto mediaPhoto : mediaPhotoList) {
            mAdapterPathList.add(mediaPhoto.getPath());
        }
        photoDetailPagerAdapter = new PhotoDetailPagerAdapter(mAdapterPathList);
        mViewPager.setAdapter(photoDetailPagerAdapter);
        mViewPager.setCurrentItem(initPage);
        for (int i = 0; i < SelectPhotoModel.getInstance().getCount(); i++) {
            String selectedPath = SelectPhotoModel.getInstance().get(i);
            if (selectedPath.equals(mAdapterPathList.get(initPage))) {
                mPhotoCheckBox.setCheckedWithoutCallback(true);
                break;
            }
        }
    }
    photoDetailPagerAdapter.setOnPhotoClickListener(this);
}
Also used : PhotoDetailPagerAdapter(com.yydcdut.noteplugin.adapter.PhotoDetailPagerAdapter) MediaPhoto(com.yydcdut.noteplugin.bean.MediaPhoto)

Aggregations

MediaPhoto (com.yydcdut.noteplugin.bean.MediaPhoto)3 Context (android.content.Context)1 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1 PhotoDetailPagerAdapter (com.yydcdut.noteplugin.adapter.PhotoDetailPagerAdapter)1 MediaFolder (com.yydcdut.noteplugin.bean.MediaFolder)1 TreeFile (com.yydcdut.noteplugin.bean.TreeFile)1 File (java.io.File)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1