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

Nicer list for folder browsing

With image button for context menu when available
parent afe0fdb7
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/listview_bottom_padding" android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false" > android:clipToPadding="false"
android:divider="?attr/background_menu_divider"
android:dividerHeight="0.1dp" >
</ListView> </ListView>
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
android:id="@+id/layout_item" android:id="@+id/layout_item"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" > android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp" >
<ImageView <ImageView
android:id="@+id/dvi_icon" android:id="@+id/dvi_icon"
...@@ -14,9 +16,10 @@ ...@@ -14,9 +16,10 @@
android:src="@drawable/icon" /> android:src="@drawable/icon" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="10dp" > android:paddingLeft="10dp" >
...@@ -43,4 +46,12 @@ ...@@ -43,4 +46,12 @@
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout> </LinearLayout>
<ImageView
android:id="@+id/item_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_more_vert_grey600_24dp"
android:clickable="true" />
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -44,6 +44,7 @@ import android.preference.PreferenceManager; ...@@ -44,6 +44,7 @@ import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -52,6 +53,8 @@ import android.widget.TextView; ...@@ -52,6 +53,8 @@ import android.widget.TextView;
public class DirectoryAdapter extends BaseAdapter { public class DirectoryAdapter extends BaseAdapter {
public final static String TAG = "VLC/DirectoryAdapter"; public final static String TAG = "VLC/DirectoryAdapter";
private ContextPopupMenuListener mContextPopupMenuListener;
public static boolean acceptedPath(String f) { public static boolean acceptedPath(String f) {
return Pattern.compile(Media.EXTENSIONS_REGEX, Pattern.CASE_INSENSITIVE).matcher(f).matches(); return Pattern.compile(Media.EXTENSIONS_REGEX, Pattern.CASE_INSENSITIVE).matcher(f).matches();
} }
...@@ -171,6 +174,7 @@ public class DirectoryAdapter extends BaseAdapter { ...@@ -171,6 +174,7 @@ public class DirectoryAdapter extends BaseAdapter {
TextView title; TextView title;
TextView text; TextView text;
ImageView icon; ImageView icon;
ImageView more;
} }
private void populateNode(DirectoryAdapter.Node n, String path) { private void populateNode(DirectoryAdapter.Node n, String path) {
...@@ -298,7 +302,7 @@ public class DirectoryAdapter extends BaseAdapter { ...@@ -298,7 +302,7 @@ public class DirectoryAdapter extends BaseAdapter {
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
DirectoryAdapter.Node selectedNode = mCurrentNode.children.get(position); DirectoryAdapter.Node selectedNode = mCurrentNode.children.get(position);
DirectoryViewHolder holder; DirectoryViewHolder holder;
View v = convertView; View v = convertView;
...@@ -315,6 +319,7 @@ public class DirectoryAdapter extends BaseAdapter { ...@@ -315,6 +319,7 @@ public class DirectoryAdapter extends BaseAdapter {
Util.setAlignModeByPref(mAlignMode, holder.title); Util.setAlignModeByPref(mAlignMode, holder.title);
holder.text = (TextView) v.findViewById(R.id.text); holder.text = (TextView) v.findViewById(R.id.text);
holder.icon = (ImageView) v.findViewById(R.id.dvi_icon); holder.icon = (ImageView) v.findViewById(R.id.dvi_icon);
holder.more = (ImageView) v.findViewById(R.id.item_more);
v.setTag(holder); v.setTag(holder);
} else } else
holder = (DirectoryViewHolder) v.getTag(); holder = (DirectoryViewHolder) v.getTag();
...@@ -346,12 +351,28 @@ public class DirectoryAdapter extends BaseAdapter { ...@@ -346,12 +351,28 @@ public class DirectoryAdapter extends BaseAdapter {
R.plurals.mediafiles_quantity, mediaFileCount, R.plurals.mediafiles_quantity, mediaFileCount,
mediaFileCount); mediaFileCount);
} }
if (holderText.isEmpty())
holder.text.setVisibility(View.GONE);
else {
holder.text.setVisibility(View.VISIBLE);
holder.text.setText(holderText); holder.text.setText(holderText);
}
if(selectedNode.isFile()) if(selectedNode.isFile())
holder.icon.setImageResource(R.drawable.icon); holder.icon.setImageResource(R.drawable.icon);
else else
holder.icon.setImageResource(R.drawable.ic_menu_folder); holder.icon.setImageResource(R.drawable.ic_menu_folder);
if (isChildFile(position)) {
holder.more.setVisibility(View.VISIBLE);
holder.more.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mContextPopupMenuListener != null)
mContextPopupMenuListener.onPopupMenu(v, position);
}
});
} else
holder.more.setVisibility(View.GONE);
return v; return v;
} }
...@@ -481,4 +502,12 @@ public class DirectoryAdapter extends BaseAdapter { ...@@ -481,4 +502,12 @@ public class DirectoryAdapter extends BaseAdapter {
} }
return file.getName(); return file.getName();
} }
public interface ContextPopupMenuListener {
void onPopupMenu(View anchor, final int position);
}
void setContextPopupMenuListener(ContextPopupMenuListener l) {
mContextPopupMenuListener = l;
}
} }
...@@ -24,6 +24,7 @@ import java.io.IOException; ...@@ -24,6 +24,7 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import org.videolan.libvlc.LibVLC; import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.audio.AudioServiceController; import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.gui.video.VideoPlayerActivity; import org.videolan.vlc.gui.video.VideoPlayerActivity;
...@@ -32,14 +33,18 @@ import org.videolan.vlc.interfaces.ISortable; ...@@ -32,14 +33,18 @@ import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.util.Util; import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCRunnable; import org.videolan.vlc.util.VLCRunnable;
import android.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.PopupMenu.OnMenuItemClickListener;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -93,6 +98,7 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable, ...@@ -93,6 +98,7 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable,
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(R.string.directories); ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(R.string.directories);
View v = inflater.inflate(R.layout.directory_view, container, false); View v = inflater.inflate(R.layout.directory_view, container, false);
mDirectoryAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
setListAdapter(mDirectoryAdapter); setListAdapter(mDirectoryAdapter);
final ListView listView = (ListView)v.findViewById(android.R.id.list); final ListView listView = (ListView)v.findViewById(android.R.id.list);
listView.setNextFocusUpId(R.id.ml_menu_search); listView.setNextFocusUpId(R.id.ml_menu_search);
...@@ -238,4 +244,29 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable, ...@@ -238,4 +244,29 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable,
} }
} }
}; };
DirectoryAdapter.ContextPopupMenuListener mContextPopupMenuListener
= new DirectoryAdapter.ContextPopupMenuListener() {
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onPopupMenu(View anchor, final int position) {
if (!LibVlcUtil.isHoneycombOrLater()) {
// Call the "classic" context menu
anchor.performLongClick();
return;
}
PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
popupMenu.getMenuInflater().inflate(R.menu.directory_view, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return onContextItemSelected(item);
}
});
popupMenu.show();
}
};
} }
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