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

Update media list on ML service finished

parent c40305aa
...@@ -38,6 +38,7 @@ import android.support.design.widget.AppBarLayout; ...@@ -38,6 +38,7 @@ import android.support.design.widget.AppBarLayout;
import android.support.design.widget.BottomSheetBehavior; import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.support.v7.widget.ViewStubCompat; import android.support.v7.widget.ViewStubCompat;
import android.view.MenuItem; import android.view.MenuItem;
...@@ -53,7 +54,6 @@ import org.videolan.vlc.R; ...@@ -53,7 +54,6 @@ import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication; import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.audio.AudioPlayer; import org.videolan.vlc.gui.audio.AudioPlayer;
import org.videolan.vlc.gui.browser.StorageBrowserFragment; import org.videolan.vlc.gui.browser.StorageBrowserFragment;
import org.videolan.vlc.gui.tv.browser.BaseTvActivity;
import org.videolan.vlc.interfaces.IRefreshable; import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.media.MediaUtils; import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Strings; import org.videolan.vlc.util.Strings;
...@@ -359,11 +359,13 @@ public class AudioPlayerContainerActivity extends BaseActivity implements Playba ...@@ -359,11 +359,13 @@ public class AudioPlayerContainerActivity extends BaseActivity implements Playba
.setAction(DialogActivity.KEY_STORAGE) .setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(MediaParsingService.EXTRA_PATH, path)); .putExtra(MediaParsingService.EXTRA_PATH, path));
} } else
owner.startService(new Intent(MediaParsingService.ACTION_RELOAD, null, owner, MediaParsingService.class)
.putExtra(MediaParsingService.EXTRA_PATH, path));
break; break;
case ACTION_MEDIA_UNMOUNTED: case ACTION_MEDIA_UNMOUNTED:
VLCApplication.getMLInstance().removeDevice(uuid); VLCApplication.getMLInstance().removeDevice(uuid);
owner.startService(new Intent(MediaParsingService.ACTION_RELOAD, null, owner, MediaParsingService.class)); LocalBroadcastManager.getInstance(owner).sendBroadcast(new Intent(MediaParsingService.ACTION_SERVICE_ENDED));
break; break;
} }
} }
......
...@@ -45,7 +45,6 @@ import android.widget.TextView; ...@@ -45,7 +45,6 @@ import android.widget.TextView;
import org.videolan.libvlc.Media; import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.MediaBrowser; import org.videolan.libvlc.util.MediaBrowser;
import org.videolan.medialibrary.Medialibrary; import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
import org.videolan.medialibrary.interfaces.MediaAddedCb; import org.videolan.medialibrary.interfaces.MediaAddedCb;
import org.videolan.medialibrary.interfaces.MediaUpdatedCb; import org.videolan.medialibrary.interfaces.MediaUpdatedCb;
import org.videolan.medialibrary.media.Album; import org.videolan.medialibrary.media.Album;
...@@ -75,7 +74,7 @@ import java.util.Arrays; ...@@ -75,7 +74,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDiscoveryCb, SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, ViewPager.OnPageChangeListener, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable { public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, ViewPager.OnPageChangeListener, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable {
public final static String TAG = "VLC/AudioBrowserFragment"; public final static String TAG = "VLC/AudioBrowserFragment";
private MediaBrowser mMediaBrowser; private MediaBrowser mMediaBrowser;
...@@ -194,7 +193,8 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis ...@@ -194,7 +193,8 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
super.onPause(); super.onPause();
mViewPager.removeOnPageChangeListener(this); mViewPager.removeOnPageChangeListener(this);
mMediaLibrary.removeDeviceDiscoveryCb(this); mMediaLibrary.removeMediaUpdatedCb();
mMediaLibrary.removeMediaAddedCb();
if (mMediaBrowser != null) { if (mMediaBrowser != null) {
mMediaBrowser.release(); mMediaBrowser.release();
mMediaBrowser = null; mMediaBrowser = null;
...@@ -212,14 +212,14 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis ...@@ -212,14 +212,14 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
super.onResume(); super.onResume();
setSearchVisibility(false); setSearchVisibility(false);
mViewPager.addOnPageChangeListener(this); mViewPager.addOnPageChangeListener(this);
if (mMediaLibrary.isInitiated()) if (mMediaLibrary.isInitiated() && !mMediaLibrary.isWorking())
fillView(); onMedialibraryReady();
else else
setupMediaLibraryReceiver(); setupMediaLibraryReceiver();
} }
protected void fillView() { protected void onMedialibraryReady() {
mMediaLibrary.addDeviceDiscoveryCb(this); super.onMedialibraryReady();
mMediaLibrary.setArtistsAddedCb(this); mMediaLibrary.setArtistsAddedCb(this);
mMediaLibrary.setAlbumsAddedCb(this); mMediaLibrary.setAlbumsAddedCb(this);
mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_AUDIO_EMPTY); mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_AUDIO_EMPTY);
...@@ -833,34 +833,13 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis ...@@ -833,34 +833,13 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements DevicesDis
mPlaylistAdapter.clear(); mPlaylistAdapter.clear();
} }
boolean mParsing = false;
@Override @Override
public void onDiscoveryStarted(String entryPoint) {} protected void onParsingServiceStarted() {
mHandler.sendEmptyMessageDelayed(SET_REFRESHING, 300);
@Override
public void onDiscoveryProgress(String entryPoint) {}
@Override
public void onDiscoveryCompleted(String entryPoint) {
mHandler.sendEmptyMessage(mParsing ? SET_REFRESHING : UNSET_REFRESHING);
}
@Override
public void onParsingStatsUpdated(int percent) {
mParsing = percent < 100;
if (percent == 100) {
mHandler.sendEmptyMessage(UPDATE_LIST);
} else if (!mSwipeRefreshLayout.isRefreshing())
mHandler.sendEmptyMessage(SET_REFRESHING);
}
@Override
public void onReloadStarted(String entryPoint) {
mHandler.sendEmptyMessage(SET_REFRESHING);
} }
@Override @Override
public void onReloadCompleted(String entryPoint) { protected void onParsingServiceFinished() {
mHandler.sendEmptyMessage(UNSET_REFRESHING); mHandler.sendEmptyMessage(UPDATE_LIST);
} }
} }
...@@ -42,6 +42,7 @@ import android.view.View; ...@@ -42,6 +42,7 @@ import android.view.View;
import org.videolan.medialibrary.Medialibrary; import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.MediaLibraryItem; import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper; import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.MediaParsingService;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication; import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.InfoActivity; import org.videolan.vlc.gui.InfoActivity;
...@@ -99,6 +100,7 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple ...@@ -99,6 +100,7 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
stopActionMode(); stopActionMode();
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mParsingServiceReceiver);
} }
public void setFabPlayVisibility(boolean enable) { public void setFabPlayVisibility(boolean enable) {
...@@ -206,15 +208,39 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple ...@@ -206,15 +208,39 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment imple
return false; return false;
} }
protected void fillView() {}; protected void onMedialibraryReady() {
IntentFilter parsingServiceFilter = new IntentFilter(MediaParsingService.ACTION_SERVICE_ENDED);
parsingServiceFilter.addAction(MediaParsingService.ACTION_SERVICE_STARTED);
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mParsingServiceReceiver, parsingServiceFilter);
};
protected void setupMediaLibraryReceiver() { protected void setupMediaLibraryReceiver() {
final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() { final BroadcastReceiver libraryReadyReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(this); LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(this);
fillView(); onMedialibraryReady();
} }
}; };
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(libraryReadyReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY)); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(libraryReadyReceiver, new IntentFilter(VLCApplication.ACTION_MEDIALIBRARY_READY));
} }
protected final BroadcastReceiver mParsingServiceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case MediaParsingService.ACTION_SERVICE_ENDED:
onParsingServiceFinished();
break;
case MediaParsingService.ACTION_SERVICE_STARTED:
onParsingServiceStarted();
break;
}
}
};
protected void onParsingServiceStarted() {}
protected void onParsingServiceFinished() {}
} }
...@@ -59,7 +59,6 @@ import org.videolan.libvlc.Media; ...@@ -59,7 +59,6 @@ import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer; import org.videolan.libvlc.MediaPlayer;
import org.videolan.medialibrary.Medialibrary; import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.Tools; import org.videolan.medialibrary.Tools;
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
import org.videolan.medialibrary.interfaces.MediaUpdatedCb; import org.videolan.medialibrary.interfaces.MediaUpdatedCb;
import org.videolan.medialibrary.media.MediaWrapper; import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BuildConfig; import org.videolan.vlc.BuildConfig;
...@@ -87,7 +86,7 @@ import java.util.List; ...@@ -87,7 +86,7 @@ import java.util.List;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class MainTvActivity extends BaseTvActivity implements OnItemViewSelectedListener, public class MainTvActivity extends BaseTvActivity implements OnItemViewSelectedListener,
OnItemViewClickedListener, OnClickListener, PlaybackService.Callback, MediaUpdatedCb, DevicesDiscoveryCb { OnItemViewClickedListener, OnClickListener, PlaybackService.Callback, MediaUpdatedCb {
private static final int NUM_ITEMS_PREVIEW = 5; private static final int NUM_ITEMS_PREVIEW = 5;
...@@ -170,7 +169,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -170,7 +169,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
/* /*
* skip browser and show directly Audio Player if a song is playing * skip browser and show directly Audio Player if a song is playing
*/ */
if (mMediaLibrary.isInitiated() && (mRowsAdapter == null || mRowsAdapter.size() == 0) && Permissions.canReadStorage()) if (mMediaLibrary.isInitiated() && !mMediaLibrary.isWorking() && (mRowsAdapter == null || mRowsAdapter.size() == 0) && Permissions.canReadStorage())
update(); update();
else { else {
updateBrowsers(); updateBrowsers();
...@@ -214,7 +213,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -214,7 +213,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
mService.addCallback(this); mService.addCallback(this);
if (mMediaLibrary.isInitiated()) { if (mMediaLibrary.isInitiated()) {
setmedialibraryListeners(); setmedialibraryListeners();
update();
} else } else
setupMediaLibraryReceiver(); setupMediaLibraryReceiver();
} }
...@@ -225,7 +223,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -225,7 +223,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
if (mService != null) if (mService != null)
mService.removeCallback(this); mService.removeCallback(this);
mMediaLibrary.removeMediaUpdatedCb(); mMediaLibrary.removeMediaUpdatedCb();
mMediaLibrary.removeDeviceDiscoveryCb(this);
} }
@Override @Override
...@@ -371,30 +368,13 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -371,30 +368,13 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
} }
@Override @Override
public void onDiscoveryStarted(String entryPoint) {} protected void onParsingServiceStarted() {
mHandler.sendEmptyMessageDelayed(SHOW_LOADING, 300);
@Override
public void onDiscoveryProgress(String entryPoint) {}
@Override
public void onDiscoveryCompleted(String entryPoint) {}
@Override
public void onParsingStatsUpdated(int percent) {
if (percent == 100)
update();
else if (mProgressBar.getVisibility() != View.VISIBLE)
mHandler.sendEmptyMessage(SHOW_LOADING);
}
@Override
public void onReloadStarted(String entryPoint) {
mHandler.sendEmptyMessage(SHOW_LOADING);
} }
@Override @Override
public void onReloadCompleted(String entryPoint) { protected void onParsingServiceFinished() {
mHandler.sendEmptyMessage(HIDE_LOADING); update();
} }
private static final int SHOW_LOADING = 0; private static final int SHOW_LOADING = 0;
...@@ -427,7 +407,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -427,7 +407,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
if (mRowsAdapter != null) if (mRowsAdapter != null)
mRowsAdapter.clear(); mRowsAdapter.clear();
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
mHandler.sendEmptyMessage(SHOW_LOADING); mHandler.sendEmptyMessageDelayed(SHOW_LOADING, 300);
mHistoryIndex.clear(); mHistoryIndex.clear();
//Video Section //Video Section
...@@ -553,11 +533,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -553,11 +533,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
updateBrowsers(); updateBrowsers();
} }
@Override
protected void onExternelDeviceChange() {
updateBrowsers();
}
@Override @Override
public void updateProgress(){} public void updateProgress(){}
...@@ -611,7 +586,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected ...@@ -611,7 +586,6 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
private void setmedialibraryListeners() { private void setmedialibraryListeners() {
mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO); mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO);
mMediaLibrary.addDeviceDiscoveryCb(this);
} }
private void setupMediaLibraryReceiver() { private void setupMediaLibraryReceiver() {
......
...@@ -33,9 +33,8 @@ import android.net.ConnectivityManager; ...@@ -33,9 +33,8 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.view.KeyEvent; import android.view.KeyEvent;
import org.videolan.medialibrary.Medialibrary; import org.videolan.medialibrary.Medialibrary;
...@@ -44,11 +43,12 @@ import org.videolan.vlc.VLCApplication; ...@@ -44,11 +43,12 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.DialogActivity; import org.videolan.vlc.gui.DialogActivity;
import org.videolan.vlc.gui.PlaybackServiceActivity; import org.videolan.vlc.gui.PlaybackServiceActivity;
import org.videolan.vlc.gui.tv.SearchActivity; import org.videolan.vlc.gui.tv.SearchActivity;
import org.videolan.vlc.util.WeakHandler;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public abstract class BaseTvActivity extends PlaybackServiceActivity { public abstract class BaseTvActivity extends PlaybackServiceActivity {
private static final String TAG = "VLC/BaseTvActivity";
protected Medialibrary mMediaLibrary; protected Medialibrary mMediaLibrary;
protected SharedPreferences mSettings; protected SharedPreferences mSettings;
boolean mRegistering = false; boolean mRegistering = false;
...@@ -70,16 +70,20 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity { ...@@ -70,16 +70,20 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
storageFilter.addAction(Intent.ACTION_MEDIA_REMOVED); storageFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
storageFilter.addAction(Intent.ACTION_MEDIA_EJECT); storageFilter.addAction(Intent.ACTION_MEDIA_EJECT);
storageFilter.addDataScheme("file"); storageFilter.addDataScheme("file");
IntentFilter parsingServiceFilter = new IntentFilter(MediaParsingService.ACTION_SERVICE_ENDED);
parsingServiceFilter.addAction(MediaParsingService.ACTION_SERVICE_STARTED);
mRegistering = true; mRegistering = true;
registerReceiver(mExternalDevicesReceiver, networkFilter); LocalBroadcastManager.getInstance(this).registerReceiver(mParsingServiceReceiver, parsingServiceFilter);
registerReceiver(mExternalDevicesReceiver, storageFilter); registerReceiver(mExternalDevicesReceiver, storageFilter);
registerReceiver(mExternalDevicesReceiver, networkFilter);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
unregisterReceiver(mExternalDevicesReceiver); unregisterReceiver(mExternalDevicesReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mParsingServiceReceiver);
} }
@Override @Override
...@@ -93,7 +97,25 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity { ...@@ -93,7 +97,25 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
protected abstract void refresh(); protected abstract void refresh();
protected abstract void onNetworkUpdated(); protected abstract void onNetworkUpdated();
protected void onExternelDeviceChange() {}
protected final BroadcastReceiver mParsingServiceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case MediaParsingService.ACTION_SERVICE_ENDED:
onParsingServiceFinished();
break;
case MediaParsingService.ACTION_SERVICE_STARTED:
onParsingServiceStarted();
break;
}
}
};
protected void onParsingServiceStarted() {}
protected void onParsingServiceFinished() {}
protected final BroadcastReceiver mExternalDevicesReceiver = new BroadcastReceiver() { protected final BroadcastReceiver mExternalDevicesReceiver = new BroadcastReceiver() {
@Override @Override
...@@ -116,37 +138,13 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity { ...@@ -116,37 +138,13 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
.setAction(DialogActivity.KEY_STORAGE) .setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(MediaParsingService.EXTRA_PATH, path)); .putExtra(MediaParsingService.EXTRA_PATH, path));
} } else
startService(new Intent(MediaParsingService.ACTION_RELOAD, null, BaseTvActivity.this, MediaParsingService.class)
.putExtra(MediaParsingService.EXTRA_PATH, path));
} else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_EJECT) || action.equalsIgnoreCase(Intent.ACTION_MEDIA_REMOVED)) { } else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_EJECT) || action.equalsIgnoreCase(Intent.ACTION_MEDIA_REMOVED)) {
mMediaLibrary.removeDevice(intent.getData().getLastPathSegment()); mMediaLibrary.removeDevice(intent.getData().getLastPathSegment());
startService(new Intent(MediaParsingService.ACTION_RELOAD, null, BaseTvActivity.this, MediaParsingService.class)); onParsingServiceFinished();
mStorageHandlerHandler.sendEmptyMessageDelayed(ACTION_MEDIA_UNMOUNTED, 2000); //Delay to cancel it in case of MOUNT
} }
} }
}; };
Handler mStorageHandlerHandler = new FileBrowserFragmentHandler(this);
protected static final int ACTION_MEDIA_MOUNTED = 1337;
protected static final int ACTION_MEDIA_UNMOUNTED = 1338;
private static class FileBrowserFragmentHandler extends WeakHandler<BaseTvActivity> {
FileBrowserFragmentHandler(BaseTvActivity owner) {
super(owner);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case ACTION_MEDIA_MOUNTED:
removeMessages(ACTION_MEDIA_UNMOUNTED);
case ACTION_MEDIA_UNMOUNTED:
getOwner().onExternelDeviceChange();
break;
}
}
}
} }
...@@ -55,7 +55,6 @@ import android.widget.TextView; ...@@ -55,7 +55,6 @@ import android.widget.TextView;
import org.videolan.libvlc.Media; import org.videolan.libvlc.Media;
import org.videolan.libvlc.util.AndroidUtil; import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Medialibrary; import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
import org.videolan.medialibrary.interfaces.MediaAddedCb; import org.videolan.medialibrary.interfaces.MediaAddedCb;
import org.videolan.medialibrary.interfaces.MediaUpdatedCb; import org.videolan.medialibrary.interfaces.MediaUpdatedCb;
import org.videolan.medialibrary.media.MediaLibraryItem; import org.videolan.medialibrary.media.MediaLibraryItem;
...@@ -82,7 +81,7 @@ import org.videolan.vlc.util.VLCInstance; ...@@ -82,7 +81,7 @@ import org.videolan.vlc.util.VLCInstance;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class VideoGridFragment extends MediaBrowserFragment implements MediaUpdatedCb, ISortable, SwipeRefreshLayout.OnRefreshListener, DevicesDiscoveryCb, MediaAddedCb, Filterable, IEventsHandler { public class VideoGridFragment extends MediaBrowserFragment implements MediaUpdatedCb, ISortable, SwipeRefreshLayout.OnRefreshListener, MediaAddedCb, Filterable, IEventsHandler {
public final static String TAG = "VLC/VideoListFragment"; public final static String TAG = "VLC/VideoListFragment";
...@@ -159,7 +158,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda ...@@ -159,7 +158,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
setSearchVisibility(false); setSearchVisibility(false);
updateViewMode(); updateViewMode();
if (mMediaLibrary.isInitiated()) if (mMediaLibrary.isInitiated())
fillView(); onMedialibraryReady();
else if (mGroup == null) else if (mGroup == null)
setupMediaLibraryReceiver(); setupMediaLibraryReceiver();
} }
...@@ -167,7 +166,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda ...@@ -167,7 +166,6 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
mMediaLibrary.removeDeviceDiscoveryCb(this);
mMediaLibrary.removeMediaUpdatedCb(); mMediaLibrary.removeMediaUpdatedCb();
mMediaLibrary.removeMediaAddedCb(); mMediaLibrary.removeMediaAddedCb();
} }
...@@ -196,11 +194,11 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda ...@@ -196,11 +194,11 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
mVideoAdapter.clear(); mVideoAdapter.clear();
} }
protected void fillView() { protected void onMedialibraryReady() {
super.onMedialibraryReady();
if (mGroup == null) { if (mGroup == null) {
mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO); mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO);
mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_VIDEO); mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_VIDEO);
mMediaLibrary.addDeviceDiscoveryCb(this);
} }
mHandler.sendEmptyMessage(UPDATE_LIST); mHandler.sendEmptyMessage(UPDATE_LIST);
} }
...@@ -458,35 +456,14 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda ...@@ -458,35 +456,14 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
super.setFabPlayVisibility(!mVideoAdapter.isEmpty() && enable); super.setFabPlayVisibility(!mVideoAdapter.isEmpty() && enable);