use of org.videolan.medialibrary.media.DummyItem in project vlc-android by videolan.
the class FileBrowserFragment method browseRoot.
@Override
protected void browseRoot() {
mMrl = null;
mRoot = true;
final FragmentActivity activity = getActivity();
if (activity == null)
return;
activity.setTitle(R.string.directories);
final String internalmemoryTitle = getString(R.string.internal_memory);
final String browserStorage = getString(R.string.browser_storages);
final String quickAccess = getString(R.string.browser_quick_access);
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
final String[] storages = AndroidDevices.getMediaDirectories();
MediaWrapper directory;
final ArrayList<MediaLibraryItem> devices = new ArrayList<>(storages.length);
final boolean isFilePicker = FileBrowserFragment.this instanceof FilePickerFragment;
if (!isFilePicker) {
devices.add(new DummyItem(browserStorage));
}
for (String mediaDirLocation : storages) {
if (!(new File(mediaDirLocation).exists()))
continue;
directory = new MediaWrapper(AndroidUtil.PathToUri(mediaDirLocation));
directory.setType(MediaWrapper.TYPE_DIR);
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
directory.setDisplayTitle(internalmemoryTitle);
else {
final String deviceName = FileUtils.getStorageTag(directory.getTitle());
if (deviceName != null)
directory.setDisplayTitle(deviceName);
}
devices.add(directory);
}
// Set folders shortcuts
if (!isFilePicker) {
devices.add(new DummyItem(quickAccess));
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_FILE.exists()) {
final MediaWrapper movies = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI);
movies.setType(MediaWrapper.TYPE_DIR);
devices.add(movies);
}
if (!isFilePicker) {
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_FILE.exists()) {
final MediaWrapper music = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI);
music.setType(MediaWrapper.TYPE_DIR);
devices.add(music);
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_FILE.exists()) {
final MediaWrapper podcasts = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI);
podcasts.setType(MediaWrapper.TYPE_DIR);
devices.add(podcasts);
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_FILE.exists()) {
final MediaWrapper downloads = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_URI);
downloads.setType(MediaWrapper.TYPE_DIR);
devices.add(downloads);
}
if (AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE.exists()) {
final MediaWrapper whatsapp = new MediaWrapper(AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE_URI);
whatsapp.setType(MediaWrapper.TYPE_DIR);
devices.add(whatsapp);
}
}
VLCApplication.runOnMainThread(new Runnable() {
@Override
public void run() {
mAdapter.update(devices);
}
});
}
});
}
use of org.videolan.medialibrary.media.DummyItem in project vlc-android by videolan.
the class NetworkBrowserFragment method updateFavorites.
private void updateFavorites() {
updateEmptyView();
if (!ExternalMonitor.isConnected()) {
if (mFavorites != 0) {
mAdapter.clear();
mFavorites = 0;
}
return;
}
List<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
int newSize = favs.size();
if (newSize == 0 && mFavorites == 0)
return;
if (!allowLAN()) {
List<MediaWrapper> toRemove = new ArrayList<>();
List<String> schemes = Arrays.asList("ftp", "sftp", "ftps", "http", "https");
for (MediaWrapper mw : favs) if (!schemes.contains(mw.getUri().getScheme()))
toRemove.add(mw);
if (!toRemove.isEmpty())
for (MediaWrapper mw : toRemove) favs.remove(mw);
newSize = favs.size();
if (newSize == 0) {
if (mFavorites != 0) {
mAdapter.clear();
mFavorites = 0;
}
return;
}
}
if (mFavorites != 0 && !mAdapter.getAll().isEmpty())
for (int i = 1; i <= mFavorites; ++i) {
// remove former favorites
mAdapter.removeItem(1);
}
if (newSize == 0 && !mAdapter.isEmpty()) {
// also remove separator if no more fav
mAdapter.removeItem(0);
// also remove separator if no more fav
mAdapter.removeItem(0);
} else {
boolean isEmpty = mAdapter.isEmpty();
if (mFavorites == 0 || isEmpty)
// add header if needed
mAdapter.addItem(new DummyItem(getString(R.string.network_favorites)), false, 0);
for (int i = 0; i < newSize; ) {
// add new favorites
mAdapter.addItem(favs.get(i), false, ++i);
}
if (mFavorites == 0 || isEmpty)
// add header if needed
mAdapter.addItem(new DummyItem(getString(R.string.network_shared_folders)), false, newSize + 1);
}
// update count
mFavorites = newSize;
if (newSize != 0)
mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
}
use of org.videolan.medialibrary.media.DummyItem in project vlc-android by videolan.
the class AudioBrowserAdapter method generateSections.
private List<MediaLibraryItem> generateSections(List<? extends MediaLibraryItem> items, int sortby) {
List<MediaLibraryItem> datalist = new ArrayList<>();
switch(sortby) {
case MediaLibraryItemComparator.SORT_BY_TITLE:
String currentLetter = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
String title = item.getTitle();
String letter = (title.isEmpty() || !Character.isLetter(title.charAt(0))) ? "#" : title.substring(0, 1).toUpperCase();
if (currentLetter == null || !TextUtils.equals(currentLetter, letter)) {
currentLetter = letter;
DummyItem sep = new DummyItem(currentLetter);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_ARTIST:
String currentArtist = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
String artist = ((MediaWrapper) item).getArtist();
if (artist == null)
artist = "";
if (currentArtist == null || !TextUtils.equals(currentArtist, artist)) {
currentArtist = artist;
DummyItem sep = new DummyItem(TextUtils.isEmpty(currentArtist) ? VLCApplication.getAppResources().getString(R.string.unknown_artist) : currentArtist);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_ALBUM:
String currentAlbum = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
String album = ((MediaWrapper) item).getAlbum();
if (album == null)
album = "";
if (currentAlbum == null || !TextUtils.equals(currentAlbum, album)) {
currentAlbum = album;
DummyItem sep = new DummyItem(TextUtils.isEmpty(currentAlbum) ? VLCApplication.getAppResources().getString(R.string.unknown_album) : currentAlbum);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_LENGTH:
String currentLengthCategory = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
int length = MediaLibraryItemComparator.getLength(item);
String lengthCategory = MediaLibraryItemComparator.lengthToCategory(length);
if (currentLengthCategory == null || !TextUtils.equals(currentLengthCategory, lengthCategory)) {
currentLengthCategory = lengthCategory;
DummyItem sep = new DummyItem(currentLengthCategory);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_DATE:
String currentYear = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
String year = MediaLibraryItemComparator.getYear(item);
if (currentYear == null || !TextUtils.equals(currentYear, year)) {
currentYear = year;
DummyItem sep = new DummyItem(currentYear);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_NUMBER:
int currentNumber = 0;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
int number = MediaLibraryItemComparator.getTracksCount(item);
if (currentNumber != number) {
currentNumber = number;
DummyItem sep = new DummyItem(currentNumber == 0 ? VLCApplication.getAppResources().getString(R.string.unknown_number) : VLCApplication.getAppResources().getQuantityString(R.plurals.songs_quantity, currentNumber, currentNumber));
datalist.add(sep);
}
datalist.add(item);
}
break;
}
return datalist;
}
use of org.videolan.medialibrary.media.DummyItem in project vlc-android by GeoffreyMetais.
the class FileBrowserFragment method browseRoot.
@Override
protected void browseRoot() {
mMrl = null;
mRoot = true;
final FragmentActivity activity = getActivity();
if (activity == null)
return;
activity.setTitle(R.string.directories);
final String internalmemoryTitle = getString(R.string.internal_memory);
final String browserStorage = getString(R.string.browser_storages);
final String quickAccess = getString(R.string.browser_quick_access);
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
final String[] storages = AndroidDevices.getMediaDirectories();
MediaWrapper directory;
final ArrayList<MediaLibraryItem> devices = new ArrayList<>(storages.length);
final boolean isFilePicker = FileBrowserFragment.this instanceof FilePickerFragment;
if (!isFilePicker) {
devices.add(new DummyItem(browserStorage));
}
for (String mediaDirLocation : storages) {
if (!(new File(mediaDirLocation).exists()))
continue;
directory = new MediaWrapper(AndroidUtil.PathToUri(mediaDirLocation));
directory.setType(MediaWrapper.TYPE_DIR);
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
directory.setDisplayTitle(internalmemoryTitle);
else {
final String deviceName = FileUtils.getStorageTag(directory.getTitle());
if (deviceName != null)
directory.setDisplayTitle(deviceName);
}
devices.add(directory);
}
// Set folders shortcuts
if (!isFilePicker) {
devices.add(new DummyItem(quickAccess));
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_FILE.exists()) {
final MediaWrapper movies = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI);
movies.setType(MediaWrapper.TYPE_DIR);
devices.add(movies);
}
if (!isFilePicker) {
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_FILE.exists()) {
final MediaWrapper music = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI);
music.setType(MediaWrapper.TYPE_DIR);
devices.add(music);
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_FILE.exists()) {
final MediaWrapper podcasts = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI);
podcasts.setType(MediaWrapper.TYPE_DIR);
devices.add(podcasts);
}
if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_FILE.exists()) {
final MediaWrapper downloads = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_URI);
downloads.setType(MediaWrapper.TYPE_DIR);
devices.add(downloads);
}
if (AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE.exists()) {
final MediaWrapper whatsapp = new MediaWrapper(AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE_URI);
whatsapp.setType(MediaWrapper.TYPE_DIR);
devices.add(whatsapp);
}
}
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
mAdapter.update(devices);
}
});
}
});
}
Aggregations