@Override public boolean onContextItemSelected(android.view.MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.add_to_watch: /* * Implement code to toggle watch of this novel */ if (info.position > -1) { PageModel novel = listItems.get(info.position); if (novel.isWatched()) { novel.setWatched(false); Toast.makeText( this, getResources().getString(R.string.removed_from_watchlist) + ": " + novel.getTitle(), Toast.LENGTH_SHORT) .show(); } else { novel.setWatched(true); Toast.makeText( this, getResources().getString(R.string.added_to_watchlist) + ": " + novel.getTitle(), Toast.LENGTH_SHORT) .show(); } NovelsDao.getInstance(this).updatePageModel(novel); adapter.notifyDataSetChanged(); } return true; case R.id.download_novel: /* * Implement code to download novel synopsis */ if (info.position > -1) { PageModel novel = listItems.get(info.position); ArrayList<PageModel> novels = new ArrayList<PageModel>(); novels.add(novel); touchedForDownload = novel.getTitle() + "'s information"; executeDownloadTask(novels); } return true; case R.id.delete_novel: if (info.position > -1) { toggleProgressBar(true); PageModel novel = listItems.get(info.position); boolean result = NovelsDao.getInstance(this).deleteNovel(novel); if (result) { listItems.remove(novel); adapter.notifyDataSetChanged(); } toggleProgressBar(false); } return true; default: return super.onContextItemSelected(item); } }
@Override protected void onRestart() { super.onRestart(); if (isInverted != UIHelper.getColorPreferences(this)) { UIHelper.Recreate(this); } if (adapter != null) adapter.notifyDataSetChanged(); }
public void onGetResult(AsyncTaskResult<?> result, Class<?> t) { Exception e = result.getError(); if (e == null) { // from LoadNovelsTask if (t == PageModel[].class) { PageModel[] list = (PageModel[]) result.getResult(); if (list != null) { adapter.clear(); adapter.addAll(list); toggleProgressBar(false); } } // from DownloadNovelDetailsTask else if (t == NovelCollectionModel[].class) { setMessageDialog(new CallbackEventData("Download complete.")); NovelCollectionModel[] list = (NovelCollectionModel[]) result.getResult(); for (NovelCollectionModel novelCol : list) { try { PageModel page = novelCol.getPageModel(); boolean found = false; for (PageModel temp : adapter.data) { if (temp.getPage().equalsIgnoreCase(page.getPage())) { found = true; break; } } if (!found) { adapter.data.add(page); } } catch (Exception e1) { Log.e(TAG, e1.getClass().toString() + ": " + e1.getMessage(), e1); } } adapter.notifyDataSetChanged(); toggleProgressBar(false); } } else { Log.e(TAG, e.getClass().toString() + ": " + e.getMessage(), e); Toast.makeText(this, e.getClass().toString() + ": " + e.getMessage(), Toast.LENGTH_LONG) .show(); } }
public void onGetResult(AsyncTaskResult<?> result, Class<?> t) { if (!isAdded()) return; Exception e = result.getError(); if (e == null) { // from LoadNovelsTask if (t == PageModel[].class) { PageModel[] list = (PageModel[]) result.getResult(); Log.d(TAG, "LoadNovelsTask result ok"); if (list != null && list.length > 0) { adapter.clear(); adapter.addAll(list); toggleProgressBar(false); // Show message if watch list is empty if (list.length == 0 && onlyWatched) { Log.d(TAG, "WatchList result set message empty"); loadingText.setVisibility(TextView.VISIBLE); loadingText.setText("Watch List is empty."); } } else { toggleProgressBar(false); loadingText.setVisibility(TextView.VISIBLE); loadingText.setText("List is empty."); Log.w(TAG, "Empty ArrayList!"); } } // from DownloadNovelDetailsTask else if (t == NovelCollectionModel[].class) { setMessageDialog(new CallbackEventData("Download complete.")); NovelCollectionModel[] list = (NovelCollectionModel[]) result.getResult(); for (NovelCollectionModel novelCol : list) { try { PageModel page = novelCol.getPageModel(); boolean found = false; for (PageModel temp : adapter.data) { if (temp.getPage().equalsIgnoreCase(page.getPage())) { found = true; break; } } if (!found) { adapter.data.add(page); } } catch (Exception e1) { Log.e(TAG, e1.getClass().toString() + ": " + e1.getMessage(), e1); } } adapter.notifyDataSetChanged(); toggleProgressBar(false); } else { Log.e(TAG, "Unknown ResultType: " + t.getName()); } } else { Log.e(TAG, e.getClass().toString() + ": " + e.getMessage(), e); Toast.makeText( getSherlockActivity(), e.getClass().toString() + ": " + e.getMessage(), Toast.LENGTH_LONG) .show(); } }