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