use of ar.rulosoft.mimanganu.adapters.MangasRecAdapter in project MiMangaNu by raulhaag.
the class MainFragment method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
final Manga manga = ((MangasRecAdapter) recyclerView.getAdapter()).getItem(lastContextMenuIndex);
if (item.getItemId() == R.id.delete) {
new AlertDialog.Builder(getContext()).setTitle(R.string.app_name).setMessage(getString(R.string.manga_delete_confirm, manga.getTitle())).setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DownloadPoolService.forceStop(manga.getId());
ServerBase serverBase = ServerBase.getServer(manga.getServerId(), getContext());
String path = Paths.generateBasePath(serverBase, manga, getActivity());
Util.getInstance().deleteRecursive(new File(path));
Database.deleteManga(getActivity(), manga.getId());
mMAdapter.remove(manga);
Util.getInstance().showFastSnackBar(getResources().getString(R.string.deleted, manga.getTitle()), getView(), getContext());
dialog.dismiss();
}
}).show();
} else if (item.getItemId() == R.id.noupdate) {
if (manga.isFinished()) {
manga.setFinished(false);
Database.setUpgradable(getActivity(), manga.getId(), false);
} else {
manga.setFinished(true);
Database.setUpgradable(getActivity(), manga.getId(), true);
}
} else if (item.getItemId() == R.id.download_all_chapters) {
ArrayList<Chapter> chapters = Database.getChapters(getActivity(), manga.getId(), Database.COL_CAP_DOWNLOADED + " != 1", true);
for (Chapter chapter : chapters) {
try {
DownloadPoolService.addChapterDownloadPool(getActivity(), chapter, false);
} catch (Exception e) {
Log.e(TAG, "Download add pool error", e);
}
}
if (chapters.size() > 1)
Util.getInstance().showFastSnackBar(getString(R.string.downloading) + " " + chapters.size() + " " + getString(R.string.chapters), getView(), getContext());
else
Util.getInstance().showFastSnackBar(getString(R.string.downloading) + " " + chapters.size() + " " + getString(R.string.chapter), getView(), getContext());
}
return super.onContextItemSelected(item);
}
use of ar.rulosoft.mimanganu.adapters.MangasRecAdapter in project MiMangaNu by raulhaag.
the class MainFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.view_mismangas, menu);
final Menu mMenu = menu;
/* Local Search */
MenuItem search = menu.findItem(R.id.action_search_local);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
searchView.setOnSearchClickListener(new SearchView.OnClickListener() {
@Override
public void onClick(View view) {
mMenu.findItem(R.id.action_view_download).setVisible(false);
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
setListManga(false);
mMenu.findItem(R.id.action_view_download).setVisible(true);
return false;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String value) {
searchView.clearFocus();
return false;
}
@Override
public boolean onQueryTextChange(String value) {
if (!value.isEmpty()) {
ArrayList<Manga> mangaList;
if (value.contains("'"))
value = value.replaceAll("'", "''");
try {
mangaList = Database.getMangasCondition(getActivity(), "id IN (" + "SELECT id " + "FROM manga " + "WHERE nombre LIKE '%" + value + "%' GROUP BY id)", null, false);
mMAdapter = new MangasRecAdapter(mangaList, getContext(), MainActivity.darkTheme, MainFragment.this);
mMAdapter.setMangaClickListener(MainFragment.this);
recyclerView.setAdapter(mMAdapter);
} catch (Exception e) {
Log.e("MF", "Exception", e);
ACRA.getErrorReporter().handleException(e);
}
}
return false;
}
});
/* Set hide/unhide checkbox */
boolean checkedRead = pm.getInt(SELECT_MODE, MODE_SHOW_ALL) > 0;
menu.findItem(R.id.action_hide_read).setChecked(checkedRead);
/* Set sort mode */
int[] sortList = { R.id.sort_last_read, R.id.sort_last_read_desc, R.id.sort_name, R.id.sort_name_desc, R.id.sort_author, R.id.sort_author_desc, R.id.sort_finished, R.id.sort_finished_asc, R.id.sort_as_added_to_db_asc, R.id.sort_as_added_to_db_desc };
menu.findItem(sortList[pm.getInt("manga_view_sort_by", 0)]).setChecked(true);
}
use of ar.rulosoft.mimanganu.adapters.MangasRecAdapter in project MiMangaNu by raulhaag.
the class MainFragment method setListManga.
public void setListManga(boolean force) {
if (recyclerView != null) {
ArrayList<Manga> mangaList = new ArrayList<>();
/*
* sort_val: 0,1 = last_read (default), 2,3 = title, 4,5 = author
* all odd numbers are asc, even numbers are desc
*
* feel free to add more sort type */
int sort_val = PreferenceManager.getDefaultSharedPreferences(getContext()).getInt("manga_view_sort_by", 0);
String sort_by;
boolean sort_ord = sort_val % 2 == 0;
switch(sort_val) {
case 2:
case 3:
sort_by = Database.COL_NAME;
break;
case 4:
case 5:
sort_by = Database.COL_AUTHOR;
break;
case 6:
case 7:
sort_by = Database.COL_IS_FINISHED;
sort_ord = !sort_ord;
break;
case 8:
case 9:
sort_by = Database.COL_ID;
sort_ord = !sort_ord;
break;
case 0:
case 1:
default:
sort_by = Database.COL_LAST_READ;
sort_ord = !sort_ord;
}
int value = PreferenceManager.getDefaultSharedPreferences(getContext()).getInt(SELECT_MODE, MODE_SHOW_ALL);
switch(value) {
case MODE_SHOW_ALL:
mangaList = Database.getMangas(getContext(), sort_by, sort_ord);
break;
case MODE_HIDE_READ:
mangaList = Database.getMangasCondition(getContext(), "id IN (" + "SELECT manga_id " + "FROM capitulos " + "WHERE estado != 1 GROUP BY manga_id)", sort_by, sort_ord);
break;
default:
break;
}
if (mMAdapter == null || sort_val < 2 || mangaList.size() > mMAdapter.getItemCount() || force) {
mMAdapter = new MangasRecAdapter(mangaList, getContext(), MainActivity.darkTheme, MainFragment.this);
mMAdapter.setMangaClickListener(MainFragment.this);
recyclerView.setAdapter(mMAdapter);
}
} else {
Log.i(TAG, "rec_view was null");
}
}
Aggregations