From 5e3cbe600246859b0e4caf2fdbcd3cd31e751b54 Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Fri, 8 Dec 2023 16:31:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E6=96=87=E4=BB=B6=20=E6=B7=BB=E5=8A=A0=E5=82=A8?= =?UTF-8?q?=E5=AD=98=E6=B8=85=E7=90=86=E5=8A=9F=E8=83=BD=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BB=E9=A2=98=E9=A2=9C=E8=89=B2=E4=B8=BA=E5=86=B7?= =?UTF-8?q?=E8=89=B2=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 1 + .../main/java/com/muqingbfq/api/playlist.java | 21 +++--- app/src/main/java/com/muqingbfq/api/url.java | 2 +- app/src/main/java/com/muqingbfq/bfqkz.java | 1 - .../com/muqingbfq/clean/fragment_clean.java | 75 +++++++++++++++++++ .../main/java/com/muqingbfq/fragment/gd.java | 10 +-- .../main/java/com/muqingbfq/fragment/mp3.java | 16 +--- .../java/com/muqingbfq/fragment/search.java | 16 ++-- .../main/java/com/muqingbfq/fragment/sz.java | 9 ++- .../com/muqingbfq/login/user_editing.java | 9 ++- app/src/main/java/com/muqingbfq/main.java | 9 +-- app/src/main/java/com/muqingbfq/mq/wj.java | 2 +- app/src/main/java/com/muqingbfq/mq/wl.java | 62 +++++++++------ .../res/layout/activity_about_software.xml | 9 +-- app/src/main/res/layout/activity_cookie.xml | 3 +- .../main/res/layout/activity_user_editing.xml | 5 +- app/src/main/res/layout/clean.xml | 18 +++++ app/src/main/res/layout/list_clean.xml | 11 +++ app/src/main/res/menu/sz.xml | 4 +- app/src/main/res/values/colors.xml | 8 +- app/src/main/res/values/themes.xml | 25 ++++++- 22 files changed, 221 insertions(+), 97 deletions(-) create mode 100644 app/src/main/java/com/muqingbfq/clean/fragment_clean.java create mode 100644 app/src/main/res/layout/clean.xml create mode 100644 app/src/main/res/layout/list_clean.xml diff --git a/app/build.gradle b/app/build.gradle index 1132477..c43637a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,4 +57,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/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8f9a43f..fe3b9c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -49,6 +49,7 @@ + list) { list.clear(); try { - JSONArray json = new JSONObject(wj.dqwb(wj.mp3_xz)) - .getJSONArray("songs"); - int length = json.length(); - for (int i = 0; i < length; i++) { - JSONObject jsonObject = json.getJSONObject(i); - String id = jsonObject.getString("id"); - String name = jsonObject.getString("name"); - String zz = jsonObject.getString("zz"); - String picUrl = jsonObject.getString("picUrl"); + File file = new File(wj.filesdri + "mp3"); + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + ID3v2 mp3File = new Mp3File(files[i]).getId3v2Tag(); + String id = files[i].getName(); + String name = mp3File.getTitle(); + String zz = mp3File.getArtist(); + String picUrl = mp3File.getUrl(); list.add(new xm(id, name, zz, picUrl)); } return true; diff --git a/app/src/main/java/com/muqingbfq/api/url.java b/app/src/main/java/com/muqingbfq/api/url.java index 16e0ab9..8885e9c 100644 --- a/app/src/main/java/com/muqingbfq/api/url.java +++ b/app/src/main/java/com/muqingbfq/api/url.java @@ -26,7 +26,7 @@ public class url extends Thread { } try { if (wj.cz(wj.mp3 + x.id)) { - return wj.mp3 + x.id; + return wj.mp3 ; } String level = "standard"; boolean wiFiConnected = gj.isWiFiConnected(); diff --git a/app/src/main/java/com/muqingbfq/bfqkz.java b/app/src/main/java/com/muqingbfq/bfqkz.java index 9588618..845201c 100644 --- a/app/src/main/java/com/muqingbfq/bfqkz.java +++ b/app/src/main/java/com/muqingbfq/bfqkz.java @@ -55,7 +55,6 @@ public class bfqkz extends Service { if (TextUtils.isEmpty(id)) { return; } - gj.sc(xm.picurl); if (TextUtils.isEmpty(xm.picurl.toString())) { xm.picurl = url.picurl(xm.id); } diff --git a/app/src/main/java/com/muqingbfq/clean/fragment_clean.java b/app/src/main/java/com/muqingbfq/clean/fragment_clean.java new file mode 100644 index 0000000..5a66d21 --- /dev/null +++ b/app/src/main/java/com/muqingbfq/clean/fragment_clean.java @@ -0,0 +1,75 @@ +package com.muqingbfq.clean; + +import android.os.Bundle; +import android.text.format.Formatter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.LinearLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.muqingbfq.R; +import com.muqingbfq.databinding.CleanBinding; +import com.muqingbfq.mq.ActivityToolbar; +import com.muqingbfq.mq.gj; +import com.muqingbfq.mq.wj; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class fragment_clean extends ActivityToolbar { + List list = new ArrayList<>(); + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + list.add(new String[]{"音乐", wj.mp3}); + list.add(new String[]{"歌单",wj.gd}); + CleanBinding binding = CleanBinding.inflate(getLayoutInflater()); + binding.toolbar.setTitle("储存清理"); + setContentView(binding.getRoot()); + binding.recyclerview.setAdapter(adapter); + } + + private final RecyclerView.Adapter adapter = new RecyclerView.Adapter() { + @NonNull + @Override + public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View inflate = LayoutInflater.from(fragment_clean.this). + inflate(R.layout.list_clean, parent, false); + return new VH(inflate); + } + + @Override + public void onBindViewHolder(@NonNull VH holder, int position) { + String[] s = list.get(position); + File file = new File(s[1]); + long leng = 0; + if (file.isDirectory()) { + gj.sc(file.toString()); + for (File a : file.listFiles()) { + leng += a.length(); + } + } + String s1 = Formatter.formatFileSize(fragment_clean.this, leng); + holder.checkBox.setText(s[0] + ":" + s1); + } + + @Override + public int getItemCount() { + return list.size(); + } + }; + + class VH extends RecyclerView.ViewHolder { + public CheckBox checkBox; + public VH(@NonNull View itemView) { + super(itemView); + checkBox = itemView.findViewById(R.id.box); + } + } +} diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 66c3687..675db3d 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -53,9 +53,6 @@ public class gd extends Fragment { GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), k / 120); gridView.setLayoutManager(gridLayoutManager); gridView.setAdapter(lbspq); - if (gdid == null) { - gdid = main.mp3_csh; - } TabLayout tabLayout = view.findViewById(R.id.tablayout); for (String name : new String[]{"推荐", "排行榜", "下载"}) { TabLayout.Tab tab = tabLayout.newTab(); @@ -127,23 +124,18 @@ public class gd extends Fragment { tx.setImageResource(R.drawable.bf); main.edit.putString(main.mp3, xm.id); main.edit.commit(); - main.mp3_csh = gdid = xm.id; + gdid = xm.id; } com.muqingbfq.fragment.gd.lbspq.notifyDataSetChanged(); }); } }.start(); }); - int color = ContextCompat.getColor(context, R.color.text); Drawable color_kg = ContextCompat.getDrawable(context, R.drawable.zt); if (xm.id.equals(gdid)) { - color = ContextCompat.getColor(context, R.color.text_cz); color_kg = ContextCompat.getDrawable(context, R.drawable.bf); - } else if (xm.cz) { - color = ContextCompat.getColor(context, R.color.text_cz_tm); } holder.kg.setImageDrawable(color_kg); - holder.textView.setTextColor(color); Glide.with(context).load(xm.picurl).apply(new RequestOptions().placeholder(R.drawable.icon)) .into(holder.imageView); } diff --git a/app/src/main/java/com/muqingbfq/fragment/mp3.java b/app/src/main/java/com/muqingbfq/fragment/mp3.java index ed6b023..699b313 100644 --- a/app/src/main/java/com/muqingbfq/fragment/mp3.java +++ b/app/src/main/java/com/muqingbfq/fragment/mp3.java @@ -22,6 +22,7 @@ import com.muqingbfq.api.playlist; import com.muqingbfq.api.url; import com.muqingbfq.bfq; import com.muqingbfq.bfqkz; +import com.muqingbfq.databinding.FragmentMp3Binding; import com.muqingbfq.home; import com.muqingbfq.list.MyViewHoder; import com.muqingbfq.main; @@ -37,10 +38,10 @@ public class mp3 extends com.muqingbfq.mq.ActivityToolbar { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.fragment_mp3); + FragmentMp3Binding inflate = FragmentMp3Binding.inflate(getLayoutInflater()); Intent intent = getIntent(); - Toolbar toolbar = findViewById(R.id.toolbar); - toolbar.setTitle(intent.getStringExtra("name")); + inflate.toolbar.setTitle(intent.getStringExtra("name")); + setContentView(inflate.getRoot()); lbspq = new spq(); RecyclerView lb = findViewById(R.id.lb); LinearLayoutManager layoutManager = new LinearLayoutManager(this); @@ -84,7 +85,6 @@ public class mp3 extends com.muqingbfq.mq.ActivityToolbar { } class spq extends RecyclerView.Adapter { - @NonNull @Override public MyViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -121,14 +121,6 @@ public class mp3 extends com.muqingbfq.mq.ActivityToolbar { } - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - } - return super.onOptionsItemSelected(item); - } - public static void startactivity(Context context, String id) { context.startActivity(new Intent(context, mp3.class).putExtra("id", id)); } diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java index 25df5e1..2f46c39 100644 --- a/app/src/main/java/com/muqingbfq/fragment/search.java +++ b/app/src/main/java/com/muqingbfq/fragment/search.java @@ -42,6 +42,7 @@ public class search extends Fragment { public FragmentSearchBinding inflate; public int i = 0; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -87,6 +88,7 @@ public class search extends Fragment { } public int k; + public void setStart(String name) { if (i == 0) { new spq(); @@ -207,15 +209,11 @@ public class search extends Fragment { bfqkz.xm = x; new url(x); } - if (!com.muqingbfq.fragment.gd.gdid.equals(bflb_db.gdid)) { - bfqkz.list.clear(); - int size = list.size(); - for (int i = 0; i < size; i++) { - bfqkz.list.add(list.get(i)); - } - } - bfqkz.mt.start(); - bfq.start(getContext()); +// if (!com.muqingbfq.fragment.gd.gdid.equals(bflb_db.gdid)) { + gd.gdid = null; + bfqkz.list.clear(); + bfqkz.list.addAll(list); + bfq.start(search.this.getContext()); }); } diff --git a/app/src/main/java/com/muqingbfq/fragment/sz.java b/app/src/main/java/com/muqingbfq/fragment/sz.java index d11f118..b975eb8 100644 --- a/app/src/main/java/com/muqingbfq/fragment/sz.java +++ b/app/src/main/java/com/muqingbfq/fragment/sz.java @@ -11,6 +11,8 @@ 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; @@ -60,6 +62,7 @@ public class sz { context.startActivity(new Intent(context, com.muqingbfq.sz.class)); // 设置中心 } else if (id == R.id.c) { + context.startActivity(new Intent(context, fragment_clean.class)); // 储存清理 } else if (id == R.id.d) { try { @@ -86,10 +89,8 @@ public class sz { context.startActivity(new Intent(context, activity_about_software.class)); // 关于软件 } else if (id == R.id.g) { - main.settoken(null, null); - setname("未登录"); - setqianming(null); - imageView.setImageResource(R.drawable.icon); + context.startActivity(new Intent(context, cookie.class)); + //绑定网易云 } } } \ No newline at end of file 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 5d82161..a8d9823 100644 --- a/app/src/main/java/com/muqingbfq/login/user_editing.java +++ b/app/src/main/java/com/muqingbfq/login/user_editing.java @@ -24,6 +24,7 @@ import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.muqingbfq.R; import com.muqingbfq.databinding.ActivityUserEditingBinding; +import com.muqingbfq.fragment.sz; import com.muqingbfq.main; import com.muqingbfq.mq.ActivityToolbar; import com.muqingbfq.mq.gj; @@ -149,7 +150,13 @@ public class user_editing extends ActivityToolbar { }; imageViewa.setOnClickListener(onClickListener); imageViewb.setOnClickListener(onClickListener); - findViewById(R.id.button2).setOnClickListener(view -> startActivity(new Intent(user_editing.this, cookie.class))); + binding.userEnd.setOnClickListener(view ->{ + finish(); + main.settoken(null, null); + sz.setname("未登录"); + sz.setqianming(null); + sz.imageView.setImageResource(R.drawable.icon); + }); findViewById(R.id.button1).setOnClickListener(view -> { // 创建OkHttpClient实例 OkHttpClient client = new OkHttpClient(); diff --git a/app/src/main/java/com/muqingbfq/main.java b/app/src/main/java/com/muqingbfq/main.java index bc67d86..96d5edb 100644 --- a/app/src/main/java/com/muqingbfq/main.java +++ b/app/src/main/java/com/muqingbfq/main.java @@ -22,7 +22,7 @@ public class main extends Application { public static SharedPreferences sp; public static SharedPreferences.Editor edit; - public static String mp3 = "mp3", mp3_csh, + public static String mp3 = "mp3", Cookie = "Cookie"; public static String account,token; @@ -36,13 +36,6 @@ public class main extends Application { sp = getSharedPreferences("Set_up", MODE_PRIVATE); edit = sp.edit(); boolean bj = false; - try { - mp3_csh = sp.getString(mp3, ""); - } catch (Exception e) { - edit.putString(mp3, ""); - edit.commit(); - mp3_csh = ""; - } try { com.muqingbfq.bfqkz.ms = sp.getInt("ms", 1); } catch (Exception e) { diff --git a/app/src/main/java/com/muqingbfq/mq/wj.java b/app/src/main/java/com/muqingbfq/mq/wj.java index 7a7b940..e8aa77c 100644 --- a/app/src/main/java/com/muqingbfq/mq/wj.java +++ b/app/src/main/java/com/muqingbfq/mq/wj.java @@ -49,7 +49,7 @@ public class wj { //如果文件不存在,创建文件 try { File parentFile = file.getParentFile(); - if (!parentFile.exists()) { + if (!parentFile.isDirectory()) { parentFile.mkdirs(); } if (!file.exists()) diff --git a/app/src/main/java/com/muqingbfq/mq/wl.java b/app/src/main/java/com/muqingbfq/mq/wl.java index f145f4f..e5a2456 100644 --- a/app/src/main/java/com/muqingbfq/mq/wl.java +++ b/app/src/main/java/com/muqingbfq/mq/wl.java @@ -1,10 +1,23 @@ package com.muqingbfq.mq; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; +import android.media.MediaMetadataRetriever; +import android.media.MediaScannerConnection; +import android.net.Uri; +import android.nfc.Tag; +import android.provider.MediaStore; + +import com.mpatric.mp3agic.ID3v2; +import com.mpatric.mp3agic.InvalidDataException; +import com.mpatric.mp3agic.Mp3File; +import com.mpatric.mp3agic.UnsupportedTagException; +import com.muqingbfq.home; import com.muqingbfq.main; import com.muqingbfq.xm; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -45,7 +58,7 @@ public class wl { return null; } - public static String post(String str, String[] a,String[] b) { + public static String post(String str, String[] a, String[] b) { OkHttpClient client = new OkHttpClient().newBuilder() .build(); @@ -66,7 +79,7 @@ public class wl { return null; } - public static JSONObject jsonpost(String str, String[] a, String[] b){ + public static JSONObject jsonpost(String str, String[] a, String[] b) { try { return new JSONObject(post(str, a, b)); } catch (JSONException e) { @@ -105,6 +118,12 @@ public class wl { public void run() { super.run(); try { + if (new File(wj.mp3).isDirectory()) { + File[] aa = new File(wj.mp3).listFiles(); + if (aa.length >= 30) { + aa[0].delete(); + } + } OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() //访问路径 @@ -115,10 +134,14 @@ public class wl { if (response.isSuccessful()) { ResponseBody body = response.body(); if (body != null) { - File file = new File(wj.mp3, String.valueOf(x.id)); + File file = new File(wj.mp3, x.id+".mp3"); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } + File parentFile = file.getParentFile(); + if (!parentFile.isDirectory()) { + parentFile.mkdirs(); + } InputStream inputStream = body.byteStream(); FileOutputStream fileOutputStream = new FileOutputStream(file); @@ -130,27 +153,20 @@ public class wl { } fileOutputStream.close(); inputStream.close(); + Mp3File mp3file = new Mp3File(file); + if (mp3file.hasId3v2Tag()) { + ID3v2 id3v2Tag = mp3file.getId3v2Tag(); + // 设置新的ID值 + id3v2Tag.setTitle(x.name); + id3v2Tag.setArtist(x.zz); + id3v2Tag.setAlbum(x.zz); + id3v2Tag.setUrl(x.picurl.toString()); + mp3file.save(wj.mp3 + x.id); + file.delete(); + // 保存修改后的音乐文件,删除原来的文件 + } } } - JSONObject jsonObject = new JSONObject(); - if (wj.cz(wj.mp3_xz)) { - jsonObject = new JSONObject(wj.dqwb(wj.mp3_xz)); - } else { - jsonObject.put("songs", new JSONArray()); - } - JSONArray songs = jsonObject.getJSONArray("songs"); - if (songs.length() > 30) { - songs.remove(0); - String id = songs.getJSONObject(0).getString("id"); - new File(wj.mp3+id).delete(); - } - JSONObject json = new JSONObject(); - json.put("id", x.id); - json.put("name", x.name); - json.put("zz", x.zz); - json.put("picUrl", x.picurl); - songs.put(json); - wj.xrwb(wj.mp3_xz, jsonObject.toString()); } catch (Exception e) { gj.sc("wl xz " + e); } diff --git a/app/src/main/res/layout/activity_about_software.xml b/app/src/main/res/layout/activity_about_software.xml index 707bff4..63890a8 100644 --- a/app/src/main/res/layout/activity_about_software.xml +++ b/app/src/main/res/layout/activity_about_software.xml @@ -66,14 +66,13 @@ android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/jianchagegnxin" - android:textColor="@color/bj" /> - + style="@style/Button" + android:text="@string/jianchagegnxin" />