Search in sources :

Example 21 with MediaLibraryItem

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);
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Bitmap(android.graphics.Bitmap) TracksProvider(org.videolan.vlc.viewmodels.audio.TracksProvider) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) AudioBrowserAdapter(org.videolan.vlc.gui.audio.AudioBrowserAdapter)

Example 22 with MediaLibraryItem

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;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Example 23 with MediaLibraryItem

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())));
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) TextInputLayout(android.support.design.widget.TextInputLayout) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 24 with MediaLibraryItem

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));
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 25 with MediaLibraryItem

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;
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Aggregations

MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)46 ArrayList (java.util.ArrayList)25 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)23 Bitmap (android.graphics.Bitmap)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)8 List (java.util.List)7 View (android.view.View)6 RecyclerView (android.support.v7.widget.RecyclerView)5 TextView (android.widget.TextView)4 Playlist (org.videolan.medialibrary.media.Playlist)4 Bundle (android.os.Bundle)3 LinkedList (java.util.LinkedList)3 Storage (org.videolan.medialibrary.media.Storage)3 ContextMenuRecyclerView (org.videolan.vlc.gui.view.ContextMenuRecyclerView)3 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 WorkerThread (android.support.annotation.WorkerThread)2 TextInputLayout (android.support.design.widget.TextInputLayout)2 ImageCardView (android.support.v17.leanback.widget.ImageCardView)2