Commit 3f2e4538 authored by Geoffrey Métais's avatar Geoffrey Métais

Ask device discover for unknown external storages

parent 3fa51dcb
......@@ -25,7 +25,6 @@ import org.videolan.vlc.gui.DialogActivity;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
import java.io.File;
import java.util.concurrent.LinkedBlockingQueue;
......@@ -178,7 +177,13 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
String[] storages = AndroidDevices.getMediaDirectories();
for (String storage : storages) {
boolean isMainStorage = TextUtils.equals(storage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
mMedialibrary.addDevice(isMainStorage ? "main-storage" : FileUtils.getFileNameFromPath(storage), storage, !isMainStorage);
boolean isNew = mMedialibrary.addDevice(isMainStorage ? "main-storage" : FileUtils.getFileNameFromPath(storage), storage, !isMainStorage);
if (!isMainStorage && isNew) {
startActivity(new Intent(MediaParsingService.this, DialogActivity.class)
.setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(EXTRA_PATH, storage));
}
}
if (mMedialibrary.init(MediaParsingService.this)) {
LocalBroadcastManager.getInstance(MediaParsingService.this).sendBroadcast(new Intent(VLCApplication.ACTION_MEDIALIBRARY_READY));
......@@ -189,18 +194,6 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
} else if (upgrade) {
mMedialibrary.forceParserRetry();
}
final String[] foldersList = mMedialibrary.getFoldersList();
final SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(MediaParsingService.this);
for (String externalStorage : AndroidDevices.getExternalStorageDirectories()) {
if (!TextUtils.equals(externalStorage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
&& !Util.arrayContains(foldersList, "file://" + externalStorage + "/")
&& !mSettings.getBoolean("ignore_"+FileUtils.getFileNameFromPath(externalStorage), false)) {
startActivity(new Intent(MediaParsingService.this, DialogActivity.class)
.setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(EXTRA_PATH, externalStorage));
}
}
}
}
});
......
......@@ -53,14 +53,12 @@ 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;
import org.videolan.vlc.util.WeakHandler;
import static org.videolan.vlc.MediaParsingService.EXTRA_PATH;
import static org.videolan.vlc.MediaParsingService.EXTRA_UUID;
public class AudioPlayerContainerActivity extends BaseActivity implements PlaybackService.Client.Callback {
public static final String TAG = "VLC/AudioPlayerContainerActivity";
......@@ -348,21 +346,24 @@ public class AudioPlayerContainerActivity extends BaseActivity implements Playba
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
AudioPlayerContainerActivity owner = getOwner();
if (owner == null)
return;
String uuid = ((Uri) msg.obj).getLastPathSegment();
switch (msg.what){
case ACTION_MEDIA_MOUNTED:
String path = ((Uri) msg.obj).getPath();
String uuid = ((Uri) msg.obj).getLastPathSegment();
removeMessages(ACTION_MEDIA_UNMOUNTED);
getOwner().updateLib();
getOwner().startActivity(new Intent(getOwner(), DialogActivity.class)
.setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(EXTRA_PATH, path)
.putExtra(EXTRA_UUID, uuid));
if (VLCApplication.getMLInstance().addDevice(uuid, path, true)) {
owner.startActivity(new Intent(owner, DialogActivity.class)
.setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(MediaParsingService.EXTRA_PATH, path));
}
break;
case ACTION_MEDIA_UNMOUNTED:
getOwner().startService(new Intent(MediaParsingService.ACTION_RELOAD, null, getOwner(), MediaParsingService.class));
getOwner().updateLib();
VLCApplication.getMLInstance().removeDevice(uuid);
owner.startService(new Intent(MediaParsingService.ACTION_RELOAD, null, owner, MediaParsingService.class));
break;
}
}
......
......@@ -48,6 +48,7 @@ import org.videolan.vlc.util.WeakHandler;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public abstract class BaseTvActivity extends PlaybackServiceActivity {
protected Medialibrary mMediaLibrary;
protected SharedPreferences mSettings;
boolean mRegistering = false;
......@@ -110,15 +111,15 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
} else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_MOUNTED)) {
String path = intent.getData().getPath();
String uuid = intent.getData().getLastPathSegment();
startActivity(new Intent(BaseTvActivity.this, DialogActivity.class)
.setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(MediaParsingService.EXTRA_PATH, path)
.putExtra(MediaParsingService.EXTRA_UUID, uuid));
mStorageHandlerHandler.sendEmptyMessageDelayed(ACTION_MEDIA_MOUNTED, 500);
if (mMediaLibrary.addDevice(uuid, path, true)) {
startActivity(new Intent(BaseTvActivity.this, DialogActivity.class)
.setAction(DialogActivity.KEY_STORAGE)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(MediaParsingService.EXTRA_PATH, path));
}
} else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_EJECT) || action.equalsIgnoreCase(Intent.ACTION_MEDIA_REMOVED)) {
mMediaLibrary.removeDevice(intent.getData().getLastPathSegment());
mMediaLibrary.reload();
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
}
}
......
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