Search in sources :

Example 1 with Playlist

use of com.wm.remusic.info.Playlist in project remusic by aa112901.

the class PlaylistInfo method getPlaylist.

public synchronized ArrayList<Playlist> getPlaylist() {
    ArrayList<Playlist> results = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = mMusicDatabase.getReadableDatabase().query(PlaylistInfoColumns.NAME, null, null, null, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            results.ensureCapacity(cursor.getCount());
            do {
                if (cursor.getString(4).equals("local"))
                    results.add(new Playlist(cursor.getLong(0), cursor.getString(1), cursor.getInt(2), cursor.getString(3), cursor.getString(4)));
            } while (cursor.moveToNext());
        }
        return results;
    } finally {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
    }
}
Also used : Playlist(com.wm.remusic.info.Playlist) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 2 with Playlist

use of com.wm.remusic.info.Playlist in project remusic by aa112901.

the class AddNetPlaylistDialog method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    // 设置无标题
    getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    if (getArguments() != null) {
        musics = getArguments().getParcelableArrayList("songs");
        author = getArguments().getString("author");
    }
    playlistInfo = PlaylistInfo.getInstance(mContext);
    playlistsManager = PlaylistsManager.getInstance(mContext);
    View view = inflater.inflate(R.layout.fragment_add_playlist, container);
    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.create_new_playlist);
    recyclerView = (RecyclerView) view.findViewById(R.id.add_playlist_recyclerview);
    linearLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
            alertDialog.setView((mContext.getLayoutInflater().inflate(R.layout.dialog, null)));
            alertDialog.show();
            Window window = alertDialog.getWindow();
            window.setContentView(R.layout.dialog);
            final EditText editText = (EditText) (window.findViewById(R.id.message));
            editText.requestFocus();
            (window.findViewById(R.id.positiveButton)).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                }
            });
            (window.findViewById(R.id.negativeButton)).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dismiss();
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            Log.e("addplay", "here");
                            String albumart = null;
                            for (MusicInfo info : musics) {
                                albumart = info.albumData;
                                if (info.islocal) {
                                    if (albumart.equals(MusicUtils.getAlbumdata(MainApplication.context, info.songId)))
                                        break;
                                } else if (!TextUtils.isEmpty(albumart)) {
                                    break;
                                }
                            }
                            long playlistid = editText.getText().hashCode();
                            playlistInfo.addPlaylist(playlistid, editText.getText().toString(), musics.size(), albumart, author);
                            playlistsManager.insertLists(mContext, playlistid, musics);
                            Intent intent = new Intent(IConstants.PLAYLIST_COUNT_CHANGED);
                            MainApplication.context.sendBroadcast(intent);
                        }
                    }).start();
                    alertDialog.dismiss();
                }
            });
        }
    });
    ArrayList<Playlist> playlists = playlistInfo.getPlaylist();
    recyclerView.setLayoutManager(layoutManager);
    AddPlaylistAdapter adapter = new AddPlaylistAdapter(playlists);
    recyclerView.setAdapter(adapter);
    // setItemDecoration();
    return view;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Window(android.view.Window) EditText(android.widget.EditText) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Playlist(com.wm.remusic.info.Playlist) MusicInfo(com.wm.remusic.info.MusicInfo) LinearLayout(android.widget.LinearLayout)

Example 3 with Playlist

use of com.wm.remusic.info.Playlist in project remusic by aa112901.

the class MainFragmentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    switch(getItemViewType(i)) {
        case 0:
            MainFragmentItem item = (MainFragmentItem) itemResults.get(i);
            itemHolder.itemtitle.setText(item.title);
            itemHolder.count.setText("(" + item.count + ")");
            itemHolder.image.setImageResource(item.avatar);
            itemHolder.image.setImageTintList(R.color.theme_color_primary);
            setOnListener(itemHolder, i);
            break;
        case 1:
            Playlist playlist = (Playlist) itemResults.get(i);
            if (createdExpanded && playlist.author.equals("local")) {
                if (playlist.albumArt != null)
                    itemHolder.albumArt.setImageURI(Uri.parse(playlist.albumArt));
                itemHolder.title.setText(playlist.name);
                itemHolder.songcount.setText(playlist.songCount + "首");
            }
            if (collectExpanded && !playlist.author.equals("local")) {
                if (playlist.albumArt != null)
                    itemHolder.albumArt.setImageURI(Uri.parse(playlist.albumArt));
                itemHolder.title.setText(playlist.name);
                itemHolder.songcount.setText(playlist.songCount + "首");
            }
            setOnPlaylistListener(itemHolder, i, playlist.id, playlist.albumArt, playlist.name);
            isLoveList = false;
            break;
        case 2:
            itemHolder.sectionItem.setText("创建的歌单" + "(" + playlists.size() + ")");
            itemHolder.sectionImg.setImageResource(R.drawable.list_icn_arr_right);
            setSectionListener(itemHolder, i);
            break;
        case 3:
            itemHolder.sectionItem.setText("收藏的歌单" + "(" + netplaylists.size() + ")");
            itemHolder.sectionImg.setImageResource(R.drawable.list_icn_arr_right);
            setSectionListener(itemHolder, i);
            break;
    }
}
Also used : Playlist(com.wm.remusic.info.Playlist)

Example 4 with Playlist

use of com.wm.remusic.info.Playlist in project remusic by aa112901.

the class PlaylistInfo method getNetPlaylist.

public synchronized ArrayList<Playlist> getNetPlaylist() {
    ArrayList<Playlist> results = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = mMusicDatabase.getReadableDatabase().query(PlaylistInfoColumns.NAME, null, null, null, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            results.ensureCapacity(cursor.getCount());
            do {
                if (!cursor.getString(4).equals("local"))
                    results.add(new Playlist(cursor.getLong(0), cursor.getString(1), cursor.getInt(2), cursor.getString(3), cursor.getString(4)));
            } while (cursor.moveToNext());
        }
        return results;
    } finally {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
    }
}
Also used : Playlist(com.wm.remusic.info.Playlist) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 5 with Playlist

use of com.wm.remusic.info.Playlist in project remusic by aa112901.

the class AddPlaylistDialog method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    // 设置无标题
    getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    if (getArguments() != null) {
        musicId = getArguments().getLongArray("songs");
    }
    playlistInfo = PlaylistInfo.getInstance(getContext());
    playlistsManager = PlaylistsManager.getInstance(getContext());
    View view = inflater.inflate(R.layout.fragment_add_playlist, container);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.create_new_playlist);
    recyclerView = (RecyclerView) view.findViewById(R.id.add_playlist_recyclerview);
    linearLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
            alertDialog.setView((getActivity().getLayoutInflater().inflate(R.layout.dialog, null)));
            alertDialog.show();
            Window window = alertDialog.getWindow();
            window.setContentView(R.layout.dialog);
            final EditText editText = (EditText) (window.findViewById(R.id.message));
            editText.requestFocus();
            (window.findViewById(R.id.positiveButton)).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                }
            });
            (window.findViewById(R.id.negativeButton)).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dismiss();
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            String albumart = null;
                            for (long id : musicId) {
                                albumart = MusicUtils.getAlbumdata(MainApplication.context, id);
                                if (albumart != null) {
                                    break;
                                }
                            }
                            // String albumart = MusicUtils.getMusicInfo(getContext(), musicId[0]).albumData;
                            playlistInfo.addPlaylist(editText.getText().hashCode(), editText.getText().toString(), musicId.length, "file://" + albumart, "local");
                            for (int i = 0; i < musicId.length; i++) {
                                playlistsManager.insert(MainApplication.context, editText.getText().hashCode(), musicId[i], i);
                            }
                            Intent intent = new Intent(IConstants.PLAYLIST_COUNT_CHANGED);
                            MainApplication.context.sendBroadcast(intent);
                        }
                    }).start();
                    alertDialog.dismiss();
                }
            });
        }
    });
    ArrayList<Playlist> playlists = playlistInfo.getPlaylist();
    recyclerView.setLayoutManager(layoutManager);
    AddPlaylistAdapter adapter = new AddPlaylistAdapter(playlists);
    recyclerView.setAdapter(adapter);
    // setItemDecoration();
    return view;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Window(android.view.Window) EditText(android.widget.EditText) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Playlist(com.wm.remusic.info.Playlist) LinearLayout(android.widget.LinearLayout)

Aggregations

Playlist (com.wm.remusic.info.Playlist)5 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 AlertDialog (android.support.v7.app.AlertDialog)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 Window (android.view.Window)2 EditText (android.widget.EditText)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)2 ArrayList (java.util.ArrayList)2 MusicInfo (com.wm.remusic.info.MusicInfo)1