Commit ca4b1471 authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais

Pass context to CustomDirectories util

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent fe905a2a
......@@ -23,6 +23,7 @@
package org.videolan.vlc.gui.browser;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
......@@ -49,7 +50,7 @@ class StorageBrowserAdapter extends BaseBrowserAdapter {
StorageBrowserAdapter(BaseBrowserFragment fragment) {
super(fragment);
updateMediaDirs();
updateMediaDirs(fragment.requireContext());
}
@Override
......@@ -78,14 +79,14 @@ class StorageBrowserAdapter extends BaseBrowserAdapter {
return false;
}
void updateMediaDirs() {
void updateMediaDirs(Context context) {
if (mMediaDirsLocation != null) mMediaDirsLocation.clear();
final String folders[] = VLCApplication.getMLInstance().getFoldersList();
mMediaDirsLocation = new ArrayList<>(folders.length);
for (String folder : folders) {
mMediaDirsLocation.add(Uri.decode(folder.startsWith("file://") ? folder.substring(7) : folder));
}
mCustomDirsLocation = new ArrayList<>(Arrays.asList(CustomDirectories.getCustomDirectories()));
mCustomDirsLocation = new ArrayList<>(Arrays.asList(CustomDirectories.getCustomDirectories(context)));
}
protected void checkBoxAction(View v, String mrl) {
......
......@@ -151,7 +151,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
public void onCtxClick(View v, int position, MediaLibraryItem item) {
if (isRootDirectory()) {
final Storage storage = (Storage) getAdapter().getItem(position);
boolean isCustom = CustomDirectories.contains(storage.getUri().getPath());
boolean isCustom = CustomDirectories.contains(storage.getUri().getPath(), requireContext());
if (isCustom) ContextSheetKt.showContext(requireActivity(), this, position, item.getTitle(), Constants.CTX_CUSTOM_REMOVE);
}
}
......@@ -159,7 +159,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
@Override
public void onCtxAction(int position, int option) {
final Storage storage = (Storage) getAdapter().getItem(position);
CustomDirectories.removeCustomDirectory(storage.getUri().getPath());
CustomDirectories.removeCustomDirectory(storage.getUri().getPath(), requireContext());
viewModel.remove(storage);
((AudioPlayerContainerActivity)getActivity()).updateLib();
}
......@@ -198,7 +198,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
public void run() {
cb.setEnabled(true);
if (success) {
((StorageBrowserAdapter) getAdapter()).updateMediaDirs();
((StorageBrowserAdapter) getAdapter()).updateMediaDirs(requireContext());
getAdapter().notifyDataSetChanged();
} else cb.setChecked(true);
}
......@@ -224,7 +224,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
mProcessingFolders.get(finalPath).setEnabled(true);
}
});
((StorageBrowserAdapter) getAdapter()).updateMediaDirs();
((StorageBrowserAdapter) getAdapter()).updateMediaDirs(requireContext());
}
}
......@@ -251,7 +251,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
}
try {
CustomDirectories.addCustomDirectory(f.getCanonicalPath());
CustomDirectories.addCustomDirectory(f.getCanonicalPath(), requireContext());
((AudioPlayerContainerActivity)getActivity()).updateLib();
} catch (IOException ignored) {}
}
......
......@@ -37,7 +37,7 @@ class StorageProvider(context: Context, dataset: LiveDataset<MediaLibraryItem>,
override fun browseRoot() {
val storages = AndroidDevices.getMediaDirectories()
val customDirectories = CustomDirectories.getCustomDirectories()
val customDirectories = CustomDirectories.getCustomDirectories(context)
var storage: Storage
val storagesList = ArrayList<MediaLibraryItem>()
for (mediaDirLocation in storages) {
......
......@@ -23,20 +23,17 @@ package org.videolan.vlc.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.videolan.vlc.VLCApplication;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CustomDirectories {
public static void addCustomDirectory(String path) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
public static void addCustomDirectory(String path, Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
List<String> dirs = new ArrayList<String>(
Arrays.asList(CustomDirectories.getCustomDirectories()));
Arrays.asList(CustomDirectories.getCustomDirectories(context)));
dirs.add(path);
StringBuilder builder = new StringBuilder();
builder.append(dirs.remove(0));
......@@ -49,8 +46,8 @@ public class CustomDirectories {
editor.apply();
}
public static void removeCustomDirectory(String path) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
public static void removeCustomDirectory(String path, Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (!preferences.getString("custom_paths", "").contains(path))
return;
List<String> dirs = new ArrayList<String>(
......@@ -74,12 +71,8 @@ public class CustomDirectories {
editor.apply();
}
public static String[] getCustomDirectories() {
return getCustomDirectories(VLCApplication.getAppContext());
}
public static String[] getCustomDirectories(Context ctx) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
public static String[] getCustomDirectories(Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final String custom_paths = preferences.getString("custom_paths", "");
if (custom_paths.equals(""))
return new String[0];
......@@ -87,7 +80,7 @@ public class CustomDirectories {
return custom_paths.split(":");
}
public static boolean contains(String directory) {
return Strings.INSTANCE.stringArrayContains(getCustomDirectories(), directory.trim());
public static boolean contains(String directory, Context context) {
return Strings.INSTANCE.stringArrayContains(getCustomDirectories(context), directory.trim());
}
}
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