From f38486e59a69f011a4349d6a86688c42c9fc61a9 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 4 Jul 2021 15:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=93=E8=BE=91=E5=9B=BE?= =?UTF-8?q?=E5=8F=AA=E6=98=BE=E7=A4=BA=E4=B8=80=E4=B8=AA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Adapters/MusicLibsAdapter.java | 17 +------ .../nas_music_player/Datas/MusicData.java | 48 +++++++++++-------- .../nas_music_player/tools/NetworkTool.java | 3 -- .../nas_music_player/views/MainActivity.java | 3 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 6 files changed, 35 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java b/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java index 65af3ca..2b04f1b 100644 --- a/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java +++ b/app/src/main/java/com/yutou/nas_music_player/Adapters/MusicLibsAdapter.java @@ -52,13 +52,11 @@ public class MusicLibsAdapter extends ArrayAdapter { public static final int LIBS_MODEL_PLAY_Collection = 5; KProgressHUD hud; List list; - Map icons; Context context; public MusicLibsAdapter(Context context, int model) { super(context, R.layout.layout_music_libs_item); list = new ArrayList<>(); - icons = new HashMap<>(); this.context = context; initData(model, true); } @@ -247,13 +245,7 @@ public class MusicLibsAdapter extends ArrayAdapter { holder.artist.setVisibility(View.GONE); } // holder.icon.setImageBitmap(ThumbnailUtils.extractThumbnail(data.getImg(), 64,64)); - if (icons.containsKey(data.getFile())) { - Glide.with(getContext()).load(icons.get(data.getFile())) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3))) - .into(holder.icon); - } else { - showImage(data, holder); - } + showImage(data, holder); holder.icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -398,8 +390,7 @@ public class MusicLibsAdapter extends ArrayAdapter { musicData.getImg(-1, -1, new NetworkInterface() { @Override public void httpGetData(Object data, int state) { - icons.put(musicData.getFile(), (Bitmap) data); - Glide.with(getContext()).load(icons.get(musicData.getFile())) + Glide.with(getContext()).load((Bitmap) data) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3))) .into(holder.icon); System.out.println("展示图片:" + state); @@ -413,10 +404,6 @@ public class MusicLibsAdapter extends ArrayAdapter { } public void onDestroy() { - for (String integer : icons.keySet()) { - Objects.requireNonNull(icons.get(integer)).recycle(); - } - icons.clear(); } public void setData(List list) { 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 c44f372..720ec2b 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 @@ -136,10 +136,10 @@ public class MusicData { if (StringUtil.isEmpty(track)) { return "0"; } - try{ + try { Integer.parseInt(track); - }catch (Exception e){ - return track.substring(0,1); + } catch (Exception e) { + return track.substring(0, 1); } return track; } @@ -152,10 +152,10 @@ public class MusicData { if (StringUtil.isEmpty(disc_no)) { return "0"; } - try{ + try { Integer.parseInt(disc_no); - }catch (Exception e){ - return disc_no.substring(0,1); + } catch (Exception e) { + return disc_no.substring(0, 1); } return disc_no; } @@ -208,12 +208,12 @@ public class MusicData { public String getFileBase64() { if (StringUtil.isEmpty(file)) return null; - return AppTools.getUrlBase64(file); + return AppTools.getUrlBase64(file); } public String getPlayUrl() { - System.out.println("播放地址:"+NetworkTool.NetworkAPI.HOME + NetworkTool.NetworkAPI.MUSIC_PLAY + System.out.println("播放地址:" + NetworkTool.NetworkAPI.HOME + NetworkTool.NetworkAPI.MUSIC_PLAY + "?random=false&token=" + NetworkTool.NetworkAPI.HTTP_KEY + "&filePath=" + getFileBase64()); return NetworkTool.NetworkAPI.HOME + NetworkTool.NetworkAPI.MUSIC_PLAY + "?random=false&token=" + NetworkTool.NetworkAPI.HTTP_KEY + "&filePath=" + getFileBase64(); @@ -221,7 +221,7 @@ public class MusicData { public String getImageUrl() { - return NetworkTool.NetworkAPI.MUSIC_IMAGE + "?fileName=" +getFileBase64(); + return NetworkTool.NetworkAPI.MUSIC_IMAGE + "?fileName=" + getFileBase64(); } public Bitmap getImg() { @@ -246,11 +246,11 @@ public class MusicData { if (isDownloadImg) { return null; } - if (StringUtil.isEmpty(file)&&StringUtil.isEmpty(title)&&StringUtil.isEmpty(album)) { + if (StringUtil.isEmpty(file) && StringUtil.isEmpty(title) && StringUtil.isEmpty(album)) { img = BitmapFactory.decodeResource(MyApplication.application.getResources(), R.mipmap.ic_launcher); return img; } - String imageSaveName=(StringUtil.isEmpty(album)?title:album)+".png"; + String imageSaveName = (StringUtil.isEmpty(album) ? title : album) + ".png"; img = AppTools.getSaveBitmap(imageSaveName); if (img != null) { if (width == -1 && height == -1) { @@ -265,18 +265,28 @@ public class MusicData { img = null; isDownloadImg = true; JSONObject json = new JSONObject(); - if(StringUtil.isEmpty(getAlbum())) { + if (StringUtil.isEmpty(getAlbum())) { json.put("fileName", getFile()); - }else{ - json.put("fileName",AppTools.getUrlBase64(getAlbum())); - json.put("type","album"); + } else { + json.put("fileName", AppTools.getUrlBase64(getAlbum())); + json.put("type", "album"); } - System.out.println("下载图片:"+ NetworkTool.NetworkAPI.MUSIC_IMAGE+"?"+NetworkTool.toGetSplice(json)); - NetworkTool.init().downloadImage(NetworkTool.NetworkAPI.MUSIC_IMAGE,json, imageSaveName,"post", new DownloadInterface() { + System.out.println("下载图片:" + NetworkTool.NetworkAPI.MUSIC_IMAGE + "?" + NetworkTool.toGetSplice(json)); + NetworkTool.init().downloadImage(NetworkTool.NetworkAPI.MUSIC_IMAGE, json, imageSaveName, "post", new DownloadInterface() { @Override public void onDownloadOver(File oldJar) { - AppTools.saveBitmap(oldJar,imageSaveName); - img=BitmapFactory.decodeFile(oldJar.getAbsolutePath()); + AppTools.saveBitmap(oldJar, imageSaveName); + img = BitmapFactory.decodeFile(oldJar.getAbsolutePath()); + AppData.handler.post(() -> { + if (width == -1 && height == -1) { + if (networkInterface != null) + networkInterface.httpGetData(img, 0); + } else { + if (networkInterface != null) + networkInterface.httpGetData(ThumbnailUtils.extractThumbnail(img, width, height), width + height); + } + }); + } @Override diff --git a/app/src/main/java/com/yutou/nas_music_player/tools/NetworkTool.java b/app/src/main/java/com/yutou/nas_music_player/tools/NetworkTool.java index 7410f2d..19e1394 100644 --- a/app/src/main/java/com/yutou/nas_music_player/tools/NetworkTool.java +++ b/app/src/main/java/com/yutou/nas_music_player/tools/NetworkTool.java @@ -114,9 +114,6 @@ public class NetworkTool { connection.setConnectTimeout(50); connection.setReadTimeout(50); connection.connect(); - InputStream inputStream = connection.getErrorStream(); - System.out.println(inputStream.read()); - inputStream.close(); System.out.println(connection.getResponseCode()); networkInterface.httpGetData(null, 0); connection.disconnect(); diff --git a/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java b/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java index 4ee17f6..08adce3 100644 --- a/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java +++ b/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java @@ -8,6 +8,7 @@ import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaControllerCompat; import android.support.v4.media.session.MediaSessionCompat; @@ -58,7 +59,7 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setBarColor(android.R.color.transparent); setContentView(R.layout.activity_main); - handler = new Handler(); + handler = new Handler(Looper.myLooper()); initView(); play.setOnClickListener(new View.OnClickListener() { @Override diff --git a/build.gradle b/build.gradle index 70312a2..8585627 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:4.2.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 a03e674..676aec8 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-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip