@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); } }
private void updateContent(boolean isRefresh, boolean onlyWatched, String api) { try { // Check size int resourceId = R.layout.novel_list_item; if (UIHelper.IsSmallScreen(this)) { resourceId = R.layout.novel_list_item_small; } if (adapter != null) { adapter.setResourceId(resourceId); } else { adapter = new PageModelAdapter(this, resourceId, listItems); } boolean alphOrder = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean(Constants.PREF_ALPH_ORDER, false); executeTask(isRefresh, onlyWatched, alphOrder, api); setListAdapter(adapter); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); Toast.makeText( this, getResources().getString(R.string.error_update) + ": " + e.getMessage(), Toast.LENGTH_LONG) .show(); } }
@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(); } }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // Get the item that was clicked PageModel o = adapter.getItem(position); String novel = o.toString(); // Create new intent Intent intent = new Intent(this, DisplayLightNovelDetailsActivity.class); intent.putExtra(Constants.EXTRA_NOVEL, novel); intent.putExtra(Constants.EXTRA_PAGE, o.getPage()); intent.putExtra(Constants.EXTRA_TITLE, o.getTitle()); intent.putExtra( Constants.EXTRA_ONLY_WATCHED, getIntent().getBooleanExtra(Constants.EXTRA_ONLY_WATCHED, false)); startActivity(intent); Log.d("DisplayLightNovelsActivity", o.getPage() + " (" + o.getTitle() + ")"); }
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // Get the item that was clicked PageModel o = adapter.getItem(position); String novel = o.toString(); // Create a bundle containing information about the novel that is clicked Bundle bundle = new Bundle(); bundle.putString(Constants.EXTRA_NOVEL, novel); bundle.putString(Constants.EXTRA_PAGE, o.getPage()); bundle.putString(Constants.EXTRA_TITLE, o.getTitle()); bundle.putBoolean( Constants.EXTRA_ONLY_WATCHED, getSherlockActivity().getIntent().getBooleanExtra(Constants.EXTRA_ONLY_WATCHED, false)); mFragListener.changeNextFragment(bundle); Log.d("DisplayLightNovelsActivity", o.getPage() + " (" + o.getTitle() + ")"); // Need to send it through }
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(); } }