Search in sources :

Example 6 with GojuonItem

use of pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem in project LiYuJapanese 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 7 with GojuonItem

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

the class DBManager method getZhuoYinWithoutHeader.

public List<GojuonItem> getZhuoYinWithoutHeader() {
    if (zhuoYinWithoutHeader == null) {
        zhuoYinWithoutHeader = new ArrayList<>();
        List<GojuonItem> query = getZhuoYin();
        for (GojuonItem item : query) {
            if (item.getRow() != 0 && item.getColumn() != 0 && item.isExisted()) {
                zhuoYinWithoutHeader.add(item);
            }
        }
    }
    return zhuoYinWithoutHeader;
}
Also used : GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)

Example 8 with GojuonItem

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

the class MemorySwipeAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    final GojuonItem item = list.get(position);
    if (convertView == null) {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_memory, parent, false);
        holder = new ViewHolder();
        holder.tv_rome = convertView.findViewById(R.id.tv_rome);
        holder.btn_yin = convertView.findViewById(R.id.btn_yin);
        holder.btn_write = convertView.findViewById(R.id.btn_write);
        holder.tv_hiragana = convertView.findViewById(R.id.tv_hiragana);
        holder.tv_katakana = convertView.findViewById(R.id.tv_katakana);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.tv_rome.setText(item.getRome());
    if (item.getCategory() == Constants.CATEGORY_AOYIN) {
        holder.tv_hiragana.setTextSize(ResourceUtils.getDimension(parent.getContext(), R.dimen.memory_item_text_size_mini));
    } else {
        holder.tv_hiragana.setTextSize(ResourceUtils.getDimension(parent.getContext(), R.dimen.memory_item_text_size));
    }
    holder.tv_hiragana.setText(item.getHiragana());
    holder.tv_katakana.setText(item.getKatakana());
    holder.btn_yin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onYinButtonClickListener != null) {
                onYinButtonClickListener.onClick(item);
            }
        }
    });
    if (item.getCategory() == Constants.CATEGORY_AOYIN) {
        holder.btn_write.setEnabled(false);
    } else {
        holder.btn_write.setEnabled(true);
        holder.btn_write.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onWriteButtonClickListener != null) {
                    onWriteButtonClickListener.onClick(item);
                }
            }
        });
    }
    return convertView;
}
Also used : TextView(android.widget.TextView) View(android.view.View) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)

Example 9 with GojuonItem

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

the class DBManager method query.

public synchronized List<GojuonItem> query() {
    if (query == null) {
        SQLiteDatabase db = DatabaseHelper.getInstance(BaseApplication.getInstance()).getReadableDatabase();
        // Cursor cursor = db.rawQuery("select * from " + DatabaseHelper.DB_TABLE_GOJUON, null);
        Cursor cursor = db.query(DatabaseHelper.DB_TABLE_GOJUON, null, null, null, null, null, null);
        query = new ArrayList<>();
        GojuonItem item;
        while (cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndex("id"));
            int row = cursor.getInt(cursor.getColumnIndex("row"));
            int column = cursor.getInt(cursor.getColumnIndex("column"));
            String hiragana = cursor.getString(cursor.getColumnIndex("hiragana"));
            String katakana = cursor.getString(cursor.getColumnIndex("katakana"));
            String rome = cursor.getString(cursor.getColumnIndex("rome"));
            int category = cursor.getInt(cursor.getColumnIndex("category"));
            int type = cursor.getInt(cursor.getColumnIndex("type"));
            boolean existed = cursor.getInt(cursor.getColumnIndex("existed")) == 1;
            item = new GojuonItem(id, row, column, hiragana, katakana, rome, category, type, existed);
            query.add(item);
        }
        cursor.close();
        db.close();
    }
    return query;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)

Example 10 with GojuonItem

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

the class GojuonFragment method setData.

@Override
public void setData(List<GojuonItem> data) {
    adapter = new GojuonRecyclerAdapter(data);
    adapter.setOnItemClickListener(new GojuonRecyclerAdapter.OnItemClickListener() {

        @Override
        public void onClick(GojuonItem item) {
            SoundPoolManager.getInstance().play(item.getRome());
        }
    });
    adapter.setOnItemLongClickListener(new GojuonRecyclerAdapter.OnItemLongClickListener() {

        @Override
        public void onLongClick(GojuonItem item) {
            Log.e(TAG, "onLongClick item:" + item.getRome() + ":" + item.getKatakana());
            GojuonGif gif = GifManager.getInstance().getJPGif(item.getRome());
            if (gif != null) {
                if (BaseApplication.TYPE_MING == Constants.TYPE_HIRAGANA) {
                    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();
                } else {
                    new ImageDialog.Builder(getContext()).setResId(gif.getKatakana()).override((int) ResourceUtils.getDimension(getContext(), R.dimen.dialog_width), (int) ResourceUtils.getDimension(getContext(), R.dimen.dialog_height)).create().show();
                }
            }
        }
    });
    mRecyclerView.setAdapter(adapter);
}
Also used : ImageDialog(pri.weiqaing.common.widget.dialog.ImageDialog) GojuonRecyclerAdapter(pri.weiqiang.liyujapanese.ui.adapter.GojuonRecyclerAdapter) GojuonGif(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonGif) GojuonItem(pri.weiqiang.liyujapanese.mvp.bean.gojuon.GojuonItem)

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