use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class PlaylistActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.playlist_activity);
initAudioPlayerContainerActivity();
mFragmentContainer = findViewById(R.id.container_list);
mOriginalBottomPadding = mFragmentContainer.getPaddingBottom();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mPlaylist = (MediaLibraryItem) (savedInstanceState != null ? savedInstanceState.getParcelable(AudioBrowserFragment.TAG_ITEM) : getIntent().getParcelableExtra(AudioBrowserFragment.TAG_ITEM));
mIsPlaylist = mPlaylist.getItemType() == MediaLibraryItem.TYPE_PLAYLIST;
mBinding.setPlaylist(mPlaylist);
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this);
mBinding.songs.setLayoutManager(new LinearLayoutManager(this));
mBinding.songs.setAdapter(mAdapter);
tracksProvider = ViewModelProviders.of(this, new TracksProvider.Factory(mPlaylist)).get(TracksProvider.class);
tracksProvider.getDataset().observe(this, new Observer<List<MediaLibraryItem>>() {
@Override
public void onChanged(@Nullable List<MediaLibraryItem> tracks) {
if (tracks != null)
mAdapter.update(tracks);
}
});
final int fabVisibility = savedInstanceState != null ? savedInstanceState.getInt(TAG_FAB_VISIBILITY) : -1;
if (!TextUtils.isEmpty(mPlaylist.getArtworkMrl())) {
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(mPlaylist.getArtworkMrl()), 0);
if (cover != null) {
mBinding.setCover(new BitmapDrawable(PlaylistActivity.this.getResources(), cover));
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
mBinding.appbar.setExpanded(true, true);
if (fabVisibility != -1)
mBinding.fab.setVisibility(fabVisibility);
}
});
} else
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
fabFallback();
}
});
}
});
} else
fabFallback();
mBinding.fab.setOnClickListener(this);
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class PlaylistActivity method onActionItemClicked.
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
List<MediaLibraryItem> list = mAdapter.getSelection();
List<MediaWrapper> tracks = new ArrayList<>();
for (MediaLibraryItem mediaItem : list) tracks.addAll(Arrays.asList(mediaItem.getTracks()));
if (item.getItemId() == R.id.action_mode_audio_playlist_up) {
Toast.makeText(this, "UP !", Toast.LENGTH_SHORT).show();
return true;
}
if (item.getItemId() == R.id.action_mode_audio_playlist_down) {
Toast.makeText(this, "DOWN !", Toast.LENGTH_SHORT).show();
return true;
}
stopActionMode();
switch(item.getItemId()) {
case R.id.action_mode_audio_play:
MediaUtils.openList(this, tracks, 0);
break;
case R.id.action_mode_audio_append:
MediaUtils.appendMedia(this, tracks);
break;
case R.id.action_mode_audio_add_playlist:
UiTools.addToPlaylist(this, tracks);
break;
case R.id.action_mode_audio_info:
showInfoDialog((MediaWrapper) list.get(0));
break;
case R.id.action_mode_audio_set_song:
AudioUtil.setRingtone((MediaWrapper) list.get(0), this);
break;
case R.id.action_mode_audio_delete:
removeFromPlaylist(tracks);
break;
default:
return false;
}
return true;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class SavePlaylistDialog method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mListView = view.findViewById(android.R.id.list);
mSaveButton = view.findViewById(R.id.dialog_playlist_save);
mCancelButton = view.findViewById(R.id.dialog_playlist_cancel);
mEmptyView = view.findViewById(android.R.id.empty);
TextInputLayout mLayout = view.findViewById(R.id.dialog_playlist_name);
mEditText = mLayout.getEditText();
mSaveButton.setOnClickListener(this);
mCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
mEditText.setOnEditorActionListener(this);
mListView.setLayoutManager(new LinearLayoutManager(view.getContext()));
mListView.setAdapter(mAdapter);
mAdapter.update(new ArrayList<MediaLibraryItem>(Arrays.asList(mMedialibrary.getPlaylists())));
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class MediaItemDiffCallback method areItemsTheSame.
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
final MediaLibraryItem oldItem = oldList.get(oldItemPosition);
final MediaLibraryItem newItem = newList.get(newItemPosition);
return oldItem == newItem || ((oldItem == null) == (newItem == null) && oldItem.equals(newItem));
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class MediaItemFilter method performFiltering.
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
final String[] queryStrings = charSequence.toString().trim().toLowerCase().split(" ");
FilterResults results = new FilterResults();
List<MediaLibraryItem> list = new ArrayList<>();
for (MediaLibraryItem item : initData()) {
for (String queryString : queryStrings) {
if (queryString.length() < 2)
continue;
if (item.getTitle() != null && item.getTitle().toLowerCase().contains(queryString)) {
list.add(item);
// avoid duplicates in search results, and skip useless processing
break;
}
}
}
results.values = list;
results.count = list.size();
return results;
}
Aggregations