diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index fb7f4a8..b589d56 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 9489cda..0c0c338 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -1,17 +1,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 14471bb..1df4b7f 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 526b4c2..9075e3e 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,16 +4,14 @@
-
-
+
-
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..7e340a7
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 0bef301..e5dde4b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,3 @@
-
@@ -97,6 +96,11 @@
+
+
+
+
+
@@ -105,7 +109,7 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index f5d9294..142c617 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -12,14 +12,16 @@ android {
applicationId "cn.wearbbs.music"
minSdkVersion 21
targetSdkVersion 31
- versionCode 11
- versionName "3.4"
+ versionCode 12
+ versionName "3.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
packagingOptions {
- exclude 'META-INF/DEPENDENCIES'
+ resources {
+ excludes += ['META-INF/DEPENDENCIES']
+ }
}
buildTypes {
release {
@@ -34,6 +36,7 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
+ namespace 'cn.wearbbs.music'
}
diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
index 12bcce7..aaed2ab 100644
--- a/app/release/output-metadata.json
+++ b/app/release/output-metadata.json
@@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
- "versionCode": 11,
- "versionName": "3.4",
+ "versionCode": 12,
+ "versionName": "3.5",
"outputFile": "app-release.apk"
}
],
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9bc540b..5d81a8b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,7 +1,6 @@
+ xmlns:tools="http://schemas.android.com/tools">
getFM() {
- PersonalFMResult result = gson.fromJson(NetWorkUtil.sendByGetUrl("/personal_fm", cookie), PersonalFMResult.class);
- if(result.getCode()==200){
- return result.getData();
- }
- return null;
- }
-
- /**
- * 搜索音乐
- *
- * @param keyword 关键词
- * @return 搜索结果
- */
- public List searchMusic(String keyword) {
- SearchResult result = gson.fromJson(NetWorkUtil.sendByGetUrl("/search?keywords=" + keyword, cookie), SearchResult.class);
- if(result.getCode()==200){
- return result.getResult().getSongs();
- }
- return null;
- }
-
- /**
- * 获取热搜
- *
- * @return 热搜关键词列表
- */
- public List getSearchHot() {
- SearchHotResult result = gson.fromJson(NetWorkUtil.sendByGetUrl("/search/hot", cookie),SearchHotResult.class);
- if(result.getCode()==200){
- return result.getResult().getHots();
- }
- return null;
- }
-
- /**
- * 获取音乐信息
- *
- * @param id 音乐id
- * @return 音乐信息
- */
- public List getMusicDetail(String id) {
- SongDetailResult result = gson.fromJson(NetWorkUtil.sendByGetUrl("/song/detail?ids=" + id, cookie),SongDetailResult.class);
- if(result.getCode()==200){
- return result.getSongs();
- }
- return null;
- }
-
- /**
- * 获取音乐信息(批量)
- *
- * @param ids 音乐id列表
- * @return 音乐信息
- */
- public List getMusicDetail(String[] ids) {
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < ids.length; i++) {
- stringBuilder.append(ids[i]);
- if ((i + 1) != ids.length) {
- stringBuilder.append(",");
- }
- }
- return gson.fromJson(NetWorkUtil.sendByGetUrl("/song/detail?ids=" + stringBuilder, cookie),SongDetailResult.class).getSongs();
- }
-
- /**
- * 获取专辑封面
- *
- * @param albumId 专辑id
- * @return 封面链接
- */
- public String getSongCover(int albumId) {
- AlbumResult result = gson.fromJson(NetWorkUtil.sendByGetUrl("/album?id=" + albumId, cookie),AlbumResult.class);
- return result.getSongs().get(0).getAlbum().getPicUrl();
- }
-
-
- /**
- * 获取音乐链接
- *
- * @param id 音乐id
- * @return 音乐链接
- */
- public String getMusicUrl(String id) {
- SongUrlResult result = gson.fromJson(NetWorkUtil.sendByGetUrl("/song/url?id=" + id, cookie),SongUrlResult.class);
- return result.getData().get(0).getUrl();
-
- }
-
- /**
- * 获取音乐链接(批量)
- *
- * @param ids 音乐id
- * @return 音乐链接
- */
- public String[] getMusicUrl(String[] ids) {
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < ids.length; i++) {
- stringBuilder.append(ids[i]);
- if ((i + 1) != ids.length) {
- stringBuilder.append(",");
- }
- }
- List data = gson.fromJson(NetWorkUtil.sendByGetUrl("/song/url?id=" + stringBuilder, cookie),SongUrlResult.class).getData();
- String[] result = new String[data.size()];
- for (int i = 0; i < data.size(); i++) {
- result[searchArrayForIndex(ids, String.valueOf(data.get(i).getId()))] = data.get(i).getUrl();
- }
- return result;
- }
-
- private int searchArrayForIndex(String[] array, String str) {
- for (int i = 0; i < array.length; i++) {
- if (array[i].equals(str)) {
- return i;
- }
- }
- return -1;
- }
-
- /**
- * 获取歌词
- *
- * @param id 音乐id
- * @return 歌词
- */
- public String getMusicLyric(String id) {
- return JSON.parseObject(NetWorkUtil.sendByGetUrl("/lyric?id=" + id, cookie))
- .getJSONObject("lrc").getString("lyric");
- }
-
- /**
- * 喜欢音乐
- *
- * @param id 音乐id
- * @return 是否成功
- */
- public Boolean likeMusic(String id, Boolean like) {
- return JSON.parseObject(NetWorkUtil.sendByGetUrl(String.format("/like?id=%s×tamp=%s&like=%b", id, System.currentTimeMillis(),like), cookie)).getInteger("code") == 200;
- }
-
- /**
- * 获取热评
- *
- * @param id 音乐id
- * @return 热评列表
- */
- public JSONArray getHotComment(String id) {
- return JSON.parseObject(NetWorkUtil.sendByGetUrl("/comment/music?id=" + id, cookie)).getJSONArray("hotComments");
- }
-
- /**
- * 发送评论
- *
- * @param id 音乐id
- * @param content 内容
- * @return 是否成功
- */
- public Boolean sendComment(String id, String content) {
- return JSON.parseObject(NetWorkUtil.sendByGetUrl(String.format("/comment?t=1&type=0&id=%s&content=%s", id, content), cookie)).getInteger("code") == 200;
- }
-
- /**
- * 点赞评论
- *
- * @param id 资源id
- * @param cid 评论id
- * @param like 是否点赞
- * @return 是否成功
- */
- public Boolean likeComment(String id, String cid, Boolean like) {
- if (like) {
- return JSON.parseObject(NetWorkUtil.sendByGetUrl(String.format("/comment/like?id=%s&cid=%s&t=1&type=1", id, cid), cookie)).getInteger("code") == 200;
- } else {
- return JSON.parseObject(NetWorkUtil.sendByGetUrl(String.format("/comment/like?id=%s&cid=%s&t=1&type=0", id, cid), cookie)).getInteger("code") == 200;
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/cn/jackuxl/api/SongApi.kt b/app/src/main/java/cn/jackuxl/api/SongApi.kt
new file mode 100644
index 0000000..8fe2eec
--- /dev/null
+++ b/app/src/main/java/cn/jackuxl/api/SongApi.kt
@@ -0,0 +1,240 @@
+package cn.jackuxl.api
+
+
+import com.google.gson.Gson
+import cn.jackuxl.model.Song
+import cn.jackuxl.util.NetWorkUtil
+import cn.jackuxl.model.result.*
+import com.alibaba.fastjson.JSON
+import com.alibaba.fastjson.JSONArray
+import java.lang.StringBuilder
+
+class SongApi(private val cookie: String) {
+ private val gson = Gson()
+
+ /**
+ * 获取私人FM
+ *
+ * @return FM返回的音乐列表
+ */
+ val fM: List?
+ get() {
+ val (code, data) = gson.fromJson(
+ NetWorkUtil.sendByGetUrl("/personal_fm", cookie),
+ PersonalFMResult::class.java
+ )
+ return if (code == 200) data else null
+ }
+
+ /**
+ * 搜索音乐
+ *
+ * @param keyword 关键词
+ * @return 搜索结果
+ */
+ fun searchMusic(keyword: String): List? {
+ val result = gson.fromJson(
+ NetWorkUtil.sendByGetUrl(
+ "/search?keywords=$keyword", cookie
+ ), SearchResult::class.java
+ )
+ return if (result.code == 200) result.result.songs else null
+ }
+
+ /**
+ * 获取热搜
+ *
+ * @return 热搜关键词列表
+ */
+ val searchHot: List?
+ get() {
+ val result = gson.fromJson(
+ NetWorkUtil.sendByGetUrl("/search/hot", cookie),
+ SearchHotResult::class.java
+ )
+ return if (result.code == 200) result.result.hots else null
+ }
+
+ /**
+ * 获取音乐信息
+ *
+ * @param id 音乐id
+ * @return 音乐信息
+ */
+ fun getMusicDetail(id: String): List? {
+ val (code, _, songs) = gson.fromJson(
+ NetWorkUtil.sendByGetUrl(
+ "/song/detail?ids=$id",
+ cookie
+ ), SongDetailResult::class.java
+ )
+ return if (code == 200) songs else null
+ }
+
+ /**
+ * 获取音乐信息(批量)
+ *
+ * @param ids 音乐id列表
+ * @return 音乐信息
+ */
+ fun getMusicDetail(ids: Array): List {
+ val stringBuilder = StringBuilder()
+ for (i in ids.indices) {
+ stringBuilder.append(ids[i])
+ if (i + 1 != ids.size) {
+ stringBuilder.append(",")
+ }
+ }
+ return gson.fromJson(
+ NetWorkUtil.sendByGetUrl("/song/detail?ids=$stringBuilder", cookie),
+ SongDetailResult::class.java
+ ).songs
+ }
+
+ /**
+ * 获取专辑封面
+ *
+ * @param albumId 专辑id
+ * @return 封面链接
+ */
+ fun getSongCover(albumId: Int): String? {
+ val songs = gson.fromJson(
+ NetWorkUtil.sendByGetUrl("/album?id=$albumId", cookie),
+ AlbumResult::class.java
+ ).songs
+ return songs[0]?.album?.picUrl
+ }
+
+ /**
+ * 获取音乐链接
+ *
+ * @param id 音乐id
+ * @return 音乐链接
+ */
+ fun getMusicUrl(id: String): String {
+ val data = gson.fromJson(
+ NetWorkUtil.sendByGetUrl("/song/url?id=$id", cookie),
+ SongUrlResult::class.java
+ ).data
+ return data[0].url
+ }
+
+ /**
+ * 获取音乐链接(批量)
+ *
+ * @param ids 音乐id
+ * @return 音乐链接
+ */
+ fun getMusicUrl(ids: Array): Array {
+ val stringBuilder = StringBuilder()
+ for (i in ids.indices) {
+ stringBuilder.append(ids[i])
+ if (i + 1 != ids.size) {
+ stringBuilder.append(",")
+ }
+ }
+ val data = gson.fromJson(
+ NetWorkUtil.sendByGetUrl("/song/url?id=$stringBuilder", cookie),
+ SongUrlResult::class.java
+ ).data
+ val result = arrayOfNulls(data.size)
+ for (i in data.indices) {
+ result[searchArrayForIndex(ids, data[i].id.toString())] = data[i].url
+ }
+ return result
+ }
+
+ private fun searchArrayForIndex(array: Array, str: String): Int {
+ for (i in array.indices) {
+ if (array[i] == str) {
+ return i
+ }
+ }
+ return -1
+ }
+
+ /**
+ * 获取歌词
+ *
+ * @param id 音乐id
+ * @return 歌词
+ */
+ fun getMusicLyric(id: String): String {
+ return JSON.parseObject(NetWorkUtil.sendByGetUrl("/lyric?id=$id", cookie))
+ .getJSONObject("lrc").getString("lyric")
+ }
+
+ /**
+ * 喜欢音乐
+ *
+ * @param id 音乐id
+ * @return 是否成功
+ */
+ fun likeMusic(id: String?, like: Boolean?): Boolean {
+ return JSON.parseObject(
+ NetWorkUtil.sendByGetUrl(
+ String.format(
+ "/like?id=%s×tamp=%s&like=%b",
+ id,
+ System.currentTimeMillis(),
+ like
+ ), cookie
+ )
+ ).getInteger("code") == 200
+ }
+
+ /**
+ * 获取热评
+ *
+ * @param id 音乐id
+ * @return 热评列表
+ */
+ fun getHotComment(id: String): JSONArray {
+ return JSON.parseObject(NetWorkUtil.sendByGetUrl("/comment/music?id=$id", cookie))
+ .getJSONArray("hotComments")
+ }
+
+ /**
+ * 发送评论
+ *
+ * @param id 音乐id
+ * @param content 内容
+ * @return 是否成功
+ */
+ fun sendComment(id: String?, content: String?): Boolean {
+ return JSON.parseObject(
+ NetWorkUtil.sendByGetUrl(
+ String.format(
+ "/comment?t=1&type=0&id=%s&content=%s",
+ id,
+ content
+ ), cookie
+ )
+ ).getInteger("code") == 200
+ }
+
+ /**
+ * 点赞评论
+ *
+ * @param id 资源id
+ * @param cid 评论id
+ * @param like 是否点赞
+ * @return 是否成功
+ */
+ fun likeComment(id: String?, cid: String?, like: Boolean): Boolean {
+
+ return if (like) {
+ JSON.parseObject(
+ NetWorkUtil.sendByGetUrl(
+ "/comment/like?id=${id}&cid=${cid}&t=1&type=1", cookie
+ )
+ ).getInteger("code") == 200
+ } else {
+ JSON.parseObject(
+ NetWorkUtil.sendByGetUrl(
+ "/comment/like?id=${id}&cid=${cid}&t=1&type=0", cookie
+ )
+ ).getInteger("code") == 200
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/cn/jackuxl/model/Album.kt b/app/src/main/java/cn/jackuxl/model/Album.kt
index c14828d..1f69a34 100644
--- a/app/src/main/java/cn/jackuxl/model/Album.kt
+++ b/app/src/main/java/cn/jackuxl/model/Album.kt
@@ -4,6 +4,7 @@ package cn.jackuxl.model
import cn.jackuxl.model.info.Info
import com.google.gson.annotations.SerializedName
+
data class Album(
@SerializedName("alias")
val alias: List,
@@ -59,4 +60,5 @@ data class Album(
val tags: String,
@SerializedName("type")
val type: String
-)
\ No newline at end of file
+)
+
diff --git a/app/src/main/java/cn/jackuxl/model/Song.kt b/app/src/main/java/cn/jackuxl/model/Song.kt
index bd87db0..e8f8a3c 100644
--- a/app/src/main/java/cn/jackuxl/model/Song.kt
+++ b/app/src/main/java/cn/jackuxl/model/Song.kt
@@ -21,7 +21,7 @@ data class Song(
@SerializedName("id")
val id: Int,
@SerializedName("mark")
- val mark: Int,
+ val mark: Long,
@SerializedName("mvid")
val mvid: Int,
@SerializedName("name")
diff --git a/app/src/main/java/cn/jackuxl/model/SongUrl.kt b/app/src/main/java/cn/jackuxl/model/SongUrl.kt
index b8f17a0..7e5ecd8 100644
--- a/app/src/main/java/cn/jackuxl/model/SongUrl.kt
+++ b/app/src/main/java/cn/jackuxl/model/SongUrl.kt
@@ -27,7 +27,7 @@ data class SongUrl(
@SerializedName("freeTrialPrivilege")
val freeTrialPrivilege: FreeTrialPrivilege,
@SerializedName("gain")
- val gain: Int,
+ val gain: Float,
@SerializedName("id")
val id: Int,
@SerializedName("level")
diff --git a/app/src/main/java/cn/jackuxl/model/privilege/Privilege.kt b/app/src/main/java/cn/jackuxl/model/privilege/Privilege.kt
index 226dd32..df9c743 100644
--- a/app/src/main/java/cn/jackuxl/model/privilege/Privilege.kt
+++ b/app/src/main/java/cn/jackuxl/model/privilege/Privilege.kt
@@ -8,41 +8,41 @@ data class Privilege(
@SerializedName("chargeInfoList")
val chargeInfoList: List,
@SerializedName("cp")
- val cp: Int,
+ val cp: Long,
@SerializedName("cs")
val cs: Boolean,
@SerializedName("dl")
- val dl: Int,
+ val dl: Long,
@SerializedName("downloadMaxbr")
- val downloadMaxbr: Int,
+ val downloadMaxbr: Long,
@SerializedName("fee")
- val fee: Int,
+ val fee: Long,
@SerializedName("fl")
- val fl: Int,
+ val fl: Long,
@SerializedName("flag")
- val flag: Int,
+ val flag: Long,
@SerializedName("freeTrialPrivilege")
val freeTrialPrivilege: FreeTrialPrivilege,
@SerializedName("id")
- val id: Int,
+ val id: Long,
@SerializedName("maxbr")
- val maxbr: Int,
+ val maxbr: Long,
@SerializedName("payed")
- val payed: Int,
+ val payed: Long,
@SerializedName("pl")
- val pl: Int,
+ val pl: Long,
@SerializedName("playMaxbr")
- val playMaxbr: Int,
+ val playMaxbr: Long,
@SerializedName("preSell")
val preSell: Boolean,
@SerializedName("rscl")
- val rscl: Int,
+ val rscl: Long,
@SerializedName("sp")
- val sp: Int,
+ val sp: Long,
@SerializedName("st")
- val st: Int,
+ val st: Long,
@SerializedName("subp")
- val subp: Int,
+ val subp: Long,
@SerializedName("toast")
val toast: Boolean
)
\ No newline at end of file
diff --git a/app/src/main/java/cn/jackuxl/model/result/AlbumResult.kt b/app/src/main/java/cn/jackuxl/model/result/AlbumResult.kt
index 0084508..826d771 100644
--- a/app/src/main/java/cn/jackuxl/model/result/AlbumResult.kt
+++ b/app/src/main/java/cn/jackuxl/model/result/AlbumResult.kt
@@ -13,5 +13,5 @@ data class AlbumResult(
@SerializedName("resourceState")
val resourceState: Boolean,
@SerializedName("songs")
- val songs: List
+ val songs: List
)
\ No newline at end of file
diff --git a/app/src/main/java/cn/wearbbs/music/adapter/MusicAdapter.java b/app/src/main/java/cn/wearbbs/music/adapter/MusicAdapter.java
index 16170a1..826b73f 100644
--- a/app/src/main/java/cn/wearbbs/music/adapter/MusicAdapter.java
+++ b/app/src/main/java/cn/wearbbs/music/adapter/MusicAdapter.java
@@ -113,7 +113,7 @@ public void onBindViewHolder(final ViewHolder viewHolder, int position) {
int finalPosition = position;
viewHolder.ll_main.setOnClickListener(v -> {
Intent intent = new Intent(activity, MainActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
EventBus.getDefault().post(new MessageEvent(data.toJSONString()));
intent.putExtra("musicIndex", finalPosition);
diff --git a/app/src/main/java/cn/wearbbs/music/adapter/MusicLibraryAdapter.java b/app/src/main/java/cn/wearbbs/music/adapter/MusicLibraryAdapter.java
index d4b6c48..0c51897 100644
--- a/app/src/main/java/cn/wearbbs/music/adapter/MusicLibraryAdapter.java
+++ b/app/src/main/java/cn/wearbbs/music/adapter/MusicLibraryAdapter.java
@@ -49,7 +49,9 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int position)
try{
Glide.with(activity).load(playListDetail.getString("coverImgUrl").replace("http://", "https://")).apply(options).into(viewHolder.iv_cover);
}
- catch (Exception ignored){}
+ catch (Exception ignored){
+ ignored.printStackTrace();
+ }
viewHolder.ll_main.setOnClickListener(v -> {
Intent intent = new Intent(activity, MusicListActivity.class);
intent.putExtra("detail", playListDetail.toJSONString());
diff --git a/app/src/main/java/cn/wearbbs/music/adapter/SongAdapter.kt b/app/src/main/java/cn/wearbbs/music/adapter/SongAdapter.kt
index 1fa3400..bda5880 100644
--- a/app/src/main/java/cn/wearbbs/music/adapter/SongAdapter.kt
+++ b/app/src/main/java/cn/wearbbs/music/adapter/SongAdapter.kt
@@ -64,7 +64,7 @@ class SongAdapter : RecyclerView.Adapter {
position--
}
val (album, _, artists, _, _, _, _, _, _, _, name) = data[position]
- val imgUrl = arrayOf("")
+ val imgUrl: Array = arrayOf("")
// 兼容音乐云盘
// if (songDetail.containsKey("simpleSong")) {
// songDetail = songDetail.getJSONObject("simpleSong");
@@ -87,10 +87,11 @@ class SongAdapter : RecyclerView.Adapter {
.error(R.drawable.ic_baseline_photo_size_select_actual_24)
try {
viewHolder.ivCover?.let {
- Glide.with(activity).load(imgUrl[0].replace("http://", "https://"))
+ Glide.with(activity).load(imgUrl[0]?.replace("http://", "https://"))
.apply(options).into(it)
}
} catch (ignored: Exception) {
+ ignored.printStackTrace()
}
}
} catch (ignored: Exception) {
diff --git a/app/src/main/java/cn/wearbbs/music/api/AppServiceApi.java b/app/src/main/java/cn/wearbbs/music/api/AppServiceApi.java
index 22bec6a..3a02a8d 100644
--- a/app/src/main/java/cn/wearbbs/music/api/AppServiceApi.java
+++ b/app/src/main/java/cn/wearbbs/music/api/AppServiceApi.java
@@ -30,11 +30,6 @@ public static boolean feedback(String content) {
}
public static void resetServer(){
- if(SharedPreferencesUtil.getString("server","vercel").equals("wearbbs")){
- NetWorkUtil.setDomain("https://music.wearbbs.cn");
- }
- else{
- NetWorkUtil.setDomain("https://api.wmusic.pro");
- }
+ NetWorkUtil.setDomain("https://api.wmusic.pro");
}
}
diff --git a/app/src/main/java/cn/wearbbs/music/fragment/ConsoleFragment.java b/app/src/main/java/cn/wearbbs/music/fragment/ConsoleFragment.java
new file mode 100644
index 0000000..887e38b
--- /dev/null
+++ b/app/src/main/java/cn/wearbbs/music/fragment/ConsoleFragment.java
@@ -0,0 +1,479 @@
+package cn.wearbbs.music.fragment;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.ProgressDialog;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.media.AudioManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.bumptech.glide.Glide;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+
+
+import cn.jackuxl.api.MVApi;
+import cn.jackuxl.api.MusicListApi;
+import cn.jackuxl.api.SongApi;
+import cn.wearbbs.music.R;
+import cn.wearbbs.music.application.MainApplication;
+import cn.wearbbs.music.event.MessageEvent;
+import cn.wearbbs.music.ui.CommentActivity;
+import cn.wearbbs.music.ui.PlayListActivity;
+import cn.wearbbs.music.ui.QRCodeActivity;
+import cn.wearbbs.music.util.DownloadUtil;
+import cn.wearbbs.music.util.SharedPreferencesUtil;
+import cn.wearbbs.music.util.ToastUtil;
+
+public class ConsoleFragment extends Fragment {
+ private AudioManager audioManager;
+ private int max, orderId;
+ private JSONArray data;
+ private Boolean liked = false,local;
+ private String cookie,artistName;
+ private JSONObject currentMusicInfo;
+ private ProgressBar pb_main;
+ private SongApi musicApi;
+
+ public static ConsoleFragment newInstance(Intent intent) {
+ ConsoleFragment fragment = new ConsoleFragment();
+ Bundle args = new Bundle();
+ args.putInt("musicIndex",intent.getIntExtra("musicIndex",0));
+ args.putBoolean("local",intent.getBooleanExtra("local",false));
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_console, container, false);
+ data = PlayerFragment.getData();
+ if (getArguments() != null && data!=null && data.size()>0) {
+ // 初始化
+ audioManager = (AudioManager) MainApplication.getContext().getSystemService(Context.AUDIO_SERVICE);
+ max = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
+ EventBus.getDefault().register(this);
+
+ local = getArguments().getBoolean("local",false);
+ orderId = PlayerFragment.getPlayOrder();
+
+ ImageView iv_repeat = view.findViewById(R.id.iv_repeat);
+ iv_repeat.setOnClickListener(this::onClick);
+ switch (orderId){
+ case PlayerFragment.PLAY_ORDER:
+ iv_repeat.setImageResource(R.drawable.icon_play_order);
+ break;
+ case PlayerFragment.PLAY_REPEAT_ONE:
+ iv_repeat.setImageResource(R.drawable.icon_play_repeat_one);
+ break;
+ case PlayerFragment.PLAY_SHUFFLE:
+ //TODO:随机播放
+ break;
+ }
+ cookie = SharedPreferencesUtil.getString("cookie", "");
+ musicApi = new SongApi(cookie);
+ currentMusicInfo = data.getJSONObject(getArguments().getInt("musicIndex",0));
+ if(currentMusicInfo.containsKey("simpleSong")){
+ currentMusicInfo = currentMusicInfo.getJSONObject("simpleSong");
+ }
+ if(currentMusicInfo.containsKey("artists")){
+ if(local){
+ artistName = currentMusicInfo.getString("artists");
+ }
+ else{
+ artistName = currentMusicInfo.getJSONArray("artists").getJSONObject(0).getString("name");
+ }
+ }
+ else if(currentMusicInfo.containsKey("ar")){
+ artistName = currentMusicInfo.getJSONArray("ar").getJSONObject(0).getString("name");
+ }
+ else{
+ artistName = getString(R.string.unknown);
+ }
+
+ pb_main = requireActivity().findViewById(R.id.pb_main);
+
+ if(currentMusicInfo.containsKey("id")){
+ new Thread(()->{
+ try {
+ MusicListApi api = new MusicListApi(SharedPreferencesUtil.getJSONObject("profile").getString("userId"), cookie);
+ String[] ids = api.getMusicListDetail(api.getMusicList().getJSONObject(0).getString("id"));
+ for (String id : ids) {
+ if (id.equals(currentMusicInfo.getString("id"))) {
+ liked = true;
+ }
+ }
+ requireActivity().runOnUiThread(()->{
+ ImageView like_view = view.findViewById(R.id.iv_like);
+ if(liked){
+ like_view.setImageResource(R.drawable.ic_baseline_favorite_24);
+
+ }
+ else{
+ like_view.setImageResource(R.drawable.ic_baseline_favorite_border_24);
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }).start();
+ }
+
+
+ // 点击事件
+ view.findViewById(R.id.iv_voiceDown).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_voiceUp).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_download).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_comment).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_share).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_mv).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_playlist).setOnClickListener(this::onClick);
+ view.findViewById(R.id.iv_like).setOnClickListener(this::onClick);
+
+ }
+ return view;
+ }
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ @SuppressLint("NonConstantResourceId")
+ public void onClick(View view) {
+ switch (view.getId()) {
+ case R.id.iv_voiceUp:
+ pb_main.setMax(max);
+ int value = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+ if(value == max){
+ ToastUtil.show(requireActivity(),"媒体音量已到最高");
+ }
+ else{
+ audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, value + 1,0); //音乐音量
+ pb_main.setProgress(value + 1);
+ }
+ break;
+ case R.id.iv_voiceDown:
+ pb_main.setMax(max);
+ value = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+ if(value == 0){
+ ToastUtil.show(requireActivity(),"媒体音量已到最低");
+ }
+ else{
+ audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, value - 1,0); //音乐音量
+ pb_main.setProgress(value - 1);
+ }
+ break;
+ case R.id.iv_like:
+ new Thread(()->{
+ try{
+ if(liked){
+ if(musicApi.likeMusic(currentMusicInfo.getString("id"),false)){
+ liked = false;
+ }
+ else{
+ ToastUtil.show(requireActivity(),"取消收藏失败");
+ }
+ }
+ else{
+ if(musicApi.likeMusic(currentMusicInfo.getString("id"),true)){
+ liked = true;
+ }
+ else{
+ ToastUtil.show(requireActivity(),"收藏失败");
+ }
+ }
+ }
+ catch (Exception e){
+ ToastUtil.show(requireActivity(),"收藏失败");
+ }
+
+ requireActivity().runOnUiThread(() -> {
+ ImageView like_view = requireView().findViewById(R.id.iv_like);
+ if(liked){
+ like_view.setImageResource(R.drawable.ic_baseline_favorite_24);
+
+ }
+ else{
+ like_view.setImageResource(R.drawable.ic_baseline_favorite_border_24);
+ }
+ });
+ }).start();
+ break;
+ case R.id.iv_download:
+ if(local){
+ ToastUtil.show(requireActivity(),"已下载");
+ }
+ else{
+ checkPermissionForDownload();
+ }
+ break;
+ case R.id.iv_comment:
+ if(currentMusicInfo.getString("id")==null){
+ ToastUtil.show(requireActivity(),"本地音乐暂不支持评论");
+ }
+ else{
+ startActivity(new Intent(requireActivity(), CommentActivity.class).putExtra("id",currentMusicInfo.getString("id")));
+ }
+ break;
+ case R.id.iv_mv:
+ if(local){
+ ToastUtil.show(requireActivity(),"本地音乐暂不支持播放MV");
+ break;
+ }
+ String mvId;
+ mvId = currentMusicInfo.containsKey("mv")?currentMusicInfo.getString("mv"):currentMusicInfo.getString("mvid");
+ if(mvId==null||mvId.isEmpty()){
+ ToastUtil.show(requireActivity(),"当前音乐无对应MV");
+ }
+ else{
+ new Thread(()->{
+ String mvUrl = new MVApi(cookie).getMVUrl(mvId);
+ if (mvUrl == null) {
+ ToastUtil.show(requireActivity(),"当前音乐无对应MV");
+ }
+ else{
+ if(SharedPreferencesUtil.getString("video_player","WristVideo").equals("WristButlerPro")){
+ Intent intent = new Intent();
+ intent.putExtra("url", mvUrl);
+ intent.putExtra("title", currentMusicInfo.getString("name"));
+ try {
+ intent.setClassName("com.cn.awg.pro", "com.cn.awg.pro.g2");
+ startActivity(intent);
+ PlayerFragment.pauseMusic();
+ }
+ catch(Exception e) {
+ ToastUtil.show(requireActivity(),"视频播放器 腕管Pro 启动失败,请检查是否已安装该应用");
+ e.printStackTrace();
+ }
+ }
+ else{
+ Intent intent = new Intent();
+ intent.putExtra("mode", 1);
+ intent.putExtra("url", mvUrl);
+ intent.putExtra("url_backup", mvUrl);
+ intent.putExtra("title", currentMusicInfo.getString("name"));
+ intent.putExtra("identity_name", "WearMusic");
+ try {
+ intent.setComponent(new ComponentName("cn.luern0313.wristvideoplayer", "cn.luern0313.wristvideoplayer.ui.PlayerActivity"));
+ startActivity(intent);
+ PlayerFragment.pauseMusic();
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ try {
+ intent.setComponent(new ComponentName("cn.luern0313.wristvideoplayer_free", "cn.luern0313.wristvideoplayer_free.ui.PlayerActivity"));
+ startActivity(intent);
+ PlayerFragment.pauseMusic();
+ }
+ catch(Exception ee)
+ {
+ ToastUtil.show(requireActivity(),"视频播放器 腕上视频 启动失败,请检查是否已安装该应用");
+ }
+ }
+ }
+ }
+ }).start();
+ }
+ break;
+ case R.id.iv_share:
+ startActivity(new Intent(requireActivity(), QRCodeActivity.class).putExtra("url","https://music.163.com/#/song?id="+currentMusicInfo.getString("id")));
+ break;
+ case R.id.iv_repeat:
+ Intent intent = new Intent();
+ ImageView iv_repeat = requireView().findViewById(R.id.iv_repeat);
+ switch (orderId){
+ case PlayerFragment.PLAY_ORDER:
+ // 处于顺序播放模式
+ orderId = PlayerFragment.PLAY_REPEAT_ONE;
+ intent.putExtra("orderId",PlayerFragment.PLAY_REPEAT_ONE);
+ iv_repeat.setImageResource(R.drawable.icon_play_repeat_one);
+ break;
+ case PlayerFragment.PLAY_REPEAT_ONE:
+ // 处于单曲循环模式
+ orderId = PlayerFragment.PLAY_ORDER;
+ intent.putExtra("orderId",PlayerFragment.PLAY_ORDER);
+ iv_repeat.setImageResource(R.drawable.icon_play_order);
+ break;
+ case PlayerFragment.PLAY_SHUFFLE:
+ //TODO:随机播放
+ break;
+ }
+ PlayerFragment.setPlayOrder(orderId);
+ break;
+ case R.id.iv_playlist:
+ startActivity(new Intent(requireActivity(), PlayListActivity.class).putExtra("local",local));
+ EventBus.getDefault().postSticky(new MessageEvent(data.toJSONString()));
+ EventBus.getDefault().unregister(this);
+ break;
+ }
+
+ }
+ public void checkPermissionForDownload(){
+ // 读取权限
+ String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
+ // 检查权限是否已授权
+ int hasPermission = MainApplication.getContext().checkSelfPermission(permission);
+ // 如果没有授权
+ if (hasPermission != PackageManager.PERMISSION_GRANTED) {
+ // 请求权限
+ requestPermissions(new String[]{permission}, 0);
+ }else {
+ // 已授权权限
+ downloadCurrentMusic();
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ if (grantResults.length > 0) {//grantResults 数组中存放的是授权结果
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ // 同意授权
+ downloadCurrentMusic();
+ }else {
+ // 拒绝授权
+ ToastUtil.show(requireActivity(),getString(R.string.permission_denied));
+ }
+ }
+ }
+
+ private ProgressDialog progressDialog;
+
+ public void downloadCurrentMusic(){
+ String fileName = currentMusicInfo.getString("name") + "--" + (artistName == null ? getString(R.string.unknown) : artistName);
+ String rootPath = MainApplication.getContext().getExternalFilesDir(null) + "/download";
+ new Thread(()->{
+ // 保存封面
+ String albumId;
+ if(currentMusicInfo.containsKey("al")){
+ albumId = currentMusicInfo.getJSONObject("al").getString("id");
+ }
+ else{
+ albumId = currentMusicInfo.getJSONObject("album").getString("id");
+ }
+ savePicture(musicApi.getSongCover(Integer.parseInt(albumId)),rootPath+"/cover/",fileName+".png");
+
+ // 保存歌词
+ File lrcDir = new File(rootPath+"/lrc/");
+ if(!lrcDir.exists()){
+ lrcDir.mkdirs();
+ }
+ try{
+ BufferedWriter out = new BufferedWriter(new FileWriter(rootPath+"/lrc/"+fileName+".lrc"));
+ out.write(musicApi.getMusicLyric(currentMusicInfo.getString("id")));
+ out.close();
+ }
+ catch (Exception ignored){}
+
+ // 保存id
+ File idDir = new File(rootPath+"/id/");
+ if(!idDir.exists()){
+ idDir.mkdirs();
+ }
+ try{
+ BufferedWriter out = new BufferedWriter(new FileWriter(rootPath+"/id/"+fileName+".txt"));
+ out.write(currentMusicInfo.getString("id"));
+ out.close();
+ }
+ catch (Exception ignored){}
+
+ // 保存音乐
+ String url = new SongApi(cookie).getMusicUrl(currentMusicInfo.getString("id")).replace("http://","https://");
+
+
+
+ requireActivity().runOnUiThread(()->{
+ progressDialog = new ProgressDialog(requireActivity());
+ progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ // 设置ProgressDialog 标题
+ progressDialog.setTitle("提示");
+ // 设置ProgressDialog 提示信息
+ progressDialog.setMessage("当前下载进度:");
+ // 设置ProgressDialog 是否可以按退回按键取消
+ progressDialog.setCancelable(false);
+ progressDialog.show();
+ progressDialog.setMax(100);
+ });
+
+
+ new DownloadUtil().download(
+ url, rootPath+"/music",
+ fileName + ".wav",
+ new DownloadUtil.OnDownloadListener() {
+ @Override
+ public void onDownloadSuccess(File file) {
+ ToastUtil.show(requireActivity(),"下载成功");
+ requireActivity().runOnUiThread(()->{
+ progressDialog.dismiss();
+ });
+ }
+
+ @Override
+ public void onDownloading(int progress) {
+ Log.d("ConsoleActivity", "onDownloading: Progress "+progress+"%");
+ requireActivity().runOnUiThread(()->{
+ progressDialog.setProgress(progress);
+ });
+ }
+
+ @Override
+ public void onDownloadFailed(Exception e) {
+ ToastUtil.show(requireActivity(),"下载失败");
+ requireActivity().runOnUiThread(()->{
+ progressDialog.dismiss();
+ });
+ }
+ }
+ );
+
+ }).start();
+
+ }
+
+ public void savePicture(String photoUrl,String path,String fileName) {
+ new Thread(()->{
+ try {
+ Bitmap bitmap = Glide.with(requireActivity())
+ .asBitmap()
+ .load(photoUrl)
+ .submit(512, 512).get();
+ File dirFile = new File(path);
+ if (!dirFile.exists()) {
+ dirFile.mkdir();
+ }
+
+ File myCaptureFile = new File(path + fileName);
+ myCaptureFile.createNewFile();
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
+ bitmap.compress(Bitmap.CompressFormat.PNG, 80, bos);
+ bos.flush();
+ bos.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }).start();
+ }
+}
diff --git a/app/src/main/java/cn/wearbbs/music/fragment/ConsoleFragment.kt b/app/src/main/java/cn/wearbbs/music/fragment/ConsoleFragment.kt
deleted file mode 100644
index ee60880..0000000
--- a/app/src/main/java/cn/wearbbs/music/fragment/ConsoleFragment.kt
+++ /dev/null
@@ -1,474 +0,0 @@
-package cn.wearbbs.music.fragment
-
-import android.Manifest
-import android.media.AudioManager
-import android.widget.ProgressBar
-import cn.jackuxl.api.SongApi
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.ViewGroup
-import cn.wearbbs.music.R
-import cn.wearbbs.music.application.MainApplication
-import cn.wearbbs.music.util.SharedPreferencesUtil
-
-import cn.jackuxl.api.MusicListApi.*
-import android.annotation.SuppressLint
-import cn.wearbbs.music.util.ToastUtil
-import android.content.Intent
-import cn.wearbbs.music.ui.CommentActivity
-import cn.jackuxl.api.MVApi.*
-import android.content.ComponentName
-import cn.wearbbs.music.ui.QRCodeActivity
-import org.greenrobot.eventbus.EventBus
-import cn.wearbbs.music.event.MessageEvent
-import cn.wearbbs.music.ui.PlayListActivity
-import android.os.Build
-import android.content.pm.PackageManager
-import android.app.ProgressDialog
-import android.content.Context
-import cn.wearbbs.music.util.DownloadUtil
-import cn.wearbbs.music.util.DownloadUtil.OnDownloadListener
-import android.graphics.Bitmap
-import android.util.Log
-import android.view.View
-import android.widget.ImageView
-import androidx.fragment.app.Fragment
-import cn.jackuxl.api.MVApi
-import cn.jackuxl.api.MusicListApi
-import cn.wearbbs.music.databinding.FragmentConsoleBinding
-import com.bumptech.glide.Glide
-import com.alibaba.fastjson.JSONArray
-import com.alibaba.fastjson.JSONObject
-import java.io.*
-
-
-class ConsoleFragment : Fragment(), View.OnClickListener {
- private lateinit var binding: FragmentConsoleBinding
- private lateinit var audioManager: AudioManager
- private lateinit var pbMain: ProgressBar
- private lateinit var songApi: SongApi
-
- private var max = 0
- private var orderId = 0
- private var data: JSONArray? = null
- private var liked = false
- private var local: Boolean? = null
- private var cookie: String? = null
- private var artistName: String? = null
-
- private var currentMusicInfo: JSONObject? = null
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- binding = FragmentConsoleBinding.inflate(layoutInflater)
- }
-
- override fun onCreateView(
- inflater: LayoutInflater,
- container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- val view = inflater.inflate(R.layout.fragment_console, container, false)
- data = PlayerFragment.getData()
- if (arguments != null && data != null && data!!.size > 0) {
- // 初始化
- audioManager = MainApplication.getContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
- max = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
- local = arguments?.getBoolean("local", false)
- orderId = PlayerFragment.getPlayOrder()
- binding.ivRepeat.setOnClickListener(this)
- when (orderId) {
- PlayerFragment.PLAY_ORDER -> binding.ivRepeat.setImageResource(R.drawable.icon_play_order)
- PlayerFragment.PLAY_REPEAT_ONE -> binding.ivRepeat.setImageResource(R.drawable.icon_play_repeat_one)
- PlayerFragment.PLAY_SHUFFLE -> {}
- }
- cookie = SharedPreferencesUtil.getString("cookie", "")
- songApi = SongApi(cookie)
- currentMusicInfo = arguments?.getInt("musicIndex", 0)?.let { data?.getJSONObject(it) }
- if (currentMusicInfo?.containsKey("simpleSong") == true) {
- currentMusicInfo = currentMusicInfo?.getJSONObject("simpleSong")
- }
- artistName = if (currentMusicInfo?.containsKey("artists") == true) {
- if (local == true) {
- currentMusicInfo?.getString("artists")
- } else {
- currentMusicInfo?.getJSONArray("artists")?.getJSONObject(0)?.getString("name")
- }
- } else if (currentMusicInfo?.containsKey("ar") == true) {
- currentMusicInfo?.getJSONArray("ar")?.getJSONObject(0)?.getString("name")
- } else {
- getString(R.string.unknown)
- }
- pbMain = requireActivity().findViewById(R.id.pb_main)
- if (currentMusicInfo?.containsKey("id") == true) {
- Thread {
- try {
- val api = MusicListApi(
- SharedPreferencesUtil.getJSONObject("profile").getString("userId"),
- cookie
- )
- val ids: Array = api.getMusicListDetail(
- api.getMusicList().getJSONObject(0).getString("id")
- )
- for (id in ids) {
- if (id == currentMusicInfo?.getString("id")) {
- liked = true
- }
- }
- requireActivity().runOnUiThread {
- binding.ivLike.apply {
- if(liked){
- setImageResource(R.drawable.ic_baseline_favorite_24)
- }
- else{
- setImageResource(R.drawable.ic_baseline_favorite_border_24)
- }
- }
- }
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }.start()
- }
-
-
- // 点击事件
-
- binding.apply {
- ivVoiceDown.setOnClickListener(this@ConsoleFragment)
- ivVoiceUp.setOnClickListener(this@ConsoleFragment)
- ivDownload.setOnClickListener(this@ConsoleFragment)
- ivComment.setOnClickListener(this@ConsoleFragment)
- ivShare.setOnClickListener(this@ConsoleFragment)
- ivMv.setOnClickListener(this@ConsoleFragment)
- ivPlaylist.setOnClickListener(this@ConsoleFragment)
- ivLike.setOnClickListener(this@ConsoleFragment)
- }
- }
- return view
- }
-
- @SuppressLint("NonConstantResourceId")
- override fun onClick(view: View) {
- when (view.id) {
- R.id.iv_voiceUp -> {
- pbMain.max = max
- val value = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
- if (value == max) {
- ToastUtil.show(requireActivity(), "媒体音量已到最高")
- } else {
- audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, value + 1, 0) //音乐音量
- pbMain.progress = value + 1
- }
- }
- R.id.iv_voiceDown -> {
- pbMain.max = max
- val value = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
- if (value == 0) {
- ToastUtil.show(requireActivity(), "媒体音量已到最低")
- } else {
- audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, value - 1, 0) //音乐音量
- pbMain.progress = value - 1
- }
- }
- R.id.iv_like -> Thread {
- try {
- if (liked) {
- if (songApi.likeMusic(currentMusicInfo?.getString("id"), false)) {
- liked = false
- } else {
- ToastUtil.show(requireActivity(), "取消收藏失败")
- }
- } else {
- if (songApi.likeMusic(currentMusicInfo?.getString("id"), true)) {
- liked = true
- } else {
- ToastUtil.show(requireActivity(), "收藏失败")
- }
- }
- } catch (e: Exception) {
- ToastUtil.show(requireActivity(), "收藏失败")
- }
- requireActivity().runOnUiThread {
- val like_view = requireView().findViewById(R.id.iv_like)
- if (liked) {
- like_view.setImageResource(R.drawable.ic_baseline_favorite_24)
- } else {
- like_view.setImageResource(R.drawable.ic_baseline_favorite_border_24)
- }
- }
- }.start()
- R.id.iv_download -> if (local == true) {
- ToastUtil.show(requireActivity(), "已下载")
- } else {
- checkPermissionForDownload()
- }
- R.id.iv_comment -> if (currentMusicInfo?.getString("id") == null) {
- ToastUtil.show(requireActivity(), "本地音乐暂不支持评论")
- } else {
- startActivity(
- Intent(requireActivity(), CommentActivity::class.java).putExtra(
- "id",
- currentMusicInfo?.getString("id")
- )
- )
- }
- R.id.iv_mv -> {
- if (local!!) {
- ToastUtil.show(requireActivity(), "本地音乐暂不支持播放MV")
- return
- }
- val mvId: String? =
- if (currentMusicInfo?.containsKey("mv") == true)
- currentMusicInfo?.getString("mv")
- else
- currentMusicInfo?.getString("mvid")
- if (mvId == null || mvId.isEmpty()) {
- ToastUtil.show(requireActivity(), "当前音乐无对应MV")
- } else {
- Thread {
- val mvUrl: String? = MVApi(cookie).getMVUrl(mvId)
- if (mvUrl == null) {
- ToastUtil.show(requireActivity(), "当前音乐无对应MV")
- } else {
- if (SharedPreferencesUtil.getString(
- "video_player",
- "WristVideo"
- ) == "WristButlerPro"
- ) {
- val intent = Intent()
- intent.putExtra("url", mvUrl)
- intent.putExtra("title", currentMusicInfo!!.getString("name"))
- try {
- intent.setClassName("com.cn.awg.pro", "com.cn.awg.pro.g2")
- startActivity(intent)
- PlayerFragment.pauseMusic()
- } catch (e: Exception) {
- ToastUtil.show(
- requireActivity(),
- "视频播放器 腕管Pro 启动失败,请检查是否已安装该应用"
- )
- e.printStackTrace()
- }
- } else {
- val intent = Intent()
- intent.putExtra("mode", 1)
- intent.putExtra("url", mvUrl)
- intent.putExtra("url_backup", mvUrl)
- intent.putExtra("title", currentMusicInfo!!.getString("name"))
- intent.putExtra("identity_name", "WearMusic")
- try {
- intent.component = ComponentName(
- "cn.luern0313.wristvideoplayer",
- "cn.luern0313.wristvideoplayer.ui.PlayerActivity"
- )
- startActivity(intent)
- PlayerFragment.pauseMusic()
- } catch (e: Exception) {
- e.printStackTrace()
- try {
- intent.component = ComponentName(
- "cn.luern0313.wristvideoplayer_free",
- "cn.luern0313.wristvideoplayer_free.ui.PlayerActivity"
- )
- startActivity(intent)
- PlayerFragment.pauseMusic()
- } catch (ee: Exception) {
- ToastUtil.show(
- requireActivity(),
- "视频播放器 腕上视频 启动失败,请检查是否已安装该应用"
- )
- }
- }
- }
- }
- }.start()
- }
- }
- R.id.iv_share -> startActivity(
- Intent(
- requireActivity(),
- QRCodeActivity::class.java
- ).putExtra(
- "url",
- "https://music.163.com/#/song?id=" + currentMusicInfo!!.getString("id")
- )
- )
- R.id.iv_repeat -> {
- val intent = Intent()
- val iv_repeat = requireView().findViewById(R.id.iv_repeat)
- when (orderId) {
- PlayerFragment.PLAY_ORDER -> {
- // 处于顺序播放模式
- orderId = PlayerFragment.PLAY_REPEAT_ONE
- intent.putExtra("orderId", PlayerFragment.PLAY_REPEAT_ONE)
- iv_repeat.setImageResource(R.drawable.icon_play_repeat_one)
- }
- PlayerFragment.PLAY_REPEAT_ONE -> {
- // 处于单曲循环模式
- orderId = PlayerFragment.PLAY_ORDER
- intent.putExtra("orderId", PlayerFragment.PLAY_ORDER)
- iv_repeat.setImageResource(R.drawable.icon_play_order)
- }
- PlayerFragment.PLAY_SHUFFLE -> {}
- }
- PlayerFragment.setPlayOrder(orderId)
- }
- R.id.iv_playlist -> {
- EventBus.getDefault().postSticky(MessageEvent(data!!.toJSONString()))
- startActivity(
- Intent(requireActivity(), PlayListActivity::class.java)
- .putExtra("local", local)
- )
- }
- }
- }
-
- private fun checkPermissionForDownload() {
- // 读取权限
- val permission = Manifest.permission.WRITE_EXTERNAL_STORAGE
- if (Build.VERSION.SDK_INT >= 23) {
- // 检查权限是否已授权
- val hasPermission = MainApplication.getContext().checkSelfPermission(permission)
- // 如果没有授权
- if (hasPermission != PackageManager.PERMISSION_GRANTED) {
- // 请求权限
- requestPermissions(arrayOf(permission), 0)
- } else {
- // 已授权权限
- downloadCurrentMusic()
- }
- } else {
- downloadCurrentMusic()
- }
- }
-
- override fun onRequestPermissionsResult(
- requestCode: Int,
- permissions: Array,
- grantResults: IntArray
- ) {
- if (grantResults.isNotEmpty()) { //grantResults 数组中存放的是授权结果
- if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- // 同意授权
- downloadCurrentMusic()
- } else {
- // 拒绝授权
- ToastUtil.show(requireActivity(), getString(R.string.permission_denied))
- }
- }
- }
-
- private lateinit var progressDialog: ProgressDialog
- private fun downloadCurrentMusic() {
- val fileName =
- currentMusicInfo?.getString("name") + "--" + if (artistName == null) getString(R.string.unknown) else artistName
- val rootPath =
- MainApplication.getContext().getExternalFilesDir(null).toString() + "/download"
- Thread {
-
- // 保存封面
- val albumId: Int? = if (currentMusicInfo?.containsKey("al") == true) {
- currentMusicInfo?.getJSONObject("al")?.getInteger("id")
- } else {
- currentMusicInfo?.getJSONObject("album")?.getInteger("id")
- }
- savePicture(songApi.getSongCover(albumId?:0), "$rootPath/cover/", "$fileName.png")
-
- // 保存歌词
- val lrcDir = File("$rootPath/lrc/")
- if (!lrcDir.exists()) {
- lrcDir.mkdirs()
- }
- try {
- val out = BufferedWriter(FileWriter("$rootPath/lrc/$fileName.lrc"))
- out.write(songApi.getMusicLyric(currentMusicInfo!!.getString("id")))
- out.close()
- } catch (ignored: Exception) {
- }
-
- // 保存id
- val idDir = File("$rootPath/id/")
- if (!idDir.exists()) {
- idDir.mkdirs()
- }
- try {
- val out = BufferedWriter(FileWriter("$rootPath/id/$fileName.txt"))
- out.write(currentMusicInfo!!.getString("id"))
- out.close()
- } catch (ignored: Exception) {
- }
-
- // 保存音乐
- val url: String = SongApi(cookie).getMusicUrl(currentMusicInfo!!.getString("id"))
- .replace("http://", "https://")
- requireActivity().runOnUiThread {
- progressDialog = ProgressDialog(requireActivity())
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL)
- // 设置ProgressDialog 标题
- progressDialog.setTitle("提示")
- // 设置ProgressDialog 提示信息
- progressDialog.setMessage("当前下载进度:")
- // 设置ProgressDialog 是否可以按退回按键取消
- progressDialog.setCancelable(false)
- progressDialog.show()
- progressDialog.max = 100
- }
- DownloadUtil().download(
- url, "$rootPath/music",
- "$fileName.wav",
- object : OnDownloadListener {
- override fun onDownloadSuccess(file: File) {
- ToastUtil.show(requireActivity(), "下载成功")
- requireActivity().runOnUiThread { progressDialog.dismiss() }
- }
-
- override fun onDownloading(progress: Int) {
- Log.d("ConsoleActivity", "onDownloading: Progress $progress%")
- requireActivity().runOnUiThread { progressDialog.progress = progress }
- }
-
- override fun onDownloadFailed(e: Exception) {
- ToastUtil.show(requireActivity(), "下载失败")
- requireActivity().runOnUiThread { progressDialog.dismiss() }
- }
- }
- )
- }.start()
- }
-
- private fun savePicture(photoUrl: String?, path: String, fileName: String) {
- Thread {
- try {
- val bitmap = Glide.with(requireActivity())
- .asBitmap()
- .load(photoUrl)
- .submit(512, 512).get()
- val dirFile = File(path)
- if (!dirFile.exists()) {
- dirFile.mkdir()
- }
- val myCaptureFile = File(path + fileName)
- myCaptureFile.createNewFile()
- val bos = BufferedOutputStream(FileOutputStream(myCaptureFile))
- bitmap.compress(Bitmap.CompressFormat.PNG, 80, bos)
- bos.flush()
- bos.close()
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }.start()
- }
-
- companion object {
- @JvmStatic
- fun newInstance(intent: Intent): ConsoleFragment {
- val fragment = ConsoleFragment()
- val args = Bundle()
- args.putInt("musicIndex", intent.getIntExtra("musicIndex", 0))
- args.putBoolean("local", intent.getBooleanExtra("local", false))
- fragment.arguments = args
- return fragment
- }
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/cn/wearbbs/music/fragment/LyricsFragment.java b/app/src/main/java/cn/wearbbs/music/fragment/LyricsFragment.java
index 3218320..b7e2aa8 100644
--- a/app/src/main/java/cn/wearbbs/music/fragment/LyricsFragment.java
+++ b/app/src/main/java/cn/wearbbs/music/fragment/LyricsFragment.java
@@ -180,7 +180,7 @@ public void onActivityResult(int requestCode,int resultCode,Intent data) {
@Override
public void handleMessage(android.os.Message msg) {
if (currentPosition > 0) {
- lrcView.updateTime(currentPosition);
+ //lrcView.updateTime(currentPosition);
}
//调取子线程
handler.sendEmptyMessageDelayed(0, 1000);
diff --git a/app/src/main/java/cn/wearbbs/music/fragment/PlayerFragment.java b/app/src/main/java/cn/wearbbs/music/fragment/PlayerFragment.java
index 9ce2b2e..8db7ab9 100644
--- a/app/src/main/java/cn/wearbbs/music/fragment/PlayerFragment.java
+++ b/app/src/main/java/cn/wearbbs/music/fragment/PlayerFragment.java
@@ -186,6 +186,7 @@ else if (binder.getPrepareStatus()) {
activity.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
catch (Exception ex){
+ ex.printStackTrace();
Looper.prepare();
ToastUtil.show(requireActivity(),"音乐地址获取失败,若多次出现此问题,请尝试重新登录");
Looper.loop();
diff --git a/app/src/main/java/cn/wearbbs/music/ui/MainActivity.java b/app/src/main/java/cn/wearbbs/music/ui/MainActivity.java
index 88e0c58..b30e530 100644
--- a/app/src/main/java/cn/wearbbs/music/ui/MainActivity.java
+++ b/app/src/main/java/cn/wearbbs/music/ui/MainActivity.java
@@ -44,12 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
EventBus.getDefault().register(this);
- if(SharedPreferencesUtil.getString("server","vercel").equals("wearbbs")){
- NetWorkUtil.setDomain("https://music.wearbbs.cn/");
- }
- else{
- NetWorkUtil.setDomain("https://api.wmusic.pro/");
- }
+ NetWorkUtil.setDomain("https://musicapi.technet.space/");
if (SharedPreferencesUtil.getBoolean("dark", false)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
diff --git a/app/src/main/java/cn/wearbbs/music/ui/MusicListActivity.java b/app/src/main/java/cn/wearbbs/music/ui/MusicListActivity.java
index d758fd3..ee676df 100644
--- a/app/src/main/java/cn/wearbbs/music/ui/MusicListActivity.java
+++ b/app/src/main/java/cn/wearbbs/music/ui/MusicListActivity.java
@@ -68,6 +68,7 @@ public void initLikeList() {
runOnUiThread(()->initMusicList(id));
}
catch (Exception e){
+ e.printStackTrace();
runOnUiThread(this::showErrorMessage);
}
}).start();
@@ -99,7 +100,9 @@ public View getHeader(){
try{
Glide.with(this).load(imgUrl).apply(options).into(iv_cover);
}
- catch (Exception ignored){}
+ catch (Exception ignored){
+ ignored.printStackTrace();
+ }
if(description==null||description.isEmpty()){
etv_summary.setVisibility(View.GONE);
}
@@ -134,6 +137,7 @@ public void initMusicList(String id){
});
}
catch (Exception e){
+ e.printStackTrace();
System.out.println("cookie:"+cookie);
runOnUiThread(this::showErrorMessage);
}
diff --git a/app/src/main/java/cn/wearbbs/music/ui/SettingsActivity.java b/app/src/main/java/cn/wearbbs/music/ui/SettingsActivity.java
index 583310c..c6eb832 100644
--- a/app/src/main/java/cn/wearbbs/music/ui/SettingsActivity.java
+++ b/app/src/main/java/cn/wearbbs/music/ui/SettingsActivity.java
@@ -62,17 +62,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
startActivity(new Intent(getActivity(), OpenSourceActivity.class));
return true;
});
-
- findPreference("server").setOnPreferenceChangeListener((preference, newValue) -> {
- if(newValue.equals("vercel")){
- NetWorkUtil.setDomain("https://api.wmusic.pro/");
- }
- else{
- NetWorkUtil.setDomain("https://music.wearbbs.cn");
- }
- return true;
- });
-
}
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml
index 6499c3d..c1984eb 100644
--- a/app/src/main/res/layout/activity_about.xml
+++ b/app/src/main/res/layout/activity_about.xml
@@ -77,7 +77,7 @@
android:background="?attr/colorPrimary"
android:onClick="onClick"
android:orientation="horizontal"
- android:visibility="visible">
+ android:visibility="gone">
+ android:visibility="gone">
WristButlerPro
-
-
- - Vercel(推荐)
- - WearBBS
-
- vercel
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1a7e3fe..e6a96c4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -74,7 +74,7 @@
官方群二维码
反馈问题
检查更新
- v%s\n音乐的力量,听你所想。\n作者: JackuXL\n出品:WearBBS\n官方QQ群:133636679\n官网:https://wmusic.pro\n论坛:https://wearbbs.cn\n使用【网易云API】开发\n特别感谢:@luern0313
+ v%s LTS\n音乐的力量,听你所想。\n作者: JackuXL\n官方QQ群:133636679\n官网:https://wmusic.pro\n敬请期待 v4.0
你还没有登录哦
@@ -94,7 +94,6 @@
二维码
播放列表
发送
- 服务器偏好
未登录
]]>
音乐储存位置:\n/storage/emulated/0/Android/data/cn.wearbbs.music/files/download/music/
diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml
index cd313d4..a5da5a6 100644
--- a/app/src/main/res/xml/root_preferences.xml
+++ b/app/src/main/res/xml/root_preferences.xml
@@ -16,14 +16,7 @@
app:key="video_player"
app:title="@string/video_player"
app:useSimpleSummaryProvider="true" />
-
-
+