/**
* Show the view options dialog when the FAB is clicked.
*/
@OnClick(R.id.fab)
void onFabClick() {
// Inflate dialog view and get views.
@SuppressLint("InflateParams")
View view = LayoutInflater.from(getContext()).inflate(R.layout.library_view_opts, null);
final RadioGroup rgSortType = ButterKnife.findById(view, R.id.rg_sort_type);
final RadioGroup rgSortDir = ButterKnife.findById(view, R.id.rg_sort_dir);
final RadioGroup rgCardType = ButterKnife.findById(view, R.id.rg_card_type);
// Set up views.
rgSortType.check(sortType.getResId());
rgSortDir.check(sortDir.getResId());
rgCardType.check(cardType.getResId());
// Construct material dialog.
new MaterialDialog.Builder(getContext())
.title(R.string.action_view_opts)
.titleGravity(GravityEnum.CENTER)
.customView(view, true)
.contentGravity(GravityEnum.CENTER)
.positiveText(R.string.ok)
.negativeText(R.string.cancel)
.onPositive((dialog, which) -> {
// Figure out which options are different.
boolean sortTypeChanged = rgSortType.getCheckedRadioButtonId() != sortType.getResId();
boolean sortDirChanged = rgSortDir.getCheckedRadioButtonId() != sortDir.getResId();
boolean cardTypeChanged = rgCardType.getCheckedRadioButtonId() != cardType.getResId();
// Save new options locally if different, then persist them all to preferences.
if (sortTypeChanged) sortType = SortType.fromResId(rgSortType.getCheckedRadioButtonId());
if (sortDirChanged) sortDir = SortDir.fromResId(rgSortDir.getCheckedRadioButtonId());
if (cardTypeChanged) cardType = BookCardType.fromResId(rgCardType.getCheckedRadioButtonId());
Minerva.prefs().putLibraryViewOpts(sortType, sortDir, cardType);
// Re-sort data if necessary.
if (sortTypeChanged || sortDirChanged) sortRealmResults();
// Switching the card type means switching the recycler view adapter, we certainly don't want to
// do that if we haven't changed it.
if (cardTypeChanged) changeCardType();
// We only need to explicitly tell the recycler view to redraw its items if we changed our sort
// options and didn't change our card type (swapping adapters to change card types would force a
// redraw anyway).
if ((sortTypeChanged || sortDirChanged) && !cardTypeChanged) //noinspection unchecked
adapter.updateRealmResults(books);
})
.show();
}
LibraryFragment.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:Minerva
作者:
评论列表
文章目录