Commit d09f0b18 authored by Geoffrey Métais's avatar Geoffrey Métais

Cardview for video browsing

parent 37805e59
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="1sp" >
<RelativeLayout
android:id="@+id/layout_item"
android:layout_width="@dimen/grid_card_width"
android:layout_height="@dimen/grid_card_height"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageView
android:id="@+id/ml_item_thumbnail"
android:layout_width="match_parent"
android:layout_height="@dimen/grid_card_thumb_height"
android:layout_alignParentTop="true"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/ml_item_title"
android:textSize="@dimen/grid_card_title_text_size"
android:textColor="?attr/list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ml_item_thumbnail"
android:layout_toLeftOf="@+id/item_more"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:gravity="center_horizontal"
android:maxLines="2" />
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/ml_item_thumbnail"
android:layout_marginTop="10dp"
android:layout_marginRight="7dp"
android:clickable="true"
android:src="@drawable/ic_more_vert_grey600_24dp" />
<TextView
android:id="@+id/ml_item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="3dp"
android:gravity="center_horizontal"
android:singleLine="true"
android:textSize="@dimen/grid_card_subtitle_text_size"
android:textColor="?attr/list_subtitle" />
<ProgressBar
android:id="@+id/ml_item_progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="false"
android:indeterminate="false"
android:maxHeight="3dip"
android:minHeight="3dip"
android:progressDrawable="@drawable/gridview_progressbar" />
</RelativeLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item"
android:layout_width="160dip"
android:layout_height="150dip"
android:orientation="vertical"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<ImageView
android:id="@+id/ml_item_thumbnail"
android:layout_width="160dip"
android:layout_height="100dip"
android:scaleType="fitCenter"
android:layout_gravity="center_horizontal" />
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/ml_item_progress"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:minHeight="2dip"
android:maxHeight="2dip"
android:progressDrawable="@drawable/gridview_progressbar"
android:focusable="false"
android:indeterminate="false" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
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="12sp"
android:textColor="?attr/list_title" />
<TextView
android:id="@+id/ml_item_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="10sp"
android:textColor="?attr/list_subtitle" />
</LinearLayout>
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_more"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:clickable="true" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_item"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<LinearLayout
card_view:cardUseCompatPadding="true"
card_view:cardElevation="1sp" >
<RelativeLayout
android:id="@+id/ml_item_layout_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ml_item_thumbnail"
android:layout_width="120dip"
android:layout_height="75dip"
android:scaleType="fitCenter" />
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/ml_item_progress"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:minHeight="2dip"
android:maxHeight="2dip"
android:progressDrawable="@drawable/gridview_progressbar"
android:focusable="false"
android:indeterminate="false" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ml_item_layout_thumbnail"
android:layout_centerVertical="true"
android:orientation="vertical">
android:scaleType="fitCenter"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/ml_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/ml_item_thumbnail"
android:layout_toLeftOf="@+id/item_more"
android:ellipsize="end"
android:maxLines="2"
android:textSize="17sp"
android:paddingLeft="12dip"
android:textColor="?attr/list_title"
android:paddingLeft="12dip" />
android:textSize="17sp" />
<TextView
android:id="@+id/ml_item_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_below="@id/ml_item_title"
android:layout_alignLeft="@id/ml_item_title"
android:paddingLeft="12dip"
android:textColor="?attr/list_subtitle"
android:paddingLeft="12dip" />
</LinearLayout>
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_more"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:clickable="true" />
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="@+id/ml_item_layout_thumbnail"
android:background="?attr/item_footer" />
</RelativeLayout>
\ No newline at end of file
android:textSize="14sp" />
<ProgressBar
android:id="@+id/ml_item_progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/ml_item_thumbnail"
android:layout_marginRight="20dip"
android:layout_marginLeft="10dip"
android:paddingBottom="3dip"
android:focusable="false"
android:indeterminate="false"
android:maxHeight="3dip"
android:minHeight="3dip"
android:progressDrawable="@drawable/gridview_progressbar" />
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dip"
android:layout_alignParentRight="true"
android:clickable="true"
android:src="@drawable/ic_more_vert_grey600_24dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="list_mode">false</bool>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="list_mode">false</bool>
</resources>
\ No newline at end of file
<resources>
<dimen name="grid_card_width">200dp</dimen>
<dimen name="grid_card_height">200dp</dimen>
<dimen name="grid_card_thumb_height">120dp</dimen>
<dimen name="grid_card_title_text_size">16sp</dimen>
<dimen name="grid_card_subtitle_text_size">12sp</dimen>
<dimen name="grid_card_vertical_spacing">10dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="list_mode">true</bool>
</resources>
\ No newline at end of file
......@@ -3,4 +3,10 @@
<dimen name="widget_margin">10dp</dimen>
<dimen name="audio_browser_item_size">50dp</dimen>
<dimen name="listview_bottom_padding">50dp</dimen>
<dimen name="grid_card_width">160dp</dimen>
<dimen name="grid_card_height">160dp</dimen>
<dimen name="grid_card_thumb_height">100dp</dimen>
<dimen name="grid_card_title_text_size">12sp</dimen>
<dimen name="grid_card_subtitle_text_size">10sp</dimen>
<dimen name="grid_card_vertical_spacing">0dp</dimen>
</resources>
\ No newline at end of file
......@@ -50,6 +50,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
......@@ -81,14 +82,7 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
protected static final String ACTION_SCAN_STOP = "org.videolan.vlc.gui.ScanStop";
protected static final int UPDATE_ITEM = 0;
/* Constants used to switch from Grid to List and vice versa */
//FIXME If you know a way to do this in pure XML please do it!
private static final int GRID_ITEM_WIDTH_DP = 156;
private static final int GRID_HORIZONTAL_SPACING_DP = 20;
private static final int GRID_VERTICAL_SPACING_DP = 20;
private static final int GRID_STRETCH_MODE = GridView.STRETCH_COLUMN_WIDTH;
private static final int LIST_HORIZONTAL_SPACING_DP = 0;
private static final int LIST_VERTICAL_SPACING_DP = 10;
private static final int LIST_STRETCH_MODE = GridView.STRETCH_COLUMN_WIDTH;
protected LinearLayout mLayoutFlipperLoading;
......@@ -207,29 +201,13 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
mVideoAdapter.clear();
}
private boolean hasSpaceForGrid(View v) {
final Activity activity = getActivity();
if (activity == null)
return true;
DisplayMetrics outMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
final int itemWidth = Util.convertDpToPx(GRID_ITEM_WIDTH_DP);
final int horizontalspacing = Util.convertDpToPx(GRID_HORIZONTAL_SPACING_DP);
final int width = mGridView.getPaddingLeft() + mGridView.getPaddingRight()
+ horizontalspacing + (itemWidth * 2);
if (width < outMetrics.widthPixels)
return true;
return false;
}
private void updateViewMode() {
if (getView() == null || getActivity() == null) {
Log.w(TAG, "Unable to setup the view");
return;
}
Resources res = getResources();
// Compute the left/right padding dynamically
DisplayMetrics outMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
......@@ -239,20 +217,15 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
sidePadding, mGridView.getPaddingBottom());
// Select between grid or list
if (hasSpaceForGrid(getView())) {
Log.d(TAG, "Switching to grid mode");
if (!res.getBoolean(R.bool.list_mode)) {
mGridView.setNumColumns(GridView.AUTO_FIT);
mGridView.setStretchMode(GRID_STRETCH_MODE);
mGridView.setHorizontalSpacing(Util.convertDpToPx(GRID_HORIZONTAL_SPACING_DP));
mGridView.setVerticalSpacing(Util.convertDpToPx(GRID_VERTICAL_SPACING_DP));
mGridView.setColumnWidth(Util.convertDpToPx(GRID_ITEM_WIDTH_DP));
mGridView.setColumnWidth(res.getDimensionPixelSize(R.dimen.grid_card_width));
mGridView.setVerticalSpacing(res.getDimensionPixelSize(R.dimen.grid_card_vertical_spacing));
mVideoAdapter.setListMode(false);
} else {
Log.d(TAG, "Switching to list mode");
mGridView.setNumColumns(1);
mGridView.setStretchMode(LIST_STRETCH_MODE);
mGridView.setHorizontalSpacing(LIST_HORIZONTAL_SPACING_DP);
mGridView.setVerticalSpacing(Util.convertDpToPx(LIST_VERTICAL_SPACING_DP));
mVideoAdapter.setListMode(true);
}
}
......
......@@ -139,9 +139,9 @@ public class VideoListAdapter extends ArrayAdapter<Media>
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (!mListMode)
v = inflater.inflate(R.layout.video_grid_item, parent, false);
v = inflater.inflate(R.layout.video_grid_card, parent, false);
else
v = inflater.inflate(R.layout.video_list_item, parent, false);
v = inflater.inflate(R.layout.video_list_card, parent, false);
holder = new ViewHolder();
holder.layout = v.findViewById(R.id.layout_item);
......@@ -203,7 +203,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
holder.subtitle.setText(text);
holder.title.setText(media.getTitle() + "\u2026"); // ellipsis
holder.more.setVisibility(View.INVISIBLE);
holder.progress.setVisibility(View.GONE);
holder.progress.setVisibility(View.INVISIBLE);
}
private void fillVideoView(ViewHolder holder, Media media) {
......@@ -219,7 +219,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
holder.progress.setProgress((int) (lastTime / 1000));
} else {
text = Strings.millisToText(media.getLength());
holder.progress.setVisibility(View.GONE);
holder.progress.setVisibility(View.INVISIBLE);
}
if (media.getWidth() > 0 && media.getHeight() > 0) {
......
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