Search in sources :

Example 1 with PhotoNoteDeleteEvent

use of com.yydcdut.note.bus.PhotoNoteDeleteEvent in project PhotoNoter by yydcdut.

the class AlbumPresenterImpl method deletePhotos.

@Override
public void deletePhotos() {
    //注意java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
    mRxPhotoNote.findByCategoryId(mCategoryId, mAlbumSortKind).observeOn(AndroidSchedulers.mainThread()).subscribe(photoNoteList -> {
        TreeMap<Integer, PhotoNote> map = getTreeMap();
        for (int i = 0; i < photoNoteList.size(); i++) {
            PhotoNote photoNote = photoNoteList.get(i);
            if (photoNote.isSelected()) {
                map.put(i, photoNote);
            }
        }
        int times = 0;
        for (Map.Entry<Integer, PhotoNote> entry : map.entrySet()) {
            photoNoteList.remove(entry.getValue());
            mAlbumView.notifyItemRemoved(entry.getKey() - times);
            times++;
            mRxPhotoNote.deletePhotoNote(entry.getValue()).subscribe(photoNotes -> {
                FilePathUtils.deleteAllFiles(entry.getValue().getPhotoName());
                mAlbumView.updateDataNoChange(photoNoteList);
            }, (throwable -> YLog.e(throwable)));
        }
        EventBus.getDefault().post(new PhotoNoteDeleteEvent());
    }, (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) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

Fragment (android.app.Fragment)1 ContentResolver (android.content.ContentResolver)1 Context (android.content.Context)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 TextUtils (android.text.TextUtils)1 R (com.yydcdut.note.R)1 CategoryCreateEvent (com.yydcdut.note.bus.CategoryCreateEvent)1 CategoryMoveEvent (com.yydcdut.note.bus.CategoryMoveEvent)1 PhotoNoteCreateEvent (com.yydcdut.note.bus.PhotoNoteCreateEvent)1 PhotoNoteDeleteEvent (com.yydcdut.note.bus.PhotoNoteDeleteEvent)1 Category (com.yydcdut.note.entity.Category)1 PhotoNote (com.yydcdut.note.entity.PhotoNote)1 ContextLife (com.yydcdut.note.injector.ContextLife)1 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)1 RxCategory (com.yydcdut.note.model.rx.RxCategory)1 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)1 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)1 IAlbumPresenter (com.yydcdut.note.presenters.home.IAlbumPresenter)1 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)1