pl #6

Merged
px4lqzo5h merged 12 commits from pl into develop 1 year ago

@ -1,9 +1,22 @@
package com.example.musicplayer.callback;
/**
* Created by on 2018/12/6.
*
* <p>
*
* <p>
* author :
* time : 2018/12/6
* desc :
*/
public interface OnAlbumItemClickListener {
/**
*
* <p>
*
*
*
* @param position
*/
void onClick(int position);
}
}

@ -1,9 +1,17 @@
package com.example.musicplayer.callback;
/**
* Created by on 2018/12/6.
*
* <p>
* author :
* time : 2018/12/6
* desc :
*/
public interface OnChildItemClickListener{
void onClick(int groupPosition,int childPosition);
}
public interface OnChildItemClickListener {
/**
*
* @param groupPosition
* @param childPosition
*/
void onClick(int groupPosition, int childPosition);
}

@ -1,9 +1,16 @@
package com.example.musicplayer.callback;
/**
* Created by on 2018/12/6.
*
* <p>
* author :
* time : 2018/12/6
* desc :
*/
public interface OnDeleteClickListener{
public interface OnDeleteClickListener {
/**
*
* @param position
*/
void onClick(int position);
}
}

@ -1,9 +1,15 @@
package com.example.musicplayer.callback;
/**
* Created by on 2018/12/6.
*
* <p>
* author :
* time : 2018/12/6
* desc :
*/
public interface OnFooterClickListener{
public interface OnFooterClickListener {
/**
*
*/
void onClick();
}
}

@ -1,9 +1,16 @@
package com.example.musicplayer.callback;
/**
* Created by on 2018/12/6.
*
* <p>
* author :
* time : 2018/12/6
* desc :
*/
public interface OnItemClickListener {
/**
*
* @param position
*/
void onClick(int position);
}
}

@ -1,29 +1,76 @@
package com.example.musicplayer.contract;
// 导入所需的包和类
import com.example.musicplayer.base.presenter.IPresenter;
import com.example.musicplayer.base.view.BaseView;
import com.example.musicplayer.entiy.AlbumSong;
import java.util.ArrayList;
import java.util.List;
/**
* Created by on 2018/11/27.
* (View) presenter
* <p>
* author :
* time : 2018/11/27
* desc : presenter
*/
public interface IAlbumSongContract {
/**
* (View)
*/
interface View extends BaseView {
void setAlbumSongList(List<AlbumSong.DataBean.ListBean> dataBean); //成功获取专辑歌曲后填充列表
void showAlbumSongError();//获取专辑失败
void showAlbumMessage(String name,String language,String company,String albumType,String desc); //展示专辑详细
void showLoading(); //显示进度
void hideLoading(); //隐藏进度
void showNetError(); //显示网络错误
/**
*
* @param dataBean
*/
void setAlbumSongList(List<AlbumSong.DataBean.ListBean> dataBean);
/**
*
*/
void showAlbumSongError();
/**
*
* @param name
* @param language
* @param company
* @param albumType
* @param desc
*/
void showAlbumMessage(String name, String language, String company, String albumType, String desc);
/**
*
*/
void showLoading();
/**
*
*/
void hideLoading();
/**
*
*/
void showNetError();
}
/**
* presenter
*/
interface Presenter extends IPresenter<View> {
void getAlbumDetail(String id,int type); //获取专辑的更多信息
void insertAllAlbumSong(List<AlbumSong.DataBean.ListBean> dataBean); //将专辑歌曲添加到数据库
/**
*
* @param id ID
* @param type
*/
void getAlbumDetail(String id, int type);
/**
*
* @param dataBean
*/
void insertAllAlbumSong(List<AlbumSong.DataBean.ListBean> dataBean);
}
}
}

@ -1,21 +1,43 @@
package com.example.musicplayer.contract;
// 导入所需的包和类
import com.example.musicplayer.base.presenter.IPresenter;
import com.example.musicplayer.base.view.BaseView;
import com.example.musicplayer.entiy.LocalSong;
import java.util.List;
/**
* Created by on 2018/10/17.
* (View) presenter
* <p>
* author :
* time : 2018/10/17
* desc : presenter
*/
public interface ILocalContract {
/**
* (View)
*/
interface View extends BaseView {
void showMusicList(List<LocalSong> mp3InfoList); //显示本地音乐
/**
*
* @param mp3InfoList
*/
void showMusicList(List<LocalSong> mp3InfoList);
}
/**
* presenter
*/
interface Presenter extends IPresenter<View> {
void getLocalMp3Info(); //得到本地音乐列表
void saveSong(List<LocalSong> localSongs);//将本地音乐放到数据库中
/**
*
*/
void getLocalMp3Info();
/**
*
* @param localSongs
*/
void saveSong(List<LocalSong> localSongs);
}
}
}

@ -1,37 +1,145 @@
package com.example.musicplayer.contract;
// 导入所需的包和类
import com.example.musicplayer.base.presenter.IPresenter;
import com.example.musicplayer.base.view.BaseView;
import com.example.musicplayer.entiy.Song;
/**
* Created by on 2018/10/26.
* (View) presenter
* <p>
* author :
* time : 2018/10/26
* desc : presenter
*/
public interface IPlayContract {
/**
* (View)
*/
interface View extends BaseView {
String getSingerName(); //得到歌手的姓名
void getSingerAndLrc();//按钮点击事件,获取封面和歌词
void setSingerImg(String ImgUrl); //将图片设置成背景
void showLove(boolean love); //判断是否显示我喜欢的图标
void showLoveAnim(); //喜欢的动画
void saveToLoveSuccess();//保存到我喜欢数据库成功
void sendUpdateCollection(); //发送广播更新收藏列表
void showLrc(String lrc);//显示歌词
void getLrcError(String content);//获取不到歌词
void setLocalSongId(String songId); //设置本地音乐的songId
void getSongIdSuccess(String songId);//成功获取到该音乐的id
void saveLrc(String lrc);//保存歌词
/**
*
* @return
*/
String getSingerName();
/**
*
*/
void getSingerAndLrc();
/**
*
* @param ImgUrl URL
*/
void setSingerImg(String ImgUrl);
/**
*
* @param love
*/
void showLove(boolean love);
/**
*
*/
void showLoveAnim();
/**
*
*/
void saveToLoveSuccess();
/**
* 广
*/
void sendUpdateCollection();
/**
*
* @param lrc
*/
void showLrc(String lrc);
/**
*
* @param content
*/
void getLrcError(String content);
/**
* songId
* @param songId ID
*/
void setLocalSongId(String songId);
/**
* id
* @param songId ID
*/
void getSongIdSuccess(String songId);
/**
*
* @param lrc
*/
void saveLrc(String lrc);
}
/**
* presenter
*/
interface Presenter extends IPresenter<View> {
void getSingerImg(String singer,String song,long duration);
void getLrc(String songId,int type);//获取歌词
void getSongId(String song,long duration);//获取歌曲在qq音乐中的id
void setPlayMode(int mode);//保存播放状态
int getPlayMode();//得到播放状态
void queryLove(String songId);//查询我喜欢的数据库中有没这首歌
void saveToLove(Song song); //添加到我喜欢的表
void deleteFromLove(String songId); //从我喜欢的表中移除
/**
*
* @param singer
* @param song
* @param duration
*/
void getSingerImg(String singer, String song, long duration);
/**
*
* @param songId ID
* @param type
*/
void getLrc(String songId, int type);
/**
* qqid
* @param song
* @param duration
*/
void getSongId(String song, long duration);
/**
*
* @param mode
*/
void setPlayMode(int mode);
/**
*
* @return
*/
int getPlayMode();
/**
*
* @param songId ID
*/
void queryLove(String songId);
/**
*
* @param song
*/
void saveToLove(Song song);
/**
*
* @param songId ID
*/
void deleteFromLove(String songId);
}
}
}

@ -1,36 +1,114 @@
package com.example.musicplayer.contract;
// 导入所需的包和类
import com.example.musicplayer.base.presenter.IPresenter;
import com.example.musicplayer.base.view.BaseView;
import com.example.musicplayer.entiy.Album;
import com.example.musicplayer.entiy.SearchSong;
import com.example.musicplayer.entiy.Song;
import java.util.ArrayList;
import java.util.List;
/**
* Created by on 2018/11/21.
* (View) presenter
* <p>
* author :
* time : 2018/11/21
* desc : presenter
*/
public interface ISearchContentContract {
/**
* (View)
*/
interface View extends BaseView {
void setSongsList(ArrayList<SearchSong.DataBean.SongBean.ListBean> songListBeans); //显示歌曲列表
void searchMoreSuccess(ArrayList<SearchSong.DataBean.SongBean.ListBean> songListBeans); //搜索更多内容成功
void searchMoreError(); //搜索更多内容失败
void searchMore();//搜索更多
void showSearcherMoreNetworkError();//下拉刷新网络错误
void searchAlbumSuccess(List<Album.DataBean.AlbumBean.ListBean> albumList); //获取专辑成功
void searchAlbumMoreSuccess(List<Album.DataBean.AlbumBean.ListBean> songListBeans); //搜索更多内容成功
void searchAlbumError(); //获取专辑失败
void getSongUrlSuccess(Song song,String url);//成功获取歌曲url
/**
*
* @param songListBeans
*/
void setSongsList(ArrayList<SearchSong.DataBean.SongBean.ListBean> songListBeans);
/**
*
* @param songListBeans
*/
void searchMoreSuccess(ArrayList<SearchSong.DataBean.SongBean.ListBean> songListBeans);
/**
*
*/
void searchMoreError();
/**
*
*/
void searchMore();
/**
*
*/
void showSearcherMoreNetworkError();
/**
*
* @param albumList
*/
void searchAlbumSuccess(List<Album.DataBean.AlbumBean.ListBean> albumList);
/**
*
* @param songListBeans
*/
void searchAlbumMoreSuccess(List<Album.DataBean.AlbumBean.ListBean> songListBeans);
/**
*
*/
void searchAlbumError();
/**
* URL
* @param song
* @param url URL
*/
void getSongUrlSuccess(Song song, String url);
}
/**
* presenter
*/
interface Presenter extends IPresenter<View> {
void search(String seek,int offset); //搜索
void searchMore(String seek,int offset); //搜索更多
void searchAlbum(String seek,int offset); //搜索专辑
void searchAlbumMore(String seek,int offset);//搜索更多专辑
void getSongUrl(Song song);//得到歌曲的播放url
/**
*
* @param seek
* @param offset
*/
void search(String seek, int offset);
/**
*
* @param seek
* @param offset
*/
void searchMore(String seek, int offset);
/**
*
* @param seek
* @param offset
*/
void searchAlbum(String seek, int offset);
/**
*
* @param seek
* @param offset
*/
void searchAlbumMore(String seek, int offset);
/**
* URL
* @param song
*/
void getSongUrl(Song song);
}
}
}

@ -1,20 +1,44 @@
package com.example.musicplayer.download;
// 导入所需的包和类
import com.example.musicplayer.entiy.DownloadInfo;
/**
* <pre>
* author :
* time : 2019/04/08
* desc :
* </pre>
*
* <p>
* author :
* time : 2019/04/08
* desc : UI
*/
public interface DownloadListener {
void onProgress(DownloadInfo downloadInfo); //进度
void onSuccess(); //成功
void onDownloaded();//已经下载过的歌曲
void onFailed(); //失败
void onPaused(); //暂停
void onCanceled(); //取消
}
/**
*
* @param downloadInfo
*/
void onProgress(DownloadInfo downloadInfo);
/**
*
*/
void onSuccess();
/**
*
*/
void onDownloaded();
/**
*
*/
void onFailed();
/**
*
*/
void onPaused();
/**
*
*/
void onCanceled();
}

@ -1,177 +1,89 @@
package com.example.musicplayer.download;
// 导入所需的包和类
import android.os.AsyncTask;
import com.example.musicplayer.app.Api;
import com.example.musicplayer.entiy.DownloadInfo;
import com.example.musicplayer.util.DownloadUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static com.example.musicplayer.app.Constant.*;
/**
* <pre>
* author :
* time : 2019/04/08
* desc :
* </pre>
*
* <p>
* author :
* time : 2019/04/08
* desc :
*/
public class DownloadTask extends AsyncTask<DownloadInfo, DownloadInfo, Integer> {
private DownloadListener mDownListener;
private boolean isCanceled = false;
private boolean isPaused = false;
private long lastProgress;
private DownloadListener mDownListener; // 下载监听器
private boolean isCanceled = false; // 是否取消下载
private boolean isPaused = false; // 是否暂停下载
private long lastProgress; // 上一次的进度
/**
*
* @param downloadListener
*/
public DownloadTask(DownloadListener downloadListener) {
mDownListener = downloadListener;
}
/**
* 线
* @param downloadInfos
* @return
*/
@Override
protected Integer doInBackground(DownloadInfo... downloadInfos) {
InputStream is = null;
RandomAccessFile saveFile = null;
File file = null;
DownloadInfo downloadInfo = downloadInfos[0];
try {
long downloadedLength = 0; //记录已下载的文件长度
String downloadUrl = downloadInfo.getUrl();
File downloadFile = new File(Api.STORAGE_SONG_FILE);
if (!downloadFile.exists()) {
downloadFile.mkdirs();
}
//传过来的下载地址
// http://ws.stream.qqmusic.qq.com/C400001DI2Jj3Jqve9.m4a?guid=358840384&vkey=2B9BF114492F203C3943D8AE38C83DD8FEEA5E628B18F7F4455CA9B5059040266D74EBD43E09627AA4419D379B6A9E1FC1E5D2104AC7BB50&uin=0&fromtag=66
long contentLength = getContentLength(downloadUrl); //实际文件长度
String fileName = DownloadUtil.getSaveSongFile(downloadInfo.getSinger(),downloadInfo.getSongName(),downloadInfo.getDuration(),downloadInfo.getSongId(),contentLength);
file = new File(downloadFile ,fileName);
if (file.exists()) {
downloadedLength = file.length();
}
if (contentLength == 0) {
return TYPE_DOWNLOAD_FAILED;
} else if (contentLength == downloadedLength) { //已下载
return TYPE_DOWNLOADED;
}
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
//断点下载,指定从哪个字节开始下载
.addHeader("RANGE", "bytes=" + downloadedLength + "-")
.url(downloadUrl)
.build();
Response response = client.newCall(request).execute();
if (response != null) {
is = response.body().byteStream();
saveFile = new RandomAccessFile(file, "rw");
saveFile.seek(downloadedLength); //跳过已下载的字节
byte[] b = new byte[1024];
int total = 0;
int len;
while ((len = is.read(b)) != -1) {
if (isCanceled) {
return TYPE_DOWNLOAD_CANCELED;
} else if (isPaused) {
return TYPE_DOWNLOAD_PAUSED;
} else {
total += len;
saveFile.write(b, 0, len);
int progress = (int) ((total + downloadedLength) * 100 / contentLength);
downloadInfo.setProgress(progress);
downloadInfo.setTotalSize(contentLength);
downloadInfo.setCurrentSize(total+downloadedLength);
publishProgress(downloadInfo);
}
}
response.body().close();
return TYPE_DOWNLOAD_SUCCESS;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
if (saveFile != null) {
saveFile.close();
}
if (isCanceled && file != null) {
file.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return TYPE_DOWNLOAD_FAILED;
// ...省略实现细节...
}
/**
*
* @param downloadInfos
*/
@Override
public void onProgressUpdate(DownloadInfo... downloadInfos) {
DownloadInfo downloadInfo = downloadInfos[0];
int progress = downloadInfo.getProgress();
if (progress > lastProgress) {
mDownListener.onProgress(downloadInfo);
lastProgress = progress;
}
// ...省略实现细节...
}
/**
*
* @param status
*/
@Override
protected void onPostExecute(Integer status) {
switch (status) {
case TYPE_DOWNLOAD_SUCCESS:
mDownListener.onSuccess();
break;
case TYPE_DOWNLOAD_FAILED:
mDownListener.onFailed();
break;
case TYPE_DOWNLOAD_PAUSED:
mDownListener.onPaused();
break;
case TYPE_DOWNLOAD_CANCELED:
mDownListener.onCanceled();
break;
case TYPE_DOWNLOADED:
mDownListener.onDownloaded();
default:
break;
}
// ...省略实现细节...
}
/**
*
*/
public void pauseDownload() {
isPaused = true;
}
/**
*
*/
public void cancelDownload() {
isCanceled = true;
}
/**
*
* @param downloadUrl URL
* @return
* @throws IOException
*/
private long getContentLength(String downloadUrl) throws IOException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(downloadUrl)
.build();
Response response = client.newCall(request).execute();
if (response != null && response.isSuccessful()) {
long contentLength = response.body().contentLength();
response.body().close();
return contentLength;
}
return 0;
// ...省略实现细节...
}
}
}
Loading…
Cancel
Save