@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); isPublished = intent.getBooleanExtra("isPublished", false); syncher = Syncher.getInstance(this); storyCon = StoryController.getInstance(this); storyMan = StoryManager.getInstance(this); emptyList = (TextView) findViewById(R.id.empty); lifedata = LifecycleData.getInstance(); ArrayList<Story> newStories = lifedata.getSearchResults(); if (newStories == null || newStories.size() == 0) { Toast.makeText(getBaseContext(), "No stories matched your search.", Toast.LENGTH_LONG).show(); } /** * Sets up a grid view and shows all the stories which are similar or match to the query which * the user inputed in search activity. If no results are found, a toast will appear. */ gridView = (GridView) findViewById(R.id.gridStoriesView); customGridAdapter = new AdapterStories(this, R.layout.browse_story_item, gridArray); gridView.setAdapter(customGridAdapter); gridView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (isPublished) { storyCon.setCurrStoryComplete(gridArray.get(arg2)); if (storyMan.existsLocally(gridArray.get(arg2).getId())) { overwriteStory(); } else { new CacheStory().execute(); } } else { storyCon.setCurrStoryIncomplete(gridArray.get(arg2)); Intent intent = new Intent(getBaseContext(), ViewStory.class); startActivity(intent); finish(); } } }); gridArray.clear(); gridArray.addAll(newStories); emptyList.setText(" "); customGridAdapter.notifyDataSetChanged(); }