Search in sources :

Example 1 with SearchAlbumInfo

use of com.wm.remusic.json.SearchAlbumInfo in project remusic by aa112901.

the class MoreFragment method setClick.

private void setClick() {
    if (muaicflowAdapter != null) {
        muaicflowAdapter.setOnItemClickListener(new MusicFlowAdapter.OnRecyclerViewItemClickListener() {

            @Override
            public void onItemClick(View view, String data) {
                switch(Integer.parseInt(data)) {
                    case 0:
                        mHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                if (adapterMusicInfo.songId == MusicPlayer.getCurrentAudioId())
                                    return;
                                long[] ids = new long[1];
                                ids[0] = adapterMusicInfo.songId;
                                HashMap<Long, MusicInfo> map = new HashMap<Long, MusicInfo>();
                                map.put(ids[0], adapterMusicInfo);
                                MusicPlayer.playNext(mContext, map, ids);
                            }
                        }, 100);
                        dismiss();
                        break;
                    case 1:
                        ArrayList<MusicInfo> musicList = new ArrayList<MusicInfo>();
                        musicList.add(adapterMusicInfo);
                        AddNetPlaylistDialog.newInstance(musicList).show(getFragmentManager(), "add");
                        dismiss();
                        break;
                    case 2:
                        Intent shareIntent = new Intent();
                        shareIntent.setAction(Intent.ACTION_SEND);
                        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + adapterMusicInfo.data));
                        shareIntent.setType("audio/*");
                        mContext.startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.shared_to)));
                        dismiss();
                        break;
                    case 3:
                        new AlertDialog.Builder(mContext).setTitle(getResources().getString(R.string.sure_to_delete_music)).setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                try {
                                    Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, adapterMusicInfo.songId);
                                    mContext.getContentResolver().delete(uri, null, null);
                                    if (MusicPlayer.getCurrentAudioId() == adapterMusicInfo.songId) {
                                        if (MusicPlayer.getQueueSize() == 0) {
                                            MusicPlayer.stop();
                                        } else {
                                            MusicPlayer.next();
                                        }
                                    }
                                    mHandler.postDelayed(new Runnable() {

                                        @Override
                                        public void run() {
                                            PlaylistsManager.getInstance(mContext).deleteMusic(mContext, adapterMusicInfo.songId);
                                            mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
                                        }
                                    }, 200);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                dismiss();
                            }
                        }).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dismiss();
                            }
                        }).show();
                        dismiss();
                        break;
                    case 4:
                        if (adapterMusicInfo.islocal) {
                            new AsyncTask<Void, Void, Void>() {

                                @Override
                                protected Void doInBackground(Void... params) {
                                    ArrayList<SearchArtistInfo> artistResults = new ArrayList<>();
                                    try {
                                        JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.artist, 1, 50)).get("result").getAsJsonObject();
                                        JsonObject artistObject = jsonObject.get("artist_info").getAsJsonObject();
                                        JsonArray artistArray = artistObject.get("artist_list").getAsJsonArray();
                                        for (JsonElement o : artistArray) {
                                            SearchArtistInfo artistInfo = MainApplication.gsonInstance().fromJson(o, SearchArtistInfo.class);
                                            artistResults.add(artistInfo);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    if (artistResults.size() == 0) {
                                        mHandler.post(new Runnable() {

                                            @Override
                                            public void run() {
                                                Toast.makeText(mContext, "没有找到该艺术家", Toast.LENGTH_SHORT).show();
                                            }
                                        });
                                    } else {
                                        SearchArtistInfo info = artistResults.get(0);
                                        Intent intent = new Intent(mContext, ArtistDetailActivity.class);
                                        intent.putExtra("artistid", info.getArtist_id());
                                        intent.putExtra("artistname", info.getAuthor());
                                        mContext.startActivity(intent);
                                    }
                                    return null;
                                }
                            }.execute();
                        } else {
                            Intent intent = new Intent(mContext, ArtistDetailActivity.class);
                            intent.putExtra("artistid", adapterMusicInfo.artistId + "");
                            intent.putExtra("artistname", adapterMusicInfo.artist);
                            mContext.startActivity(intent);
                        }
                        dismiss();
                        break;
                    case 5:
                        if (adapterMusicInfo.islocal) {
                            new AsyncTask<Void, Void, Void>() {

                                @Override
                                protected Void doInBackground(Void... params) {
                                    ArrayList<SearchAlbumInfo> albumResults = new ArrayList<SearchAlbumInfo>();
                                    try {
                                        JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.albumName, 1, 10)).get("result").getAsJsonObject();
                                        JsonObject albumObject = jsonObject.get("album_info").getAsJsonObject();
                                        JsonArray albumArray = albumObject.get("album_list").getAsJsonArray();
                                        for (JsonElement o : albumArray) {
                                            SearchAlbumInfo albumInfo = MainApplication.gsonInstance().fromJson(o, SearchAlbumInfo.class);
                                            albumResults.add(albumInfo);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    if (albumResults.size() == 0) {
                                        mHandler.post(new Runnable() {

                                            @Override
                                            public void run() {
                                                Toast.makeText(mContext, "没有找到所属专辑", Toast.LENGTH_SHORT).show();
                                            }
                                        });
                                    } else {
                                        SearchAlbumInfo info = albumResults.get(0);
                                        Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
                                        intent.putExtra("albumid", info.getAlbum_id());
                                        intent.putExtra("albumart", info.getPic_small());
                                        intent.putExtra("albumname", info.getTitle());
                                        intent.putExtra("albumdetail", info.getAlbum_desc());
                                        mContext.startActivity(intent);
                                    }
                                    return null;
                                }
                            };
                        } else {
                            Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
                            intent.putExtra("albumid", adapterMusicInfo.albumId + "");
                            intent.putExtra("albumart", adapterMusicInfo.albumData);
                            intent.putExtra("albumname", adapterMusicInfo.albumName);
                            mContext.startActivity(intent);
                        }
                        dismiss();
                        break;
                    case 6:
                        if (adapterMusicInfo.islocal) {
                            new AlertDialog.Builder(mContext).setTitle(getResources().getString(R.string.sure_to_set_ringtone)).setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Uri ringUri = Uri.parse("file://" + adapterMusicInfo.data);
                                    RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_NOTIFICATION, ringUri);
                                    dialog.dismiss();
                                    Toast.makeText(mContext, getResources().getString(R.string.set_ringtone_successed), Toast.LENGTH_SHORT).show();
                                    dismiss();
                                }
                            }).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).show();
                        } else {
                        }
                        break;
                    case 7:
                        MusicDetailFragment detailFrament = MusicDetailFragment.newInstance(adapterMusicInfo);
                        detailFrament.show(getActivity().getSupportFragmentManager(), "detail");
                        dismiss();
                        break;
                    default:
                        break;
                }
            }
        });
        recyclerView.setAdapter(muaicflowAdapter);
        return;
    }
    commonAdapter.setOnItemClickListener(new OverFlowAdapter.OnRecyclerViewItemClickListener() {

        @Override
        public void onItemClick(View view, String data) {
            switch(Integer.parseInt(data)) {
                case 0:
                    mHandler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            HashMap<Long, MusicInfo> infos = new HashMap<Long, MusicInfo>();
                            int len = list.size();
                            long[] listid = new long[len];
                            for (int i = 0; i < len; i++) {
                                MusicInfo info = list.get(i);
                                listid[i] = info.songId;
                                infos.put(listid[i], info);
                            }
                            MusicPlayer.playAll(infos, listid, 0, false);
                        }
                    }, 60);
                    dismiss();
                    break;
                case 1:
                    AddNetPlaylistDialog.newInstance(list).show(getFragmentManager(), "add");
                    dismiss();
                    break;
                case 2:
                    new AsyncTask<Void, Void, Void>() {

                        @Override
                        protected Void doInBackground(Void... params) {
                            for (MusicInfo music : list) {
                                if (MusicPlayer.getCurrentAudioId() == music.songId) {
                                    if (MusicPlayer.getQueueSize() == 0) {
                                        MusicPlayer.stop();
                                    } else {
                                        MusicPlayer.next();
                                    }
                                }
                                Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, music.songId);
                                mContext.getContentResolver().delete(uri, null, null);
                                PlaylistsManager.getInstance(mContext).deleteMusic(mContext, music.songId);
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void v) {
                            mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
                        }
                    }.execute();
                    //                        Handler handler1 = new Handler();
                    //                        handler1.postDelayed(new Runnable() {
                    //                            @Override
                    //                            public void run() {
                    //                                for (final MusicInfo music : list) {
                    //                                    PlaylistsManager.getInstance(mContext).deleteMusic(mContext, music.songId);
                    //                                }
                    //                            }
                    //                        }, 100);
                    //                            file = new File(music.data);
                    //                            if (file.exists())
                    //                                file.delete();
                    //                            if (file.exists() == false) {
                    //                                mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                    //                                        Uri.parse("file://" + music.data)));
                    //                            }
                    //  HandlerUtil.CommonHandler handler1 = new HandlerUtil.CommonHandler(mContext);
                    //                new Handler().postDelayed(new Runnable() {
                    //                    @Override
                    //                    public void run() {
                    //                        mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
                    //                    }
                    //                }, 600);
                    dismiss();
                    break;
            }
        }
    });
    recyclerView.setAdapter(commonAdapter);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) MusicFlowAdapter(com.wm.remusic.adapter.MusicFlowAdapter) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Uri(android.net.Uri) SearchArtistInfo(com.wm.remusic.json.SearchArtistInfo) ArtistDetailActivity(com.wm.remusic.activity.ArtistDetailActivity) OverFlowAdapter(com.wm.remusic.adapter.OverFlowAdapter) SearchAlbumInfo(com.wm.remusic.json.SearchAlbumInfo) AlbumsDetailActivity(com.wm.remusic.activity.AlbumsDetailActivity) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 2 with SearchAlbumInfo

use of com.wm.remusic.json.SearchAlbumInfo in project remusic by aa112901.

the class NetMoreFragment method setClick.

private void setClick() {
    muaicflowAdapter.setOnItemClickListener(new MusicFlowAdapter.OnRecyclerViewItemClickListener() {

        @Override
        public void onItemClick(View view, String data) {
            switch(Integer.parseInt(data)) {
                case 0:
                    mHandler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            if (adapterMusicInfo.songId == MusicPlayer.getCurrentAudioId())
                                return;
                            long[] ids = new long[1];
                            ids[0] = adapterMusicInfo.songId;
                            HashMap<Long, MusicInfo> map = new HashMap<Long, MusicInfo>();
                            map.put(ids[0], adapterMusicInfo);
                            MusicPlayer.playNext(mContext, map, ids);
                        }
                    }, 100);
                    dismiss();
                    break;
                case 1:
                    final ArrayList<MusicInfo> musicList = new ArrayList<MusicInfo>();
                    musicList.add(adapterMusicInfo);
                    AddNetPlaylistDialog.newInstance(musicList).show(getFragmentManager(), "add");
                    dismiss();
                    break;
                case 2:
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + adapterMusicInfo.data));
                    shareIntent.setType("audio/*");
                    mContext.startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.shared_to)));
                    dismiss();
                    break;
                case 3:
                    new AlertDialog.Builder(mContext).setTitle("要下载音乐吗").setPositiveButton(mContext.getString(R.string.sure), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Down.downMusic(MainApplication.context, adapterMusicInfo.songId + "", adapterMusicInfo.musicName, adapterMusicInfo.artist);
                            dialog.dismiss();
                        }
                    }).setNegativeButton(mContext.getString(R.string.cancel), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
                    dismiss();
                    break;
                case 4:
                    if (adapterMusicInfo.islocal) {
                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                ArrayList<SearchArtistInfo> artistResults = new ArrayList<>();
                                try {
                                    JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.artist, 1, 50)).get("result").getAsJsonObject();
                                    JsonObject artistObject = jsonObject.get("artist_info").getAsJsonObject();
                                    JsonArray artistArray = artistObject.get("artist_list").getAsJsonArray();
                                    for (JsonElement o : artistArray) {
                                        SearchArtistInfo artistInfo = MainApplication.gsonInstance().fromJson(o, SearchArtistInfo.class);
                                        artistResults.add(artistInfo);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                if (artistResults.size() == 0) {
                                    mHandler.post(new Runnable() {

                                        @Override
                                        public void run() {
                                            Toast.makeText(mContext, "没有找到该艺术家", Toast.LENGTH_SHORT).show();
                                        }
                                    });
                                } else {
                                    SearchArtistInfo info = artistResults.get(0);
                                    Intent intent = new Intent(mContext, ArtistDetailActivity.class);
                                    intent.putExtra("artistid", info.getArtist_id());
                                    intent.putExtra("artistname", info.getAuthor());
                                    //                                        intent.putExtra("albumid", info.getAlbum_id());
                                    //                                        intent.putExtra("albumart", info.getPic_small());
                                    //                                        intent.putExtra("albumname", info.getTitle());
                                    //                                        intent.putExtra("albumdetail",info.getAlbum_desc());
                                    mContext.startActivity(intent);
                                }
                                return null;
                            }
                        }.execute();
                    } else {
                        Intent intent = new Intent(mContext, ArtistDetailActivity.class);
                        intent.putExtra("artistid", adapterMusicInfo.artistId + "");
                        intent.putExtra("artistname", adapterMusicInfo.artist);
                        mContext.startActivity(intent);
                    }
                    dismiss();
                    break;
                case 5:
                    if (adapterMusicInfo.islocal) {
                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                ArrayList<SearchAlbumInfo> albumResults = new ArrayList<SearchAlbumInfo>();
                                try {
                                    JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Search.searchMerge(adapterMusicInfo.albumName, 1, 10)).get("result").getAsJsonObject();
                                    //                                        JsonObject artistObject =  jsonObject.get("artist_info").getAsJsonObject();
                                    //                                        JsonArray artistArray = artistObject.get("artist_list").getAsJsonArray();
                                    //                                        for (JsonElement o : artistArray) {
                                    //                                            SearchArtistInfo artistInfo =  MainApplication.gsonInstance().fromJson(o, SearchArtistInfo.class);
                                    //                                            artistResults.add(artistInfo);
                                    //                                        }
                                    Log.e("search", jsonObject.toString());
                                    JsonObject albumObject = jsonObject.get("album_info").getAsJsonObject();
                                    JsonArray albumArray = albumObject.get("album_list").getAsJsonArray();
                                    for (JsonElement o : albumArray) {
                                        SearchAlbumInfo albumInfo = MainApplication.gsonInstance().fromJson(o, SearchAlbumInfo.class);
                                        albumResults.add(albumInfo);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                if (albumResults.size() == 0) {
                                    mHandler.post(new Runnable() {

                                        @Override
                                        public void run() {
                                            Toast.makeText(mContext, "没有找到所属专辑", Toast.LENGTH_SHORT).show();
                                        }
                                    });
                                } else {
                                    SearchAlbumInfo info = albumResults.get(0);
                                    Log.e("search", info.getAlbum_id() + "  " + info.getTitle());
                                    Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
                                    intent.putExtra("albumid", info.getAlbum_id());
                                    intent.putExtra("albumart", info.getPic_small());
                                    intent.putExtra("albumname", info.getTitle());
                                    intent.putExtra("albumdetail", info.getAlbum_desc());
                                    mContext.startActivity(intent);
                                }
                                return null;
                            }
                        }.execute();
                    } else {
                        Intent intent = new Intent(mContext, AlbumsDetailActivity.class);
                        intent.putExtra("albumid", adapterMusicInfo.albumId + "");
                        intent.putExtra("albumart", adapterMusicInfo.albumData);
                        intent.putExtra("albumname", adapterMusicInfo.albumName);
                        mContext.startActivity(intent);
                    }
                    dismiss();
                    break;
                case 6:
                    MusicDetailFragment detailFrament = MusicDetailFragment.newInstance(adapterMusicInfo);
                    detailFrament.show(getActivity().getSupportFragmentManager(), "detail");
                    dismiss();
                    break;
                default:
                    break;
            }
        }
    });
    recyclerView.setAdapter(muaicflowAdapter);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) MusicFlowAdapter(com.wm.remusic.adapter.MusicFlowAdapter) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SearchArtistInfo(com.wm.remusic.json.SearchArtistInfo) ArtistDetailActivity(com.wm.remusic.activity.ArtistDetailActivity) SearchAlbumInfo(com.wm.remusic.json.SearchAlbumInfo) AlbumsDetailActivity(com.wm.remusic.activity.AlbumsDetailActivity) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) MusicInfo(com.wm.remusic.info.MusicInfo)

Aggregations

DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 AsyncTask (android.os.AsyncTask)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 TextView (android.widget.TextView)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 AlbumsDetailActivity (com.wm.remusic.activity.AlbumsDetailActivity)2 ArtistDetailActivity (com.wm.remusic.activity.ArtistDetailActivity)2 MusicFlowAdapter (com.wm.remusic.adapter.MusicFlowAdapter)2 MusicInfo (com.wm.remusic.info.MusicInfo)2 SearchAlbumInfo (com.wm.remusic.json.SearchAlbumInfo)2 SearchArtistInfo (com.wm.remusic.json.SearchArtistInfo)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Uri (android.net.Uri)1 OverFlowAdapter (com.wm.remusic.adapter.OverFlowAdapter)1