From 20b80d380a2f3abd85d4d7f29777ba25692eeb3d Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 18 Mar 2022 09:32:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8E=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=80=9A?= =?UTF-8?q?=E8=AE=AF=E7=94=B1=E6=96=87=E4=BB=B6=E5=90=8D=E6=94=B9=E6=88=90?= =?UTF-8?q?MD5=20=E4=BF=AE=E5=A4=8D=E4=B8=93=E8=BE=91=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E4=BC=9A=E9=97=AA=E9=80=80=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 - .../nas_music_player/Datas/MusicData.java | 8 ++++---- .../Datas/PreviousPlayerList.java | 2 +- .../containers/MusicContainer.java | 5 +++-- .../nas_music_player/network/HttpManager.java | 11 +++++++++-- .../views/AlbumsActivity.java | 19 ++++++++++++------- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5bdc677..b4529d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,6 @@ android { } } compileSdkVersion 30 - buildToolsVersion "30.0.2" defaultConfig { applicationId "com.yutou.nas_music_player" diff --git a/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java b/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java index 39eb5c0..f238f9f 100644 --- a/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java +++ b/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java @@ -223,10 +223,10 @@ public class MusicData { public String getPlayUrl() { - System.out.println("播放地址:" + HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY - + "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getFileBase64()); - return HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY - + "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getFileBase64(); + String url= HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY + + "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getMd5(); + System.out.println("播放地址:" +url); + return url; } diff --git a/app/src/main/java/com/yutou/nas_music_player/Datas/PreviousPlayerList.java b/app/src/main/java/com/yutou/nas_music_player/Datas/PreviousPlayerList.java index 12d9024..ad8613c 100644 --- a/app/src/main/java/com/yutou/nas_music_player/Datas/PreviousPlayerList.java +++ b/app/src/main/java/com/yutou/nas_music_player/Datas/PreviousPlayerList.java @@ -15,7 +15,7 @@ public class PreviousPlayerList { public void add(MusicData musicData){ MusicData tmp = null; for (MusicData data : list) { - if(data.getFile().equals(musicData.getFile())){ + if(data.getMd5().equals(musicData.getMd5())){ tmp=data; } 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 82cb227..dac76ac 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 @@ -304,12 +304,13 @@ public class MusicContainer { } private MediaMetadataCompat metadataCompat; - private String metaDataFile; + private String metaDataFile=""; public MediaMetadataCompat getMetadataCompat(MusicData data) { - if (data.getFile().equals(metaDataFile)) { + if (data.getMd5().equals(metaDataFile)) { return metadataCompat; } + metaDataFile=data.getMd5(); MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.getTitle()); builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, data.getArtist()); diff --git a/app/src/main/java/com/yutou/nas_music_player/network/HttpManager.java b/app/src/main/java/com/yutou/nas_music_player/network/HttpManager.java index 5bc6cad..c8edae9 100644 --- a/app/src/main/java/com/yutou/nas_music_player/network/HttpManager.java +++ b/app/src/main/java/com/yutou/nas_music_player/network/HttpManager.java @@ -28,6 +28,7 @@ import java.time.Duration; import java.time.temporal.TemporalUnit; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.TimeUnit; @@ -178,7 +179,11 @@ public class HttpManager { @Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { - networkInterface.httpGetData(response.body().string(), response.code()); + String body = response.body().string(); + int code = response.code(); + AppData.handler.post(() -> { + networkInterface.httpGetData(body, code); + }); } }); } @@ -311,7 +316,9 @@ public class HttpManager { Log.toast(MyApplication.application, "下载完成,重启生效"); if (downloadInterface != null) { - downloadInterface.onDownloadOver(oldJar); + AppData.handler.post(() -> { + downloadInterface.onDownloadOver(oldJar); + }); } } catch (Exception e) { diff --git a/app/src/main/java/com/yutou/nas_music_player/views/AlbumsActivity.java b/app/src/main/java/com/yutou/nas_music_player/views/AlbumsActivity.java index 834f6e8..a78bf64 100644 --- a/app/src/main/java/com/yutou/nas_music_player/views/AlbumsActivity.java +++ b/app/src/main/java/com/yutou/nas_music_player/views/AlbumsActivity.java @@ -20,6 +20,7 @@ import com.yutou.nas_music_player.Interfaces.NetworkInterface; import com.yutou.nas_music_player.R; import com.yutou.nas_music_player.containers.MediaBrowserHelper; import com.yutou.nas_music_player.containers.MusicContainer; +import com.yutou.nas_music_player.tools.AppData; import java.util.ArrayList; import java.util.List; @@ -34,6 +35,7 @@ public class AlbumsActivity extends AppCompatActivity { private AppBarLayout appBarLayout; private TextView breakApp; private int model;//0 专辑, 1 歌手, 2 收藏 + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -68,7 +70,7 @@ public class AlbumsActivity extends AppCompatActivity { List list = (List) data; adapter.setData(list); adapter.notifyDataSetChanged(); - if(list.isEmpty()) + if (list.isEmpty()) return; list.get(0).getImg(-1, -1, new NetworkInterface() { @Override @@ -100,7 +102,10 @@ public class AlbumsActivity extends AppCompatActivity { public void httpGetData(Object data, int state) { List list = (List) data; adapter.setData(list); - adapter.notifyDataSetChanged(); + AppData.handler.post(() -> { + adapter.notifyDataSetChanged(); + + }); list.get(0).getImg(-1, -1, new NetworkInterface() { @Override public void httpGetData(Object data, int state) { @@ -134,13 +139,13 @@ public class AlbumsActivity extends AppCompatActivity { breakApp = findViewById(R.id.breakApp); appBarLayout = findViewById(R.id.appbar); listView.setLayoutManager(new LinearLayoutManager(this)); - adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(),model); + adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(), model); listView.setAdapter(adapter); appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> { - if(verticalOffset<-200){ - breakApp.setTextColor(getResources().getColor(R.color.musicArtist,null)); - }else{ - breakApp.setTextColor(getResources().getColor(R.color.musicTitle,null)); + if (verticalOffset < -200) { + breakApp.setTextColor(getResources().getColor(R.color.musicArtist, null)); + } else { + breakApp.setTextColor(getResources().getColor(R.color.musicTitle, null)); } }); appBarLayout.setOnClickListener(v -> finish()); diff --git a/build.gradle b/build.gradle index f48f612..28b85bc 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 71f6744..90beb44 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip