Commit 7226467a authored by Geoffrey Métais's avatar Geoffrey Métais

Alert Dialog to propose ext storage scan

parent 59c18fe9
......@@ -697,6 +697,8 @@
<string name="resume">Resume</string>
<string name="length">Length</string>
<string name="tv_settings_hint">Long press OK button to check/uncheck directories</string>
<string name="ml_external_storage_title">New external storage detected</string>
<string name="ml_external_storage_msg">Do you want VLC to add device %1$s to your medialibrary?</string>
<string-array name="chroma_formats" translatable="false">
<item>RGB 32-bit</item>
......
......@@ -7,9 +7,11 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Binder;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
......@@ -18,6 +20,7 @@ import android.text.TextUtils;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
import org.videolan.vlc.gui.DialogActivity;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Strings;
......@@ -32,8 +35,10 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
public final static String ACTION_INIT = "medialibrary_init";
public final static String ACTION_RELOAD = "medialibrary_reload";
public final static String ACTION_DISCOVER = "medialibrary_discover";
public final static String ACTION_DISCOVER_DEVICE = "medialibrary_discover_device";
public final static String EXTRA_PATH = "extra_path";
public final static String EXTRA_UUID = "extra_uuid";
public final static String ACTION_RESUME_SCAN = "action_resume_scan";
public final static String ACTION_PAUSE_SCAN = "action_pause_scan";
......@@ -91,10 +96,21 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
case ACTION_DISCOVER:
discover(intent.getStringExtra(EXTRA_PATH));
break;
case ACTION_DISCOVER_DEVICE:
discoverStorage(intent.getStringExtra(EXTRA_PATH), intent.getStringExtra(EXTRA_UUID));
break;
}
return START_NOT_STICKY;
}
private void discoverStorage(String path, String uuid) {
if (!TextUtils.isEmpty(uuid))
mMedialibrary.addDevice(uuid, path, true);
for (String folder : Medialibrary.getBlackList())
mMedialibrary.banFolder(path + folder);
discover(path);
}
private void discover(String path) {
mFolderToDiscover = "";
mMedialibrary.discover(path);
......@@ -128,18 +144,21 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
for (File folder : Medialibrary.getDefaultFolders())
if (folder.exists())
mMedialibrary.discover(folder.getPath());
String[] foldersList = mMedialibrary.getFoldersList();
for (String externalStorage : AndroidDevices.getExternalStorageDirectories()) {
if (!TextUtils.equals(externalStorage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
&& !Util.arrayContains(foldersList, "file://" + externalStorage + "/")) {
for (String folder : Medialibrary.getBlackList())
mMedialibrary.banFolder(externalStorage + folder);
mMedialibrary.discover(externalStorage);
}
}
} 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));
}
}
}
}
});
......
......@@ -32,15 +32,12 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
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.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.ViewStubCompat;
import android.view.MenuItem;
......@@ -61,9 +58,13 @@ import org.videolan.vlc.gui.audio.AudioPlayer;
import org.videolan.vlc.gui.browser.StorageBrowserFragment;
import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.FileUtils;
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, PlaybackService.Callback {
public static final String TAG = "VLC/AudioPlayerContainerActivity";
......@@ -376,16 +377,17 @@ public class AudioPlayerContainerActivity extends BaseActivity implements Playba
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Medialibrary ml = VLCApplication.getMLInstance();
switch (msg.what){
case ACTION_MEDIA_MOUNTED:
String path = ((Uri) msg.obj).getPath();
String uuid = ((Uri) msg.obj).getLastPathSegment();
removeMessages(ACTION_MEDIA_UNMOUNTED);
ml.addDevice(path, path, true);
getOwner().updateLib();
Intent mlIntent = new Intent(MediaParsingService.ACTION_DISCOVER, null, getOwner(), MediaParsingService.class);
mlIntent.putExtra(MediaParsingService.EXTRA_PATH, path);
getOwner().startService(mlIntent);
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));
break;
case ACTION_MEDIA_UNMOUNTED:
getOwner().startService(new Intent(MediaParsingService.ACTION_RELOAD, null, getOwner(), MediaParsingService.class));
......
......@@ -26,6 +26,8 @@ package org.videolan.vlc.gui;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import org.videolan.vlc.MediaParsingService;
import org.videolan.vlc.gui.dialogs.ExternalStorageDialog;
import org.videolan.vlc.gui.dialogs.VlcDialog;
import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
......@@ -38,6 +40,7 @@ public class DialogActivity extends BaseActivity {
public static final String KEY_QUESTION = "QuestionDialog";
public static final String KEY_PROGRESS = "ProgressDialog";
public static final String KEY_STREAM = "streamDialog";
public static final String KEY_STORAGE = "storageDialog";
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -56,11 +59,22 @@ public class DialogActivity extends BaseActivity {
case KEY_STREAM:
setupStreamDialog();
break;
case KEY_STORAGE:
setupStorageDialog();
break;
default:
finish();
}
}
private void setupStorageDialog() {
ExternalStorageDialog dialog = new ExternalStorageDialog();
Bundle b = new Bundle(1);
b.putString(MediaParsingService.EXTRA_PATH, getIntent().getStringExtra(MediaParsingService.EXTRA_PATH));
dialog.setArguments(b);
dialog.show(getSupportFragmentManager(), "fragment_storage");
}
private void setupStreamDialog() {
new MRLPanelFragment().show(getSupportFragmentManager(), "fragment_mrl");
}
......
package org.videolan.vlc.gui.dialogs;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
import org.videolan.vlc.MediaParsingService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.util.FileUtils;
public class ExternalStorageDialog extends AppCompatDialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
ViewCompat.setBackground(getActivity().getWindow().getDecorView(),
ContextCompat.getDrawable(getActivity(), android.R.drawable.screen_background_dark_transparent));
final String path = getArguments().getString(MediaParsingService.EXTRA_PATH);
final String name = FileUtils.getFileNameFromPath(path);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final String message = String.format(VLCApplication.getAppResources().getString(R.string.ml_external_storage_msg), name);
builder.setTitle(R.string.ml_external_storage_title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent serviceInent = new Intent(MediaParsingService.ACTION_DISCOVER_DEVICE, null, getActivity(), MediaParsingService.class);
serviceInent.putExtra(MediaParsingService.EXTRA_PATH, path);
if (getActivity() != null) {
getActivity().startService(serviceInent);
getActivity().finish();
}
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext())
.edit()
.putBoolean("ignore_"+ name, true)
.apply();
if (getActivity() != null)
getActivity().finish();
}
});
// Create the AlertDialog object and return it
return builder.create();
}
@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
if (getActivity() != null)
getActivity().finish();
}
}
......@@ -39,7 +39,9 @@ import android.preference.PreferenceManager;
import android.view.KeyEvent;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.vlc.MediaParsingService;
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;
......@@ -105,12 +107,14 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED)
onNetworkUpdated();
} else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_MOUNTED)) {
String path = intent.getData().getPath();
String uuid = intent.getData().getLastPathSegment();
mMediaLibrary.addDevice(uuid, path, true);
mMediaLibrary.discover(path);
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);
} else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_EJECT) || action.equalsIgnoreCase(Intent.ACTION_MEDIA_REMOVED)) {
mMediaLibrary.removeDevice(intent.getData().getLastPathSegment());
......
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