use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class AudioBrowserFragment method handleContextItemSelected.
protected boolean handleContextItemSelected(final MenuItem item, final int position) {
final int mode = mViewPager.getCurrentItem();
final AudioBrowserAdapter adapter = mAdapters[mode];
if (position < 0 && position >= adapter.getItemCount())
return false;
final int id = item.getItemId();
final MediaLibraryItem mediaItem = adapter.getItem(position);
if (id == R.id.audio_list_browser_delete) {
final MediaLibraryItem previous = position > 0 ? adapter.getItem(position - 1) : null;
final MediaLibraryItem next = position < adapter.getItemCount() - 1 ? adapter.getItem(position + 1) : null;
final String message;
final Runnable action;
final Runnable cancel;
final MediaLibraryItem separator = previous != null && previous.getItemType() == MediaLibraryItem.TYPE_DUMMY && (next == null || next.getItemType() == MediaLibraryItem.TYPE_DUMMY) ? previous : null;
if (separator != null)
adapter.remove(separator, mediaItem);
else
adapter.remove(mediaItem);
if (mode == MODE_PLAYLIST) {
cancel = null;
message = getString(R.string.playlist_deleted);
action = new Runnable() {
@Override
public void run() {
deletePlaylist((Playlist) mediaItem);
}
};
} else if (mode == MODE_SONG) {
message = getString(R.string.file_deleted);
cancel = new Runnable() {
@Override
public void run() {
if (separator != null)
adapter.addItems(separator, mediaItem);
else
adapter.addItems(mediaItem);
}
};
action = new Runnable() {
@Override
public void run() {
deleteMedia(mediaItem, true, cancel);
}
};
if (!checkWritePermission((MediaWrapper) mediaItem, new Runnable() {
@Override
public void run() {
final View v = getView();
if (v != null)
UiTools.snackerWithCancel(getView(), message, action, cancel);
}
}))
return false;
} else
return false;
final View v = getView();
if (v != null)
UiTools.snackerWithCancel(getView(), message, action, cancel);
return true;
}
if (id == R.id.audio_list_browser_set_song) {
if (mSongsAdapter.getItemCount() <= position)
return false;
AudioUtil.setRingtone((MediaWrapper) mSongsAdapter.getItem(position), getActivity());
return true;
}
if (id == R.id.audio_view_info) {
showInfoDialog(mSongsAdapter.getItem(position));
return true;
}
if (id == R.id.audio_view_add_playlist) {
UiTools.addToPlaylist(getActivity(), mediaItem.getTracks(), SavePlaylistDialog.KEY_NEW_TRACKS);
return true;
}
int startPosition;
MediaWrapper[] medias;
boolean useAllItems = id == R.id.audio_list_browser_play_all;
boolean append = id == R.id.audio_list_browser_append;
boolean insert_next = id == R.id.audio_list_browser_insert_next;
// Play/Append
if (useAllItems) {
if (mSongsAdapter.getItemCount() <= position)
return false;
final List<MediaLibraryItem> mediaList = new ArrayList<>();
startPosition = mSongsAdapter.getListWithPosition(mediaList, position);
medias = Arrays.copyOf(mediaList.toArray(), mediaList.size(), MediaWrapper[].class);
} else {
startPosition = 0;
if (position >= adapter.getItemCount())
return false;
medias = mediaItem.getTracks();
}
if (append)
MediaUtils.appendMedia(getActivity(), medias);
else if (insert_next)
MediaUtils.insertNext(getActivity(), medias);
else
MediaUtils.openArray(getActivity(), medias, startPosition);
return true;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class BaseAudioBrowser method onActionItemClicked.
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
final List<MediaLibraryItem> list = getCurrentAdapter().getSelection();
stopActionMode();
if (!list.isEmpty()) {
final List<MediaWrapper> tracks = new ArrayList<>();
for (MediaLibraryItem mediaItem : list) tracks.addAll(Arrays.asList(mediaItem.getTracks()));
switch(item.getItemId()) {
case R.id.action_mode_audio_play:
MediaUtils.openList(getActivity(), tracks, 0);
break;
case R.id.action_mode_audio_append:
MediaUtils.appendMedia(getActivity(), tracks);
break;
case R.id.action_mode_audio_add_playlist:
UiTools.addToPlaylist(getActivity(), tracks);
break;
case R.id.action_mode_audio_info:
showInfoDialog(list.get(0));
break;
case R.id.action_mode_audio_set_song:
AudioUtil.setRingtone((MediaWrapper) list.get(0), getActivity());
break;
default:
return false;
}
}
return true;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class BaseBrowserFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mAdapter == null)
mAdapter = new BaseBrowserAdapter(this);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
registerForContextMenu(mRecyclerView);
mSwipeRefreshLayout.setOnRefreshListener(this);
mProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
public void onChanged(@Nullable List<MediaLibraryItem> mediaLibraryItems) {
mAdapter.update(mediaLibraryItems);
}
});
mProvider.getDescriptionUpdate().observe(this, new Observer<Pair<Integer, String>>() {
@Override
public void onChanged(@Nullable Pair<Integer, String> pair) {
if (pair != null)
mAdapter.notifyItemChanged(pair.getFirst(), pair.getSecond());
}
});
initFavorites();
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class BaseBrowserFragment method onDestroyActionMode.
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
int index = -1;
for (MediaLibraryItem media : mAdapter.getAll()) {
++index;
if (media.hasStateFlags(MediaLibraryItem.FLAG_SELECTED)) {
media.removeStateFlags(MediaLibraryItem.FLAG_SELECTED);
mAdapter.notifyItemChanged(index, media);
}
}
mAdapter.resetSelectionCount();
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class InfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.info_activity);
initAudioPlayerContainerActivity();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mItem = (MediaLibraryItem) (savedInstanceState != null ? savedInstanceState.getParcelable(TAG_ITEM) : getIntent().getParcelableExtra(TAG_ITEM));
if (mItem == null) {
finish();
return;
}
if (mItem.getId() == 0L) {
MediaLibraryItem libraryItem = VLCApplication.getMLInstance().getMedia(((MediaWrapper) mItem).getUri());
if (libraryItem != null)
mItem = libraryItem;
}
mBinding.setItem(mItem);
final int fabVisibility = savedInstanceState != null ? savedInstanceState.getInt(TAG_FAB_VISIBILITY) : -1;
if (!TextUtils.isEmpty(mItem.getArtworkMrl())) {
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(mItem.getArtworkMrl()), 0);
if (cover != null) {
mBinding.setCover(new BitmapDrawable(InfoActivity.this.getResources(), cover));
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
ViewCompat.setNestedScrollingEnabled(mBinding.container, true);
mBinding.appbar.setExpanded(true, true);
if (fabVisibility != -1)
mBinding.fab.setVisibility(fabVisibility);
}
});
} else
noCoverFallback();
}
});
} else
noCoverFallback();
mBinding.fab.setOnClickListener(this);
if (mItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
mAdapter = new MediaInfoAdapter();
mBinding.list.setLayoutManager(new LinearLayoutManager(mBinding.getRoot().getContext()));
mBinding.list.setAdapter(mAdapter);
mCheckFileTask = (CheckFileTask) new CheckFileTask().execute();
mParseTracksTask = (ParseTracksTask) new ParseTracksTask().execute();
}
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
updateMeta();
}
});
}
Aggregations