fix:修复随机可能会重复的问题
add:新增长按添加到播放列表功能 update:更新POPdialog依赖
This commit is contained in:
parent
3ef606b89e
commit
ed47603a29
Binary file not shown.
@ -7,9 +7,11 @@ import android.graphics.Bitmap;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.PopupWindow;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -19,7 +21,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
|
||||||
import com.yutou.nas_music_player.Datas.MusicData;
|
import com.yutou.nas_music_player.Datas.MusicData;
|
||||||
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
||||||
import com.yutou.nas_music_player.MyApplication;
|
import com.yutou.nas_music_player.MyApplication;
|
||||||
@ -176,7 +177,17 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
super.bind(data);
|
super.bind(data);
|
||||||
collectionDir(data);
|
collectionDir(data);
|
||||||
topDir(data);
|
topDir(data);
|
||||||
itemView.setOnClickListener(v -> clickAllList(data));
|
itemView.setOnClickListener(v -> {
|
||||||
|
clickAllList(data);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View view) {
|
||||||
|
showPOPWindows(data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +226,17 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
dislike = itemView.findViewById(R.id.dislike);
|
dislike = itemView.findViewById(R.id.dislike);
|
||||||
icon = itemView.findViewById(R.id.album_image);
|
icon = itemView.findViewById(R.id.album_image);
|
||||||
play_mask = itemView.findViewById(R.id.play_mask);
|
play_mask = itemView.findViewById(R.id.play_mask);
|
||||||
|
|
||||||
|
icon.setTag("icon");
|
||||||
|
title.setTag("title");
|
||||||
|
artist.setTag("artist");
|
||||||
|
message.setTag("message");
|
||||||
|
buttons.setTag("buttons");
|
||||||
|
collection.setTag("collection");
|
||||||
|
top.setTag("top");
|
||||||
|
dislike.setTag("dislike");
|
||||||
|
play_mask.setTag("play_mask");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void collectionDir(MusicData data) {
|
protected void collectionDir(MusicData data) {
|
||||||
@ -306,6 +328,7 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void clickAlbum(MusicData data) {
|
protected void clickAlbum(MusicData data) {
|
||||||
|
System.out.println("点击item");
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return;
|
return;
|
||||||
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
||||||
@ -463,5 +486,52 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopupWindow popupWindow = null;
|
||||||
|
|
||||||
|
protected void showPOPWindows(MusicData data) {
|
||||||
|
Button button = new Button(context);
|
||||||
|
button.setText("添加到列表");
|
||||||
|
button.setOnClickListener(view -> {
|
||||||
|
AppTools.showHud(context);
|
||||||
|
if(!data.isDir()){
|
||||||
|
MusicContainer.getInstance().addPlayList(data);
|
||||||
|
AppTools.hideHud();
|
||||||
|
AppTools.toast( "已添加到队列中");
|
||||||
|
popupWindow.dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("path", data.getFile());
|
||||||
|
json.put("type", true);
|
||||||
|
MusicContainer.getLibs().onDirMusicData(json, new NetworkInterface() {
|
||||||
|
@Override
|
||||||
|
public void httpGetData(Object data1, int state) {
|
||||||
|
List<MusicData> list = (List<MusicData>) data1;
|
||||||
|
int i = 0;
|
||||||
|
for (MusicData musicData : list) {
|
||||||
|
if (!musicData.isDir()) {
|
||||||
|
MusicContainer.getInstance().addPlayList(musicData);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppTools.hideHud();
|
||||||
|
AppTools.toast(i + "首歌已添加到队列中");
|
||||||
|
popupWindow.dismiss();
|
||||||
|
MusicContainer.getInstance().setPlayModel(MusicContainer.PLAY_MODEL_ORDER);
|
||||||
|
MusicContainer.getInstance().playNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void httpError(Exception e) {
|
||||||
|
AppTools.toast("添加失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
popupWindow = new PopupWindow(button, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
popupWindow.setOutsideTouchable(true);
|
||||||
|
|
||||||
|
popupWindow.showAsDropDown(itemView, 200, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,13 +72,14 @@ public class MusicContainer {
|
|||||||
collectionMapList = new LinkedHashMap<>();
|
collectionMapList = new LinkedHashMap<>();
|
||||||
previousPlayerList = new PreviousPlayerList();
|
previousPlayerList = new PreviousPlayerList();
|
||||||
browserHelpers = new ArrayList<>();
|
browserHelpers = new ArrayList<>();
|
||||||
playIndex = ConfigTools.getPreferences().getInt("playIndex", -1);
|
playIndex = ConfigTools.getConfigPreferences().getInt("playIndex", -1);
|
||||||
initMediaPlayer();
|
initMediaPlayer();
|
||||||
libs = new MusicLibs();
|
libs = new MusicLibs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayModel(int playModel) {
|
public void setPlayModel(int playModel) {
|
||||||
this.playModel = playModel;
|
this.playModel = playModel;
|
||||||
|
ConfigTools.getConfigPreferences().edit().putInt("playModel", playModel).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMediaPlayer() {
|
private void initMediaPlayer() {
|
||||||
@ -235,7 +236,7 @@ public class MusicContainer {
|
|||||||
isPause = false;
|
isPause = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConfigTools.getPreferences().edit().putInt("playIndex", playIndex).apply();
|
ConfigTools.getConfigPreferences().edit().putInt("playIndex", playIndex).apply();
|
||||||
nowPlayData = data;
|
nowPlayData = data;
|
||||||
String url = data.getPlayUrl();
|
String url = data.getPlayUrl();
|
||||||
previousPlayerList.add(data);
|
previousPlayerList.add(data);
|
||||||
@ -401,9 +402,8 @@ public class MusicContainer {
|
|||||||
playOfAllRandom();
|
playOfAllRandom();
|
||||||
AppTools.toast("当前播放列表为空,随机播放");
|
AppTools.toast("当前播放列表为空,随机播放");
|
||||||
} else {//播放列表中的歌单
|
} else {//播放列表中的歌单
|
||||||
ConfigTools.getPreferences().edit().putInt("playModel", MusicContainer.PLAY_MODEL_ORDER).apply();
|
|
||||||
if (isRandom) {
|
if (isRandom) {
|
||||||
playIndex = new Random().nextInt(playList.size());
|
playIndex = randomPlayIndex();
|
||||||
} else {
|
} else {
|
||||||
if (playList.size() > (playIndex + 1)) {
|
if (playList.size() > (playIndex + 1)) {
|
||||||
playIndex++;
|
playIndex++;
|
||||||
@ -416,6 +416,14 @@ public class MusicContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int randomPlayIndex() {
|
||||||
|
int tmp = new Random().nextInt(playList.size());
|
||||||
|
if (tmp == playIndex) {
|
||||||
|
return randomPlayIndex();
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单曲循环
|
* 单曲循环
|
||||||
*/
|
*/
|
||||||
@ -478,6 +486,10 @@ public class MusicContainer {
|
|||||||
this.playList.addAll(dataList);
|
this.playList.addAll(dataList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlayList(MusicData data) {
|
||||||
|
this.playList.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
public int getPlayModel() {
|
public int getPlayModel() {
|
||||||
return playModel;
|
return playModel;
|
||||||
}
|
}
|
||||||
@ -486,6 +498,10 @@ public class MusicContainer {
|
|||||||
return playIndex;
|
return playIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPlayIndex(int i) {
|
||||||
|
this.playIndex = i;
|
||||||
|
}
|
||||||
|
|
||||||
public class MusicLibs {
|
public class MusicLibs {
|
||||||
|
|
||||||
private MusicLibs() {
|
private MusicLibs() {
|
||||||
|
Loading…
Reference in New Issue
Block a user