修复专辑图只显示一个的问题

This commit is contained in:
Yutousama 2021-07-04 15:34:01 +08:00
parent 249568aa11
commit f38486e59a
6 changed files with 35 additions and 40 deletions

View File

@ -52,13 +52,11 @@ public class MusicLibsAdapter extends ArrayAdapter<MusicData> {
public static final int LIBS_MODEL_PLAY_Collection = 5;
KProgressHUD hud;
List<MusicData> list;
Map<String, Bitmap> 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<MusicData> {
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> {
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<MusicData> {
}
public void onDestroy() {
for (String integer : icons.keySet()) {
Objects.requireNonNull(icons.get(integer)).recycle();
}
icons.clear();
}
public void setData(List<MusicData> list) {

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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"

View File

@ -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