Compare commits
10 Commits
release/1.
...
b04bd7ca5a
| Author | SHA1 | Date | |
|---|---|---|---|
| b04bd7ca5a | |||
| ed47603a29 | |||
| 3ef606b89e | |||
| 6dfaf02422 | |||
| 72c9ce32c0 | |||
| 0dedeaf301 | |||
| 51f1b9494e | |||
| e2285ec1c5 | |||
| 6de3eeeb2f | |||
| 3cc08fc13d |
@@ -12,12 +12,12 @@ android {
|
|||||||
keyPassword '34864394'
|
keyPassword '34864394'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileSdkVersion 30
|
compileSdkVersion 32
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.yutou.nas_music_player"
|
applicationId "com.yutou.nas_music_player"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 32
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.1"
|
versionName "1.1"
|
||||||
|
|
||||||
@@ -44,14 +44,14 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.android.material:material:1.4.0'
|
implementation 'com.google.android.material:material:1.6.0'
|
||||||
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
|
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.aar"])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||||
implementation 'androidx.work:work-runtime:2.5.0'
|
implementation 'androidx.work:work-runtime:2.7.1'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.2.0'
|
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
|
|||||||
BIN
app/libs/POPDialog-release.aar
Normal file
BIN
app/libs/POPDialog-release.aar
Normal file
Binary file not shown.
@@ -14,9 +14,10 @@
|
|||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true">
|
||||||
<activity
|
<activity
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="fullSensor"
|
||||||
android:name=".views.OpenActivity"
|
android:name=".views.OpenActivity"
|
||||||
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
|
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
@@ -46,7 +47,8 @@
|
|||||||
<action android:name="android.media.browse.MediaBrowserService" />
|
<action android:name="android.media.browse.MediaBrowserService" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
<receiver android:name="androidx.media.session.MediaButtonReceiver">
|
<receiver android:name="androidx.media.session.MediaButtonReceiver"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MEDIA_BUTTON" />
|
<action android:name="android.intent.action.MEDIA_BUTTON" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -45,14 +46,15 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
public static final int LIBS_MODEL_PLAY_LIST = 4;
|
public static final int LIBS_MODEL_PLAY_LIST = 4;
|
||||||
public static final int LIBS_MODEL_PLAY_Collection = 5;
|
public static final int LIBS_MODEL_PLAY_Collection = 5;
|
||||||
|
|
||||||
public interface OnClickAction{
|
public interface OnClickAction {
|
||||||
void onClick(Intent intent,View view);
|
void onClick(Intent intent, View view);
|
||||||
}
|
|
||||||
protected OnClickAction clickAction;
|
|
||||||
public void setOnClickAction(OnClickAction onClickAction) {
|
|
||||||
this.clickAction=onClickAction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected OnClickAction clickAction;
|
||||||
|
|
||||||
|
public void setOnClickAction(OnClickAction onClickAction) {
|
||||||
|
this.clickAction = onClickAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
List<MusicData> list = new ArrayList<>();
|
List<MusicData> list = new ArrayList<>();
|
||||||
@@ -141,7 +143,7 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setModel(int model) {
|
public void setModel(int model) {
|
||||||
this.model=model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolderCollection extends ViewHolder {
|
public class ViewHolderCollection extends ViewHolder {
|
||||||
@@ -175,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;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,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) {
|
||||||
@@ -298,22 +321,23 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
||||||
intent.putExtra("model", 2);
|
intent.putExtra("model", 2);
|
||||||
intent.putExtra("fid", data.getId());
|
intent.putExtra("fid", data.getId());
|
||||||
intent.putExtra("image",data.getImg(AppData.imageWidth, AppData.imageHigh));
|
intent.putExtra("image", data.getImg(AppData.imageWidth, AppData.imageHigh));
|
||||||
if(clickAction!=null){
|
if (clickAction != null) {
|
||||||
clickAction.onClick(intent,icon);
|
clickAction.onClick(intent, icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
intent.putExtra("model", 0);
|
intent.putExtra("model", 0);
|
||||||
intent.putExtra("album", data.getAlbum());
|
intent.putExtra("album", data.getAlbum());
|
||||||
intent.putExtra("image",data.getImg(AppData.imageWidth, AppData.imageHigh));
|
intent.putExtra("image", data.getImg(AppData.imageWidth, AppData.imageHigh));
|
||||||
intent.putExtra("color",AppTools.getImageColor(data.getImg(AppData.minImageWidth,AppData.minImageHigh)));
|
intent.putExtra("color", AppTools.getImageColor(data.getImg(AppData.minImageWidth, AppData.minImageHigh)));
|
||||||
if(clickAction!=null){
|
if (clickAction != null) {
|
||||||
clickAction.onClick(intent,icon);
|
clickAction.onClick(intent, icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,8 +390,8 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
icon.setOnClickListener(new View.OnClickListener() {
|
icon.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (data.getImg(AppData.minImageWidth,AppData.minImageHigh) != null) {
|
if (data.getImg(AppData.minImageWidth, AppData.minImageHigh) != null) {
|
||||||
Glide.with(MyApplication.application).load(data.getImg(AppData.minImageWidth,AppData.minImageHigh))
|
Glide.with(MyApplication.application).load(data.getImg(AppData.minImageWidth, AppData.minImageHigh))
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||||
.into(icon);
|
.into(icon);
|
||||||
icon.setTag("img");
|
icon.setTag("img");
|
||||||
@@ -411,11 +435,10 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
.setTitle("添加文件夹到队列")
|
.setTitle("添加文件夹到队列")
|
||||||
.setMessage("将文件夹中所有歌曲添加到队列?")
|
.setMessage("将文件夹中所有歌曲添加到队列?")
|
||||||
.setPositiveButton("添加", new DialogInterface.OnClickListener() {
|
.setPositiveButton("添加", new DialogInterface.OnClickListener() {
|
||||||
KProgressHUD hud;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
hud = AppTools.showLoading(itemView.getContext());
|
AppTools.showHud(itemView.getContext());
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("path", data.getFile());
|
json.put("path", data.getFile());
|
||||||
json.put("type", true);
|
json.put("type", true);
|
||||||
@@ -425,14 +448,15 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
List<MusicData> list = (List<MusicData>) data;
|
List<MusicData> list = (List<MusicData>) data;
|
||||||
for (MusicData musicData : list) {
|
for (MusicData musicData : list) {
|
||||||
MusicContainer.getInstance().addTmpList(musicData);
|
MusicContainer.getInstance().addTmpList(musicData);
|
||||||
hud.dismiss();
|
|
||||||
}
|
}
|
||||||
|
AppTools.hideHud();
|
||||||
|
AppTools.toast(list.size() + "首歌已添加到队列中");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void httpError(Exception e) {
|
public void httpError(Exception e) {
|
||||||
|
AppTools.toast("添加失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -448,7 +472,7 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
|
|
||||||
|
|
||||||
protected void showImage(MusicData musicData, ViewHolder holder) {
|
protected void showImage(MusicData musicData, ViewHolder holder) {
|
||||||
musicData.getImg(AppData.minImageWidth,AppData.minImageHigh, new NetworkInterface() {
|
musicData.getImg(AppData.minImageWidth, AppData.minImageHigh, new NetworkInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void httpGetData(Object data, int state) {
|
public void httpGetData(Object data, int state) {
|
||||||
Glide.with(MyApplication.application).load((Bitmap) data)
|
Glide.with(MyApplication.application).load((Bitmap) data)
|
||||||
@@ -462,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class PreviousPlayerList {
|
public class PreviousPlayerList {
|
||||||
private static final int INDEX=10;//记录十条
|
private static final int INDEX=10;//记录十条
|
||||||
private List<MusicData> list;
|
private final List<MusicData> list;
|
||||||
public PreviousPlayerList(){
|
public PreviousPlayerList(){
|
||||||
list=new ArrayList<>();
|
list=new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,16 @@ import java.io.IOException;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
public class MusicContainer {
|
public class MusicContainer {
|
||||||
@@ -68,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() {
|
||||||
@@ -231,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);
|
||||||
@@ -358,6 +363,9 @@ public class MusicContainer {
|
|||||||
tmpList.remove(0);
|
tmpList.remove(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (playIndex < 0 || playIndex > playList.size()) {
|
||||||
|
playIndex = 0;
|
||||||
|
}
|
||||||
switch (playModel) {
|
switch (playModel) {
|
||||||
case PLAY_MODEL_ORDER:
|
case PLAY_MODEL_ORDER:
|
||||||
playOrder(false);
|
playOrder(false);
|
||||||
@@ -379,6 +387,9 @@ public class MusicContainer {
|
|||||||
*/
|
*/
|
||||||
public void playPrevious() {
|
public void playPrevious() {
|
||||||
playIndex--;
|
playIndex--;
|
||||||
|
if(playIndex<0){
|
||||||
|
playIndex=0;
|
||||||
|
}
|
||||||
MusicData data = previousPlayerList.getMusicData();
|
MusicData data = previousPlayerList.getMusicData();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
play(data);
|
play(data);
|
||||||
@@ -397,9 +408,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++;
|
||||||
@@ -412,6 +422,14 @@ public class MusicContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int randomPlayIndex() {
|
||||||
|
int tmp = new Random().nextInt(playList.size());
|
||||||
|
if (tmp == playIndex) {
|
||||||
|
return randomPlayIndex();
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单曲循环
|
* 单曲循环
|
||||||
*/
|
*/
|
||||||
@@ -430,10 +448,10 @@ public class MusicContainer {
|
|||||||
|
|
||||||
public List<MusicData> getPlayList() {
|
public List<MusicData> getPlayList() {
|
||||||
System.out.println("playList.size() = " + playList.size() + " tmpList.size() = " + tmpList.size());
|
System.out.println("playList.size() = " + playList.size() + " tmpList.size() = " + tmpList.size());
|
||||||
if (!tmpList.isEmpty()) {
|
List<MusicData> tmp = new ArrayList<>();
|
||||||
return tmpList;
|
tmp.addAll(tmpList);
|
||||||
}
|
tmp.addAll(playList);
|
||||||
return playList;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -474,6 +492,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;
|
||||||
}
|
}
|
||||||
@@ -482,6 +504,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() {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class AppTools {
|
|||||||
AppData.handler.post(new Runnable() {
|
AppData.handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(MyApplication.application, s, Toast.LENGTH_LONG).show();
|
Toast.makeText(MyApplication.application, s, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,9 @@ public class ConfigTools {
|
|||||||
public static SharedPreferences getPreferences(){
|
public static SharedPreferences getPreferences(){
|
||||||
return MyApplication.application.getSharedPreferences("app_config", Context.MODE_PRIVATE);
|
return MyApplication.application.getSharedPreferences("app_config", Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
public static SharedPreferences getConfigPreferences(){
|
||||||
|
return MyApplication.application.getSharedPreferences("config", Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class AlbumsActivity extends AppCompatActivity {
|
|||||||
breakApp.setOnClickListener(v -> finish());
|
breakApp.setOnClickListener(v -> finish());
|
||||||
playAll.setOnClickListener(v -> {
|
playAll.setOnClickListener(v -> {
|
||||||
MusicContainer.getInstance().setPlayList(new ArrayList<>(adapter.getMusicDatas()));
|
MusicContainer.getInstance().setPlayList(new ArrayList<>(adapter.getMusicDatas()));
|
||||||
MusicContainer.getInstance().playNext();
|
browserHelper.play(adapter.getMusicDatas().get(0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import android.support.v4.media.MediaMetadataCompat;
|
|||||||
import android.support.v4.media.session.MediaControllerCompat;
|
import android.support.v4.media.session.MediaControllerCompat;
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
import android.support.v4.media.session.MediaSessionCompat;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
|
import android.view.GestureDetector;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -22,10 +24,14 @@ import android.widget.Toast;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityOptionsCompat;
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
import androidx.core.util.Pair;
|
import androidx.core.util.Pair;
|
||||||
|
import androidx.core.view.GestureDetectorCompat;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
|
import com.yutou.nas_music_player.Adapters.MusicLibsAdapter;
|
||||||
import com.yutou.nas_music_player.Datas.MusicData;
|
import com.yutou.nas_music_player.Datas.MusicData;
|
||||||
import com.yutou.nas_music_player.R;
|
import com.yutou.nas_music_player.R;
|
||||||
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
|
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
|
||||||
@@ -33,6 +39,7 @@ import com.yutou.nas_music_player.containers.MusicContainer;
|
|||||||
import com.yutou.nas_music_player.tools.AppData;
|
import com.yutou.nas_music_player.tools.AppData;
|
||||||
import com.yutou.nas_music_player.tools.AppTools;
|
import com.yutou.nas_music_player.tools.AppTools;
|
||||||
import com.yutou.nas_music_player.tools.ConfigTools;
|
import com.yutou.nas_music_player.tools.ConfigTools;
|
||||||
|
import com.yutou.popdialog.POPDialog;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -51,6 +58,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private TextView positionTime, durationTime, bitRate, playIndex;
|
private TextView positionTime, durationTime, bitRate, playIndex;
|
||||||
private SeekBar seekBar;
|
private SeekBar seekBar;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
|
|
||||||
|
private GestureDetectorCompat touch;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||||
@@ -130,51 +140,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int model = (int) playModel.getTag();
|
int model = (int) playModel.getTag();
|
||||||
if (model == MusicContainer.PLAY_MODEL_LIST_RANDOM) {
|
if (model == MusicContainer.PLAY_MODEL_LIST_RANDOM) {
|
||||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM,true);
|
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setPlayModelButton(model + 1,true);
|
setPlayModelButton(model + 1, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getWindow().getDecorView().setOnTouchListener(new View.OnTouchListener() {
|
|
||||||
float downPosition_x = 0, downPosition_y = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
||||||
downPosition_x = event.getRawX();
|
|
||||||
downPosition_y = event.getRawY();
|
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
||||||
if (Math.abs(downPosition_x - event.getRawX()) < 500 && downPosition_y - event.getRawY() > 500) {
|
|
||||||
Pair<View, String> pImage = Pair.create((View) album_image, "main_album_image");
|
|
||||||
Pair<View, String> pPrevious = Pair.create((View) previous, "previous");
|
|
||||||
Pair<View, String> pPlay = Pair.create((View) play, "play");
|
|
||||||
Pair<View, String> pNext = Pair.create((View) next, "next");
|
|
||||||
Pair<View, String> pTitle = Pair.create((View) title, "title");
|
|
||||||
Pair<View, String> pArtist = Pair.create((View) artist, "artist");
|
|
||||||
Pair<View, String> pBar = Pair.create((View) seekBar, "bar");
|
|
||||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this,
|
|
||||||
pImage,
|
|
||||||
pPrevious,
|
|
||||||
pPlay,
|
|
||||||
pNext,
|
|
||||||
pBar,
|
|
||||||
pTitle,
|
|
||||||
pArtist).toBundle();
|
|
||||||
|
|
||||||
Intent intent = new Intent(
|
|
||||||
MainActivity.this, PlayLibsActivity.class);
|
|
||||||
intent.putExtra("bar_pos", seekBar.getProgress());
|
|
||||||
if (bundle != null) {
|
|
||||||
startActivity(intent, bundle);
|
|
||||||
} else {
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
browserHelper = new MediaBrowserHelper(this);
|
browserHelper = new MediaBrowserHelper(this);
|
||||||
browserHelper.regPlayListener(new PlayListener());
|
browserHelper.regPlayListener(new PlayListener());
|
||||||
|
|
||||||
@@ -270,7 +242,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
AppTools.toast("列表随机");
|
AppTools.toast("列表随机");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM,isButton);
|
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, isButton);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConfigTools.getPreferences().edit().putInt("playModel", model).apply();
|
ConfigTools.getPreferences().edit().putInt("playModel", model).apply();
|
||||||
@@ -301,6 +273,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
seekBar = findViewById(R.id.seekBar);
|
seekBar = findViewById(R.id.seekBar);
|
||||||
playModel = findViewById(R.id.playModel);
|
playModel = findViewById(R.id.playModel);
|
||||||
playIndex = findViewById(R.id.playIndex);
|
playIndex = findViewById(R.id.playIndex);
|
||||||
|
touch = new GestureDetectorCompat(this, new MyTouch());
|
||||||
int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||||
setPlayModelButton(model);
|
setPlayModelButton(model);
|
||||||
}
|
}
|
||||||
@@ -341,29 +314,62 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return super.onKeyUp(keyCode, event);
|
return super.onKeyUp(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
float downX = 0;
|
|
||||||
float downY = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
return touch.onTouchEvent(event);
|
||||||
downX = event.getRawX();
|
|
||||||
downY = event.getRawY();
|
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
||||||
pass(event.getRawX(), event.getRawY());
|
|
||||||
}
|
|
||||||
return super.onTouchEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pass(float upX, float upY) {
|
private void toPlayList() {
|
||||||
boolean isOkY = Math.abs(upY - downY) <= 200;
|
Pair<View, String> pImage = Pair.create((View) album_image, "main_album_image");
|
||||||
if (upX - downX > 200 && isOkY) {
|
Pair<View, String> pPrevious = Pair.create((View) previous, "previous");
|
||||||
previous.callOnClick();
|
Pair<View, String> pPlay = Pair.create((View) play, "play");
|
||||||
} else if (upX - downX < -200 && isOkY) {
|
Pair<View, String> pNext = Pair.create((View) next, "next");
|
||||||
next.callOnClick();
|
Pair<View, String> pTitle = Pair.create((View) title, "title");
|
||||||
|
Pair<View, String> pArtist = Pair.create((View) artist, "artist");
|
||||||
|
Pair<View, String> pBar = Pair.create((View) seekBar, "bar");
|
||||||
|
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this,
|
||||||
|
pImage,
|
||||||
|
pPrevious,
|
||||||
|
pPlay,
|
||||||
|
pNext,
|
||||||
|
pBar,
|
||||||
|
pTitle,
|
||||||
|
pArtist).toBundle();
|
||||||
|
|
||||||
|
Intent intent = new Intent(
|
||||||
|
MainActivity.this, PlayLibsActivity.class);
|
||||||
|
intent.putExtra("bar_pos", seekBar.getProgress());
|
||||||
|
if (bundle != null) {
|
||||||
|
startActivity(intent, bundle);
|
||||||
|
} else {
|
||||||
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showPOPDialog() {
|
||||||
|
List<MusicData> playList = MusicContainer.getInstance().getPlayList();
|
||||||
|
POPDialog dialog = new POPDialog(this);
|
||||||
|
RecyclerView recyclerView = null;
|
||||||
|
dialog.enableExitButton(true);
|
||||||
|
if (playList.isEmpty()) {
|
||||||
|
dialog.setTitle("播放列表");
|
||||||
|
dialog.setMessage("播放列表为空,正在全列表随机播放");
|
||||||
|
} else {
|
||||||
|
dialog.setTitle("播放列表:" + playList.size());
|
||||||
|
MusicLibsAdapter adapter = new MusicLibsAdapter(this);
|
||||||
|
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
recyclerView = new RecyclerView(this);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
recyclerView.setLayoutParams(params);
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
adapter.setData(playList);
|
||||||
|
adapter.setBrowserHelper(browserHelper);
|
||||||
|
dialog.setContentView(recyclerView);
|
||||||
|
}
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
private class PlayListener extends MediaControllerCompat.Callback {
|
private class PlayListener extends MediaControllerCompat.Callback {
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
@Override
|
@Override
|
||||||
@@ -403,13 +409,30 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onSessionDestroyed() {
|
public void onSessionDestroyed() {
|
||||||
super.onSessionDestroyed();
|
super.onSessionDestroyed();
|
||||||
System.out.println("连接被销毁");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onQueueChanged(List<MediaSessionCompat.QueueItem> queue) {
|
public void onQueueChanged(List<MediaSessionCompat.QueueItem> queue) {
|
||||||
super.onQueueChanged(queue);
|
super.onQueueChanged(queue);
|
||||||
System.out.println("不知道是啥变换了");
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MyTouch extends GestureDetector.SimpleOnGestureListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||||
|
float x = e1.getX() - e2.getX();
|
||||||
|
float y = e1.getY() - e2.getY();
|
||||||
|
if (Math.abs(x) < 200 && y > 300) {
|
||||||
|
showPOPDialog();
|
||||||
|
} else if (Math.abs(x) < 200 && y < -500) {
|
||||||
|
toPlayList();
|
||||||
|
} else if (Math.abs(y) < 200 && x > 300) {
|
||||||
|
next.callOnClick();
|
||||||
|
} else if (Math.abs(y) < 200 && x < -300) {
|
||||||
|
previous.callOnClick();
|
||||||
|
}
|
||||||
|
return super.onFling(e1, e2, velocityX, velocityY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ package com.yutou.nas_music_player.views;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
classpath 'com.android.tools.build:gradle:7.2.0'
|
||||||
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|||||||
Reference in New Issue
Block a user