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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations