From 22cd5b5e30d28638a5fe258ceeb2398ee438f702 Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Tue, 26 Dec 2023 12:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=96=9C=E6=AC=A2=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E9=80=BB=E8=BE=91=E5=92=8C=E5=82=A8=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 +- app/debug/output-metadata.json | 4 +- app/src/main/java/com/muqingbfq/MP3.java | 2 +- .../main/java/com/muqingbfq/MediaPlayer.java | 176 ++++++++---------- .../com/muqingbfq/api/FileDownloader.java | 11 +- .../main/java/com/muqingbfq/api/resource.java | 19 -- app/src/main/java/com/muqingbfq/api/url.java | 40 ++-- app/src/main/java/com/muqingbfq/bfq.java | 5 +- app/src/main/java/com/muqingbfq/bfqkz.java | 20 +- .../java/com/muqingbfq/fragment/Media.java | 24 ++- .../java/com/muqingbfq/fragment/bfq_db.java | 12 +- .../main/java/com/muqingbfq/fragment/gd.java | 122 +++++++++--- .../com/muqingbfq/fragment/gd_adapter.java | 35 +--- .../main/java/com/muqingbfq/fragment/sz.java | 41 ---- .../java/com/muqingbfq/fragment/wode.java | 171 +++++++++++++++++ app/src/main/java/com/muqingbfq/home.java | 4 +- .../main/java/com/muqingbfq/list/list_gd.java | 93 --------- .../com/muqingbfq/login/user_editing.java | 6 +- .../com/muqingbfq/login/user_message.java | 8 +- app/src/main/res/layout/activity_home.xml | 30 ++- app/src/main/res/layout/fragment_sz.xml | 41 ---- app/src/main/res/layout/fragment_wd.xml | 86 +++++++++ app/src/main/res/layout/list_gd_b.xml | 40 ++++ app/src/main/res/layout/view_button.xml | 19 ++ 24 files changed, 614 insertions(+), 398 deletions(-) create mode 100644 app/src/main/java/com/muqingbfq/fragment/wode.java delete mode 100644 app/src/main/java/com/muqingbfq/list/list_gd.java create mode 100644 app/src/main/res/layout/fragment_wd.xml create mode 100644 app/src/main/res/layout/list_gd_b.xml create mode 100644 app/src/main/res/layout/view_button.xml diff --git a/app/build.gradle b/app/build.gradle index 9429f86..bcad2c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ android { //noinspection OldTargetApi targetSdk 31 versionCode 1 - versionName "1.7.6" + versionName "1.7.8" } compileOptions { @@ -56,7 +56,6 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation("androidx.media3:media3-exoplayer:1.2.0") //修改音乐标签库 implementation 'com.mpatric:mp3agic:0.9.1' } \ No newline at end of file diff --git a/app/debug/output-metadata.json b/app/debug/output-metadata.json index a06209a..73f4637 100644 --- a/app/debug/output-metadata.json +++ b/app/debug/output-metadata.json @@ -12,8 +12,8 @@ "filters": [], "attributes": [], "versionCode": 1, - "versionName": "1.7.6", - "outputFile": "Cloud_music-debug-v1.7.6.apk" + "versionName": "1.7.8", + "outputFile": "Cloud_music-debug-v1.7.8.apk" } ], "elementType": "File" diff --git a/app/src/main/java/com/muqingbfq/MP3.java b/app/src/main/java/com/muqingbfq/MP3.java index 17823f9..d2b7f64 100644 --- a/app/src/main/java/com/muqingbfq/MP3.java +++ b/app/src/main/java/com/muqingbfq/MP3.java @@ -5,7 +5,7 @@ import java.util.Objects; public class MP3 { public String id, name, zz; // 音乐的贴图 - public Object picurl; + public String picurl; public MP3(String id, String name, String zz, String picurl) { this.id = id; this.name = name; diff --git a/app/src/main/java/com/muqingbfq/MediaPlayer.java b/app/src/main/java/com/muqingbfq/MediaPlayer.java index bab5008..1f1fc4e 100644 --- a/app/src/main/java/com/muqingbfq/MediaPlayer.java +++ b/app/src/main/java/com/muqingbfq/MediaPlayer.java @@ -4,33 +4,35 @@ import static com.muqingbfq.bfqkz.xm; import android.annotation.SuppressLint; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.media.AudioAttributes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.media3.common.MediaItem; -import androidx.media3.common.PlaybackException; -import androidx.media3.common.Player; -import androidx.media3.exoplayer.ExoPlayer; 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.mpatric.mp3agic.ID3v2; +import com.mpatric.mp3agic.Mp3File; import com.muqingbfq.fragment.Media; import com.muqingbfq.fragment.bflb_db; import com.muqingbfq.fragment.bfq_db; import com.muqingbfq.fragment.search; import com.muqingbfq.mq.gj; +import com.muqingbfq.mq.wj; -public class MediaPlayer { - public ExoPlayer build; +import java.io.IOException; + +public class MediaPlayer extends android.media.MediaPlayer { // 每秒更新一次进度 public Runnable updateSeekBar = new Runnable() { @Override public void run() { - if (build != null && build.isPlaying() && Media.lrcview != null) { - long position = build.getCurrentPosition(); + if (isPlaying() && Media.view != null) { + long position = getCurrentPosition(); Media.setProgress((int) position); } main.handler.postDelayed(this, 1000); // 每秒更新一次进度 @@ -39,50 +41,26 @@ public class MediaPlayer { @SuppressLint("UnsafeOptInUsageError") public MediaPlayer() { - build = new ExoPlayer.Builder(home.appCompatActivity).build(); - build.addListener(new Player.Listener() { + setOnErrorListener(new OnErrorListener() { @Override - public void onPlaybackStateChanged(@Player.State int state) { - switch (state) { - case Player.STATE_READY: - bfui(); - break; - - case Player.STATE_ENDED: - int i = bfqkz.getmti(bfqkz.ms); - bfqkz.xm = bfqkz.list.get(i); - new Thread() { - @Override - public void run() { - super.run(); - bfqkz.mp3(com.muqingbfq.api. - url.hq(bfqkz.xm)); - } - }.start(); - break; - - case Player.STATE_BUFFERING: - case Player.STATE_IDLE: - break; - } - if (Media.view != null) { - main.handler.removeCallbacks(updateSeekBar); // 在播放开始时启动更新进度 - long duration = build.getDuration(); - Media.setMax((int) build.getDuration()); - Media.setTime_a(bfq_an.getTime(duration)); - long position = build.getCurrentPosition(); - Media.setProgress((int) position); - main.handler.post(updateSeekBar); // 在播放开始时启动更新进度 - } - // 在这里将进度更新到UI上 - } - - - @Override - public void onPlayerError(@NonNull PlaybackException error) { - gj.sc(error); + public boolean onError(android.media.MediaPlayer mediaPlayer, int i, int i1) { + //针对错误进行相应的处理 bfqkz.list.remove(bfqkz.xm); - Player.Listener.super.onPlayerError(error); + bfqkz.xm = bfqkz.list.get(bfqkz.getmti(bfqkz.ms)); + new Thread() { + @Override + public void run() { + super.run(); + bfqkz.mp3(com.muqingbfq.api. + url.hq(bfqkz.xm)); + } + }.start(); + return false; + } + }); + setOnCompletionListener(new OnCompletionListener() { + @Override + public void onCompletion(android.media.MediaPlayer mediaPlayer) { int i = bfqkz.getmti(bfqkz.ms); bfqkz.xm = bfqkz.list.get(i); new Thread() { @@ -94,73 +72,64 @@ public class MediaPlayer { } }.start(); } - - @Override - public void onIsPlayingChanged(boolean isPlaying) { - Media.setbf(isPlaying); - } }); -// build.setShuffleModeEnabled(true); + setAudioAttributes(new AudioAttributes + .Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .build()); + main.handler.post(updateSeekBar); // 在播放开始时启动更新进度 } - public void pause() { - if (build.isPlaying()) { - build.pause(); + @Override + public void pause() throws IllegalStateException { + if (isPlaying()) { + super.pause(); + Media.setbf(false); } } - public void start() { + @Override + public void start() throws IllegalStateException { if (bfqkz.xm == null) { if (bfqkz.list != null && bfqkz.list.size() > 0) { bfq_an.xyq(); } return; } - build.play(); + super.start(); + Media.setbf(true); } // 创建 MediaItem 列表 // public static List list = new ArrayList<>(); - @SuppressLint("NotifyDataSetChanged") - public void setDataSource(String path) { - DataSource(path); + @Override + public void setDataSource(String path) throws IOException { + reset(); + super.setDataSource(path); + prepare(); + start(); main.handler.post(() -> { - build.setPlayWhenReady(true); - start(); + bfui(); + if (Media.view != null) { + main.handler.removeCallbacks(updateSeekBar); // 在播放开始时启动更新进度 + long duration = getDuration(); + Media.setMax((int) getDuration()); + Media.setTime_a(bfq_an.getTime(duration)); + long position = getCurrentPosition(); + Media.setProgress((int) position); + main.handler.post(updateSeekBar); // 在播放开始时启动更新进度 + } + // 在这里将进度更新到UI上 }); } - @SuppressLint("NotifyDataSetChanged") - public void DataSource(String path) { - if (path == null) { - return; - } - MediaItem mediaItem = MediaItem.fromUri(path); -/* if (!list.contains(mediaItem)) { - list.add(mediaItem); - }*/ - main.handler.post(() -> { -// build.setMediaItems(list); -// build.seekToDefaultPosition(getmti(bfqkz.ms)); - build.setMediaItem(mediaItem); - build.prepare(); - gj.sc(build.getMediaItemCount()); - }); + public void DataSource(String path) throws Exception { + reset(); + super.setDataSource(path); + prepare(); } - public boolean isPlaying() { - if (build == null) { - return false; - } - return build.isPlaying(); - } - - public void seekTo(long a) { - build.seekTo(a); - } - - @SuppressLint("NotifyDataSetChanged") - private void bfui() { + public void setTX() { Glide.with(main.application) .asBitmap() .load(bfqkz.xm.picurl) @@ -169,6 +138,17 @@ public class MediaPlayer { public boolean onLoadFailed(@Nullable GlideException e, Object model, @NonNull Target target, boolean isFirstResource) { bfq.bitmap = null; + try { + Mp3File mp3file = new Mp3File(wj.mp3 + bfqkz.xm.id); + if (mp3file.hasId3v2Tag()) { + ID3v2 id3v2Tag = mp3file.getId3v2Tag(); + byte[] albumImage = id3v2Tag.getAlbumImage(); + bfq.bitmap= + BitmapFactory.decodeByteArray(albumImage, 0, albumImage.length); + } + } catch (Exception a) { + gj.sc(a); + } bfqkz.notify.setBitmap(); return false; } @@ -182,12 +162,15 @@ public class MediaPlayer { } }) .submit(); + } + @SuppressLint("NotifyDataSetChanged") + public void bfui() { + setTX(); String name = xm.name, zz = bfqkz.xm.zz; if (Media.view != null) { Media.setProgress(0); Media.setname(name); Media.setzz(zz); - bfq_an.islike(); } bfq_db.setname(name + "/" + zz); if (com.muqingbfq.fragment.mp3.lbspq != null) { @@ -198,7 +181,6 @@ public class MediaPlayer { } if (bflb_db.adapter != null) { bflb_db.adapter.notifyDataSetChanged(); - gj.sc(1); } } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/api/FileDownloader.java b/app/src/main/java/com/muqingbfq/api/FileDownloader.java index 6052fc7..5f6528f 100644 --- a/app/src/main/java/com/muqingbfq/api/FileDownloader.java +++ b/app/src/main/java/com/muqingbfq/api/FileDownloader.java @@ -5,6 +5,7 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.pm.PackageManager; +import android.graphics.Bitmap; import android.graphics.Color; import android.os.Build; import android.os.Environment; @@ -19,9 +20,11 @@ import com.mpatric.mp3agic.Mp3File; import com.mpatric.mp3agic.UnsupportedTagException; import com.muqingbfq.MP3; import com.muqingbfq.R; +import com.muqingbfq.bfq; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -58,7 +61,6 @@ public class FileDownloader { // 下载失败处理 return; } - File outputFile = new File(wj.mp3, "nihao"); File parentFile = outputFile.getParentFile(); if (!parentFile.isDirectory()) { @@ -89,7 +91,12 @@ public class FileDownloader { id3v2Tag.setTitle(x.name); id3v2Tag.setArtist(x.zz); id3v2Tag.setAlbum(x.zz); - id3v2Tag.setUrl(x.picurl.toString()); + id3v2Tag.setLyrics(bfq.lrc); + ByteArrayOutputStream o = new ByteArrayOutputStream(); + bfq.bitmap.compress(Bitmap.CompressFormat.JPEG, 100, o); + byte[] imageData = o.toByteArray(); + id3v2Tag.setAlbumImage(imageData, "image/jpeg"); + o.close(); mp3file.save(wj.mp3 + x.id); outputFile.delete(); } diff --git a/app/src/main/java/com/muqingbfq/api/resource.java b/app/src/main/java/com/muqingbfq/api/resource.java index a422abb..dd7c238 100644 --- a/app/src/main/java/com/muqingbfq/api/resource.java +++ b/app/src/main/java/com/muqingbfq/api/resource.java @@ -87,25 +87,6 @@ public class resource { } } - public static void 下载(List list) { - list.add(new xm("mp3_hc.json", "最近播放", R.drawable.zt, true)); - list.add(new xm("mp3_like.json", "喜欢", R.drawable.like, true)); - list.add(new xm("mp3_xz.json", "下载", R.drawable.download, true)); - try { - JSONObject date = new JSONObject(wj.dqwb(wj.gd_xz)); - for (Iterator it = date.keys(); it.hasNext(); ) { - String id = it.next(); - boolean cz = wj.cz(wj.gd + id); - JSONObject jsonObject = date.getJSONObject(id); - String name = jsonObject.getString("name"); - String picUrl = jsonObject.getString("picUrl"); - list.add(new xm(id, name, picUrl, cz)); - } - } catch (Exception e) { - gj.sc(e); - } - } - private static void add(JSONObject jsonObject, List list) throws Exception { String id = jsonObject.getString("id"); boolean cz = wj.cz(wj.gd + id); diff --git a/app/src/main/java/com/muqingbfq/api/url.java b/app/src/main/java/com/muqingbfq/api/url.java index 622342f..9650d83 100644 --- a/app/src/main/java/com/muqingbfq/api/url.java +++ b/app/src/main/java/com/muqingbfq/api/url.java @@ -1,8 +1,11 @@ package com.muqingbfq.api; import com.mpatric.mp3agic.ID3v2; +import com.mpatric.mp3agic.InvalidDataException; import com.mpatric.mp3agic.Mp3File; +import com.mpatric.mp3agic.UnsupportedTagException; import com.muqingbfq.MP3; +import com.muqingbfq.bfq; import com.muqingbfq.fragment.Media; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; @@ -16,6 +19,7 @@ import org.json.JSONObject; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import okhttp3.Call; @@ -38,12 +42,12 @@ public class url extends Thread { gc(x.id); } try { + if (wj.cz(wj.mp3 + x.id)) { + return wj.mp3 + x.id; + } if (wj.cz(wj.filesdri + "hc/" + x.id)) { return wj.filesdri + "hc/" + x.id; } - if (wj.cz(wj.mp3+x.id)) { - return wj.mp3 + x.id; - } String level = "standard"; boolean wiFiConnected = gj.isWiFiConnected(); if (wiFiConnected) { @@ -106,7 +110,6 @@ public class url extends Thread { id3v2Tag.setTitle(x.name); id3v2Tag.setArtist(x.zz); id3v2Tag.setAlbum(x.zz); - id3v2Tag.setUrl(x.picurl.toString()); mp3file.save(wj.filesdri + "hc/" + x.id); file.delete(); // 保存修改后的音乐文件,删除原来的文件 @@ -134,15 +137,24 @@ public class url extends Thread { public static void gc(String id) { - String lrc = null, tlyric = null; - try { - JSONObject jsonObject = new JSONObject(wl.hq("/lyric?id=" + id)); - lrc = jsonObject.getJSONObject("lrc").getString("lyric"); - tlyric = jsonObject.getJSONObject("tlyric").getString("lyric"); - } catch (Exception e) { - gj.sc("url gc(int id) lrc: " + e); + String file = wj.mp3 + id; + if (wj.cz(file)) { + try { + Mp3File mp3file = new Mp3File(file); + if (mp3file.hasId3v2Tag()) { + ID3v2 id3v2Tag = mp3file.getId3v2Tag(); + bfq.lrc = id3v2Tag.getLyrics(); + } + if (bfq.lrc == null) { + bfq.lrc = wl.hq("/lyric?id=" + id); + } + } catch (Exception e) { + gj.sc(e); + } + }else { + bfq.lrc = wl.hq("/lyric?id=" + id); } - Media.loadLyric(lrc, tlyric); + Media.loadLyric(); } public static String picurl(String id) { @@ -151,8 +163,8 @@ public class url extends Thread { return new JSONObject(hq).getJSONArray("songs").getJSONObject(0) .getJSONObject("al").getString("picUrl"); } catch (Exception e) { - yc.start(e); + gj.sc(e); } return null; } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index f243422..bf54a82 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -42,7 +42,7 @@ public class bfq extends AppCompatActivity { @SuppressLint("StaticFieldLeak") public static AppCompatActivity context; public ActivityBfqBinding inflate; - + public static String lrc; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -75,7 +75,7 @@ public class bfq extends AppCompatActivity { inflate.bfqListMp3. setOnClickListener(view1 -> com.muqingbfq.fragment.bflb_db.start(this)); inflate.control.setOnClickListener(new bfq_an.control(inflate.control)); - if (bfqkz.mt != null && bfqkz.mt.build.isPlaying()) { + if (bfqkz.mt != null && bfqkz.mt.isPlaying()) { inflate.kg.setImageResource(R.drawable.bf); } @@ -110,6 +110,7 @@ public class bfq extends AppCompatActivity { Media.setname(bfqkz.xm.name); Media.setzz(bfqkz.xm.zz); bfq_an.islike(); + bfqkz.mt.setTX(); } inflate.download.setOnClickListener(view -> { if (wj.cz(wj.mp3 + bfqkz.xm.id)) { diff --git a/app/src/main/java/com/muqingbfq/bfqkz.java b/app/src/main/java/com/muqingbfq/bfqkz.java index 72b587b..ad7c040 100644 --- a/app/src/main/java/com/muqingbfq/bfqkz.java +++ b/app/src/main/java/com/muqingbfq/bfqkz.java @@ -14,7 +14,6 @@ import android.text.TextUtils; import android.view.KeyEvent; import androidx.annotation.Nullable; -import androidx.media3.common.MediaItem; import com.muqingbfq.api.url; import com.muqingbfq.mq.BluetoothMusicController; @@ -26,7 +25,7 @@ import java.util.List; import java.util.Random; public class bfqkz extends Service { - public static MediaPlayer mt; + public static MediaPlayer mt = new MediaPlayer(); public static List list = new ArrayList<>(); public static List lishi_list = new ArrayList<>(); public static int ms; @@ -46,7 +45,6 @@ public class bfqkz extends Service { } else if (s == 2) { i = new Random().nextInt(bfqkz.list.size()); } - mt.build.seekToDefaultPosition(i); return i; } @@ -54,9 +52,23 @@ public class bfqkz extends Service { public static void mp3(String id) { try { if (TextUtils.isEmpty(id)) { + //针对错误进行相应的处理 + if (bfqkz.list.size() < 1) { + return; + } + bfqkz.list.remove(bfqkz.xm); + bfqkz.xm = bfqkz.list.get(bfqkz.getmti(bfqkz.ms)); + new Thread() { + @Override + public void run() { + super.run(); + bfqkz.mp3(com.muqingbfq.api. + url.hq(bfqkz.xm)); + } + }.start(); return; } - if (TextUtils.isEmpty(xm.picurl.toString())) { + if (TextUtils.isEmpty(xm.picurl)) { xm.picurl = url.picurl(xm.id); } if (bfqkz.lishi_list.size() >= 100) { diff --git a/app/src/main/java/com/muqingbfq/fragment/Media.java b/app/src/main/java/com/muqingbfq/fragment/Media.java index e5488ac..c94e9af 100644 --- a/app/src/main/java/com/muqingbfq/fragment/Media.java +++ b/app/src/main/java/com/muqingbfq/fragment/Media.java @@ -25,6 +25,9 @@ import com.muqingbfq.home; import com.muqingbfq.main; import com.muqingbfq.mq.gj; +import org.json.JSONException; +import org.json.JSONObject; + import me.wcy.lrcview.LrcView; public class Media extends Fragment { @@ -114,7 +117,7 @@ public class Media extends Fragment { time_b = inflate.timeB; //初始化歌词组件 lrcview.setDraggable(true, (view, time) -> { - bfqkz.mt.build.seekTo(Math.toIntExact(time)); + bfqkz.mt.seekTo(Math.toIntExact(time)); return false; }); if (!isTablet(com.muqingbfq.bfq.context)) { @@ -139,10 +142,10 @@ public class Media extends Fragment { //初始化播放器列表 if (bfqkz.xm != null) { main.handler.removeCallbacks(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 - long duration = bfqkz.mt.build.getDuration(); - tdt.setMax((int) bfqkz.mt.build.getDuration()); + long duration = bfqkz.mt.getDuration(); + tdt.setMax((int) bfqkz.mt.getDuration()); setTime_a(bfq_an.getTime(duration)); - long position = bfqkz.mt.build.getCurrentPosition(); + long position = bfqkz.mt.getCurrentPosition(); setProgress((int) position); main.handler.post(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 } @@ -155,10 +158,19 @@ public class Media extends Fragment { Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } - public static void loadLyric(String a, String b) { - if (lrcview == null || a == null) { + public static void loadLyric() { + if (lrcview == null || com.muqingbfq.bfq.lrc == null) { return; } + JSONObject jsonObject; + String a = null, b = null; + try { + jsonObject = new JSONObject(com.muqingbfq.bfq.lrc); + a = jsonObject.getJSONObject("lrc").getString("lyric"); + b = jsonObject.getJSONObject("tlyric").getString("lyric"); + } catch (Exception e) { + gj.sc(e); + } lrcview.loadLrc(a, b); } diff --git a/app/src/main/java/com/muqingbfq/fragment/bfq_db.java b/app/src/main/java/com/muqingbfq/fragment/bfq_db.java index 690088b..b0af1c2 100644 --- a/app/src/main/java/com/muqingbfq/fragment/bfq_db.java +++ b/app/src/main/java/com/muqingbfq/fragment/bfq_db.java @@ -22,9 +22,11 @@ import com.muqingbfq.bfq; import com.muqingbfq.bfq_an; import com.muqingbfq.bfqkz; import com.muqingbfq.home; +import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; import com.muqingbfq.xm; +import java.io.IOException; import java.lang.reflect.Type; import java.util.List; @@ -46,14 +48,20 @@ public class bfq_db extends Fragment { } bfqkz.xm = wj.getMP3FromFile(); - bfqkz.mt = new MediaPlayer(); if (bfqkz.xm != null) { new Thread(){ @Override public void run() { super.run(); String hq = url.hq(bfqkz.xm); - bfqkz.mt.DataSource(hq); + if (hq == null) { + return; + } + try { + bfqkz.mt.DataSource(hq); + } catch (Exception e) { + gj.sc(e); + } } }.start(); } diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 2a00f5e..1cb3d37 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -2,6 +2,7 @@ package com.muqingbfq.fragment; import android.annotation.SuppressLint; import android.content.Context; +import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; @@ -13,6 +14,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -20,22 +22,30 @@ import androidx.viewpager2.widget.ViewPager2; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.card.MaterialCardView; -import com.muqingbfq.MP3; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.muqingbfq.R; import com.muqingbfq.api.playlist; import com.muqingbfq.bfq_an; import com.muqingbfq.bfqkz; import com.muqingbfq.databinding.FragmentGdBinding; -import com.muqingbfq.list.list_gd; import com.muqingbfq.main; +import com.muqingbfq.mq.gj; +import com.muqingbfq.mq.wj; +import com.muqingbfq.mq.wl; import com.muqingbfq.xm; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class gd extends Fragment { public static String gdid; FragmentGdBinding binding; + @Override public void onResume() { super.onResume(); @@ -49,27 +59,8 @@ public class gd extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentGdBinding.inflate(inflater, container, false); - binding.viewPager.setAdapter(new FragmentStateAdapter(getActivity()) { - @NonNull - @Override - public Fragment createFragment(int position) { - switch (position) { - case 0: - return new gd_adapter(); - case 1: - return new gd_adapter.paihangbang(); - case 2: - return new gd_adapter.wuode(); - default: - return new Fragment(); - } - } + binding.viewPager.setAdapter(new adaper(getActivity())); - @Override - public int getItemCount() { - return 3; - } - }); // 将 ViewPager2 绑定到 TabLayout binding.tablayout.setOnItemSelectedListener(item -> { int itemId = item.getItemId(); @@ -81,7 +72,8 @@ public class gd extends Fragment { binding.viewPager.setCurrentItem(2); } return true; - });binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { + }); + binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override public void onPageSelected(int position) { switch (position) { @@ -93,12 +85,36 @@ public class gd extends Fragment { break; case 2: binding.tablayout.setSelectedItemId(R.id.c); + wode fragment = (wode) list.get(position); + fragment.sx(); break; } } }); return binding.getRoot(); } + + List list = new ArrayList<>(); + + private class adaper extends FragmentStateAdapter { + public adaper(@NonNull FragmentActivity fragmentActivity) { + super(fragmentActivity); + list.add(new gd_adapter()); + list.add(new gd_adapter.paihangbang()); + list.add(new wode()); + } + + @NonNull + @Override + public Fragment createFragment(int position) { + return list.get(position); + } + @Override + public int getItemCount() { + return list.size(); + } + } + public static class baseadapter extends RecyclerView.Adapter { Context context; List list; @@ -123,9 +139,63 @@ public class gd extends Fragment { @Override public void onBindViewHolder(@NonNull VH holder, int position) { xm xm = list.get(position); - list_gd gd = new list_gd(xm,this); - holder.cardView.setOnClickListener(gd); - holder.cardView.setOnLongClickListener(gd); + holder.cardView.setOnClickListener(view -> { + Context context = view.getContext(); + Intent intent = new Intent(context, mp3.class); + intent.putExtra("id", xm.id); + intent.putExtra("name", xm.name); + context.startActivity(intent); + }); + holder.cardView.setOnLongClickListener(view -> { + String[] stringArray = view.getResources() + .getStringArray(R.array.gd_list); + new MaterialAlertDialogBuilder(view.getContext()).setItems(stringArray, (dialog, id) -> { + new Thread() { + @Override + public void run() { + if (id == 0) { + String hq = wl.hq(playlist.api + xm.id + "&limit=30"); + if (hq != null) { + wj.xrwb(wj.gd + xm.id, hq); + xm.cz = true; + try { + JSONObject jsonObject = new JSONObject(); + if (wj.cz(wj.gd_xz)) { + jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz))); + } + JSONObject json = new JSONObject(); + json.put("name", xm.name); + json.put("picUrl", xm.picurl); + jsonObject.put(xm.id, json); + wj.xrwb(wj.gd_xz, jsonObject.toString()); + } catch (JSONException e) { + gj.sc("list gd onclick thear " + e); + } + } + + } else if (id == 2) { + wj.sc(wj.gd + xm.id); + if (xm.id.equals("mp3_xz.json")) { + wj.sc(new File(wj.mp3)); + } + xm.cz = false; + try { + JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz))); + jsonObject.remove(xm.id); + list.remove(xm); + wj.xrwb(wj.gd_xz, jsonObject.toString()); + } catch (JSONException e) { + gj.sc(e); + } + } + main.handler.post(() -> notifyDataSetChanged()); + } + }.start(); + // 在这里处理菜单项的点击事件 + dialog.dismiss(); + }).show(); + return false; + }); holder.textView.setText(xm.name); holder.kg.setOnClickListener(view1 -> { ImageView tx = (ImageView) view1; diff --git a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java index fc08c85..92caf04 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java @@ -2,6 +2,7 @@ package com.muqingbfq.fragment; import android.annotation.SuppressLint; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -17,6 +18,9 @@ import androidx.recyclerview.widget.RecyclerView; import com.muqingbfq.R; import com.muqingbfq.api.resource; +import com.muqingbfq.databinding.FragmentWdBinding; +import com.muqingbfq.login.user_editing; +import com.muqingbfq.login.user_logs; import com.muqingbfq.main; import com.muqingbfq.xm; @@ -50,10 +54,8 @@ public class gd_adapter extends Fragment { } public static class paihangbang extends Fragment { - List list = new ArrayList<>(); gd.baseadapter baseadapter; - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -78,35 +80,6 @@ public class gd_adapter extends Fragment { return layout; } } - - public static class wuode extends Fragment { - List list = new ArrayList<>(); - gd.baseadapter baseadapter; - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - FrameLayout layout = new FrameLayout(getContext()); - RecyclerView recyclerView = new RecyclerView(layout.getContext()); - int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); - GridLayoutManager gridLayoutManager = new GridLayoutManager(layout.getContext(), k / 120); - recyclerView.setLayoutManager(gridLayoutManager); - layout.addView(recyclerView); - baseadapter = new gd.baseadapter(getContext(), list); - recyclerView.setAdapter(baseadapter); - new Thread() { - @SuppressLint("NotifyDataSetChanged") - @Override - public void run() { - super.run(); - resource.下载(list); - main.handler.postDelayed(new sx(baseadapter),500); - } - }.start(); - return layout; - } - } - private static class sx implements Runnable { gd.baseadapter baseadapter; diff --git a/app/src/main/java/com/muqingbfq/fragment/sz.java b/app/src/main/java/com/muqingbfq/fragment/sz.java index b975eb8..2d75e9a 100644 --- a/app/src/main/java/com/muqingbfq/fragment/sz.java +++ b/app/src/main/java/com/muqingbfq/fragment/sz.java @@ -4,56 +4,15 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import com.muqingbfq.R; import com.muqingbfq.activity_about_software; import com.muqingbfq.clean.fragment_clean; import com.muqingbfq.login.cookie; -import com.muqingbfq.login.user_editing; -import com.muqingbfq.login.user_logs; -import com.muqingbfq.login.user_message; -import com.muqingbfq.main; import com.muqingbfq.mq.gj; public class sz { - @SuppressLint("StaticFieldLeak") - public static TextView name, jieshao; - @SuppressLint("StaticFieldLeak") - public static ImageView imageView; - Context context; - - public sz(Context context, View view) { - this.context = context; - name = view.findViewById(R.id.sz_text1); - jieshao = view.findViewById(R.id.sz_text2); - imageView = view.findViewById(R.id.image); - view.findViewById(R.id.xdbj). - setOnClickListener(v -> { - if (main.getToken() == null) { - context.startActivity(new Intent(context, user_logs.class)); - } else { - context.startActivity(new Intent(context, user_editing.class)); - } - }); - new user_message(); - } - - public static void setname(String string) { - main.handler.post(() -> name.setText(string)); - } - public static void setqianming(String string) { - main.handler.post(() -> { - if (string == null) { - jieshao.setText(""); - } else { - jieshao.setText(string); - } - }); - } @SuppressLint("NonConstantResourceId") public static void switch_sz(Context context, int id) { if (id == R.id.a) { diff --git a/app/src/main/java/com/muqingbfq/fragment/wode.java b/app/src/main/java/com/muqingbfq/fragment/wode.java new file mode 100644 index 0000000..3a965f1 --- /dev/null +++ b/app/src/main/java/com/muqingbfq/fragment/wode.java @@ -0,0 +1,171 @@ +package com.muqingbfq.fragment; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.Glide; +import com.muqingbfq.R; +import com.muqingbfq.databinding.FragmentWdBinding; +import com.muqingbfq.login.user_editing; +import com.muqingbfq.login.user_logs; +import com.muqingbfq.login.user_message; +import com.muqingbfq.main; +import com.muqingbfq.mq.gj; +import com.muqingbfq.mq.wj; +import com.muqingbfq.xm; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class wode extends Fragment { + + @SuppressLint("StaticFieldLeak") + public static TextView name, jieshao; + @SuppressLint("StaticFieldLeak") + public static ImageView imageView; + + FragmentWdBinding binding; + private final List list = new ArrayList<>(); + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + binding = FragmentWdBinding.inflate(inflater, container, false); + View view = binding.getRoot(); + name = binding.text1; + jieshao = binding.text2; + imageView = binding.imageView; + binding.cardview.setOnClickListener(v -> { + if (main.getToken() == null) { + startActivity(new Intent(getContext(), user_logs.class)); + } else { + startActivity(new Intent(getContext(), user_editing.class)); + } + }); + + new user_message(); + int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); + GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), k / 120); + binding.recyclerview1.setLayoutManager(gridLayoutManager); + final Object[][] lista ={ + {R.drawable.bf,"最近播放"}, + {R.drawable.download,"下载音乐"}, + {R.drawable.like,"喜欢音乐"}, + {R.drawable.icon,"本地搜索"}, + {R.drawable.icon,"我的歌单"}, + {R.drawable.icon,"导入歌单"}, + {R.drawable.icon,"开发中"}, + {R.drawable.icon,"开发者"} + }; + binding.recyclerview1.setAdapter(new RecyclerView.Adapter() { + @NonNull + @Override + public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View inflate = View.inflate(getContext(), R.layout.view_button, null); + return new VH(inflate); + } + + @Override + public void onBindViewHolder(@NonNull VH holder, int position) { + String s = lista[position][1].toString(); + holder.textView.setText(s); + Glide.with(getContext()) + .load(lista[position][0]) + .into(holder.imageView); + holder.itemView.setOnClickListener(view -> { + Intent a = new Intent(getContext(), com.muqingbfq.fragment.mp3.class); + switch (position) { + case 0: + a.putExtra("id", "mp3_hc.json"); + a.putExtra("name", s); + getContext().startActivity(a); + break; + case 1: + a.putExtra("id", "mp3_xz.json"); + a.putExtra("name", s); + getContext().startActivity(a); + break; + case 2: + a.putExtra("id", "mp3_like.json"); + a.putExtra("name", s); + getContext().startActivity(a); + break; + case 3: + break; + + } + }); + } + + @Override + public int getItemCount() { + return lista.length; + } + }); + sx(); + binding.recyclerview2.setLayoutManager(new LinearLayoutManager(getContext()){ + @Override + public boolean canScrollVertically() { + return false;//禁止滑动 + } + }); + binding.recyclerview2.setFocusable(false); + binding.recyclerview2.setAdapter(new gd.baseadapter(getContext(),list)); + return view; + } + + class VH extends RecyclerView.ViewHolder { + public ImageView imageView; + public TextView textView; + public VH(@NonNull View itemView) { + super(itemView); + imageView = itemView.findViewById(R.id.image); + textView = itemView.findViewById(R.id.text1); + } + } + + public void sx(){ + try { + list.clear(); + JSONObject date = new JSONObject(wj.dqwb(wj.gd_xz)); + for (Iterator it = date.keys(); it.hasNext(); ) { + String id = it.next(); + boolean cz = wj.cz(wj.gd + id); + JSONObject jsonObject = date.getJSONObject(id); + String name = jsonObject.getString("name"); + String picUrl = jsonObject.getString("picUrl"); + list.add(new xm(id, name, picUrl, cz)); + } + binding.recyclerview2.getAdapter().notifyDataSetChanged(); + } catch (Exception e) { + gj.sc(e); + } + } + public static void setname(String string) { + main.handler.post(() -> name.setText(string)); + } + public static void setqianming(String string) { + main.handler.post(() -> { + if (string == null) { + jieshao.setText(""); + } else { + jieshao.setText(string); + } + }); + } +} diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java index ac3e7b1..452614c 100644 --- a/app/src/main/java/com/muqingbfq/home.java +++ b/app/src/main/java/com/muqingbfq/home.java @@ -39,6 +39,9 @@ public class home extends AppCompatActivity { appCompatActivity = this; setTheme(R.style.Theme_muqing); super.onCreate(savedInstanceState); + if (true) { + com.muqingbfq.mq.floating.start(this); + } setContentView(R.layout.activity_home); DisplayMetrics dm = getResources().getDisplayMetrics(); main.k = dm.widthPixels; @@ -81,7 +84,6 @@ public class home extends AppCompatActivity { com.muqingbfq.fragment.sz.switch_sz(home.this, item.getItemId()); return false; }); - new com.muqingbfq.fragment.sz(this, chb.getHeaderView(0)); //初始化播放器组件 // 启动Service if (serviceIntent == null) { diff --git a/app/src/main/java/com/muqingbfq/list/list_gd.java b/app/src/main/java/com/muqingbfq/list/list_gd.java deleted file mode 100644 index 8b598dd..0000000 --- a/app/src/main/java/com/muqingbfq/list/list_gd.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.muqingbfq.list; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.view.View; - -import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.muqingbfq.R; -import com.muqingbfq.api.playlist; -import com.muqingbfq.fragment.gd; -import com.muqingbfq.main; -import com.muqingbfq.mq.gj; -import com.muqingbfq.mq.wj; -import com.muqingbfq.mq.wl; -import com.muqingbfq.xm; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.util.Objects; - -public class list_gd implements View.OnClickListener, View.OnLongClickListener { - xm xm; - gd.baseadapter adaper; - public list_gd(com.muqingbfq.xm xm,gd.baseadapter baseadapter) { - this.xm = xm; - this.adaper = baseadapter; - } - - @SuppressLint("NotifyDataSetChanged") - @Override - public void onClick(View view) { - Context context = view.getContext(); - Intent intent = new Intent(context, com.muqingbfq.fragment.mp3.class); - intent.putExtra("id", xm.id); - intent.putExtra("name", xm.name); - context.startActivity(intent); - } - - - @Override - public boolean onLongClick(View view) { - String[] stringArray = view.getResources() - .getStringArray(R.array.gd_list); - new MaterialAlertDialogBuilder(view.getContext()).setItems(stringArray, (dialog, id) -> { - new Thread() { - @Override - public void run() { - if (id == 0) { - String hq = wl.hq(playlist.api + xm.id + "&limit=30"); - if (hq != null) { - wj.xrwb(wj.gd + xm.id, hq); - xm.cz = true; - try { - JSONObject jsonObject = new JSONObject(); - if (wj.cz(wj.gd_xz)) { - jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz))); - } - JSONObject json = new JSONObject(); - json.put("name", xm.name); - json.put("picUrl", xm.picurl); - jsonObject.put(xm.id, json); - wj.xrwb(wj.gd_xz, jsonObject.toString()); - } catch (JSONException e) { - gj.sc("list gd onclick thear " + e); - } - } - - } else if (id == 2) { - wj.sc(wj.gd + xm.id); - if (xm.id.equals("mp3_xz.json")) { - wj.sc(new File(wj.mp3)); - } - xm.cz = false; - try { - JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz))); - jsonObject.remove(xm.id); - wj.xrwb(wj.gd_xz, jsonObject.toString()); - } catch (JSONException e) { - gj.sc(e); - } - } - main.handler.post(() -> adaper.notifyDataSetChanged()); - } - }.start(); - // 在这里处理菜单项的点击事件 - dialog.dismiss(); - }).show(); - return false; - } -} diff --git a/app/src/main/java/com/muqingbfq/login/user_editing.java b/app/src/main/java/com/muqingbfq/login/user_editing.java index 26321a2..2902cb9 100644 --- a/app/src/main/java/com/muqingbfq/login/user_editing.java +++ b/app/src/main/java/com/muqingbfq/login/user_editing.java @@ -152,9 +152,9 @@ public class user_editing extends FragmentActivity { binding.userEnd.setOnClickListener(view ->{ finish(); main.settoken(null, null); - sz.setname("未登录"); - sz.setqianming(null); - sz.imageView.setImageResource(R.drawable.icon); + com.muqingbfq.fragment.wode.setname("未登录"); + com.muqingbfq.fragment.wode.setqianming(null); + com.muqingbfq.fragment.wode.imageView.setImageResource(R.drawable.icon); }); findViewById(R.id.button1).setOnClickListener(view -> { // 创建OkHttpClient实例 diff --git a/app/src/main/java/com/muqingbfq/login/user_message.java b/app/src/main/java/com/muqingbfq/login/user_message.java index e60fadd..2046fcd 100644 --- a/app/src/main/java/com/muqingbfq/login/user_message.java +++ b/app/src/main/java/com/muqingbfq/login/user_message.java @@ -30,16 +30,16 @@ public class user_message extends Thread { string strings = get(); main.handler.post(() -> { com.muqingbfq.fragment. - sz.setname(strings.userName()); + wode.setname(strings.userName()); com.muqingbfq.fragment. - sz.setqianming(strings.introduce()); + wode.setqianming(strings.introduce()); com.bumptech.glide.Glide.with(com.muqingbfq.fragment. - sz.imageView) + wode.imageView) .load(strings.headIcon()) .placeholder(R.drawable.icon)//图片加载出来前,显示的图片 .error(R.drawable.icon)//图片加载失败后,显示的图片 .into(com.muqingbfq.fragment. - sz.imageView); + wode.imageView); }); } catch (Exception e) { gj.sc(e); diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index f38b321..bebda5f 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -19,15 +19,31 @@ android:layout_height="match_parent" android:orientation="vertical"> - - + - + android:layout_height="wrap_content"> + + + + - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_wd.xml b/app/src/main/res/layout/fragment_wd.xml new file mode 100644 index 0000000..54b9d8b --- /dev/null +++ b/app/src/main/res/layout/fragment_wd.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_gd_b.xml b/app/src/main/res/layout/list_gd_b.xml new file mode 100644 index 0000000..3725255 --- /dev/null +++ b/app/src/main/res/layout/list_gd_b.xml @@ -0,0 +1,40 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_button.xml b/app/src/main/res/layout/view_button.xml new file mode 100644 index 0000000..7d4e9b3 --- /dev/null +++ b/app/src/main/res/layout/view_button.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file