diff --git a/app/build.gradle b/app/build.gradle index 1c7d0b1..9de644a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,7 +19,7 @@ android { minSdkVersion 23 targetSdkVersion 32 versionCode 1 - versionName "1.2" + versionName "1.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -71,7 +71,6 @@ dependencies { implementation 'com.kaopiz:kprogresshud:1.2.0' implementation 'com.github.promeg:tinypinyin:2.0.3' implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.95' - implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' implementation "androidx.room:room-runtime:2.4.3" diff --git a/app/src/main/java/com/yutou/nas_music_player/Adapters/AlbumsRecyclerAdapter.java b/app/src/main/java/com/yutou/nas_music_player/Adapters/AlbumsRecyclerAdapter.java index b96b687..c0ac3dc 100644 --- a/app/src/main/java/com/yutou/nas_music_player/Adapters/AlbumsRecyclerAdapter.java +++ b/app/src/main/java/com/yutou/nas_music_player/Adapters/AlbumsRecyclerAdapter.java @@ -23,6 +23,7 @@ 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 com.yutou.nas_music_player.tools.ImageLoader; import java.util.List; @@ -70,36 +71,8 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter() { @Override - public void httpGetData(Object bitmap, int state) { - super.httpGetData(data, state); - Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class); - intent.putExtra("model", 0); - intent.putExtra("album", data.getAlbum()); - intent.putExtra("image", HttpManager.NetworkAPI.HOME+data.getImageUrl()); - intent.putExtra("color", AppTools.getImageColor((Bitmap) bitmap)); - if (clickAction != null) { - clickAction.onClick(intent, icon); + public void onData(Bitmap bitmap) { + if(bitmap!=null){ + Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class); + intent.putExtra("model", 0); + intent.putExtra("album", data.getAlbum()); + intent.putExtra("image", data.getImageUrl()); + intent.putExtra("color", AppTools.getImageColor(bitmap)); + if (clickAction != null) { + clickAction.onClick(intent, icon); + } } } }); @@ -397,22 +400,6 @@ public class MusicLibsAdapter extends RecyclerView.Adapter { + public abstract void onData(T t); +} diff --git a/app/src/main/java/com/yutou/nas_music_player/MyApplication.java b/app/src/main/java/com/yutou/nas_music_player/MyApplication.java index cf6dc38..0eeb258 100644 --- a/app/src/main/java/com/yutou/nas_music_player/MyApplication.java +++ b/app/src/main/java/com/yutou/nas_music_player/MyApplication.java @@ -9,6 +9,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.yutou.nas_music_player.tools.ImageLoader; import com.yutou.nas_music_player.views.OpenActivity; import java.lang.ref.WeakReference; @@ -39,6 +40,7 @@ public class MyApplication extends Application { public void onCreate() { super.onCreate(); MyApplication.application = this; + ImageLoader.getInstance(this); registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { diff --git a/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java b/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java index 4ff10e4..43b54b0 100644 --- a/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java +++ b/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java @@ -10,6 +10,7 @@ import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; import com.yutou.nas_music_player.Datas.MusicData; +import com.yutou.nas_music_player.Interfaces.AbsObjectInterface; import com.yutou.nas_music_player.MyApplication; import com.yutou.nas_music_player.services.MusicService; import com.yutou.nas_music_player.tools.AppData; @@ -70,7 +71,13 @@ public class MediaBrowserHelper { public void run() { for (MediaControllerCompat.Callback callback : callbacks) { if (callback != null) { - callback.onMetadataChanged(MusicContainer.getInstance().getNowPlayMetadataCompat()); + MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface() { + @Override + public void onData(MediaMetadataCompat mediaMetadataCompat) { + callback.onMetadataChanged(mediaMetadataCompat); + } + }); + } } 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 5b37035..368b335 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 @@ -4,6 +4,7 @@ import static android.media.MediaPlayer.SEEK_PREVIOUS_SYNC; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Bitmap; import android.media.MediaPlayer; import android.net.Uri; import android.os.Build; @@ -19,12 +20,14 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.yutou.nas_music_player.Datas.MusicData; import com.yutou.nas_music_player.Datas.PreviousPlayerList; +import com.yutou.nas_music_player.Interfaces.AbsObjectInterface; import com.yutou.nas_music_player.Interfaces.NetworkInterface; import com.yutou.nas_music_player.MyApplication; import com.yutou.nas_music_player.network.HttpManager; import com.yutou.nas_music_player.tools.AppData; import com.yutou.nas_music_player.tools.AppTools; import com.yutou.nas_music_player.tools.ConfigTools; +import com.yutou.nas_music_player.tools.ImageLoader; import com.yutou.nas_music_player.tools.StringUtil; import java.io.IOException; @@ -267,7 +270,7 @@ public class MusicContainer { ConfigTools.getPreferences().edit().putString(ConfigTools.previous_music, JSONObject.toJSONString(tmp)).apply(); MediaNotificationManager manager = MediaNotificationManager.getInstance(); if (manager != null) { - // manager.getService().updateNotification(); + // manager.getService().updateNotification(); } tmp = null; } catch (IOException e) { @@ -288,11 +291,12 @@ public class MusicContainer { private Timer playTimer; - public MediaMetadataCompat getNowPlayMetadataCompat() { + public void getNowPlayMetadataCompat(AbsObjectInterface objectInterface) { if (nowPlayData == null) { - return null; + objectInterface.onData(null); + } else { + getMetadataCompat(nowPlayData, objectInterface); } - return getMetadataCompat(nowPlayData); } public Long getYear(String year) { @@ -313,27 +317,33 @@ public class MusicContainer { private MediaMetadataCompat metadataCompat; private String metaDataFile = ""; - public MediaMetadataCompat getMetadataCompat(MusicData data) { + public void getMetadataCompat(MusicData data, AbsObjectInterface objectInterface) { if (data.getMd5().equals(metaDataFile)) { - return metadataCompat; + objectInterface.onData(metadataCompat); + return; } 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()); - builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, data.getTitle()); - builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, data.getAlbum()); - builder.putString(MediaMetadataCompat.METADATA_KEY_COMPOSER, data.getComposer()); - builder.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, getYear(data.getYear())); - builder.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, Long.parseLong(data.getTrack())); - builder.putLong(MediaMetadataCompat.METADATA_KEY_DISC_NUMBER, Long.parseLong(data.getDisc_no())); - builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, ((int) (data.getDurationAsDouble() * 1000))); - if (data.getImg() != null) { - builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, data.getImg()); - } - builder.putString("md5", data.getMd5()); - metadataCompat = builder.build(); - return metadataCompat; + ImageLoader.getInstance().getImageBitmap(data.getImageUrl(), -1, -1, new AbsObjectInterface() { + @Override + public void onData(Bitmap bitmap) { + MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); + builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.getTitle()); + builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, data.getArtist()); + builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, data.getTitle()); + builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, data.getAlbum()); + builder.putString(MediaMetadataCompat.METADATA_KEY_COMPOSER, data.getComposer()); + builder.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, getYear(data.getYear())); + builder.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, Long.parseLong(data.getTrack())); + builder.putLong(MediaMetadataCompat.METADATA_KEY_DISC_NUMBER, Long.parseLong(data.getDisc_no())); + builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, ((int) (data.getDurationAsDouble() * 1000))); + if (bitmap != null) { + builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap); + } + builder.putString("md5", data.getMd5()); + metadataCompat = builder.build(); + objectInterface.onData(metadataCompat); + } + }); } public static MusicLibs getLibs() { @@ -346,8 +356,9 @@ public class MusicContainer { isPause = true; mediaPlayer.pause(); } - public void play(){ - isPause=false; + + public void play() { + isPause = false; mediaPlayer.start(); } @@ -393,8 +404,8 @@ public class MusicContainer { */ public void playPrevious() { playIndex--; - if(playIndex<0){ - playIndex=0; + if (playIndex < 0) { + playIndex = 0; } MusicData data = previousPlayerList.getMusicData(); if (data != null) { 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 14d08a0..28c6455 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 @@ -44,7 +44,7 @@ public class HttpManager { public static class NetworkAPI { public static final String HTTP_KEY = "OHreoKn2CSlDipWV6phEupAqPIX2LJFl"; - public static String HOME = ""; + public static String HOME = "http://nas.cnmglz.com:8000/nas"; public static String MUSIC_LIST = HOME + "/music/list.do"; public static String MUSIC_Album = HOME + "/music/getAlbum.do"; public static String MUSIC_Collection_Dir_List = HOME + "/music/favorite/dir/list.do"; @@ -64,7 +64,7 @@ public class HttpManager { private HttpManager() { System.out.println("初始化NetWork"); - httpGet("http://192.168.31.88:8000/public/version.do", new NetworkInterface() { + /*httpGet("http://192.168.31.88:8000/public/version.do", new NetworkInterface() { @Override public void httpGetData(Object data, int state) { System.out.println("state = " + state); @@ -102,7 +102,7 @@ public class HttpManager { } }); } - }); + });*/ } public static HttpManager getInstance() { diff --git a/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java b/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java index 3b734d5..4cefbab 100644 --- a/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java +++ b/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java @@ -19,6 +19,7 @@ import androidx.annotation.Nullable; import androidx.media.MediaBrowserServiceCompat; import com.yutou.nas_music_player.Datas.MusicData; +import com.yutou.nas_music_player.Interfaces.AbsObjectInterface; import com.yutou.nas_music_player.containers.MediaBrowserHelper; import com.yutou.nas_music_player.containers.MediaNotificationManager; import com.yutou.nas_music_player.containers.MusicContainer; @@ -94,10 +95,15 @@ public class MusicService extends MediaBrowserServiceCompat { } mState = state.getState(); MusicData data = MusicContainer.getInstance().getNowPlayData(); - MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getMetadataCompat(data); - Notification notification = notificationManager.getNotification(metadataCompat, builderState(state.getPosition()).build(), getSessionToken()); - notificationManager.getManager() - .notify(MediaNotificationManager.NOTIFICATION_ID, notification); + MusicContainer.getInstance().getMetadataCompat(data, new AbsObjectInterface() { + @Override + public void onData(MediaMetadataCompat mediaMetadataCompat) { + Notification notification = notificationManager.getNotification(mediaMetadataCompat, builderState(state.getPosition()).build(), getSessionToken()); + notificationManager.getManager() + .notify(MediaNotificationManager.NOTIFICATION_ID, notification); + } + }); + } }); System.out.println("注册receiver"); @@ -119,25 +125,35 @@ public class MusicService extends MediaBrowserServiceCompat { @Override public void onLoadChildren(@NonNull String parentId, @NonNull Result> result) { List mediaItems = new ArrayList<>(); - MediaMetadataCompat compat = MusicContainer.getInstance().getNowPlayMetadataCompat(); - System.out.println(compat); - if (compat != null) { - MediaBrowserCompat.MediaItem mediaItem = new MediaBrowserCompat.MediaItem(compat.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); - mediaItems.add(mediaItem); - } - result.sendResult(mediaItems); + MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface() { + @Override + public void onData(MediaMetadataCompat compat) { + System.out.println(compat); + if (compat != null) { + MediaBrowserCompat.MediaItem mediaItem = new MediaBrowserCompat.MediaItem(compat.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); + mediaItems.add(mediaItem); + } + result.sendResult(mediaItems); + } + }); + } public void seekToNotification(long pos) { MusicData data = MusicContainer.getInstance().getNowPlayData(); if (!playMd5.equals(data.getMd5())) { playMd5 = data.getMd5(); - mediaSession.setMetadata(MusicContainer.getInstance().getNowPlayMetadataCompat()); - updateNotification(); + MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface() { + @Override + public void onData(MediaMetadataCompat mediaMetadataCompat) { + mediaSession.setMetadata(mediaMetadataCompat); + updateNotification(); + mediaSession.setPlaybackState(new PlaybackStateCompat.Builder() + .setActions(MEDIA_SESSION_ACTIONS) + .setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build()); + } + }); } - mediaSession.setPlaybackState(new PlaybackStateCompat.Builder() - .setActions(MEDIA_SESSION_ACTIONS) - .setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build()); } public PlaybackStateCompat.Builder builderState(long position) { @@ -180,15 +196,20 @@ public class MusicService extends MediaBrowserServiceCompat { public void updateNotification() { - MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat(); - System.out.println("更新通知栏:" + metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID)); - //mediaSession.setMetadata(metadataCompat); - mediaSession.setActive(true); - Notification notification = - notificationManager.getNotification( - metadataCompat, builderState(0).build(), getSessionToken()); - notificationManager.getManager() - .notify(MediaNotificationManager.NOTIFICATION_ID, notification); + MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface() { + @Override + public void onData(MediaMetadataCompat metadataCompat) { + System.out.println("更新通知栏:" + metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID)); + //mediaSession.setMetadata(metadataCompat); + mediaSession.setActive(true); + Notification notification = + notificationManager.getNotification( + metadataCompat, builderState(0).build(), getSessionToken()); + notificationManager.getManager() + .notify(MediaNotificationManager.NOTIFICATION_ID, notification); + } + }); + } public class MediaSessionCallback extends MediaSessionCompat.Callback { @@ -203,12 +224,17 @@ public class MusicService extends MediaBrowserServiceCompat { isRegReceiver = true; } mState = PlaybackStateCompat.STATE_PLAYING; - MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat(); - mediaSession.setMetadata(metadataCompat); - mediaSession.setActive(true); - Notification notification = notificationManager.getNotification(metadataCompat, builderState(0).build(), getSessionToken()); - startForeground(MediaNotificationManager.NOTIFICATION_ID, notification); - MusicContainer.getInstance().play(MusicContainer.getInstance().getNowPlayData()); + MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface() { + @Override + public void onData(MediaMetadataCompat metadataCompat) { + mediaSession.setMetadata(metadataCompat); + mediaSession.setActive(true); + Notification notification = notificationManager.getNotification(metadataCompat, builderState(0).build(), getSessionToken()); + startForeground(MediaNotificationManager.NOTIFICATION_ID, notification); + MusicContainer.getInstance().play(MusicContainer.getInstance().getNowPlayData()); + } + }); + } @Override diff --git a/app/src/main/java/com/yutou/nas_music_player/tools/AppTools.java b/app/src/main/java/com/yutou/nas_music_player/tools/AppTools.java index 6966954..bfb0de6 100644 --- a/app/src/main/java/com/yutou/nas_music_player/tools/AppTools.java +++ b/app/src/main/java/com/yutou/nas_music_player/tools/AppTools.java @@ -11,10 +11,6 @@ import android.widget.Toast; import androidx.palette.graphics.Palette; import com.kaopiz.kprogresshud.KProgressHUD; -import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache; -import com.nostra13.universalimageloader.core.DisplayImageOptions; -import com.nostra13.universalimageloader.core.ImageLoader; -import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.yutou.nas_music_player.MyApplication; import com.yutou.nas_music_player.R; @@ -104,32 +100,6 @@ public class AppTools { return stringBuilder.toString(); } - private static DisplayImageOptions initDisplayOptions() { - DisplayImageOptions.Builder displayImageOptionsBuilder = new DisplayImageOptions.Builder(); - displayImageOptionsBuilder.cacheInMemory(false); - displayImageOptionsBuilder.cacheOnDisk(true); - displayImageOptionsBuilder.showImageForEmptyUri(R.drawable.ic_launcher_background); - displayImageOptionsBuilder.showImageOnFail(R.mipmap.ic_launcher); - return displayImageOptionsBuilder.build(); - } - - public static ImageLoader initImageLoader(Context context) { - if(imageLoader!=null){ - return imageLoader; - } - - imageLoader = ImageLoader.getInstance(); - ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context); - File cachePath = new File(context.getFilesDir().getAbsolutePath() + "/cache/"); - if (!cachePath.exists()) { - cachePath.exists(); - } - builder.diskCache(new UnlimitedDiskCache(cachePath)); - builder.defaultDisplayImageOptions(initDisplayOptions()); - - imageLoader.init(builder.build()); - return imageLoader; - } public static String getUrlBase64(String text) { return new String(Base64.encode(text.getBytes(), Base64.DEFAULT)).replace("\n", ""); diff --git a/app/src/main/java/com/yutou/nas_music_player/tools/ImageLoader.java b/app/src/main/java/com/yutou/nas_music_player/tools/ImageLoader.java new file mode 100644 index 0000000..1a815a9 --- /dev/null +++ b/app/src/main/java/com/yutou/nas_music_player/tools/ImageLoader.java @@ -0,0 +1,94 @@ +package com.yutou.nas_music_player.tools; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.util.Log; +import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.request.FutureTarget; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.CustomTarget; +import com.bumptech.glide.request.transition.Transition; +import com.yutou.nas_music_player.Interfaces.AbsObjectInterface; + +import java.util.concurrent.ExecutionException; + +import jp.wasabeef.glide.transformations.BlurTransformation; +import jp.wasabeef.glide.transformations.RoundedCornersTransformation; + +public class ImageLoader { + private static ImageLoader manager; + private Context context; + + private ImageLoader(Context context) { + this.context = context; + } + + public static ImageLoader getInstance(Context context) { + if (manager == null) { + manager = new ImageLoader(context); + } + return manager; + } + + public static ImageLoader getInstance() { + return manager; + } + + public void showImage(ImageView imageView, String url, int imageWidth, int imageHigh, boolean isRounded, boolean isBlurTransformation) { + Log.w("图片地址", "url: " + url); + RequestBuilder builder = Glide.with(context) + .load(url) + .placeholder(imageView.getDrawable()); + if (imageWidth != -1 && imageHigh != -1) { + builder = builder.override(imageWidth, imageHigh); + } + if (isRounded) { + builder = builder.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3))); + } + if (isBlurTransformation) { + builder = builder.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))); + } + builder.into(imageView); + } + + public void showImage(ImageView imageView, String url) { + showImage(imageView, url, -1, -1, false, false); + } + + public void showImage(ImageView imageView, String url, int imageWidth, int imageHigh) { + showImage(imageView, url, imageWidth, imageHigh, false, false); + } + + public void showImage(ImageView imageView, String url, int imageWidth, int imageHigh, boolean isRounded) { + showImage(imageView, url, imageWidth, imageHigh, isRounded, false); + } + + public void getImageBitmap(String url, int imageWidth, int imageHigh, AbsObjectInterface objectInterface) { + RequestBuilder builder = Glide.with(context) + .asBitmap() + .load(url); + if (imageWidth != -1 && imageHigh != -1) { + builder = builder.override(imageWidth, imageHigh); + } + builder.into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + objectInterface.onData(resource); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + + } + +} 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 62a8596..58496c9 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 @@ -19,7 +19,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; -import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; import com.yutou.nas_music_player.Adapters.AlbumsRecyclerAdapter; import com.yutou.nas_music_player.Datas.MusicData; import com.yutou.nas_music_player.Interfaces.NetworkInterface; @@ -27,7 +26,7 @@ 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 com.yutou.nas_music_player.tools.AppTools; +import com.yutou.nas_music_player.tools.ImageLoader; import java.util.ArrayList; import java.util.List; @@ -64,18 +63,8 @@ public class AlbumsActivity extends AppCompatActivity { } String imageUrl = getIntent().getStringExtra("image"); if (imageUrl != null) { - AppTools.initImageLoader(this).displayImage(imageUrl, album_image); - AppTools.initImageLoader(this) - .loadImage(imageUrl, new SimpleImageLoadingListener() { - @Override - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - super.onLoadingComplete(imageUri, view, loadedImage); - Glide.with(AlbumsActivity.this).load(loadedImage) - .apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))) - .into(image_background); - } - }); - + ImageLoader.getInstance(this).showImage(album_image, imageUrl, -1, -1, true); + ImageLoader.getInstance(this).showImage(image_background, imageUrl, -1, -1, false,true); } else { album_image.setImageResource(R.mipmap.ic_launcher); Glide.with(AlbumsActivity.this).load(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) @@ -105,20 +94,7 @@ public class AlbumsActivity extends AppCompatActivity { adapter.notifyDataSetChanged(); if (list.isEmpty()) return; - list.get(0).getImg(AppData.imageWidth, AppData.imageHigh, new NetworkInterface() { - @Override - public void httpGetData(Object data, int state) { - album_image.setImageBitmap((Bitmap) data); - Glide.with(AlbumsActivity.this).load(data) - .apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))) - .into(image_background); - } - - @Override - public void httpError(Exception e) { - - } - }); + ImageLoader.getInstance(AlbumsActivity.this).showImage(image_background, list.get(0).getImageUrl(), AppData.imageWidth, AppData.imageHigh, true); } @Override 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 f20856d..92bffce 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 @@ -42,6 +42,7 @@ import com.yutou.nas_music_player.containers.MusicContainer; import com.yutou.nas_music_player.tools.AppData; import com.yutou.nas_music_player.tools.AppTools; import com.yutou.nas_music_player.tools.ConfigTools; +import com.yutou.nas_music_player.tools.ImageLoader; import com.yutou.popdialog.POPDialog; import java.util.List; @@ -112,7 +113,7 @@ public class MainActivity extends AppCompatActivity { } setPlayModelButton(model + 1, true); }); - playListener=new PlayListener(); + playListener = new PlayListener(); browserHelper = MediaBrowserHelper.getInstance(); browserHelper.regPlayListener(playListener); @@ -197,28 +198,8 @@ public class MainActivity extends AppCompatActivity { private void setImage(MusicData data) { // setBarColor(data.getImageColor()); - data.getImg(AppData.imageWidth, AppData.imageHigh,new DefaultNetworkInterface(){ - @Override - public void httpGetData(Object bitmap, int state) { - super.httpGetData(data, state); - Glide.with(MainActivity.this).load(bitmap) - .placeholder(album_image.getDrawable()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3))) - .into(album_image); - Glide.with(MainActivity.this).load(bitmap) - .placeholder(background_image.getDrawable()) - .apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))) - .into(background_image); - } - }); - /* data.getImg(AppData.minImageWidth, AppData.minImageHigh,new DefaultNetworkInterface(){ - @Override - public void httpGetData(Object bitmap, int state) { - super.httpGetData(data, state); - - } - });*/ - + ImageLoader.getInstance(this).showImage(album_image, data.getImageUrl(), AppData.imageWidth, AppData.imageHigh, true); + ImageLoader.getInstance(this).showImage(background_image, data.getImageUrl(),AppData.imageWidth, AppData.imageHigh, false, true); } private void initView() { @@ -315,8 +296,8 @@ public class MainActivity extends AppCompatActivity { List playList = MusicContainer.getInstance().getPlayList(); POPDialog dialog = new POPDialog(this); RecyclerView recyclerView = null; - Button clear=new Button(this); - LinearLayout layout=new LinearLayout(this); + Button clear = new Button(this); + LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); clear.setText("清空列表"); dialog.enableExitButton(true); @@ -326,13 +307,13 @@ public class MainActivity extends AppCompatActivity { } else { dialog.setTitle("播放列表:" + playList.size()); MusicLibsAdapter adapter = new MusicLibsAdapter(this); - // ItemTouchHelper touchHelper=new ItemTouchHelper(new MusicItemTouchAdapterCallback()); + // ItemTouchHelper touchHelper=new ItemTouchHelper(new MusicItemTouchAdapterCallback()); 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); - // touchHelper.attachToRecyclerView(recyclerView); + // touchHelper.attachToRecyclerView(recyclerView); adapter.setData(playList); adapter.setBrowserHelper(browserHelper); clear.setOnClickListener(view -> { diff --git a/app/src/main/java/com/yutou/nas_music_player/views/PlayLibsActivity.java b/app/src/main/java/com/yutou/nas_music_player/views/PlayLibsActivity.java index 207e454..075ae5f 100644 --- a/app/src/main/java/com/yutou/nas_music_player/views/PlayLibsActivity.java +++ b/app/src/main/java/com/yutou/nas_music_player/views/PlayLibsActivity.java @@ -31,6 +31,7 @@ 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 com.yutou.nas_music_player.tools.ImageLoader; import com.yutou.nas_music_player.views.Fragments.MusicLibsFragment; import java.util.ArrayList; @@ -177,12 +178,6 @@ public class PlayLibsActivity extends AppCompatActivity { } - private void setImage(Bitmap data) { - Glide.with(this).load(data) - .placeholder(album_image.getDrawable()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3))) - .into(album_image); - } @SuppressLint("SetTextI18n") private void setPlayData(final MusicData data) { @@ -192,17 +187,7 @@ public class PlayLibsActivity extends AppCompatActivity { artist.setText(data.getArtist()); progressBar.setMax((int) (data.getDurationAsDouble() * 1000)); progressBar.setProgress(bar_pos); - data.getImg(AppData.minImageWidth, AppData.minImageHigh, new NetworkInterface() { - @Override - public void httpGetData(Object data, int state) { - setImage((Bitmap) data); - } - - @Override - public void httpError(Exception e) { - - } - }); + ImageLoader.getInstance(this).showImage(album_image, data.getImageUrl(), AppData.minImageWidth, AppData.minImageHigh, true); } @Override @@ -254,9 +239,5 @@ public class PlayLibsActivity extends AppCompatActivity { super.onQueueChanged(queue); System.out.println("不知道是啥变换了"); } - - public void setImage() { - - } } }