Search in sources :

Example 16 with GojuonItem

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem in project MyJapanese by 54wall.

the class GojuonFragmentModelImpl method getData.

@Override
public void getData(final int category, Consumer<List<GojuonItem>> consumer) {
    Disposable disposable = Observable.create(new ObservableOnSubscribe<List<GojuonItem>>() {

        @Override
        public void subscribe(ObservableEmitter<List<GojuonItem>> emitter) throws Exception {
            List<GojuonItem> list;
            switch(category) {
                case Constants.CATEGORY_QINGYIN:
                    list = DBManager.getInstance().getQingYin();
                    break;
                case Constants.CATEGORY_ZHUOYIN:
                    list = DBManager.getInstance().getZhuoYin();
                    break;
                case Constants.CATEGORY_AOYIN:
                    list = DBManager.getInstance().getAoYin();
                    break;
                default:
                    list = null;
                    break;
            }
            if (list == null) {
                emitter.onError(new Exception());
            } else {
                emitter.onNext(list);
            }
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
    mCompositeDisposable.add(disposable);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 17 with GojuonItem

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem in project MyJapanese by 54wall.

the class PuzzleActivityPresenterImpl method loadData.

@Override
public void loadData() {
    List<GojuonItem> items = model.getItems();
    List<GojuonItem> jams = new ArrayList<>();
    GojuonItem current = items.get(0);
    jams.add(items.get(1));
    jams.add(items.get(2));
    jams.add(items.get(3));
    view.setData(current, jams);
}
Also used : ArrayList(java.util.ArrayList) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)

Example 18 with GojuonItem

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem in project MyJapanese by 54wall.

the class MemoryFragment method setData.

@Override
public void setData(List<GojuonItem> data) {
    if (adapter == null) {
        adapter = new MemorySwipeAdapter(data);
        adapter.setOnWriteButtonClickListener(new MemorySwipeAdapter.OnWriteButtonClickListener() {

            @Override
            public void onClick(GojuonItem item) {
                GojuonGif gif = GifManager.getInstance().getJPGif(item.getRome());
                if (gif != null) {
                    new ImageDialog.Builder(getContext()).setResId(gif.getHiragana()).override((int) ResourceUtils.getDimension(getContext(), R.dimen.dialog_width), (int) ResourceUtils.getDimension(getContext(), R.dimen.dialog_height)).create().show();
                }
            }
        });
        adapter.setOnYinButtonClickListener(new MemorySwipeAdapter.OnYinButtonClickListener() {

            @Override
            public void onClick(GojuonItem item) {
                SoundPoolManager.getInstance().play(item.getRome());
            }
        });
    }
    adapter.setList(data);
    mSwipeFlingAdapterView.setAdapter(adapter);
}
Also used : ImageDialog(pri.weiqaing.common.widget.dialog.ImageDialog) GojuonGif(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonGif) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem) MemorySwipeAdapter(pri.weiqiang.liyujapanese.ui.adapter.MemorySwipeAdapter)

Example 19 with GojuonItem

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem in project MyJapanese by 54wall.

the class GojuonRecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    GojuonItem item = list.get(position);
    if (BaseApplication.TYPE_MING == Constants.TYPE_HIRAGANA) {
        holder.tv_jiaming.setText(item.getHiragana());
    } else {
        holder.tv_jiaming.setText(item.getKatakana());
    }
    if (holder.tv_rome != null) {
        holder.tv_rome.setText(item.getRome());
    }
    holder.item = item;
    if (getItemViewType(position) == Constants.TYPE_ITEM && holder.item.isExisted()) {
        holder.view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onClick(holder.item);
                }
            }
        });
        if (holder.item.getCategory() != Constants.CATEGORY_AOYIN) {
            holder.view.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    if (onItemLongClickListener != null) {
                        onItemLongClickListener.onLongClick(holder.item);
                    }
                    return true;
                }
            });
        }
    }
}
Also used : TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)

Example 20 with GojuonItem

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem in project LiYuJapanese by 54wall.

the class MemoryFragment method setData.

@Override
public void setData(List<GojuonItem> data) {
    if (adapter == null) {
        adapter = new MemorySwipeAdapter(data);
        adapter.setOnWriteButtonClickListener(new MemorySwipeAdapter.OnWriteButtonClickListener() {

            @Override
            public void onClick(GojuonItem item) {
                GojuonGif gif = GifManager.getInstance().getJPGif(item.getRome());
                if (gif != null) {
                    new ImageDialog.Builder(getContext()).setResId(gif.getHiragana()).override((int) ResourceUtils.getDimension(getContext(), R.dimen.dialog_width), (int) ResourceUtils.getDimension(getContext(), R.dimen.dialog_height)).create().show();
                }
            }
        });
        adapter.setOnYinButtonClickListener(new MemorySwipeAdapter.OnYinButtonClickListener() {

            @Override
            public void onClick(GojuonItem item) {
                SoundPoolManager.getInstance().play(item.getRome());
            }
        });
    }
    adapter.setList(data);
    mSwipeFlingAdapterView.setAdapter(adapter);
}
Also used : ImageDialog(pri.weiqaing.common.widget.dialog.ImageDialog) GojuonGif(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonGif) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem) MemorySwipeAdapter(pri.weiqiang.liyujapanese.ui.adapter.MemorySwipeAdapter)

Aggregations

GojuonItem (pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)28 GojuonItemComporator (pri.weiqiang.liyujapanese.comparator.GojuonItemComporator)6 View (android.view.View)4 TextView (android.widget.TextView)4 ImageDialog (pri.weiqaing.common.widget.dialog.ImageDialog)4 GojuonGif (pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonGif)4 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 ObservableEmitter (io.reactivex.ObservableEmitter)2 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)2 Disposable (io.reactivex.disposables.Disposable)2 ArrayList (java.util.ArrayList)2 GojuonRecyclerAdapter (pri.weiqiang.liyujapanese.ui.adapter.GojuonRecyclerAdapter)2 MemorySwipeAdapter (pri.weiqiang.liyujapanese.ui.adapter.MemorySwipeAdapter)2