use of com.wm.remusic.json.SearchArtistInfo 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);
}
use of com.wm.remusic.json.SearchArtistInfo 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);
}
Aggregations