@Override protected void onStartLoading() { Log.d("KD", "onStartLoading()" + "Action movie"); super.onStartLoading(); // get model Model model = Model.getInstance(); // get movies from model List<ITunesMovie> movies = model.getMovies(); // if movie list is empty if (0 == movies.size()) { Log.d(TAG, "No movie found in model, downloading top list from iTunes..."); // start downloading movie list from iTunes forceLoad(); } else { Log.d(TAG, "Delivering movies..."); // deliver movies to adapter deliverResult(movies); } }
/** Populate new items in the list. */ @Override public View getView(int position, View convertView, ViewGroup parent) { Log.d(TAG, "getView(" + position + ")"); // get model instance Model model = URLlist.Comedy; // get movie by position ITunesMovie movie = model.getMovieByPosition(position); // view holder keeps reference to avoid further findViewbyId() calls ViewHolder viewHolder; View view; if (convertView == null) { view = mInflater.inflate(R.layout.list_item_layout, parent, false); // create view holder for new view viewHolder = new ViewHolder(); // set view holder fields from layout viewHolder.wa = (WebView) view.findViewById(R.id.amazon); viewHolder.rankTextView = ((TextView) view.findViewById(R.id.rankTextView)); viewHolder.movieSmallImageLoadingProgressBar = ((ProgressBar) view.findViewById(R.id.movieSmalleImageLoadingProgressBar)); viewHolder.movieSmallImageView = ((ImageView) view.findViewById(R.id.movieSmallImageView)); viewHolder.movieTitleTextView = ((TextView) view.findViewById(R.id.movieTitleTextView)); viewHolder.movieCopyrightTextView = ((TextView) view.findViewById(R.id.movieCopyrightTextView)); viewHolder.freeitune = ((TextView) view.findViewById(R.id.freeitune)); viewHolder.freeitune.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.freeitunestvshow.com/")); MainActivity.context.startActivity(browserIntent); } }); // // set view holder in view view.setTag(viewHolder); } else { // use convert view view = convertView; // get view holder from view viewHolder = (ViewHolder) view.getTag(); // this movie is ready if (movie.getId() == viewHolder.movieId) { Log.d(TAG, "View is up to date, reusing..."); return view; } // if } // if Log.d(TAG, "Setting up view..."); // update movie id viewHolder.movieId = movie.getId(); viewHolder.wa.getSettings().setJavaScriptEnabled(true); String D = webdata; viewHolder.wa.setLabelFor(position); viewHolder.wa.clearHistory(); viewHolder.wa.loadUrl("about:blank"); viewHolder.wa.loadData( D.replace( "#XX#", URLlist.Comedy.getMovieByPosition(position) .getTitle() .replaceAll(".*-", "") .replace(" ", "%20")), "text/html", "utf-8"); viewHolder.wa.setBackgroundColor(Color.TRANSPARENT); viewHolder.wa.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); // update movie rank // viewHolder.rankTextView.setText("" + (1 + position)); viewHolder.rankTextView.setTag(movie.getId()); viewHolder.rankTextView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub ITunesMovie movie = URLlist.Comedy.getMovieByPosition(Integer.parseInt(v.getTag() + "")); Intent browserIntent = new Intent(MainActivity.context, com.bangla.natok.prova.MainActivity.class); com.bangla.natok.prova.MainActivity.url = movie.getTitle().replaceAll(".*-", "").toString(); MainActivity.context.startActivity(browserIntent); } }); // // - // update movie image (if possible) // - if (null != movie.getSmallImageUrl()) { // start background image loader (using multiple cores) new ImageLoader( viewHolder.movieSmallImageView, viewHolder.movieSmallImageLoadingProgressBar, movie.getImageUrl(), 60, 90) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } // if // - // update movie title viewHolder.movieTitleTextView.setText(movie.getTitle()); // update movie copyright viewHolder.movieCopyrightTextView.setText(movie.getSummary()); viewHolder.movieCopyrightTextView.setMaxLines(3); viewHolder.movieCopyrightTextView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub ((TextView) v).setMaxLines(100); } }); return view; }