Commit 03b4e833 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Switch from ListView to GridView for the video fragment

parent 3d057274
......@@ -65,7 +65,7 @@
android:name=".gui.video.VideoActivityGroup"
android:theme="@android:style/Theme.NoTitleBar" />
<activity
android:name=".gui.video.VideoListFragment"
android:name=".gui.video.VideoGridFragment"
android:theme="@style/Theme.VLC"/>
<activity
android:name=".gui.video.MediaInfoActivity"
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/item_common" >
<GridView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="150dip"
android:fastScrollEnabled="true"
android:horizontalSpacing="20dp"
android:verticalSpacing="20dp"
android:stretchMode="spacingWidthUniform" />
<LinearLayout
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview_nomedia"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/nomedia"
android:textSize="20dip"
android:visibility="visible" />
<LinearLayout
android:id="@+id/layout_flipper_loading"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:visibility="invisible" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="@string/loading"
android:textSize="20dip" />
<ViewFlipper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left"
android:autoStart="true"
android:flipInterval="1000" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_no_period"
android:textSize="20dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_1_period"
android:textSize="20dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_2_period"
android:textSize="20dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/load_3_period"
android:textSize="20dip" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item"
android:layout_width="150dip"
android:layout_height="150dip"
android:orientation="vertical"
android:gravity="center_vertical"
android:background="#444">
<ImageView
android:id="@+id/ml_item_thumbnail"
android:layout_width="120dip"
android:layout_height="80dip"
android:scaleType="centerCrop"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/ml_item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:ellipsize="end"
android:maxLines="2"
android:textSize="12dip"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/ml_item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="10dip"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -32,7 +32,7 @@ import java.util.Stack;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.audio.AudioBrowserFragment;
import org.videolan.vlc.gui.video.VideoListFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import android.content.Context;
import android.content.SharedPreferences;
......@@ -75,7 +75,7 @@ public class MediaLibrary {
public void loadMediaItems(Context context) {
if (mLoadingThread == null || mLoadingThread.getState() == State.TERMINATED) {
isStopping = false;
VideoListFragment.actionScanStart(context.getApplicationContext());
VideoGridFragment.actionScanStart(context.getApplicationContext());
mLoadingThread = new Thread(new GetMediaItemsRunnable(context.getApplicationContext()));
mLoadingThread.start();
}
......@@ -326,7 +326,7 @@ public class MediaLibrary {
MainActivity.clearTextInfo(mContext);
MainActivity.hideProgressBar(mContext);
VideoListFragment.actionScanStop(mContext);
VideoGridFragment.actionScanStop(mContext);
if (mRestart) {
Log.d(TAG, "Restarting scan");
......
......@@ -30,7 +30,7 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.video.VideoListFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import android.content.Context;
import android.graphics.Bitmap;
......@@ -42,7 +42,7 @@ import android.view.Display;
public class ThumbnailerManager implements Runnable {
public final static String TAG = "VLC/ThumbnailerManager";
private VideoListFragment mVideoListFragment;
private VideoGridFragment mVideoGridFragment;
private final Queue<Media> mItems = new LinkedList<Media>();
......@@ -65,7 +65,7 @@ public class ThumbnailerManager implements Runnable {
mPrefix = mContext.getResources().getString(R.string.thumbnail);
}
public void start(VideoListFragment videoListFragment) {
public void start(VideoGridFragment videoGridFragment) {
if (mLibVlc == null) {
try {
mLibVlc = LibVLC.getInstance();
......@@ -78,8 +78,8 @@ public class ThumbnailerManager implements Runnable {
isStopping = false;
if (mThread == null || mThread.getState() == State.TERMINATED) {
mVideoListFragment = videoListFragment;
mVideoListFragment.setThumbnailerManager(this);
mVideoGridFragment = videoGridFragment;
mVideoGridFragment.setThumbnailerManager(this);
mThread = new Thread(this);
mThread.start();
}
......@@ -125,7 +125,7 @@ public class ThumbnailerManager implements Runnable {
Log.d(TAG, "Thumbnailer started");
while (!isStopping) {
mVideoListFragment.resetBarrier();
mVideoGridFragment.resetBarrier();
lock.lock();
// Get the id of the file browser item to create its thumbnail.
boolean interrupted = false;
......@@ -174,11 +174,11 @@ public class ThumbnailerManager implements Runnable {
item.setPicture(mContext, thumbnail);
// Post to the file browser the new item.
mVideoListFragment.setItemToUpdate(item);
mVideoGridFragment.setItemToUpdate(item);
// Wait for the file browser to process the change.
try {
mVideoListFragment.await();
mVideoGridFragment.await();
} catch (InterruptedException e) {
Log.i(TAG, "interruption probably requested by stop()");
break;
......@@ -191,8 +191,8 @@ public class ThumbnailerManager implements Runnable {
/* cleanup */
MainActivity.hideProgressBar(mContext);
MainActivity.clearTextInfo(mContext);
mVideoListFragment.setThumbnailerManager(null);
mVideoListFragment = null;
mVideoGridFragment.setThumbnailerManager(null);
mVideoGridFragment = null;
Log.d(TAG, "Thumbnailer stopped");
}
}
......@@ -33,7 +33,7 @@ import org.videolan.vlc.Util;
import org.videolan.vlc.VLCCallbackTask;
import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
import org.videolan.vlc.gui.video.VideoListAdapter;
import org.videolan.vlc.gui.video.VideoListFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.widget.AudioMiniPlayer;
......@@ -383,7 +383,7 @@ public class MainActivity extends SherlockFragmentActivity {
/* Start the thumbnailer */
if (id.equals("video"))
mThumbnailerManager.start((VideoListFragment)fragment);
mThumbnailerManager.start((VideoGridFragment)fragment);
return fragment;
}
......
......@@ -28,7 +28,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.audio.AudioBrowserFragment;
import org.videolan.vlc.gui.video.VideoListFragment;
import org.videolan.vlc.gui.video.VideoGridFragment;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
......@@ -122,7 +122,7 @@ public class SidebarAdapter extends BaseAdapter {
if(id.equals("audio")) {
f = new AudioBrowserFragment();
} else if(id.equals("video")) {
f = new VideoListFragment();
f = new VideoGridFragment();
} else if(id.endsWith("directories")) {
f = new DirectoryViewFragment();
} else if(id.equals("history")) {
......
......@@ -25,6 +25,7 @@ import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import org.videolan.android.ui.SherlockGridFragment;
import org.videolan.vlc.DatabaseManager;
import org.videolan.vlc.Media;
import org.videolan.vlc.MediaLibrary;
......@@ -54,13 +55,11 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListFragment;
public class VideoListFragment extends SherlockListFragment implements ISortable {
public class VideoGridFragment extends SherlockGridFragment implements ISortable {
public final static String TAG = "VLC/VideoListFragment";
......@@ -78,7 +77,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
private ThumbnailerManager mThumbnailerManager;
/* All subclasses of Fragment must include a public empty constructor. */
public VideoListFragment() { }
public VideoGridFragment() { }
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -91,7 +90,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.video_list, container, false);
View v = inflater.inflate(R.layout.video_grid, container, false);
// init the information for the scan (1/2)
mLayoutFlipperLoading = (LinearLayout) v.findViewById(R.id.layout_flipper_loading);
......@@ -103,7 +102,7 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
registerForContextMenu(getListView());
registerForContextMenu(getGridView());
// init the information for the scan (2/2)
IntentFilter filter = new IntentFilter();
......@@ -150,9 +149,9 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
public void onGridItemClick(GridView l, View v, int position, long id) {
playVideo(position);
super.onListItemClick(l, v, position, id);
super.onGridItemClick(l, v, position, id);
}
protected void playVideo(int position) {
......@@ -202,14 +201,14 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
*/
private Handler mHandler = new VideoListHandler(this);
private static class VideoListHandler extends WeakHandler<VideoListFragment> {
public VideoListHandler(VideoListFragment owner) {
private static class VideoListHandler extends WeakHandler<VideoGridFragment> {
public VideoListHandler(VideoGridFragment owner) {
super(owner);
}
@Override
public void handleMessage(Message msg) {
VideoListFragment fragment = getOwner();
VideoGridFragment fragment = getOwner();
if(fragment == null) return;
switch (msg.what) {
......
......@@ -35,6 +35,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -127,18 +128,20 @@ public class VideoListAdapter extends ArrayAdapter<Media>
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.video_list_item, parent, false);
v = inflater.inflate(R.layout.video_grid_item, parent, false);
holder = new ViewHolder();
holder.layout = v.findViewById(R.id.layout_item);
holder.thumbnail = (ImageView) v.findViewById(R.id.ml_item_thumbnail);
holder.title = (TextView) v.findViewById(R.id.ml_item_title);
holder.subtitle = (TextView) v.findViewById(R.id.ml_item_subtitle);
v.setTag(holder);
/* Set the layoutParams based on the values set in the video_grid_item.xml root element */
v.setLayoutParams(new GridView.LayoutParams(v.getLayoutParams().width, v.getLayoutParams().height));
} else
holder = (ViewHolder) v.getTag();
Media media = getItem(position);
Util.setItemBackground(holder.layout, position);
//Util.setItemBackground(holder.layout, position);
holder.title.setText(media.getTitle());
Bitmap thumbnail;
......@@ -154,7 +157,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
ColorStateList titleColor = v.getResources().getColorStateList(media.getLocation().equals(mLastMRL)
? R.color.list_title_last
: R.color.list_title);
holder.title.setTextColor(titleColor);
//holder.title.setTextColor(titleColor);
long lastTime = media.getTime();
String text;
......@@ -167,7 +170,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
text = String.format("%s",
Util.millisToString(media.getLength()));
}
if (media.getWidth() > 0 && media.getHeight() > 0) {
text += String.format(" - %dx%d", media.getWidth(), media.getHeight());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment