Commit fedc8720 authored by Edward Wang's avatar Edward Wang

Add DirectoryViewFragment and related missing files

Folder clipart from http://openclipart.org/detail/74023/folder-by-vorre-74023, public domain.
parent 3c504a03
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/item_common"
android:dividerHeight="1dp">
</ListView>
package org.videolan.vlc.gui;
import java.io.IOException;
import java.util.ArrayList;
import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.LibVLC;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.gui.audio.AudioDirectoryAdapter;
import org.videolan.vlc.gui.audio.AudioPlayerActivity;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.interfaces.ISortable;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import com.actionbarsherlock.app.SherlockListFragment;
public class DirectoryViewFragment extends SherlockListFragment implements ISortable {
public final static String TAG = "VLC/DirectoryViewFragment";
private AudioDirectoryAdapter mDirectoryAdapter;
private Context mContext;
public DirectoryViewFragment(Context context) {
mContext = context;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDirectoryAdapter = new AudioDirectoryAdapter(mContext);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.directory_view, container, false);
setListAdapter(mDirectoryAdapter);
return v;
}
@Override
public void onListItemClick(ListView l, View v, int p, long id) {
Boolean success = mDirectoryAdapter.browse(p);
if(!success) { /* Clicked on a media file */
AudioServiceController audioController = AudioServiceController.getInstance();
String mediaFile = mDirectoryAdapter.getMediaLocation(p);
try {
if(!LibVLC.getExistingInstance().hasVideoTrack(mediaFile)) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add(mDirectoryAdapter.getMediaLocation(p));
audioController.load(arrayList, 0);
Intent intent = new Intent(getActivity(), AudioPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
audioController.stop();
Intent intent = new Intent(getActivity(), VideoPlayerActivity.class);
intent.putExtra("itemLocation", mediaFile);
startActivity(intent);
}
} catch (IOException e) {
/* disk error maybe? */
}
}
}
@Override
public void sortBy(int sortby) {
// TODO
Util.toaster(getActivity(), R.string.notavailable);
}
}
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