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 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/listview_bottom_padding"
android:clipToPadding="false" >
android:clipToPadding="false"
android:divider="?attr/background_menu_divider"
android:dividerHeight="0.1dp" >
</ListView>
......@@ -3,7 +3,9 @@
android:id="@+id/layout_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp" >
<ImageView
android:id="@+id/dvi_icon"
......@@ -14,9 +16,10 @@
android:src="@drawable/icon" />
<LinearLayout
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp" >
......@@ -43,4 +46,12 @@
android:textSize="14sp" />
</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>
\ No newline at end of file
......@@ -44,6 +44,7 @@ import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
......@@ -52,6 +53,8 @@ import android.widget.TextView;
public class DirectoryAdapter extends BaseAdapter {
public final static String TAG = "VLC/DirectoryAdapter";
private ContextPopupMenuListener mContextPopupMenuListener;
public static boolean acceptedPath(String f) {
return Pattern.compile(Media.EXTENSIONS_REGEX, Pattern.CASE_INSENSITIVE).matcher(f).matches();
}
......@@ -171,6 +174,7 @@ public class DirectoryAdapter extends BaseAdapter {
TextView title;
TextView text;
ImageView icon;
ImageView more;
}
private void populateNode(DirectoryAdapter.Node n, String path) {
......@@ -298,7 +302,7 @@ public class DirectoryAdapter extends BaseAdapter {
}
@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);
DirectoryViewHolder holder;
View v = convertView;
......@@ -315,6 +319,7 @@ public class DirectoryAdapter extends BaseAdapter {
Util.setAlignModeByPref(mAlignMode, holder.title);
holder.text = (TextView) v.findViewById(R.id.text);
holder.icon = (ImageView) v.findViewById(R.id.dvi_icon);
holder.more = (ImageView) v.findViewById(R.id.item_more);
v.setTag(holder);
} else
holder = (DirectoryViewHolder) v.getTag();
......@@ -346,12 +351,28 @@ public class DirectoryAdapter extends BaseAdapter {
R.plurals.mediafiles_quantity, mediaFileCount,
mediaFileCount);
}
holder.text.setText(holderText);
if (holderText.isEmpty())
holder.text.setVisibility(View.GONE);
else {
holder.text.setVisibility(View.VISIBLE);
holder.text.setText(holderText);
}
if(selectedNode.isFile())
holder.icon.setImageResource(R.drawable.icon);
else
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;
}
......@@ -481,4 +502,12 @@ public class DirectoryAdapter extends BaseAdapter {
}
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;
import java.util.List;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.R;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
......@@ -32,14 +33,18 @@ import org.videolan.vlc.interfaces.ISortable;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCRunnable;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
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.ContextMenuInfo;
import android.view.LayoutInflater;
......@@ -93,6 +98,7 @@ public class DirectoryViewFragment extends ListFragment implements IRefreshable,
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(R.string.directories);
View v = inflater.inflate(R.layout.directory_view, container, false);
mDirectoryAdapter.setContextPopupMenuListener(mContextPopupMenuListener);
setListAdapter(mDirectoryAdapter);
final ListView listView = (ListView)v.findViewById(android.R.id.list);
listView.setNextFocusUpId(R.id.ml_menu_search);
......@@ -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