Search in sources :

Example 11 with Category

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

the class EditCategoryPresenterImpl method handleMessage.

@Override
public boolean handleMessage(Message msg) {
    switch(msg.what) {
        case MESSAGE_RENAME_NONE:
            deleteCategories();
            return false;
        case MESSAGE_DELETE_NONE:
            sortCategories();
            return false;
        case MESSAGE_FINISH:
            if (mDeleteCategoryIdList.size() > 0) {
                EventBus.getDefault().post(new CategoryDeleteEvent());
            } else {
                EventBus.getDefault().post(new CategoryEditEvent());
            }
            mEditCategoryView.hideProgressBar();
            mEditCategoryView.finishActivity();
            return false;
        default:
            mCurrentMessage++;
            break;
    }
    if (mCurrentMessage == mRenameCategoryLabelMap.size()) {
        deleteCategories();
    } else if (mCurrentMessage == mRenameCategoryLabelMap.size() + mDeleteCategoryIdList.size()) {
        sortCategories();
    } else if (mCurrentMessage == mRenameCategoryLabelMap.size() + mDeleteCategoryIdList.size() + 1) {
        mRxCategory.getAllCategories().subscribe((categories -> {
            // todo 删除图片,删除PhotoNote
            boolean checked = false;
            for (Category category : categories) {
                checked |= category.isCheck();
            }
            if (!checked && categories.size() > 0) {
                categories.get(0).setCheck(true);
                mRxCategory.updateCategory(categories.get(0)).subscribe();
            }
        // todo 当所有的都没有了怎么办
        }), (throwable -> YLog.e(throwable)), () -> mHandler.sendEmptyMessage(MESSAGE_FINISH));
    }
    return false;
}
Also used : 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) Category(com.yydcdut.note.entity.Category) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryDeleteEvent(com.yydcdut.note.bus.CategoryDeleteEvent) CategoryEditEvent(com.yydcdut.note.bus.CategoryEditEvent)

Example 12 with Category

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

the class CheckService method checkCategoryPhotoNumber.

/**
 * 判断category中的photoNumber是否正确
 */
private void checkCategoryPhotoNumber() {
    mRxCategory.getAllCategories().subscribe(categories -> {
        for (Category category : categories) {
            mRxPhotoNote.findByCategoryId(category.getId(), ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNoteList1 -> {
                if (category.getPhotosNumber() != photoNoteList1.size()) {
                    category.setPhotosNumber(photoNoteList1.size());
                    mRxCategory.updateCategory(category).subscribe();
                }
            }, (throwable -> YLog.e(throwable)));
        }
    });
}
Also used : RxCategory(com.yydcdut.note.model.rx.RxCategory) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Intent(android.content.Intent) IBinder(android.os.IBinder) IntentService(android.app.IntentService) NoteApplication(com.yydcdut.note.NoteApplication) Const(com.yydcdut.note.utils.Const) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Schedulers(rx.schedulers.Schedulers) PhotoNote(com.yydcdut.note.entity.PhotoNote) Nullable(android.support.annotation.Nullable) YLog(com.yydcdut.note.utils.YLog) RxCategory(com.yydcdut.note.model.rx.RxCategory) Category(com.yydcdut.note.entity.Category)

Example 13 with Category

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

the class AlbumFragment method showAddCategoryDialog.

/**
 * 添加category的dialog
 */
private void showAddCategoryDialog() {
    View v = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edittext, null);
    final EditText editText = (EditText) v.findViewById(R.id.edit_dialog);
    new AlertDialog.Builder(getContext(), R.style.note_dialog).setTitle(R.string.dialog_title_new).setCancelable(false).setView(v).setPositiveButton(R.string.dialog_btn_ok, (dialog, which) -> mAlbumPresenter.createCategory(editText.getText().toString())).setNegativeButton(R.string.dialog_btn_cancel, (dialog, which) -> dialog.dismiss()).show();
}
Also used : EditText(android.widget.EditText) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) Uri(android.net.Uri) AlbumPresenterImpl(com.yydcdut.note.presenters.home.impl.AlbumPresenterImpl) Animator(android.animation.Animator) OnClick(butterknife.OnClick) BindView(butterknife.BindView) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) Category(com.yydcdut.note.entity.Category) View(android.view.View) AlbumAdapter(com.yydcdut.note.adapter.recycler.AlbumAdapter) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) BaseFragment(com.yydcdut.note.views.BaseFragment) RequestType(com.yydcdut.note.aspect.permission.RequestType) SettingActivity(com.yydcdut.note.views.setting.impl.SettingActivity) IntentFilter(android.content.IntentFilter) GalleryActivity(com.yydcdut.note.views.gallery.impl.GalleryActivity) BroadcastReceiver(android.content.BroadcastReceiver) CircleProgressBarLayout(com.yydcdut.note.widget.CircleProgressBarLayout) ViewGroup(android.view.ViewGroup) List(java.util.List) Context(android.content.Context) ButterKnife(butterknife.ButterKnife) Intent(android.content.Intent) SandBoxService(com.yydcdut.note.service.SandBoxService) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) Const(com.yydcdut.note.utils.Const) MenuInflater(android.view.MenuInflater) MotionEvent(android.view.MotionEvent) RevealView(com.yydcdut.note.widget.RevealView) Toast(android.widget.Toast) CameraActivity(com.yydcdut.note.views.camera.impl.CameraActivity) Menu(android.view.Menu) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) FloatingActionsMenu(com.yydcdut.note.widget.fab.FloatingActionsMenu) LayoutInflater(android.view.LayoutInflater) Point(android.graphics.Point) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) File(java.io.File) PhotoViewHolder(com.yydcdut.note.adapter.recycler.vh.PhotoViewHolder) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) ViewTreeObserver(android.view.ViewTreeObserver) PhotoNote(com.yydcdut.note.entity.PhotoNote) DetailActivity(com.yydcdut.note.views.note.impl.DetailActivity) Activity(android.app.Activity) EditText(android.widget.EditText) BindView(butterknife.BindView) View(android.view.View) IAlbumView(com.yydcdut.note.views.home.IAlbumView) RevealView(com.yydcdut.note.widget.RevealView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 14 with Category

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

the class CategoryDBTest method testUpdateCategory.

public void testUpdateCategory() {
    CategoryDB categoryDB = new CategoryDB(this.getInstrumentation().getTargetContext());
    List<Category> categoryList = categoryDB.findAll();
    Category category = categoryList.get(0);
    category.setLabel("789456");
    mRxCategory.updateCategory(category).subscribe(new Subscriber<List<Category>>() {

        @Override
        public void onCompleted() {
            YLog.i("yuyidong", "onCompleted");
        }

        @Override
        public void onError(Throwable e) {
            YLog.i("yuyidong", "onError,,,e--->" + e.getMessage());
        }

        @Override
        public void onNext(List<Category> categories) {
            YLog.i("yuyidong", "categories.size()--->" + categories.size());
            for (Category category : categories) {
                YLog.i("yuyidong", category.toString());
            }
        }
    });
}
Also used : RxCategory(com.yydcdut.note.model.rx.RxCategory) Category(com.yydcdut.note.entity.Category) CategoryDB(com.yydcdut.note.model.dao.CategoryDB) List(java.util.List)

Aggregations

Category (com.yydcdut.note.entity.Category)14 Context (android.content.Context)8 Inject (javax.inject.Inject)8 ContextLife (com.yydcdut.note.injector.ContextLife)7 RxCategory (com.yydcdut.note.model.rx.RxCategory)7 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)7 List (java.util.List)7 Handler (android.os.Handler)6 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)6 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)6 YLog (com.yydcdut.note.utils.YLog)6 PhotoNote (com.yydcdut.note.entity.PhotoNote)5 IView (com.yydcdut.note.views.IView)5 EventBus (org.greenrobot.eventbus.EventBus)5 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)5 Schedulers (rx.schedulers.Schedulers)5 Intent (android.content.Intent)4 R (com.yydcdut.note.R)4 CategoryDeleteEvent (com.yydcdut.note.bus.CategoryDeleteEvent)4 CategoryEditEvent (com.yydcdut.note.bus.CategoryEditEvent)4