From 39020493e6c43a8b8abf573d6d692c8d3e24a7e6 Mon Sep 17 00:00:00 2001 From: litingting Date: Thu, 31 Oct 2024 18:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=96=9C=E7=88=B1=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 13 +- app/objectbox-models/default.json | 62 +++++ app/src/main/AndroidManifest.xml | 5 +- .../com/hi/music/player/MusicApplication.java | 9 + .../music/player/adapter/AdapterLikeSong.java | 75 ++++++ .../player/api/HomeItemClickListener.java | 8 +- .../hi/music/player/api/LikeSongListener.java | 10 + .../com/hi/music/player/helper/MyValue.java | 14 +- .../hi/music/player/javabean/BoxLikeSong.java | 80 ++++++ .../response/ResponsePlayListInfo.java | 21 +- .../media3/MyMediaControllerManager.java | 2 +- .../player/objectbox/ObjectBoxManager.java | 109 ++++++++ .../player/ui/activity/LikeSongActivity.java | 95 +++++++ .../player/ui/activity/PlayActivity.java | 56 ++++- .../ui/activity/ResultListActivity.java | 16 +- .../player/ui/fragmnt/ProfileFragment.java | 92 ++++++- app/src/main/res/drawable/bg_library.xml | 7 + app/src/main/res/drawable/bg_like_layout.xml | 7 + app/src/main/res/drawable/ic_download.xml | 12 + app/src/main/res/drawable/icon_download.xml | 19 ++ app/src/main/res/drawable/icon_liked.xml | 9 + .../main/res/drawable/icon_liked_white.xml | 9 + app/src/main/res/drawable/icon_not_like.xml | 9 + app/src/main/res/drawable/im_place.xml | 9 + .../main/res/drawable/play_black_gradient.xml | 8 + app/src/main/res/drawable/selector_like.xml | 6 + .../main/res/layout/activity_like_song.xml | 53 ++++ app/src/main/res/layout/activity_play.xml | 232 ++++++++++++------ app/src/main/res/layout/fragment_profile.xml | 228 ++++++++--------- app/src/main/res/layout/item_like_song.xml | 66 +++++ app/src/main/res/values/colors.xml | 3 + app/src/main/res/values/strings.xml | 7 +- build.gradle.kts | 7 + 33 files changed, 1119 insertions(+), 239 deletions(-) create mode 100644 app/objectbox-models/default.json create mode 100644 app/src/main/java/com/hi/music/player/adapter/AdapterLikeSong.java create mode 100644 app/src/main/java/com/hi/music/player/api/LikeSongListener.java create mode 100644 app/src/main/java/com/hi/music/player/javabean/BoxLikeSong.java create mode 100644 app/src/main/java/com/hi/music/player/objectbox/ObjectBoxManager.java create mode 100644 app/src/main/java/com/hi/music/player/ui/activity/LikeSongActivity.java create mode 100644 app/src/main/res/drawable/bg_library.xml create mode 100644 app/src/main/res/drawable/bg_like_layout.xml create mode 100644 app/src/main/res/drawable/ic_download.xml create mode 100644 app/src/main/res/drawable/icon_download.xml create mode 100644 app/src/main/res/drawable/icon_liked.xml create mode 100644 app/src/main/res/drawable/icon_liked_white.xml create mode 100644 app/src/main/res/drawable/icon_not_like.xml create mode 100644 app/src/main/res/drawable/im_place.xml create mode 100644 app/src/main/res/drawable/play_black_gradient.xml create mode 100644 app/src/main/res/drawable/selector_like.xml create mode 100644 app/src/main/res/layout/activity_like_song.xml create mode 100644 app/src/main/res/layout/item_like_song.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4737347..26bae0b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,8 @@ plugins { id("com.android.application") +// id("org.jetbrains.kotlin.android") +// id ("kotlin-kapt") + id("io.objectbox") } android { @@ -26,6 +29,9 @@ android { ) } } +// kotlinOptions{ +// jvmTarget = "1.8" +// } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -56,7 +62,7 @@ dependencies { implementation("androidx.paging:paging-runtime-ktx:3.3.2") implementation("com.github.bumptech.glide:glide:4.16.0") - annotationProcessor("com.github.bumptech.glide:compiler:4.16.0") +// kapt("com.github.bumptech.glide:compiler:4.16.0") // Glide 的图片变换库,包括高斯模糊 implementation ("jp.wasabeef:glide-transformations:4.3.0") @@ -75,6 +81,7 @@ dependencies { //----------media3 - implementation ("com.geyifeng.immersionbar:immersionbar:3.2.2") - implementation ("com.geyifeng.immersionbar:immersionbar-components:3.2.2") + +// implementation ("com.geyifeng.immersionbar:immersionbar:3.2.2") +// implementation ("com.geyifeng.immersionbar:immersionbar-components:3.2.2") } \ No newline at end of file diff --git a/app/objectbox-models/default.json b/app/objectbox-models/default.json new file mode 100644 index 0000000..e08abd4 --- /dev/null +++ b/app/objectbox-models/default.json @@ -0,0 +1,62 @@ +{ + "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", + "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", + "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", + "entities": [ + { + "id": "1:7260744904384376845", + "lastPropertyId": "7:5800407979727692220", + "name": "BoxLikeSong", + "properties": [ + { + "id": "1:745788217094734749", + "name": "id", + "type": 6, + "flags": 1 + }, + { + "id": "2:2477600117284929424", + "name": "songName", + "type": 9 + }, + { + "id": "3:79559302744310012", + "name": "singerName", + "type": 9 + }, + { + "id": "4:5779546109489824553", + "name": "videoId", + "type": 9 + }, + { + "id": "5:2803528372963628007", + "name": "covert", + "type": 9 + }, + { + "id": "6:3852926266057742085", + "name": "durationMs", + "type": 6 + }, + { + "id": "7:5800407979727692220", + "name": "duration", + "type": 9 + } + ], + "relations": [] + } + ], + "lastEntityId": "1:7260744904384376845", + "lastIndexId": "0:0", + "lastRelationId": "0:0", + "lastSequenceId": "0:0", + "modelVersion": 5, + "modelVersionParserMinimum": 5, + "retiredEntityUids": [], + "retiredIndexUids": [], + "retiredPropertyUids": [], + "retiredRelationUids": [], + "version": 1 +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 33d41eb..523258f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,6 +22,9 @@ android:supportsRtl="true" android:theme="@style/Theme.MusicApp" tools:targetApi="31"> + @@ -41,7 +44,7 @@ + android:screenOrientation="portrait" /> diff --git a/app/src/main/java/com/hi/music/player/MusicApplication.java b/app/src/main/java/com/hi/music/player/MusicApplication.java index 46c77e4..ecc6130 100644 --- a/app/src/main/java/com/hi/music/player/MusicApplication.java +++ b/app/src/main/java/com/hi/music/player/MusicApplication.java @@ -5,7 +5,11 @@ import android.content.Context; import com.hi.music.player.api.MediaControllerStatusListener; import com.hi.music.player.helper.CommonUtils; +import com.hi.music.player.javabean.MyObjectBox; import com.hi.music.player.media3.MyMediaControllerManager; +import com.hi.music.player.objectbox.ObjectBoxManager; + +import io.objectbox.BoxStore; public class MusicApplication extends Application { @@ -16,6 +20,8 @@ public class MusicApplication extends Application { public static String visitorData; + + public static void setVisitorData(String visitorData) { MusicApplication.visitorData = visitorData; } @@ -28,6 +34,7 @@ public class MusicApplication extends Application { public void onCreate() { super.onCreate(); myApplication = this; + ObjectBoxManager.init(this); MyMediaControllerManager.getInstance().init(new MediaControllerStatusListener() { @Override public void onMediaControllerComplete(boolean isOk) { @@ -35,4 +42,6 @@ public class MusicApplication extends Application { } }); } + + } diff --git a/app/src/main/java/com/hi/music/player/adapter/AdapterLikeSong.java b/app/src/main/java/com/hi/music/player/adapter/AdapterLikeSong.java new file mode 100644 index 0000000..73b16f3 --- /dev/null +++ b/app/src/main/java/com/hi/music/player/adapter/AdapterLikeSong.java @@ -0,0 +1,75 @@ +package com.hi.music.player.adapter; + +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.Target; +import com.hi.music.player.MusicApplication; +import com.hi.music.player.R; +import com.hi.music.player.databinding.ItemLikeSongBinding; +import com.hi.music.player.databinding.ItemSingerBinding; +import com.hi.music.player.helper.CommonUtils; +import com.hi.music.player.javabean.BoxLikeSong; +import com.hi.music.player.javabean.response.child.ResponseSingle; + +public class AdapterLikeSong extends BaseAdapter { + + @Override + protected ItemLikeSongBinding getViewBinding(ViewGroup parent) { + return ItemLikeSongBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + VHolder itemHolder = (VHolder) holder; + ItemLikeSongBinding vb = itemHolder.getVb(); + BoxLikeSong boxLikeSong = data.get(position); + + + Glide.with(MusicApplication.myApplication) + .asDrawable() + .load(boxLikeSong.getCovert()) + .apply(RequestOptions.bitmapTransform(new RoundedCorners(CommonUtils.dpToPx(4)))) + .placeholder(R.drawable.placeholder) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target target, boolean isFirstResource) { + CommonUtils.LogMsg(e.getMessage()); + return false; + } + + @Override + public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target target, @NonNull DataSource dataSource, boolean isFirstResource) { + return false; + } + }) + .into(vb.imCovert); + vb.tvTitle.setText(boxLikeSong.getSongName()); + vb.tvSingerName.setText(boxLikeSong.getSingerName()); + + vb.getRoot().setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(homeItemClickListener!= null){ + int absoluteAdapterPosition = itemHolder.getAbsoluteAdapterPosition(); + homeItemClickListener.onClickLikeSong(boxLikeSong,absoluteAdapterPosition); + } + } + }); + + } + + +} diff --git a/app/src/main/java/com/hi/music/player/api/HomeItemClickListener.java b/app/src/main/java/com/hi/music/player/api/HomeItemClickListener.java index 8fe1d6d..242b5bf 100644 --- a/app/src/main/java/com/hi/music/player/api/HomeItemClickListener.java +++ b/app/src/main/java/com/hi/music/player/api/HomeItemClickListener.java @@ -1,5 +1,6 @@ package com.hi.music.player.api; +import com.hi.music.player.javabean.BoxLikeSong; import com.hi.music.player.javabean.response.ResponsePlayListInfo; import com.hi.music.player.javabean.response.ResponseSearch; import com.hi.music.player.javabean.response.child.ResponseCategory; @@ -47,7 +48,7 @@ public interface HomeItemClickListener { } /** - * 点击搜索结果第 + * 点击搜索结果 * @param */ default void onClickSearchResult(ResponseSearchChild responseSearchChild){ @@ -66,4 +67,9 @@ public interface HomeItemClickListener { } + + default void onClickLikeSong(BoxLikeSong boxLikeSong, int index){ + + } + } diff --git a/app/src/main/java/com/hi/music/player/api/LikeSongListener.java b/app/src/main/java/com/hi/music/player/api/LikeSongListener.java new file mode 100644 index 0000000..ef28c33 --- /dev/null +++ b/app/src/main/java/com/hi/music/player/api/LikeSongListener.java @@ -0,0 +1,10 @@ +package com.hi.music.player.api; + +import com.hi.music.player.javabean.BoxLikeSong; + +import java.util.List; + +public interface LikeSongListener { + + void onLikeSongChange(List data); +} diff --git a/app/src/main/java/com/hi/music/player/helper/MyValue.java b/app/src/main/java/com/hi/music/player/helper/MyValue.java index 94c6764..9b66f5d 100644 --- a/app/src/main/java/com/hi/music/player/helper/MyValue.java +++ b/app/src/main/java/com/hi/music/player/helper/MyValue.java @@ -41,8 +41,16 @@ public class MyValue { */ public static String KEY_PLAY_ACTIVITY_MV = "click_mv"; + /** + * 进入PlayActivity传递的即将播放的歌曲videoId + */ + public static String KEY_PLAY_VIDEO_ID = "video_id"; - + /** + * 进入PlayActivity传递的即将播放的歌曲index(针对在进入PlayActivity之前已经调用vmApplication.reSetPlayList + * 重置了播放列表的情况) + */ + public static String KEY_PLAY_INDEX = "play_index"; @@ -79,6 +87,10 @@ public class MyValue { public final static int TYPE_ENTER_PANEL = 3; + //从喜爱歌曲进入 + public final static int TYPE_ENTER_LIKE= 4; + + //-----------------------------PlayActivity diff --git a/app/src/main/java/com/hi/music/player/javabean/BoxLikeSong.java b/app/src/main/java/com/hi/music/player/javabean/BoxLikeSong.java new file mode 100644 index 0000000..4a6612d --- /dev/null +++ b/app/src/main/java/com/hi/music/player/javabean/BoxLikeSong.java @@ -0,0 +1,80 @@ +package com.hi.music.player.javabean; + +import io.objectbox.annotation.Entity; +import io.objectbox.annotation.Id; + +@Entity +public class BoxLikeSong { + @Id + public long id; + private String songName; + + private String singerName; + private String videoId; + + private String covert; + private long durationMs; + private String duration ; + + + + public BoxLikeSong( ) { + + } + + public BoxLikeSong(String songName, String singerName, String videoId, String covert,long durationMs,String duration) { + this.songName = songName; + this.singerName = singerName; + this.videoId = videoId; + this.covert = covert; + this.durationMs = durationMs; + this.duration = duration; + } + + + public long getDurationMs() { + return durationMs; + } + public String getDuration() { + return duration; + } + + public void setDuration(String duration) { + this.duration = duration; + } + public void setDurationMs(long durationMs) { + this.durationMs = durationMs; + } + + public String getSingerName() { + return singerName; + } + + public void setSingerName(String singerName) { + this.singerName = singerName; + } + + public String getVideoId() { + return videoId; + } + + public void setVideoId(String videoId) { + this.videoId = videoId; + } + + public String getCovert() { + return covert; + } + + public void setCovert(String covert) { + this.covert = covert; + } + + public String getSongName() { + return songName; + } + + public void setSongName(String songName) { + this.songName = songName; + } +} diff --git a/app/src/main/java/com/hi/music/player/javabean/response/ResponsePlayListInfo.java b/app/src/main/java/com/hi/music/player/javabean/response/ResponsePlayListInfo.java index 561a5f5..bf72860 100644 --- a/app/src/main/java/com/hi/music/player/javabean/response/ResponsePlayListInfo.java +++ b/app/src/main/java/com/hi/music/player/javabean/response/ResponsePlayListInfo.java @@ -43,19 +43,18 @@ public class ResponsePlayListInfo implements Serializable { private String params; private String musicVideoType; + public ResponsePlayListInfo() { -// -// //------------自定义属性,由另外接口请求返回的数据流组装 -// private String audioUrlLow; -// -// private String audioUrlMedium; - - - - - - + } + public ResponsePlayListInfo(String covert, String songTitle, String singerName, long durationMs, String videoId,String duration) { + this.covert = covert; + SongTitle = songTitle; + SingerName = singerName; + DurationMs = durationMs; + this.Duration = duration; + this.videoId = videoId; + } public String getDescribe() { return describe; diff --git a/app/src/main/java/com/hi/music/player/media3/MyMediaControllerManager.java b/app/src/main/java/com/hi/music/player/media3/MyMediaControllerManager.java index ac6a1dc..8626f2b 100644 --- a/app/src/main/java/com/hi/music/player/media3/MyMediaControllerManager.java +++ b/app/src/main/java/com/hi/music/player/media3/MyMediaControllerManager.java @@ -330,7 +330,7 @@ public class MyMediaControllerManager { MediaMetadata_builder.setArtworkUri(Uri.parse(playInfo.getCovert())); MediaMetadata_builder.setTitle(playInfo.getSongTitle()); - CommonUtils.LogMsg("----------添加播放列表 i=" + i + "---" + playInfo.getSingerName() + "-------VideoId=" + videoId); + CommonUtils.LogMsg("----------添加播放列表 i=" + i + "---" + playInfo.getSingerName() + "-------VideoId=" + videoId+"---playInfo.getDuration()="+playInfo.getDuration()); // MediaMetadata_builder.setRecordingYear(Integer.parseInt(playInfo.getYear())); builder.setMediaMetadata(MediaMetadata_builder.build()); mediaController.addMediaItem(builder.build()); diff --git a/app/src/main/java/com/hi/music/player/objectbox/ObjectBoxManager.java b/app/src/main/java/com/hi/music/player/objectbox/ObjectBoxManager.java new file mode 100644 index 0000000..b61d67e --- /dev/null +++ b/app/src/main/java/com/hi/music/player/objectbox/ObjectBoxManager.java @@ -0,0 +1,109 @@ +package com.hi.music.player.objectbox; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.hi.music.player.api.LikeSongListener; +import com.hi.music.player.helper.CommonUtils; +import com.hi.music.player.javabean.BoxLikeSong; +import com.hi.music.player.javabean.BoxLikeSong_; +import com.hi.music.player.javabean.MyObjectBox; + +import java.util.List; + +import io.objectbox.Box; +import io.objectbox.BoxStore; +import io.objectbox.android.AndroidScheduler; +import io.objectbox.query.Query; +import io.objectbox.query.QueryBuilder; +import io.objectbox.reactive.DataObserver; +import io.objectbox.reactive.DataSubscription; +import io.objectbox.reactive.DataSubscriptionList; + +public class ObjectBoxManager { + + private static BoxStore boxStore; + + private static Box boxLikeSongBox; + + private static DataSubscription observer; + + + public static void init(Context context) { + boxStore = MyObjectBox.builder().androidContext(context).build(); + } + + public static Box getObjectBoxLike() { + if (boxLikeSongBox == null) { + return boxStore.boxFor(BoxLikeSong.class); + } + return boxLikeSongBox; + } + + public static DataSubscription setLikeDataListener(LikeSongListener listener) { + Query build = getObjectBoxLike().query().build(); + return build.subscribe(new DataSubscriptionList()) + .on(AndroidScheduler.mainThread()) + .observer(new DataObserver>() { + @Override + public void onData(@NonNull List data) { + CommonUtils.LogMsg("------ProfileFragment 11data=" + data.size()); + listener.onLikeSongChange(data); + } + }); + + } + + public static void insertOrUpdateLike(BoxLikeSong boxLikeSong) { + Box objectBoxLike = getObjectBoxLike(); + String videoId = boxLikeSong.getVideoId(); + BoxLikeSong first = objectBoxLike.query() + .equal(BoxLikeSong_.videoId, videoId, QueryBuilder.StringOrder.CASE_SENSITIVE) + .build() + .findFirst(); + if (first == null) { + CommonUtils.LogErrorMsg("-----------添加 song=" + boxLikeSong.getSongName() + "---videoId=" + videoId); + objectBoxLike.put(boxLikeSong); + } else { + CommonUtils.LogErrorMsg("-----------已经存在 song=" + boxLikeSong.getSongName() + "---videoId=" + videoId); + } + + } + + + public static void deleteLike(BoxLikeSong boxLikeSong) { + Box objectBoxLike = getObjectBoxLike(); + String videoId = boxLikeSong.getVideoId(); + List boxLikeSongs = objectBoxLike.query() + .equal(BoxLikeSong_.videoId, videoId, QueryBuilder.StringOrder.CASE_SENSITIVE) + .build() + .find(); + for (BoxLikeSong song : boxLikeSongs) { + objectBoxLike.remove(song); + CommonUtils.LogErrorMsg("-------onLikeSongChange-deleteLike song=" + song.getSongName()); + } + + } + + public static List queryAllLike() { + return getObjectBoxLike().query() + .build() + .find(); + } + + public static boolean queryIsLike(String videoId) { + Box objectBoxLike = getObjectBoxLike(); + BoxLikeSong first = objectBoxLike.query() + .equal(BoxLikeSong_.videoId, videoId, QueryBuilder.StringOrder.CASE_SENSITIVE) + .build() + .findFirst(); + if (first == null) { + return false; + } else { + return true; + } + + } + +} diff --git a/app/src/main/java/com/hi/music/player/ui/activity/LikeSongActivity.java b/app/src/main/java/com/hi/music/player/ui/activity/LikeSongActivity.java new file mode 100644 index 0000000..d2985c3 --- /dev/null +++ b/app/src/main/java/com/hi/music/player/ui/activity/LikeSongActivity.java @@ -0,0 +1,95 @@ +package com.hi.music.player.ui.activity; + +import android.content.Intent; +import android.view.View; + +import androidx.recyclerview.widget.LinearLayoutManager; + +import com.hi.music.player.R; +import com.hi.music.player.adapter.AdapterLikeSong; +import com.hi.music.player.api.HomeItemClickListener; +import com.hi.music.player.databinding.ActivityLikeSongBinding; +import com.hi.music.player.helper.CommonUtils; +import com.hi.music.player.helper.MyValue; +import com.hi.music.player.javabean.BoxLikeSong; +import com.hi.music.player.javabean.response.ResponsePlayListInfo; +import com.hi.music.player.objectbox.ObjectBoxManager; + +import java.util.ArrayList; +import java.util.List; + +public class LikeSongActivity extends BaseActivity implements HomeItemClickListener { + + + private List boxLikeSongs; + @Override + protected ActivityLikeSongBinding getViewBinding() { + return ActivityLikeSongBinding.inflate(getLayoutInflater()); + } + + @Override + protected void onCreateInit() { + boxLikeSongs = ObjectBoxManager.queryAllLike(); + AdapterLikeSong adapterLikeSong = new AdapterLikeSong(); + adapterLikeSong.setHomeItemClickListener(this); + adapterLikeSong.setData(boxLikeSongs); + vb.recycler.setLayoutManager(new LinearLayoutManager(this)); + vb.recycler.setAdapter(adapterLikeSong); + vb.tvSongSize.setText(String.format(getString(R.string.like_song), boxLikeSongs.size())); + } + + @Override + protected void onInitClick() { + vb.imBack.setOnClickListener(this); + } + + @Override + public boolean isFullScreen() { + return true; + } + + @Override + public boolean statusBarLight() { + return false; + } + + @Override + public boolean showPanel() { + return false; + } + + @Override + public void onClick(View v) { + if(v.equals(vb.imBack)){ + finish(); + } + } + + @Override + public void onClickLikeSong(BoxLikeSong boxLikeSong, int index) { + List playList = new ArrayList<>(); + for(BoxLikeSong song:boxLikeSongs){ + String videoId1 = song.getVideoId(); + String songName = song.getSongName(); + String covert = song.getCovert(); + String singerName = song.getSingerName(); + long durationMs = song.getDurationMs(); + String duration = song.getDuration(); + + ResponsePlayListInfo playListInfo = new ResponsePlayListInfo(covert, songName, singerName, durationMs, videoId1,duration); + playList.add(playListInfo); + } + vmApplication.reSetPlayList(playList); + + String videoId = boxLikeSong.getVideoId(); + CommonUtils.LogMsg("-------------like进入 传值 videoId= "+videoId); + Intent intent = new Intent(this, PlayActivity.class); + intent.putExtra(MyValue.KEY_PLAY_VIDEO_ID, videoId); + intent.putExtra(MyValue.KEY_PLAY_INDEX, index); + intent.putExtra(MyValue.KEY_ENTER_SOURCE, MyValue.TYPE_ENTER_LIKE); + startActivity(intent); + + + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hi/music/player/ui/activity/PlayActivity.java b/app/src/main/java/com/hi/music/player/ui/activity/PlayActivity.java index 36caf89..4d18b30 100644 --- a/app/src/main/java/com/hi/music/player/ui/activity/PlayActivity.java +++ b/app/src/main/java/com/hi/music/player/ui/activity/PlayActivity.java @@ -32,18 +32,21 @@ import com.bumptech.glide.request.target.Target; import com.hi.music.player.MusicApplication; import com.hi.music.player.R; import com.hi.music.player.adapter.AdapterPlayList; +import com.hi.music.player.api.LikeSongListener; import com.hi.music.player.api.MediaControllerListener; import com.hi.music.player.api.onImageColorListener; import com.hi.music.player.api.onPlayNextListener; import com.hi.music.player.databinding.ActivityPlayBinding; import com.hi.music.player.helper.CommonUtils; import com.hi.music.player.helper.MyValue; +import com.hi.music.player.javabean.BoxLikeSong; import com.hi.music.player.javabean.CustomerUrlInfo; import com.hi.music.player.javabean.response.ResponsePlayListInfo; import com.hi.music.player.javabean.response.ResponsePlayUrl; import com.hi.music.player.javabean.response.child.ResponseCategory; import com.hi.music.player.javabean.response.child.ResponseSingle; import com.hi.music.player.media3.MyMediaControllerManager; +import com.hi.music.player.objectbox.ObjectBoxManager; import com.hi.music.player.ui.activity.viewmodel.VMApplication; import com.hi.music.player.ui.activity.viewmodel.VMPlay; @@ -168,6 +171,14 @@ public class PlayActivity extends BaseActivity implements S vb.progressBarLoading.setVisibility(View.GONE); vb.btnPlay.setSelected(mediaControllerManager.getIsPlaying()); break; + + case MyValue.TYPE_ENTER_LIKE: + // 4--从喜爱歌曲进入 + updateMediaPlayList(); + videoId = intent.getStringExtra(MyValue.KEY_PLAY_VIDEO_ID); + mDefaultPlayStartIndex = intent.getIntExtra(MyValue.KEY_PLAY_INDEX, mDefaultPlayStartIndex); + CommonUtils.LogMsg("-------------like进入 videoId= "+videoId+"---mDefaultPlayStartIndex="+mDefaultPlayStartIndex); + break; } @@ -177,7 +188,7 @@ public class PlayActivity extends BaseActivity implements S if (customerUrlInfo.isNeedPlayNow() && customerUrlInfo.getPlayUrl() == null) { // TODO: 2024/9/26 需要马上播放这首歌曲,但是此次网络请求失败 CommonUtils.LogErrorMsg("-------------需要马上播放这首歌曲,但是此次网络请求失败"); - updateErrorLayout(getString(R.string.song_loading_failed),true); + updateErrorLayout(getString(R.string.song_loading_failed), true); netError = 1; mCustomerUrlInfo = customerUrlInfo; initShowPlayList(false); @@ -193,6 +204,8 @@ public class PlayActivity extends BaseActivity implements S } } }); + + } @@ -203,13 +216,13 @@ public class PlayActivity extends BaseActivity implements S if (playList == null) { CommonUtils.LogErrorMsg("--------更新-playList null"); netError = 0; - updateErrorLayout(getString(R.string.playList_loading_failed),true); + updateErrorLayout(getString(R.string.playList_loading_failed), true); vb.progressBarLoading.setVisibility(View.GONE); return; } CommonUtils.LogMsg("--------更新-playList " + playList.size() + "--videoId=" + videoId); if (playList.size() > 0) { - updateErrorLayout(null,false); + updateErrorLayout(null, false); setPlayListAndGetUrl(playList, videoId, mDefaultPlayStartIndex); } @@ -222,7 +235,7 @@ public class PlayActivity extends BaseActivity implements S vb.layoutError.linearRetry.setVisibility(View.VISIBLE); else vb.layoutError.linearRetry.setVisibility(View.GONE); - if(msg!= null&&!msg.isEmpty()){ + if (msg != null && !msg.isEmpty()) { vb.layoutError.tvErrorMsg.setText(msg); } } @@ -249,7 +262,7 @@ public class PlayActivity extends BaseActivity implements S private void initMediaController() { int repeatMode = mediaControllerManager.getRepeatMode(); - CommonUtils.LogMsg("-------------repeatMode="+repeatMode); + CommonUtils.LogMsg("-------------repeatMode=" + repeatMode); vb.btnLoop.setImageResource(imageStates[repeatMode]); mediaControllerManager.addListener(vmApplication, new MediaControllerListener() { @Override @@ -289,7 +302,7 @@ public class PlayActivity extends BaseActivity implements S CommonUtils.LogMsg("------------- 播放ing getCurIndex=" + mediaControllerManager.getCurIndex()); vb.progressBarLoading.setVisibility(View.GONE); - updateErrorLayout(null,false); + updateErrorLayout(null, false); vb.btnPlay.setSelected(true); vb.layoutPlayList.imPlay.setSelected(true); break; @@ -332,6 +345,8 @@ public class PlayActivity extends BaseActivity implements S vb.btnMusicList.setOnClickListener(this); vb.layoutError.tvRetry.setOnClickListener(this); vb.btnLoop.setOnClickListener(this); + vb.layoutLike.setOnClickListener(this); + vb.layoutDownload.setOnClickListener(this); } @@ -367,7 +382,7 @@ public class PlayActivity extends BaseActivity implements S private void loadInfo(MediaItem mediaItem) { MediaMetadata mediaMetadata = mediaItem.mediaMetadata; - CommonUtils.LogMsg("--------------加载当前播放歌曲信息 "); + CommonUtils.LogMsg("--------------加载当前播放歌曲信息 mediaMetadata.description="+mediaMetadata.description); if (mediaMetadata.artworkUri != null) { loadCovert(mediaMetadata.artworkUri.toString()); } @@ -384,6 +399,10 @@ public class PlayActivity extends BaseActivity implements S updatePlayListUi(); } + //刷新当前歌曲的喜爱状态 + boolean isLike = ObjectBoxManager.queryIsLike(mediaItem.mediaId); + vb.imLike.setSelected(isLike); + } private void loadCovert(String url) { @@ -484,6 +503,7 @@ public class PlayActivity extends BaseActivity implements S return false; } + @OptIn(markerClass = UnstableApi.class) @Override public void onClick(View v) { if (v.equals(vb.btnPlay)) { @@ -521,7 +541,7 @@ public class PlayActivity extends BaseActivity implements S } } else if (v.equals(vb.layoutError.tvRetry)) { //重试按钮 - updateErrorLayout(null,false); + updateErrorLayout(null, false); switch (netError) { case 0: switch (mEnterType) { @@ -557,6 +577,26 @@ public class PlayActivity extends BaseActivity implements S vb.btnLoop.setImageResource(imageStates[currentMode]); CommonUtils.LogMsg("----currentMode=" + currentMode); mediaControllerManager.setMode(currentMode); + } else if (v.equals(vb.layoutLike)) { + boolean selected = vb.imLike.isSelected(); + vb.imLike.setSelected(!selected); + boolean newSelect = vb.imLike.isSelected(); + MediaItem curMediaItem = mediaControllerManager.getCurMediaItem(); + MediaMetadata mediaMetadata = curMediaItem.mediaMetadata; + if (mediaMetadata.title != null && mediaMetadata.artist != null&&mediaMetadata.durationMs!= null&&mediaMetadata.description!= null) { + BoxLikeSong boxLikeSong = new BoxLikeSong(mediaMetadata.title.toString(), + mediaMetadata.artist.toString(), + curMediaItem.mediaId, + String.valueOf(mediaMetadata.artworkUri), + mediaMetadata.durationMs,mediaMetadata.description.toString()); + if (newSelect) { + ObjectBoxManager.insertOrUpdateLike(boxLikeSong); + } else { + ObjectBoxManager.deleteLike(boxLikeSong); + } + } + + } } diff --git a/app/src/main/java/com/hi/music/player/ui/activity/ResultListActivity.java b/app/src/main/java/com/hi/music/player/ui/activity/ResultListActivity.java index be137ea..64d6fb6 100644 --- a/app/src/main/java/com/hi/music/player/ui/activity/ResultListActivity.java +++ b/app/src/main/java/com/hi/music/player/ui/activity/ResultListActivity.java @@ -161,12 +161,12 @@ public class ResultListActivity extends BaseActivity } - @Override - public void onClickResultAlbum(ResponseResultListChild child, int index) { - Intent intent = new Intent(this, CategoryListActivity.class); -// intent.putExtra(MyValue.KEY_CATEGORY_LIST_TYPE, pageType); - intent.putExtra(MyValue.KEY_CATEGORY_LIST_SINGER_NAME, child.getSongName()); - intent.putExtra(MyValue.KEY_CATEGORY_LIST_BROWSER_ID, child.getBrowserId()); - startActivity(intent); - } +// @Override +// public void onClickResultAlbum(ResponseResultListChild child, int index) { +// Intent intent = new Intent(this, CategoryListActivity.class); +//// intent.putExtra(MyValue.KEY_CATEGORY_LIST_TYPE, pageType); +// intent.putExtra(MyValue.KEY_CATEGORY_LIST_SINGER_NAME, child.getSongName()); +// intent.putExtra(MyValue.KEY_CATEGORY_LIST_BROWSER_ID, child.getBrowserId()); +// startActivity(intent); +// } } \ No newline at end of file diff --git a/app/src/main/java/com/hi/music/player/ui/fragmnt/ProfileFragment.java b/app/src/main/java/com/hi/music/player/ui/fragmnt/ProfileFragment.java index b99b884..12b27f4 100644 --- a/app/src/main/java/com/hi/music/player/ui/fragmnt/ProfileFragment.java +++ b/app/src/main/java/com/hi/music/player/ui/fragmnt/ProfileFragment.java @@ -1,18 +1,108 @@ package com.hi.music.player.ui.fragmnt; +import static com.hi.music.player.javabean.BoxLikeSong_.covert; + +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.target.Target; +import com.hi.music.player.MusicApplication; +import com.hi.music.player.R; +import com.hi.music.player.api.LikeSongListener; import com.hi.music.player.databinding.FragmentProfileBinding; +import com.hi.music.player.helper.CommonUtils; +import com.hi.music.player.javabean.BoxLikeSong; +import com.hi.music.player.objectbox.ObjectBoxManager; +import com.hi.music.player.ui.activity.LikeSongActivity; + +import java.util.List; + +import io.objectbox.reactive.DataSubscription; -public class ProfileFragment extends BaseFragment { +public class ProfileFragment extends BaseFragment implements View.OnClickListener{ + private DataSubscription dataSubscription; + + private int likeSongSCount = 0; @Override protected FragmentProfileBinding getFragmentVb() { return FragmentProfileBinding.inflate(getLayoutInflater()); } + + + @Override protected void initView() { + dataSubscription = ObjectBoxManager.setLikeDataListener(new LikeSongListener() { + @Override + public void onLikeSongChange(List data) { + CommonUtils.LogMsg("------onLikeSongChange data=" + data.size()); + int size = data.size(); + likeSongSCount = size; + Vb.tvLikeSize.setText(String.format(getString(R.string.like_song), size)); + if (size == 0) { + Vb.likeCovert.setVisibility(View.GONE); + Vb.likeDefault.setVisibility(View.VISIBLE); + } else { + Vb.likeCovert.setVisibility(View.VISIBLE); + Vb.likeDefault.setVisibility(View.GONE); + BoxLikeSong boxLikeSong = data.get(size - 1); + Glide.with(requireContext()) + .asDrawable() + .load(boxLikeSong.getCovert()) + .placeholder(R.drawable.placeholder) + .error(R.drawable.placeholder) + .into(Vb.likeCovert); + } + } + }); + + Vb.relayoutLike.setOnClickListener(this); + Vb.relayoutDownload.setOnClickListener(this); + } + + @Override + public void onStart() { + super.onStart(); + CommonUtils.LogMsg("------ProfileFragment-onStart"); + + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + if(dataSubscription!= null){ + dataSubscription.cancel(); + } + CommonUtils.LogMsg("------ProfileFragment-onDestroyView"); + } + + @Override + public void onDestroy() { + super.onDestroy(); + CommonUtils.LogMsg("------ProfileFragment-onDestroy"); + } + + @Override + public void onClick(View v) { + if(v.equals(Vb.relayoutLike)){ + if(likeSongSCount>0){ + Intent intent = new Intent(requireActivity(), LikeSongActivity.class); + startActivity(intent); + } + } } } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_library.xml b/app/src/main/res/drawable/bg_library.xml new file mode 100644 index 0000000..7938f56 --- /dev/null +++ b/app/src/main/res/drawable/bg_library.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_like_layout.xml b/app/src/main/res/drawable/bg_like_layout.xml new file mode 100644 index 0000000..052ada0 --- /dev/null +++ b/app/src/main/res/drawable/bg_like_layout.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_download.xml b/app/src/main/res/drawable/ic_download.xml new file mode 100644 index 0000000..e9918f7 --- /dev/null +++ b/app/src/main/res/drawable/ic_download.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/icon_download.xml b/app/src/main/res/drawable/icon_download.xml new file mode 100644 index 0000000..a5161c8 --- /dev/null +++ b/app/src/main/res/drawable/icon_download.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/app/src/main/res/drawable/icon_liked.xml b/app/src/main/res/drawable/icon_liked.xml new file mode 100644 index 0000000..2445315 --- /dev/null +++ b/app/src/main/res/drawable/icon_liked.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/icon_liked_white.xml b/app/src/main/res/drawable/icon_liked_white.xml new file mode 100644 index 0000000..e7666ac --- /dev/null +++ b/app/src/main/res/drawable/icon_liked_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/icon_not_like.xml b/app/src/main/res/drawable/icon_not_like.xml new file mode 100644 index 0000000..6b5fe93 --- /dev/null +++ b/app/src/main/res/drawable/icon_not_like.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/im_place.xml b/app/src/main/res/drawable/im_place.xml new file mode 100644 index 0000000..c6fdfa1 --- /dev/null +++ b/app/src/main/res/drawable/im_place.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/play_black_gradient.xml b/app/src/main/res/drawable/play_black_gradient.xml new file mode 100644 index 0000000..dd3a561 --- /dev/null +++ b/app/src/main/res/drawable/play_black_gradient.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_like.xml b/app/src/main/res/drawable/selector_like.xml new file mode 100644 index 0000000..e5c716a --- /dev/null +++ b/app/src/main/res/drawable/selector_like.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_like_song.xml b/app/src/main/res/layout/activity_like_song.xml new file mode 100644 index 0000000..28ada3b --- /dev/null +++ b/app/src/main/res/layout/activity_like_song.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_play.xml b/app/src/main/res/layout/activity_play.xml index ccac461..43cf9bc 100644 --- a/app/src/main/res/layout/activity_play.xml +++ b/app/src/main/res/layout/activity_play.xml @@ -8,6 +8,11 @@ android:background="@color/black" tools:context=".ui.activity.PlayActivity"> + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + + + app:layout_constraintTop_toTopOf="@id/card_playerView" /> - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="@id/card_playerView" /> + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/layout_like" /> - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 7c43f94..a77259e 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="#1e2b28" + android:background="@color/black" tools:context=".ui.fragmnt.ProfileFragment"> @@ -13,7 +13,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center_vertical" - android:paddingStart="16dp" + android:paddingStart="15dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:text="@string/library" @@ -32,148 +32,128 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - - - - + android:layout_height="match_parent"> + - + android:layout_width="80dp" + android:layout_height="80dp" + android:src="@drawable/im_place" + android:layout_centerInParent="true" + android:id="@+id/like_default"/> - - + - - + - + + + + - + + + + android:layout_height="160dp" + android:layout_marginEnd="15dp" + app:cardBackgroundColor="@color/library_color" + app:cardCornerRadius="16dp" + app:layout_constraintHorizontal_weight="1" + app:layout_constraintLeft_toRightOf="@id/view" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="@id/like_song"> - - + android:layout_height="match_parent"> - - + android:id="@+id/download_default" + android:layout_width="80dp" + android:layout_height="80dp" + android:layout_centerInParent="true" + android:src="@drawable/im_place" /> - - + - - + - + + - - + - - - - - - - diff --git a/app/src/main/res/layout/item_like_song.xml b/app/src/main/res/layout/item_like_song.xml new file mode 100644 index 0000000..08e60c0 --- /dev/null +++ b/app/src/main/res/layout/item_like_song.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9752ca4..839cf76 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -6,6 +6,8 @@ #FFFFFF #DFD0D0 #26000000 + #99000000 + #33FFFFFF #4DFFFFFF #99FFFFFF #59FFFFFF @@ -14,6 +16,7 @@ #FF424242 #80F988 #E03D3D3F + #242529 #99000000 #000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95feed5..ff32a6b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,7 +8,7 @@ Trending in Shorts New Releases Musicoo - Profile + Library Listen Music Anytime Resource Loading... Ready to sleep @@ -32,4 +32,9 @@ Playlist loading failed %d:%02d:%02d %d:%02d + Like + Download + Songs %d + Offline %d + Favorite Songs \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ac1a937..564f71e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,11 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id("com.android.application") version "8.1.3" apply false +// id("org.jetbrains.kotlin.android") version "1.9.22" apply false +} + +buildscript { + dependencies { + classpath("io.objectbox:objectbox-gradle-plugin:4.0.3") + } } \ No newline at end of file