Search in sources :

Example 1 with MediaPhoto

use of com.yydcdut.note.entity.gallery.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 (mSelectPhotoModel.contains(mediaPhoto.getPath())) {
        holder.checkBox.setCheckedWithoutCallback(true);
    } else {
        holder.checkBox.setCheckedWithoutCallback(false);
    }
    holder.imageView.setImageDrawable(new ColorDrawable(Color.rgb(mRandom.nextInt(255), mRandom.nextInt(255), mRandom.nextInt(255))));
    ImageLoaderManager.displayImage("file:/" + mediaPhoto.getThumbPath(), holder.imageView, ImageLoaderManager.getGalleryOptions());
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) MediaPhoto(com.yydcdut.note.entity.gallery.MediaPhoto)

Example 2 with MediaPhoto

use of com.yydcdut.note.entity.gallery.MediaPhoto in project PhotoNoter by yydcdut.

the class RxGalleryPhotos method findInDatabase.

private void findInDatabase(MediaFolder 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(mContext.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
    if (cursor == null) {
        return;
    }
    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);
        }
    }
}
Also used : MediaPhoto(com.yydcdut.note.entity.gallery.MediaPhoto) ArrayList(java.util.ArrayList) MediaFolder(com.yydcdut.note.entity.gallery.MediaFolder) Cursor(android.database.Cursor) File(java.io.File)

Example 3 with MediaPhoto

use of com.yydcdut.note.entity.gallery.MediaPhoto in project PhotoNoter by yydcdut.

the class PhotoDetailPresenterImpl method initViewPager.

@Override
public void initViewPager() {
    if (isPreviewSelected) {
        List<String> selectedPathList = null;
        mAdapterPathList = new ArrayList<>(mSelectPhotoModel.getCount());
        for (int i = 0; i < mSelectPhotoModel.getCount(); i++) {
            mAdapterPathList.add(mSelectPhotoModel.get(i));
        }
        mPhotoDetailView.setAdapter(mAdapterPathList, mInitPage);
        mPhotoDetailView.initAdapterData(isPreviewSelected, selectedPathList);
        mPhotoDetailView.setToolbarTitle((mPhotoDetailView.getCurrentPosition() + 1) + "/" + mAdapterPathList.size());
    } else {
        mRxGalleryPhotos.findByMedia().observeOn(AndroidSchedulers.mainThread()).subscribe(stringMediaFolderMap -> {
            List<MediaPhoto> mediaPhotoList = stringMediaFolderMap.get(mFolderName).getMediaPhotoList();
            List<String> selectedPathList = null;
            mAdapterPathList = new ArrayList<>(mediaPhotoList.size());
            for (MediaPhoto mediaPhoto : mediaPhotoList) {
                mAdapterPathList.add(mediaPhoto.getPath());
            }
            selectedPathList = new ArrayList<>(mSelectPhotoModel.getCount());
            for (int i = 0; i < mSelectPhotoModel.getCount(); i++) {
                selectedPathList.add(mSelectPhotoModel.get(i));
            }
            mPhotoDetailView.setAdapter(mAdapterPathList, mInitPage);
            mPhotoDetailView.initAdapterData(isPreviewSelected, selectedPathList);
            mPhotoDetailView.setToolbarTitle((mPhotoDetailView.getCurrentPosition() + 1) + "/" + mAdapterPathList.size());
        }, (throwable -> YLog.e(throwable)));
    }
}
Also used : MediaPhoto(com.yydcdut.note.entity.gallery.MediaPhoto) Context(android.content.Context) IPhotoDetailView(com.yydcdut.note.views.gallery.IPhotoDetailView) IPhotoDetailPresenter(com.yydcdut.note.presenters.gallery.IPhotoDetailPresenter) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) RxGalleryPhotos(com.yydcdut.note.model.gallery.RxGalleryPhotos) NonNull(android.support.annotation.NonNull) SelectPhotoModel(com.yydcdut.note.model.gallery.SelectPhotoModel) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) ContextLife(com.yydcdut.note.injector.ContextLife) R(com.yydcdut.note.R) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) MediaPhoto(com.yydcdut.note.entity.gallery.MediaPhoto)

Example 4 with MediaPhoto

use of com.yydcdut.note.entity.gallery.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.note.entity.gallery.MediaFolder) Cursor(android.database.Cursor) WeakReference(java.lang.ref.WeakReference) MediaPhoto(com.yydcdut.note.entity.gallery.MediaPhoto) File(java.io.File) NonNull(android.support.annotation.NonNull)

Example 5 with MediaPhoto

use of com.yydcdut.note.entity.gallery.MediaPhoto in project PhotoNoter by yydcdut.

the class RxGalleryPhotos method findByMedia.

@NonNull
public Observable<Map<String, MediaFolder>> findByMedia() {
    return Observable.create(new Observable.OnSubscribe<Map<String, MediaFolder>>() {

        @Override
        public void call(Subscriber<? super Map<String, MediaFolder>> subscriber) {
            if (mMediaCache == null || mMediaCache.size() == 0) {
                mMediaCache = new HashMap<>();
                MediaFolder mediaFolder4All = new MediaFolder(MediaFolder.ALL, new ArrayList<MediaPhoto>());
                mMediaCache.put(MediaFolder.ALL, mediaFolder4All);
                findInDatabase(mediaFolder4All);
            }
            subscriber.onNext(mMediaCache);
        }
    }).subscribeOn(Schedulers.io());
}
Also used : Subscriber(rx.Subscriber) MediaPhoto(com.yydcdut.note.entity.gallery.MediaPhoto) MediaFolder(com.yydcdut.note.entity.gallery.MediaFolder) HashMap(java.util.HashMap) Map(java.util.Map) NonNull(android.support.annotation.NonNull)

Aggregations

MediaPhoto (com.yydcdut.note.entity.gallery.MediaPhoto)5 NonNull (android.support.annotation.NonNull)3 MediaFolder (com.yydcdut.note.entity.gallery.MediaFolder)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 Cursor (android.database.Cursor)2 File (java.io.File)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 R (com.yydcdut.note.R)1 ContextLife (com.yydcdut.note.injector.ContextLife)1 RxGalleryPhotos (com.yydcdut.note.model.gallery.RxGalleryPhotos)1 SelectPhotoModel (com.yydcdut.note.model.gallery.SelectPhotoModel)1 IPhotoDetailPresenter (com.yydcdut.note.presenters.gallery.IPhotoDetailPresenter)1 YLog (com.yydcdut.note.utils.YLog)1 IView (com.yydcdut.note.views.IView)1 IPhotoDetailView (com.yydcdut.note.views.gallery.IPhotoDetailView)1 WeakReference (java.lang.ref.WeakReference)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1