use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.
the class UiTools method setOnDragListener.
public static void setOnDragListener(final Activity activity) {
final View view = AndroidUtil.isNougatOrLater ? activity.getWindow().peekDecorView() : null;
if (view != null)
view.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch(event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
return true;
case DragEvent.ACTION_DROP:
final ClipData clipData = event.getClipData();
if (clipData == null)
return false;
final int itemsCount = clipData.getItemCount();
for (int i = 0; i < itemsCount; i++) {
final DragAndDropPermissions permissions = activity.requestDragAndDropPermissions(event);
if (permissions != null) {
final ClipData.Item item = clipData.getItemAt(i);
if (item.getUri() != null)
MediaUtils.openUri(activity, item.getUri());
else if (item.getText() != null) {
final Uri uri = Uri.parse(item.getText().toString());
final MediaWrapper media = new MediaWrapper(uri);
if (!"file".equals(uri.getScheme()))
media.setType(MediaWrapper.TYPE_STREAM);
MediaUtils.openMedia(activity, media);
}
return true;
}
}
return false;
default:
return false;
}
}
});
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.
the class VideoListAdapter method getListWithPosition.
int getListWithPosition(List<MediaWrapper> list, int position) {
MediaWrapper mw;
int offset = 0;
for (int i = 0; i < getItemCount(); ++i) {
mw = getDataset().get(i);
if (mw instanceof MediaGroup) {
for (MediaWrapper item : ((MediaGroup) mw).getAll()) list.add(item);
if (i < position)
offset += ((MediaGroup) mw).size() - 1;
} else
list.add(mw);
}
return position + offset;
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.
the class AsyncImageLoader method loadPicture.
@BindingAdapter({ "media" })
public static void loadPicture(View v, MediaLibraryItem item) {
if (item == null || item.getItemType() == MediaLibraryItem.TYPE_GENRE || item.getItemType() == MediaLibraryItem.TYPE_PLAYLIST)
return;
final boolean isMedia = item.getItemType() == MediaLibraryItem.TYPE_MEDIA;
final boolean isGroup = isMedia && ((MediaWrapper) item).getType() == MediaWrapper.TYPE_GROUP;
final String cacheKey = isGroup ? "group:" + item.getTitle() : ThumbnailsProvider.getMediaCacheKey(isMedia, item);
final Bitmap bitmap = cacheKey != null ? sBitmapCache.getBitmapFromMemCache(cacheKey) : null;
if (bitmap != null) {
updateTargetImage(bitmap, v, DataBindingUtil.findBinding(v));
return;
}
if (isMedia && !isGroup && item.getId() == 0L) {
MediaWrapper mw = (MediaWrapper) item;
final int type = mw.getType();
final boolean isMediaFile = type == MediaWrapper.TYPE_AUDIO || type == MediaWrapper.TYPE_VIDEO;
final Uri uri = mw.getUri();
if (!isMediaFile && !(type == MediaWrapper.TYPE_DIR && "upnp".equals(uri.getScheme())))
return;
if (isMediaFile && "file".equals(uri.getScheme())) {
mw = sMedialibrary.getMedia(uri);
if (mw != null)
item = mw;
}
}
loadImage(MLItemCoverFetcher.obtain().init(v, item), v);
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.
the class CardPresenter method onBindViewHolder.
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item, List<Object> payloads) {
if (payloads.isEmpty())
onBindViewHolder(viewHolder, item);
else {
final ViewHolder holder = ((ViewHolder) viewHolder);
final MediaLibraryItem media = (MediaLibraryItem) item;
for (Object data : payloads) {
switch((int) data) {
case Constants.UPDATE_DESCRIPTION:
holder.mCardView.setContentText(media.getDescription());
break;
case Constants.UPDATE_THUMB:
AsyncImageLoader.loadPicture(holder.mCardView, media);
break;
case Constants.UPDATE_TIME:
final MediaWrapper mediaWrapper = (MediaWrapper) item;
Tools.setMediaDescription(mediaWrapper);
holder.mCardView.setContentText(mediaWrapper.getDescription());
// update seen check if time is reset to 0
if (mediaWrapper.getTime() > 0)
break;
case Constants.UPDATE_SEEN:
final MediaWrapper mw = (MediaWrapper) item;
if (mIsSeenMediaMarkerVisible && mw.getType() == MediaWrapper.TYPE_VIDEO && mw.getSeen() > 0L)
holder.mCardView.setBadgeImage(ContextCompat.getDrawable(mContext, R.drawable.ic_seen_tv_normal));
break;
}
}
}
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class Medialibrary method findMedia.
// If media is not in ML, find it with its path
public MediaWrapper findMedia(MediaWrapper mw) {
if (mIsInitiated && mw != null && mw.getId() == 0L) {
Uri uri = mw.getUri();
MediaWrapper libraryMedia = getMedia(uri);
if (libraryMedia == null && TextUtils.equals("file", uri.getScheme()) && uri.getPath() != null && uri.getPath().startsWith("/sdcard")) {
uri = Tools.convertLocalUri(uri);
libraryMedia = getMedia(uri);
}
if (libraryMedia != null)
return libraryMedia;
}
return mw;
}
Aggregations