Commit fbb4e0e4 authored by Alexandre Perraud's avatar Alexandre Perraud Committed by Jean-Baptiste Kempf
Browse files

Explicit message when scanning multimedia library



    Works only for video for now.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 539383b1
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<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">
android:background="@color/item_common" >
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
......@@ -11,11 +11,43 @@
android:divider="@color/item_common"
android:dividerHeight="1dp"
android:fastScrollEnabled="true" />
<TextView
<LinearLayout
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="@string/nomedia"
android:textSize="20dip" />
</FrameLayout>
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" />
<ViewFlipper
android:id="@+id/flipper_loading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoStart="true"
android:flipInterval="1000"
android:visibility="invisible" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/loadmedia"
android:textSize="20dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="" />
</ViewFlipper>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
......@@ -65,6 +65,7 @@
<string name="loading">Loading…</string>
<string name="please_wait">Please wait…</string>
<string name="nomedia">No media files found, please transfer files to your device or adjust your preferences.</string>
<string name="loadmedia">Loading...</string>
<string name="mediafiles">Media files</string>
<string name="notavailable">not available</string>
<string name="nosubdirectory">No subdirectories.</string>
......
......@@ -32,6 +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 android.content.Context;
import android.content.SharedPreferences;
......@@ -59,6 +60,7 @@ public class MediaLibrary {
public void loadMediaItems(Context context) {
if (mLoadingThread == null || mLoadingThread.getState() == State.TERMINATED) {
VideoListFragment.actionScanStart(context.getApplicationContext());
mLoadingThread = new Thread(new GetMediaItemsRunnable(context.getApplicationContext()));
mLoadingThread.start();
}
......@@ -151,6 +153,10 @@ public class MediaLibrary {
return items;
}
public boolean ismLoadingThreadrunning () {
return mLoadingThread.isAlive();
};
private class GetMediaItemsRunnable implements Runnable {
private final Stack<File> directories = new Stack<File>();
......@@ -286,6 +292,9 @@ public class MediaLibrary {
// hide progressbar in footer
MainActivity.clearTextInfo(mContext);
MainActivity.hideProgressBar(mContext);
VideoListFragment.actionScanStop(mContext);
mContext = null;
}
};
......
......@@ -37,12 +37,15 @@ import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.interfaces.ISortable;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
......@@ -52,10 +55,19 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ViewFlipper;
import com.actionbarsherlock.app.SherlockListFragment;
public class VideoListFragment extends SherlockListFragment implements ISortable {
protected static final String ACTION_SCAN_START = "org.videolan.vlc.gui.ScanStart";
protected static final String ACTION_SCAN_STOP = "org.videolan.vlc.gui.ScanStop";
protected ViewFlipper mFlipperViewLoading;
protected TextView mTextViewNomedia;
public final static String TAG = "VLC/VideoListFragment";
private VideoListAdapter mVideoAdapter;
......@@ -85,6 +97,11 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.video_list, container, false);
// init the information for the scan (1/2)
mFlipperViewLoading = (ViewFlipper) v.findViewById(R.id.flipper_loading);
mTextViewNomedia = (TextView) v.findViewById(R.id.textview_nomedia);
return v;
}
......@@ -92,6 +109,18 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
registerForContextMenu(getListView());
// init the information for the scan (2/2)
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_SCAN_START);
filter.addAction(ACTION_SCAN_STOP);
getActivity().registerReceiver(messageReceiverVideoListFragment, filter);
Log.i(TAG,"mMediaLibrary.ismLoadingThreadrunning() " + Boolean.toString(mMediaLibrary.ismLoadingThreadrunning()));
if (mMediaLibrary.ismLoadingThreadrunning()) {
actionScanStart(getActivity().getApplicationContext());
}
updateList();
}
......@@ -119,12 +148,13 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
mThumbnailerManager.interrupt();
mBarrier.reset();
mVideoAdapter.clear();
getActivity().unregisterReceiver(messageReceiverVideoListFragment);
super.onDestroy();
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
playVideo(position);
playVideo(position);
super.onListItemClick(l, v, position, id);
}
......@@ -141,31 +171,31 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
@Override
public boolean onContextItemSelected(MenuItem menu) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menu.getMenuInfo();
switch (menu.getItemId())
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menu.getMenuInfo();
switch (menu.getItemId())
{
case R.id.video_list_play:
playVideo(info.position);
return true;
case R.id.video_list_info:
Intent intent = new Intent(getActivity(), MediaInfoActivity.class);
intent.putExtra("itemLocation",
mVideoAdapter.getItem(info.position).getLocation());
startActivity(intent);
return true;
case R.id.video_list_delete:
final int positionDelete = info.position;
AlertDialog alertDialog = CommonDialogs.deleteMedia(
getActivity(),
mVideoAdapter.getItem(positionDelete).getLocation(),
new VlcRunnable() {
@Override
public void run(Object o) {
mVideoAdapter.remove(mVideoAdapter.getItem(positionDelete));
}
});
alertDialog.show();
return true;
case R.id.video_list_play:
playVideo(info.position);
return true;
case R.id.video_list_info:
Intent intent = new Intent(getActivity(), MediaInfoActivity.class);
intent.putExtra("itemLocation",
mVideoAdapter.getItem(info.position).getLocation());
startActivity(intent);
return true;
case R.id.video_list_delete:
final int positionDelete = info.position;
AlertDialog alertDialog = CommonDialogs.deleteMedia(
getActivity(),
mVideoAdapter.getItem(positionDelete).getLocation(),
new VlcRunnable() {
@Override
public void run(Object o) {
mVideoAdapter.remove(mVideoAdapter.getItem(positionDelete));
}
});
alertDialog.show();
return true;
}
return super.onContextItemSelected(menu);
}
......@@ -193,12 +223,12 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
if(fragment == null) return;
switch (msg.what) {
case UPDATE_ITEM:
fragment.updateItem();
break;
case MediaLibrary.MEDIA_ITEMS_UPDATED:
fragment.updateList();
break;
case UPDATE_ITEM:
fragment.updateItem();
break;
case MediaLibrary.MEDIA_ITEMS_UPDATED:
fragment.updateList();
break;
}
}
};
......@@ -245,4 +275,34 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
mBarrier.await();
}
private final BroadcastReceiver messageReceiverVideoListFragment = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase(ACTION_SCAN_START)) {
mFlipperViewLoading.setVisibility(View.VISIBLE);
mTextViewNomedia.setVisibility(View.INVISIBLE);
} else if (action.equalsIgnoreCase(ACTION_SCAN_STOP)) {
mFlipperViewLoading.setVisibility(View.INVISIBLE);
mTextViewNomedia.setVisibility(View.VISIBLE);
}
}
};
public static void actionScanStart(Context context) {
if (context == null)
return;
Intent intent = new Intent();
intent.setAction(ACTION_SCAN_START);
context.getApplicationContext().sendBroadcast(intent);
}
public static void actionScanStop(Context context) {
if (context == null)
return;
Intent intent = new Intent();
intent.setAction(ACTION_SCAN_STOP);
context.getApplicationContext().sendBroadcast(intent);
}
}
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