优化下载音乐文件

添加储存清理功能
修改主题颜色为冷色调
This commit is contained in:
muqing 2023-12-08 16:31:48 +08:00
parent b086443ac7
commit 5e3cbe6002
22 changed files with 221 additions and 97 deletions

View File

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

View File

@ -49,6 +49,7 @@
<activity android:name=".login.enroll" />
<activity android:name=".login.user_logs" />
<activity android:name=".login.user_editing" />
<activity android:name=".clean.fragment_clean" />
<activity android:name=".activity_search" />
<activity
android:name=".bfq"

View File

@ -2,6 +2,8 @@ package com.muqingbfq.api;
import android.annotation.SuppressLint;
import com.mpatric.mp3agic.ID3v2;
import com.mpatric.mp3agic.Mp3File;
import com.muqingbfq.fragment.gd;
import com.muqingbfq.fragment.mp3;
import com.muqingbfq.main;
@ -13,6 +15,7 @@ import com.muqingbfq.xm;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.util.Iterator;
import java.util.List;
@ -75,7 +78,6 @@ public class playlist extends Thread {
String picUrl = jsonObject.getString("picUrl");
list.add(new xm(id, name, zz, picUrl));
}
// main.handler.post(new mp3.lbspq_sx());
return true;
} catch (Exception e) {
gj.sc("失败的错误 " + e);
@ -86,15 +88,14 @@ public class playlist extends Thread {
public static boolean hq_xz(List<xm> 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;

View File

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

View File

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

View File

@ -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<String[]> 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<VH> adapter = new RecyclerView.Adapter<VH>() {
@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);
}
}
}

View File

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

View File

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

View File

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

View File

@ -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));
//绑定网易云
}
}
}

View File

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

View File

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

View File

@ -49,7 +49,7 @@ public class wj {
//如果文件不存在创建文件
try {
File parentFile = file.getParentFile();
if (!parentFile.exists()) {
if (!parentFile.isDirectory()) {
parentFile.mkdirs();
}
if (!file.exists())

View File

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

View File

@ -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" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/juanzeng"
android:textColor="@color/bj" />
style="@style/Button"
android:text="@string/juanzeng" />
</LinearLayout>
</LinearLayout>

View File

@ -9,7 +9,8 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="绑定网易云音乐"/>
app:title="绑定网易云音乐"
app:subtitle="(Cookie保存在本地)"/>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"

View File

@ -131,13 +131,14 @@
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<Button
android:id="@+id/button2"
android:id="@+id/user_end"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="6dp"
android:text="绑定网易云(Cookie储在本地)" />
app:icon="@drawable/user_end"
android:text="@string/tuichudenglu" />
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,18 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</LinearLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox
android:id="@+id/box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name" />
</LinearLayout>

View File

@ -31,6 +31,6 @@
<item
android:id="@+id/g"
android:icon="@drawable/user_end"
android:title="@string/tuichudenglu" />
android:icon="@drawable/icon"
android:title="绑定网易云" />
</menu>

View File

@ -10,14 +10,10 @@
<color name="text_cz">#03A9F4</color>
<color name="text_cz_tm">#9903A9F4</color>
<color name="text">@color/black</color>
<color name="text">#000000</color>
<color name="text_tm">#80000000</color>
<color name="tm">#00FFFFFF</color>
<color name="bj">@color/white</color>
<color name="lrc_normal_text_color">#A2A2A2</color>
<color name="lrc_current_text_color">#000000</color>
<color name="lrc_timeline_text_color">#343434</color>
<color name="lrc_timeline_color">#809E9E9E</color>
<color name="lrc_time_text_color">#809E9E9E</color>
<color name="button_bj">#B3E5FC</color>
</resources>

View File

@ -10,11 +10,26 @@
<style name="Theme.start" parent="Theme.Material3.DayNight">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!-- <item name="android:textColorTertiary">@color/text</item>-->
<!-- <item name="android:textColorPrimary">@color/text</item>-->
<item name="android:statusBarColor">@color/tm</item>
<!-- 控件选中时的颜色,默认使用colorAccent -->
<!-- <item name="android:colorControlActivated">#FF7F50</item>-->
<!-- 设置文本颜色 -->
<item name="android:textColorPrimary">@color/text</item>
<item name="android:colorPrimary">#00BCD4</item>
<item name="colorPrimaryDark">#8000BCD4</item>
<item name="tabStyle">@style/Widget.App.TabLayout</item>
</style>
<style name="Widget.App.TabLayout" parent="Widget.Material3.TabLayout">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.TabLayout</item>
<!-- <item name="tabTextAppearance">@style/TextAppearance.App.LabelLarge</item>-->
</style>
<style name="ThemeOverlay.App.TabLayout" parent="">
<item name="colorPrimary">#00BCD4</item>
<item name="colorOnSurface">#ADD8E6</item>
</style>
<style name="fragment_dialog" parent="Theme.muqing">
<item name="android:windowIsTranslucent">true</item>
@ -32,4 +47,10 @@
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">@drawable/start</item>
</style>
<!-- 按钮主题-->
<style name="Button">
<item name="android:backgroundTint">#1C71A9</item>
</style>
</resources>