@Override public void onLoaderReset(Loader<Cursor> loader) { Resources Res = getActivity().getResources(); // if (PopMoviesConstants.DEBUG) Log.i( Res.getString(R.string.logcat_tag), LOG_TAG + ":" + // "OnLoaderReset" ); mMovieListAdapter.swapCursor(null); }
private void updateEmptyView() { if (mMovieListAdapter.getCount() == 0) { if (mAlternateView != null) if (!Utilities.isNetworkAvailable(this.getActivity())) { mAlternateView.setText(getResources().getString(R.string.no_internet_message)); } else mAlternateView.setText(getResources().getString(R.string.no_movie_available)); } }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { mMovieListAdapter.swapCursor(data); Resources Res = getActivity().getResources(); if (PopMoviesConstants.DEBUG) Log.i( Res.getString(R.string.logcat_tag), LOG_TAG + ":" + "OnLoadFinished + (" + data.getCount() + " ) Records found"); if (mPosition != GridView.INVALID_POSITION) { // TODO set gridview position to mPosition - need to check if this works mGridview.setSelection(mPosition); } updateEmptyView(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Resources Res = getActivity().getResources(); if (PopMoviesConstants.DEBUG) Log.i(Res.getString(R.string.logcat_tag), LOG_TAG + ":" + "Inside onCreateView"); mMovieListAdapter = new MovieListAdapter((Context) this.getActivity(), null /* getMovielistCursor() */, 0); View rootView; rootView = inflater.inflate(R.layout.fragment_main, container, false); setImageParams(); mGridview = (GridView) rootView.findViewById(R.id.pomoviepostergridview); // mHeaderView = (TextView) rootView.findViewById(R.id.MovieListHeader); mAlternateView = (TextView) rootView.findViewById(R.id.empty_grid_view); mGridview.setEmptyView(mAlternateView); mGridview.setAdapter(mMovieListAdapter); if (PopMoviesConstants.DEBUG) Log.i( Res.getString(R.string.logcat_tag), LOG_TAG + ":" + "Inside onCreateView after setAdapter "); mMovieListAdapter.setImageSizeDetails(mImageSize, mImageSpacing); if (mPosition != GridView.INVALID_POSITION) { mGridview.setSelection(mPosition); } mGridview.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { mPosition = position; Cursor movieItem = (Cursor) parent.getItemAtPosition(position); int selectedMovieDBId = movieItem.getInt(COL_MOVIE_ID); long selectedMovieId = movieItem.getInt(COL_ID); // displayToast(v.getContext(), "" + position + " id=<" + id + "> _ID=(" + // selectedMovieId // + ") MovieDBID = ( " + selectedMovieDBId + ")"); if (PopMoviesConstants.DEBUG) Log.i( "PopMovies1", LOG_TAG + ":" + " onItemClick: position=<" + position + "> id=<" + id + ">"); // displayMovieDetails(parent, position); /* Launch the detail activity ****************************** String InstanceTagLocal = PopMoviesConstants.DETAIL_ACTIVITY_INSTANCE_TAG; Intent intent = new Intent(v.getContext(), MovieDetailActivity.class); intent.putExtra(InstanceTagLocal, selectedMovieId); startActivity(intent); **************************************************** */ mCallbacks.onItemSelected(selectedMovieId); if (Utilities.isNetworkAvailable(getActivity())) initiateTrailernReviewDownload( selectedMovieDBId, selectedMovieId); // starting the trailer & Review download } }); if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { mPosition = savedInstanceState.getInt(SELECTED_KEY); } return rootView; }