Search in sources :

Example 6 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class SandBoxServicePresenterImpl method makePhoto.

/**
     * 做图
     *
     * @param sandPhoto
     */
private void makePhoto(SandPhoto sandPhoto) {
    byte[] rowData = getDataFromFile(sandPhoto.getFileName(), sandPhoto.getSize());
    if (rowData == null) {
        return;
    }
    byte[] data;
    if (sandPhoto.getImageFormat() == ImageFormat.JPEG) {
        data = rowData;
    } else {
        data = decodeNV21(rowData, sandPhoto.getSandExif().getImageWidth(), sandPhoto.getSandExif().getImageLength());
    }
    if (data == null) {
        return;
    }
    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    } catch (OutOfMemoryError e) {
        YLog.e(e);
    }
    String fileName = sandPhoto.getTime() + ".jpg";
    if (FilePathUtils.savePhoto(fileName, bitmap)) {
        FilePathUtils.saveSmallPhoto(fileName, bitmap);
    }
    PhotoNote photoNote = new PhotoNote(fileName, sandPhoto.getTime(), sandPhoto.getTime(), "", "", sandPhoto.getTime(), sandPhoto.getTime(), sandPhoto.getCategoryId());
    photoNote.setPaletteColor(Utils.getPaletteColor(bitmap));
    mRxPhotoNote.savePhotoNote(photoNote).subscribe(photoNote1 -> {
    }, (throwable -> YLog.e(throwable)));
    try {
        setExif(photoNote, sandPhoto.getSandExif(), sandPhoto.getCameraId(), sandPhoto.isMirror());
    } catch (IOException e) {
        YLog.e(e);
    }
    deleteFromDBAndSDCard(sandPhoto);
    //        bitmap.recycle();
    System.gc();
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) Rect(android.graphics.Rect) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SandPhoto(com.yydcdut.note.entity.SandPhoto) BitmapFactory(android.graphics.BitmapFactory) ExifInterface(android.media.ExifInterface) Observable(rx.Observable) Inject(javax.inject.Inject) Const(com.yydcdut.note.utils.Const) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Utils(com.yydcdut.note.utils.Utils) ImageFormat(android.graphics.ImageFormat) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SandExif(com.yydcdut.note.entity.SandExif) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Message(android.os.Message) Bitmap(android.graphics.Bitmap) YuvImage(android.graphics.YuvImage) ISandBoxServiceView(com.yydcdut.note.views.service.ISandBoxServiceView) PhotoNote(com.yydcdut.note.entity.PhotoNote) ISandBoxServicePresenter(com.yydcdut.note.presenters.service.ISandBoxServicePresenter) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) InputStream(java.io.InputStream) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException)

Example 7 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class AlbumPresenterImpl method changePhotosCategory.

@Override
public void changePhotosCategory(int toCategoryId) {
    if (mCategoryId != toCategoryId) {
        mRxPhotoNote.findByCategoryId(mCategoryId, mAlbumSortKind).observeOn(AndroidSchedulers.mainThread()).map(photoNoteList -> {
            TreeMap<Integer, PhotoNote> map = getTreeMap();
            for (int i = 0; i < photoNoteList.size(); i++) {
                PhotoNote photoNote = photoNoteList.get(i);
                if (photoNote.isSelected()) {
                    photoNote.setSelected(false);
                    photoNote.setCategoryId(toCategoryId);
                    map.put(i, photoNote);
                }
            }
            int times = 0;
            for (Map.Entry<Integer, PhotoNote> entry : map.entrySet()) {
                photoNoteList.remove(entry.getValue());
                mAlbumView.notifyItemRemoved(entry.getKey() - times);
                mRxPhotoNote.updatePhotoNote(entry.getValue()).subscribe((photoNotes -> {
                }), (throwable -> YLog.e(throwable)));
                times++;
            }
            return map.size();
        }).subscribe(integer -> {
            mRxCategory.updateChangeCategory(mCategoryId, toCategoryId, integer).subscribe(categories -> {
                mRxPhotoNote.refreshByCategoryId(mCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe((photoNoteList) -> mAlbumView.updateDataNoChange(photoNoteList), (throwable -> YLog.e(throwable)));
                mRxPhotoNote.refreshByCategoryId(toCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNotes -> {
                }, (throwable -> YLog.e(throwable)));
                EventBus.getDefault().post(new CategoryMoveEvent());
            }, (throwable -> YLog.e(throwable)));
        }, (throwable -> YLog.e(throwable)));
    }
}
Also used : Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Uri(android.net.Uri) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) ContentResolver(android.content.ContentResolver) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) Fragment(android.app.Fragment) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) Subscriber(rx.Subscriber) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) LocalStorageUtils(com.yydcdut.note.utils.LocalStorageUtils) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IAlbumPresenter(com.yydcdut.note.presenters.home.IAlbumPresenter) List(java.util.List) Permission(com.yydcdut.note.utils.permission.Permission) TreeMap(java.util.TreeMap) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) Comparator(java.util.Comparator) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) TreeMap(java.util.TreeMap) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent)

Example 8 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class EditCategoryPresenterImpl method deleteCategories.

/**
     * 删除分类
     */
private void deleteCategories() {
    if (mDeleteCategoryIdList.size() > 0) {
        mRxCategory.refreshCategories().observeOn(Schedulers.io()).subscribe(categories -> {
            for (int id : mDeleteCategoryIdList) {
                mRxPhotoNote.findByCategoryId(id, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNoteList -> {
                    for (PhotoNote photoNote : photoNoteList) {
                        FilePathUtils.deleteAllFiles(photoNote.getPhotoName());
                    }
                    mRxPhotoNote.deletePhotoNotes(photoNoteList, id).subscribe((photoNoteList2 -> {
                    }), (throwable -> YLog.e(throwable)));
                }, (throwable -> YLog.e(throwable)));
                mRxCategory.delete(id).subscribe(categories2 -> mHandler.sendEmptyMessage(1), (throwable -> YLog.e(throwable)));
            }
        }, (throwable -> YLog.e(throwable)));
    } else {
        mHandler.sendEmptyMessage(MESSAGE_DELETE_NONE);
    }
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) HashMap(java.util.HashMap) IEditCategoryPresenter(com.yydcdut.note.presenters.setting.IEditCategoryPresenter) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Schedulers(rx.schedulers.Schedulers) R(com.yydcdut.note.R) RxCategory(com.yydcdut.note.model.rx.RxCategory) Iterator(java.util.Iterator) CategoryEditEvent(com.yydcdut.note.bus.CategoryEditEvent) IEditCategoryView(com.yydcdut.note.views.setting.IEditCategoryView) List(java.util.List) Message(android.os.Message) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) CategoryDeleteEvent(com.yydcdut.note.bus.CategoryDeleteEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView)

Example 9 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class AlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(PhotoViewHolder holder, int position) {
    PhotoNote photoNote = mPhotoNoteList.get(position);
    if (photoNote.isSelected()) {
        holder.checkLayout.setVisibility(View.VISIBLE);
    } else {
        holder.checkLayout.setVisibility(View.INVISIBLE);
    }
    ImageLoaderManager.displayImage(photoNote.getSmallPhotoPathWithFile(), holder.imageView);
    int color = photoNote.getPaletteColor();
    AppCompat.setBackgroundDrawable(holder.checkLayout, new ColorDrawable(Color.argb(0x70, Color.red(color), Color.green(color), Color.blue(color))));
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote) ColorDrawable(android.graphics.drawable.ColorDrawable)

Example 10 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class AlbumPresenterImpl method savePhotoFromLocal.

@Override
public void savePhotoFromLocal(final Uri imageUri) {
    PhotoNote photoNote = new PhotoNote(System.currentTimeMillis() + ".jpg", System.currentTimeMillis(), System.currentTimeMillis(), "", "", System.currentTimeMillis(), System.currentTimeMillis(), mCategoryId);
    mRxPhotoNote.savePhotoNote(photoNote).map(photoNote1 -> {
        ContentResolver cr = mContext.getContentResolver();
        try {
            FilePathUtils.copyFile(cr.openInputStream(imageUri), photoNote1.getBigPhotoPathWithoutFile());
            FilePathUtils.saveSmallPhotoFromBigPhoto(photoNote1.getBigPhotoPathWithFile(), photoNote1.getPhotoName());
        } catch (FileNotFoundException e) {
            YLog.e(e);
        } catch (IOException e) {
            YLog.e(e);
        }
        photoNote1.setPaletteColor(Utils.getPaletteColor(ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
        mRxPhotoNote.updatePhotoNote(photoNote1).subscribe(photoNotes -> {
        }, (throwable -> YLog.e(throwable)));
        return photoNote1;
    }).doOnSubscribe(() -> mAlbumView.showProgressBar()).subscribeOn(AndroidSchedulers.mainThread()).subscribe(photoNote2 -> {
        EventBus.getDefault().post(new PhotoNoteCreateEvent());
        mRxPhotoNote.findByCategoryId(mCategoryId, mAlbumSortKind).observeOn(AndroidSchedulers.mainThread()).subscribe(photoNoteList -> {
            mAlbumView.updateData(photoNoteList);
            switch(mAlbumSortKind) {
                case ComparatorFactory.FACTORY_CREATE_CLOSE:
                case ComparatorFactory.FACTORY_EDITED_CLOSE:
                    mAlbumView.notifyItemInserted(photoNoteList.size() - 1);
                    break;
                case ComparatorFactory.FACTORY_CREATE_FAR:
                case ComparatorFactory.FACTORY_EDITED_FAR:
                    mAlbumView.notifyItemInserted(0);
                    break;
            }
            mAlbumView.hideProgressBar();
        });
    }, (throwable -> YLog.e(throwable)));
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Uri(android.net.Uri) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) ContentResolver(android.content.ContentResolver) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) Fragment(android.app.Fragment) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) Subscriber(rx.Subscriber) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) LocalStorageUtils(com.yydcdut.note.utils.LocalStorageUtils) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IAlbumPresenter(com.yydcdut.note.presenters.home.IAlbumPresenter) List(java.util.List) Permission(com.yydcdut.note.utils.permission.Permission) TreeMap(java.util.TreeMap) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) Comparator(java.util.Comparator) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ContentResolver(android.content.ContentResolver)

Aggregations

PhotoNote (com.yydcdut.note.entity.PhotoNote)18 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)10 Context (android.content.Context)8 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)8 YLog (com.yydcdut.note.utils.YLog)8 IView (com.yydcdut.note.views.IView)8 ArrayList (java.util.ArrayList)8 Inject (javax.inject.Inject)8 Handler (android.os.Handler)7 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)7 Utils (com.yydcdut.note.utils.Utils)7 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 List (java.util.List)7 R (com.yydcdut.note.R)6 Category (com.yydcdut.note.entity.Category)6 ContextLife (com.yydcdut.note.injector.ContextLife)6 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)6 RxCategory (com.yydcdut.note.model.rx.RxCategory)6 Map (java.util.Map)6