diff --git a/app/libs/POPDialog-release.aar b/app/libs/POPDialog-release.aar index 8798a58..570f379 100644 Binary files a/app/libs/POPDialog-release.aar and b/app/libs/POPDialog-release.aar differ diff --git a/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java b/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java index 0a63c51..d8c2380 100644 --- a/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java +++ b/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java @@ -7,9 +7,11 @@ import android.graphics.Bitmap; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupWindow; import android.widget.Toast; import androidx.annotation.NonNull; @@ -19,7 +21,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.alibaba.fastjson.JSONObject; import com.bumptech.glide.Glide; 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.Interfaces.NetworkInterface; import com.yutou.nas_music_player.MyApplication; @@ -176,7 +177,17 @@ public class MusicLibsAdapter extends RecyclerView.Adapter 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 { + 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 list = (List) 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); + } } } diff --git a/app/src/main/java/com/yutou/nas_music_player/containers/MusicContainer.java b/app/src/main/java/com/yutou/nas_music_player/containers/MusicContainer.java index 5a33f2f..0e9daf1 100644 --- a/app/src/main/java/com/yutou/nas_music_player/containers/MusicContainer.java +++ b/app/src/main/java/com/yutou/nas_music_player/containers/MusicContainer.java @@ -72,13 +72,14 @@ public class MusicContainer { collectionMapList = new LinkedHashMap<>(); previousPlayerList = new PreviousPlayerList(); browserHelpers = new ArrayList<>(); - playIndex = ConfigTools.getPreferences().getInt("playIndex", -1); + playIndex = ConfigTools.getConfigPreferences().getInt("playIndex", -1); initMediaPlayer(); libs = new MusicLibs(); } public void setPlayModel(int playModel) { this.playModel = playModel; + ConfigTools.getConfigPreferences().edit().putInt("playModel", playModel).apply(); } private void initMediaPlayer() { @@ -235,7 +236,7 @@ public class MusicContainer { isPause = false; return; } - ConfigTools.getPreferences().edit().putInt("playIndex", playIndex).apply(); + ConfigTools.getConfigPreferences().edit().putInt("playIndex", playIndex).apply(); nowPlayData = data; String url = data.getPlayUrl(); previousPlayerList.add(data); @@ -401,9 +402,8 @@ public class MusicContainer { playOfAllRandom(); AppTools.toast("当前播放列表为空,随机播放"); } else {//播放列表中的歌单 - ConfigTools.getPreferences().edit().putInt("playModel", MusicContainer.PLAY_MODEL_ORDER).apply(); if (isRandom) { - playIndex = new Random().nextInt(playList.size()); + playIndex = randomPlayIndex(); } else { if (playList.size() > (playIndex + 1)) { 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; + } + /** * 单曲循环 */ @@ -434,7 +442,7 @@ public class MusicContainer { public List getPlayList() { System.out.println("playList.size() = " + playList.size() + " tmpList.size() = " + tmpList.size()); - List tmp=new ArrayList<>(); + List tmp = new ArrayList<>(); tmp.addAll(tmpList); tmp.addAll(playList); return tmp; @@ -478,6 +486,10 @@ public class MusicContainer { this.playList.addAll(dataList); } + public void addPlayList(MusicData data) { + this.playList.add(data); + } + public int getPlayModel() { return playModel; } @@ -486,6 +498,10 @@ public class MusicContainer { return playIndex; } + public void setPlayIndex(int i) { + this.playIndex = i; + } + public class MusicLibs { private MusicLibs() {