[Android] Nicer search results presentation

Geoffrey Métais git at videolan.org
Thu Apr 16 17:31:56 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 16 17:09:44 2015 +0200| [6b30d7e2ad8b4a27aee229c3ac5bc39ece22551e] | committer: Geoffrey Métais

Nicer search results presentation

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6b30d7e2ad8b4a27aee229c3ac5bc39ece22551e
---

 .../videolan/vlc/gui/SearchSuggestionsAdapter.java |   46 +++++++++++++++++---
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
index 1c7c7b7..df7b6f6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchSuggestionsAdapter.java
@@ -24,22 +24,28 @@ package org.videolan.vlc.gui;
 
 import android.content.Context;
 import android.database.Cursor;
+import android.graphics.Bitmap;
 import android.support.v4.widget.CursorAdapter;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import org.videolan.vlc.MediaDatabase;
 import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.gui.audio.AudioUtil;
+import org.videolan.vlc.util.BitmapUtil;
 import org.videolan.vlc.util.Util;
 
 public class SearchSuggestionsAdapter extends CursorAdapter {
 
     public final static String TAG = "VLC/SearchSuggestionsAdapter";
+    private static int backgroundColor;
 
     MediaLibrary mMediaLibrary = MediaLibrary.getInstance();
     SuggestionDisplay activity;
@@ -51,25 +57,53 @@ public class SearchSuggestionsAdapter extends CursorAdapter {
     public SearchSuggestionsAdapter(Context context, Cursor cursor){
         super(context, cursor, false);
         activity = (SuggestionDisplay) context;
+        backgroundColor = Util.getColorFromAttribute(context, R.attr.background_menu);
     }
 
     @Override
     public View newView(Context context, Cursor cursor, ViewGroup parent) {
         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-        View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
+        View view = inflater.inflate(R.layout.audio_browser_item, parent, false);
         return view;
     }
 
     @Override
     public void bindView(View view, final Context context, Cursor cursor) {
         final String location = cursor.getString(cursor.getColumnIndex(MediaDatabase.MEDIA_LOCATION));
-        TextView tv = (TextView) view.findViewById(android.R.id.text1);
-        tv.setText(cursor.getString(cursor.getColumnIndex(MediaDatabase.MEDIA_TITLE)));
-        tv.setBackgroundColor(Util.getColorFromAttribute(context, R.attr.background_menu));
-        tv.setOnClickListener(new View.OnClickListener() {
+        final MediaWrapper mw = mMediaLibrary.getMediaItem(location);
+        view.findViewById(R.id.item_more).setVisibility(View.GONE);
+        TextView tv1 = (TextView) view.findViewById(R.id.title);
+        tv1.setText(cursor.getString(cursor.getColumnIndex(MediaDatabase.MEDIA_TITLE)));
+        view.setBackgroundColor(backgroundColor);
+
+        String artist = mw.getAlbumArtist();
+        if (artist == null)
+            artist = mw.getArtist();
+        if (artist != null) {
+            TextView tv2 = (TextView) view.findViewById(R.id.subtitle);
+            tv2.setText(artist);
+        } else
+            view.findViewById(R.id.subtitle).setVisibility(View.GONE);
+
+        Bitmap artwork;
+        ImageView coverView = (ImageView) view.findViewById(R.id.cover);
+        if (mw.getType() == MediaWrapper.TYPE_AUDIO)
+            artwork = AudioUtil.getCover(context, mw, context.getResources().getDimensionPixelSize(R.dimen.audio_browser_item_size));
+        else if (mw.getType() == MediaWrapper.TYPE_VIDEO)
+            artwork = BitmapUtil.getPictureFromCache(mw);
+        else
+            artwork = null;
+        if (artwork != null) {
+            coverView.setVisibility(View.VISIBLE);
+            coverView.setImageBitmap(artwork);
+        } else
+            coverView.setVisibility(View.INVISIBLE);
+
+
+        view.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                Util.openMedia(context, mMediaLibrary.getMediaItem(location));
+                Util.openMedia(context, mw);
             }
         });
         view.setOnTouchListener(new View.OnTouchListener() {



More information about the Android mailing list