diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/WikiLocationsAdapter.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/WikiLocationsAdapter.java index 7b723cf..f609f0d 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/WikiLocationsAdapter.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/WikiLocationsAdapter.java @@ -1,6 +1,7 @@ package pl.tpolgrabia.urbanexplorer.adapters; import android.content.Context; +import android.graphics.BitmapFactory; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -25,22 +26,25 @@ public class WikiLocationsAdapter extends ArrayAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View inflatedView; - if (convertView != null) { - // reusing old view - inflatedView = convertView; - } else { - inflatedView = inflater.inflate(R.layout.wiki_locations_item,parent,false); - } + View itemView; + // reusing old view + itemView = convertView != null ? convertView : inflater.inflate(R.layout.wiki_locations_item, parent, false); WikiAppObject wikiPage = getItem(position); + if (wikiPage.getPageId() != null && wikiPage.getPageId().equals(itemView.getTag())) { + // all data were previously loaded + return itemView; + } + + itemView.setTag(wikiPage.getPageId()); // wiki page image preview - ImageView imgPreview = (ImageView) inflatedView.findViewById(R.id.wiki_locs_item_img_preview); + ImageView imgPreview = (ImageView) itemView.findViewById(R.id.wiki_locs_item_img_preview); String url = wikiPage.getThumbnail() != null ? wikiPage.getThumbnail() : null; - TextView locDistanceInfo = (TextView) inflatedView.findViewById(R.id.wiki_locs_item_distance); + TextView locDistanceInfo = (TextView) itemView.findViewById(R.id.wiki_locs_item_distance); locDistanceInfo.setText("" + wikiPage.getDistance() / 1000.0 + " km"); + imgPreview.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.noimage)); if (url != null) { ImageLoader.getInstance().displayImage( @@ -50,10 +54,10 @@ public class WikiLocationsAdapter extends ArrayAdapter { } // wiki page title - TextView pageTitle = (TextView) inflatedView.findViewById(R.id.wiki_locs_item_title); + TextView pageTitle = (TextView) itemView.findViewById(R.id.wiki_locs_item_title); pageTitle.setText(wikiPage.getTitle()); - return inflatedView; + return itemView; } } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioAdapter.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioAdapter.java index 9a92e2c..1b5321a 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioAdapter.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioAdapter.java @@ -1,6 +1,7 @@ package pl.tpolgrabia.urbanexplorer.fragments; import android.content.Context; +import android.graphics.BitmapFactory; import android.support.v4.app.FragmentActivity; import android.view.LayoutInflater; import android.view.View; @@ -31,13 +32,21 @@ public class PanoramioAdapter extends ArrayAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View itemView = inflater.inflate(R.layout.location_item, parent, false); + View itemView = convertView != null ? convertView : inflater.inflate(R.layout.location_item, parent, false); + final PanoramioImageInfo item = getItem(position); + + if (item.getPhotoId() != null && item.getPhotoId().equals(itemView.getTag())) { + // if it is the the same object f.e. add new objects to the collection (without the slide) + // the refresh makes blinking without this + return itemView; + } + TextView locDesc = (TextView) itemView.findViewById(R.id.location_description); - locDesc.setText(getItem(position).getPhotoTitle()); - final String photoUrl = getItem(position).getPhotoFileUrl(); + itemView.setTag(item.getPhotoId()); + locDesc.setText(item.getPhotoTitle()); + final String photoUrl = item.getPhotoFileUrl(); ImageView photoImg = (ImageView) itemView.findViewById(R.id.photo_img); - // photoImg.setImageBitmap(bm); - // photoImg.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_launcher)); + photoImg.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.noimage)); ImageLoader.getInstance().displayImage(photoUrl, photoImg, MainActivity.options); return itemView; } diff --git a/app/src/main/res/drawable/noimage.png b/app/src/main/res/drawable/noimage.png new file mode 100644 index 0000000..b6ffa81 Binary files /dev/null and b/app/src/main/res/drawable/noimage.png differ diff --git a/app/src/main/res/layout/location_item.xml b/app/src/main/res/layout/location_item.xml index 203569c..f1473f8 100644 --- a/app/src/main/res/layout/location_item.xml +++ b/app/src/main/res/layout/location_item.xml @@ -7,7 +7,8 @@ + android:layout_height="80dp" + android:layout_marginRight="10dp"/>