更改喜欢音乐逻辑和储存

This commit is contained in:
muqing 2023-12-26 12:26:34 +08:00
parent a1e0a80ac6
commit 22cd5b5e30
24 changed files with 614 additions and 398 deletions

View File

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

View File

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

View File

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

View File

@ -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,52 +41,12 @@ 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);
int i = bfqkz.getmti(bfqkz.ms);
bfqkz.xm = bfqkz.list.get(i);
bfqkz.xm = bfqkz.list.get(bfqkz.getmti(bfqkz.ms));
new Thread() {
@Override
public void run() {
@ -93,74 +55,81 @@ public class MediaPlayer {
url.hq(bfqkz.xm));
}
}.start();
}
@Override
public void onIsPlayingChanged(boolean isPlaying) {
Media.setbf(isPlaying);
return false;
}
});
// build.setShuffleModeEnabled(true);
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() {
@Override
public void run() {
super.run();
bfqkz.mp3(com.muqingbfq.api.
url.hq(bfqkz.xm));
}
}.start();
}
});
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<MediaItem> list = new ArrayList<>();
@SuppressLint("NotifyDataSetChanged")
public void setDataSource(String path) {
DataSource(path);
main.handler.post(() -> {
build.setPlayWhenReady(true);
@Override
public void setDataSource(String path) throws IOException {
reset();
super.setDataSource(path);
prepare();
start();
});
}
@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());
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上
});
}
public boolean isPlaying() {
if (build == null) {
return false;
}
return build.isPlaying();
public void DataSource(String path) throws Exception {
reset();
super.setDataSource(path);
prepare();
}
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<Bitmap> 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);
}
}
}

View File

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

View File

@ -87,25 +87,6 @@ public class resource {
}
}
public static void 下载(List<xm> 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<String> 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<xm> list) throws Exception {
String id = jsonObject.getString("id");
boolean cz = wj.cz(wj.gd + id);

View File

@ -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.filesdri + "hc/" + x.id)) {
return wj.filesdri + "hc/" + x.id;
}
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;
}
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;
String file = wj.mp3 + id;
if (wj.cz(file)) {
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);
Mp3File mp3file = new Mp3File(file);
if (mp3file.hasId3v2Tag()) {
ID3v2 id3v2Tag = mp3file.getId3v2Tag();
bfq.lrc = id3v2Tag.getLyrics();
}
Media.loadLyric(lrc, tlyric);
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();
}
public static String picurl(String id) {
@ -151,7 +163,7 @@ 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;
}

View File

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

View File

@ -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<MP3> list = new ArrayList<>();
public static List<MP3> 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;
}
if (TextUtils.isEmpty(xm.picurl.toString())) {
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)) {
xm.picurl = url.picurl(xm.id);
}
if (bfqkz.lishi_list.size() >= 100) {

View File

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

View File

@ -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);
if (hq == null) {
return;
}
try {
bfqkz.mt.DataSource(hq);
} catch (Exception e) {
gj.sc(e);
}
}
}.start();
}

View File

@ -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<Fragment> 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<VH> {
Context context;
List<xm> 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;

View File

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

View File

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

View File

@ -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<com.muqingbfq.xm> 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<VH>() {
@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<String> 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);
}
});
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -19,15 +19,31 @@
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"/>
</com.google.android.material.appbar.AppBarLayout>
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:autofillHints=""
android:background="@drawable/ui_editview"
android:hint="@string/search"
android:gravity="center"
android:imeOptions="actionSearch"
android:inputType="text"
android:minHeight="48dp"
android:paddingStart="3dp"
android:paddingEnd="3dp" />
</LinearLayout>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/gd"
android:name="com.muqingbfq.fragment.gd"

View File

@ -8,45 +8,4 @@
tools:context=".fragment.sz"
android:fitsSystemWindows="true"
android:focusable="true">
<LinearLayout
android:id="@+id/xdbj"
android:layout_margin="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="horizontal"
tools:ignore="UselessParent">
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="16dp"
app:cardUseCompatPadding="true">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/icon" />
</com.google.android.material.card.MaterialCardView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/sz_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:textSize="26sp" />
<TextView
android:id="@+id/sz_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginBottom="35dp"
android:text="我是一名小小的游客" />
</LinearLayout>
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
app:contentPadding="6dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="65dp"
android:layout_height="65dp"
android:src="@drawable/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text1"
android:text="@string/app_name"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
app:cardUseCompatPadding="true"
app:contentPadding="6dp"
app:layout_constraintTop_toBottomOf="@+id/cardview">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
app:cardUseCompatPadding="true"
app:contentPadding="6dp"
app:layout_constraintTop_toBottomOf="@+id/cardview2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview"
android:layout_width="120dp"
android:layout_height="120dp"
app:cardUseCompatPadding="true">
<ImageView
android:id="@+id/fh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
<ImageView
android:id="@+id/kg"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="6dp"
android:layout_gravity="bottom|end"
android:src="@drawable/zt"/>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="@+id/wb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="16dp"
android:lines="2"
android:maxLines="2"
android:text="@string/name"
android:textColor="@color/text" />
</LinearLayout>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="@+id/image"
android:layout_width="56dp"
android:layout_height="56dp"
android:background="@null"
android:src="@drawable/icon"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"/>
</LinearLayout>