添加用户引导登录

This commit is contained in:
muqing 2024-01-12 17:08:52 +08:00
parent dfcb99848e
commit f00b765c91
14 changed files with 174 additions and 244 deletions

View File

@ -18,7 +18,7 @@ android {
//noinspection OldTargetApi //noinspection OldTargetApi
targetSdk 31 targetSdk 31
versionCode 1 versionCode 1
versionName "1.9.1" versionName "1.9.3"
} }
compileOptions { compileOptions {

View File

@ -12,8 +12,8 @@
"filters": [], "filters": [],
"attributes": [], "attributes": [],
"versionCode": 1, "versionCode": 1,
"versionName": "1.9.0", "versionName": "1.9.3",
"outputFile": "Cloud_music-debug-v1.9.0.apk" "outputFile": "Cloud_music-debug-v1.9.3.apk"
} }
], ],
"elementType": "File" "elementType": "File"

View File

@ -27,6 +27,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback; import okhttp3.Callback;
@ -49,7 +50,13 @@ public class FileDownloader {
.show(); .show();
}); });
} }
public FileDownloader() {
String file_url = wj.mp3;
public FileDownloader(String x,MP3 mp3,boolean hc) {
if (hc) {
file_url = wj.filesdri + "hc/";
}
downloadFile(x,mp3);
} }
public void downloadFile(MP3 x) { public void downloadFile(MP3 x) {
Request request = new Request.Builder() Request request = new Request.Builder()
@ -80,6 +87,7 @@ public class FileDownloader {
} }
}); });
} }
long fileSizeDownloaded = 0; long fileSizeDownloaded = 0;
public void downloadFile(String url, MP3 x) { public void downloadFile(String url, MP3 x) {
Request request = new Request.Builder() Request request = new Request.Builder()
@ -100,7 +108,7 @@ public class FileDownloader {
// 下载失败处理 // 下载失败处理
return; return;
} }
File outputFile = new File(wj.mp3, x.id + ".mp3"); File outputFile = new File(file_url, x.id + ".mp3");
File parentFile = outputFile.getParentFile(); File parentFile = outputFile.getParentFile();
if (!parentFile.isDirectory()) { if (!parentFile.isDirectory()) {
parentFile.mkdirs(); parentFile.mkdirs();
@ -143,7 +151,7 @@ public class FileDownloader {
id3v2Tag.setAlbumImage(execute.body().bytes(), "image/jpeg"); id3v2Tag.setAlbumImage(execute.body().bytes(), "image/jpeg");
} }
o.close(); o.close();
mp3file.save(wj.mp3 + x.id); mp3file.save(file_url + x.id);
outputFile.delete(); outputFile.delete();
} }
// 保存修改后的音乐文件删除原来的文件 // 保存修改后的音乐文件删除原来的文件

View File

@ -39,7 +39,11 @@ public class playlist extends Thread {
if (wj.cz(wj.gd + uid)) { if (wj.cz(wj.gd + uid)) {
hq = wj.dqwb(wj.gd + uid); hq = wj.dqwb(wj.gd + uid);
} else { } else {
hq = wl.hq(api + uid + "&limit=100" + "&cookie=" + wl.Cookie); if (wj.cz(wj.filesdri + "user.mq")) {
hq = wl.hq(api + uid + "&limit=100" + "&cookie=" + wl.Cookie);
} else {
hq = wl.hq(api + uid + "&limit=100");
}
} }
JSONObject json = new JSONObject(hq); JSONObject json = new JSONObject(hq);
JSONArray songs = json.getJSONArray("songs"); JSONArray songs = json.getJSONArray("songs");

View File

@ -1,11 +1,15 @@
package com.muqingbfq.api; package com.muqingbfq.api;
import android.content.Intent;
import com.mpatric.mp3agic.ID3v2; import com.mpatric.mp3agic.ID3v2;
import com.mpatric.mp3agic.Mp3File; import com.mpatric.mp3agic.Mp3File;
import com.muqingbfq.MP3; import com.muqingbfq.MP3;
import com.muqingbfq.bfq; import com.muqingbfq.bfq;
import com.muqingbfq.fragment.Media; import com.muqingbfq.fragment.Media;
import com.muqingbfq.home; import com.muqingbfq.home;
import com.muqingbfq.login.user_logs;
import com.muqingbfq.main;
import com.muqingbfq.mq.gj; import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj; import com.muqingbfq.mq.wj;
import com.muqingbfq.mq.wl; import com.muqingbfq.mq.wl;
@ -15,16 +19,6 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class url extends Thread { public class url extends Thread {
public static String api = "/song/url/v1"; public static String api = "/song/url/v1";
MP3 x; MP3 x;
@ -35,8 +29,6 @@ public class url extends Thread {
} }
public static String hq(MP3 x) { public static String hq(MP3 x) {
getLrc(x.id);
Media.loadLyric();
try { try {
if (wj.cz(wj.mp3 + x.id)) { if (wj.cz(wj.mp3 + x.id)) {
return wj.mp3 + x.id; return wj.mp3 + x.id;
@ -55,73 +47,23 @@ public class url extends Thread {
return null; return null;
} }
JSONObject json = new JSONObject(hq); JSONObject json = new JSONObject(hq);
gj.sc(json);
if (json.getInt("code") == -460) { if (json.getInt("code") == -460) {
String message = json.getString("message"); String message = json.getString("message");
gj.xcts(home.appCompatActivity, message + "-可能需要登录网易云"); main.handler.post(() -> {
gj.ts(home.appCompatActivity, message);
home.appCompatActivity.startActivity(new Intent(home.appCompatActivity
, user_logs.class));
});
return null; return null;
} }
getLrc(x.id);
Media.loadLyric();
JSONArray data = json.getJSONArray("data"); JSONArray data = json.getJSONArray("data");
JSONObject jsonObject = data.getJSONObject(0); JSONObject jsonObject = data.getJSONObject(0);
String url = jsonObject.getString("url"); String url = jsonObject.getString("url");
if (wiFiConnected) { if (wiFiConnected) {
new Thread() { new FileDownloader(url, x,true);
@Override
public void run() {
super.run();
try {
if (new File(wj.filesdri + "hc").isDirectory()) {
File[] aa = new File(wj.filesdri + "hc").listFiles();
if (aa.length >= 30) {
aa[0].delete();
}
}
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
//访问路径
.url(url)
.build();
Call call = client.newCall(request);
Response response = call.execute();
if (response.isSuccessful()) {
ResponseBody body = response.body();
if (body != null) {
File file = new File(wj.filesdri + "hc", 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);
// 替换为实际要保存的文件路径
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
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);
mp3file.save(wj.filesdri + "hc/" + x.id);
file.delete();
// 保存修改后的音乐文件删除原来的文件
}
}
}
} catch (Exception e) {
gj.sc("wl xz " + e);
}
}
}.start();
} }
return url; return url;
} catch (JSONException e) { } catch (JSONException e) {

View File

@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -27,6 +28,7 @@ import com.muqingbfq.api.FileDownloader;
import com.muqingbfq.api.url; import com.muqingbfq.api.url;
import com.muqingbfq.databinding.ActivityBfqBinding; import com.muqingbfq.databinding.ActivityBfqBinding;
import com.muqingbfq.fragment.Media; import com.muqingbfq.fragment.Media;
import com.muqingbfq.login.user_logs;
import com.muqingbfq.mq.gj; import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj; import com.muqingbfq.mq.wj;
import com.muqingbfq.mq.wl; import com.muqingbfq.mq.wl;
@ -50,6 +52,10 @@ public class bfq extends AppCompatActivity {
private void setLrc() { private void setLrc() {
lrcView = binding.lrcView; lrcView = binding.lrcView;
ViewGroup.LayoutParams layoutParams = binding.cardview.getLayoutParams(); ViewGroup.LayoutParams layoutParams = binding.cardview.getLayoutParams();
DisplayMetrics dm = getResources().getDisplayMetrics();
main.k = dm.widthPixels;
main.g = dm.heightPixels;
layoutParams.height = main.k - 100; layoutParams.height = main.k - 100;
layoutParams.width = main.k - 100; layoutParams.width = main.k - 100;
binding.cardview.setLayoutParams(layoutParams); binding.cardview.setLayoutParams(layoutParams);
@ -148,11 +154,21 @@ public class bfq extends AppCompatActivity {
try { try {
JSONObject json = new JSONObject(hq); JSONObject json = new JSONObject(hq);
JSONArray data = json.getJSONArray("data"); JSONArray data = json.getJSONArray("data");
if (json.getInt("code") == -460) {
String message = json.getString("message");
main.handler.post(() -> {
gj.ts(home.appCompatActivity, message);
home.appCompatActivity.startActivity(new Intent(home.appCompatActivity
, user_logs.class));
});
return;
}
JSONObject jsonObject = data.getJSONObject(0); JSONObject jsonObject = data.getJSONObject(0);
String url = jsonObject.getString("url"); String url = jsonObject.getString("url");
new FileDownloader(bfq.this).downloadFile(url, bfqkz.xm); new FileDownloader(bfq.this).downloadFile(url, bfqkz.xm);
} catch (JSONException e) { } catch (JSONException e) {
throw new RuntimeException(e); gj.sc(e);
} }
} }
}.start(); }.start();

View File

@ -94,7 +94,7 @@ public class gd_adapter extends Fragment {
} }
bfqkz.list.add(0, x); bfqkz.list.add(0, x);
// bfqkz.list.addAll(list); // bfqkz.list.addAll(list);
bfq.start(getContext()); // bfq.start(getContext());
}); });
Glide.with(getContext()).load(x.picurl) Glide.with(getContext()).load(x.picurl)
.apply(new RequestOptions().placeholder(R.drawable.ic_launcher_foreground)) .apply(new RequestOptions().placeholder(R.drawable.ic_launcher_foreground))

View File

@ -25,6 +25,7 @@ import com.muqingbfq.R;
import com.muqingbfq.XM; import com.muqingbfq.XM;
import com.muqingbfq.databinding.FragmentWdBinding; import com.muqingbfq.databinding.FragmentWdBinding;
import com.muqingbfq.login.user_logs; import com.muqingbfq.login.user_logs;
import com.muqingbfq.login.visitor;
import com.muqingbfq.main; import com.muqingbfq.main;
import com.muqingbfq.mq.EditViewDialog; import com.muqingbfq.mq.EditViewDialog;
import com.muqingbfq.mq.gj; import com.muqingbfq.mq.gj;
@ -66,43 +67,21 @@ public class wode extends Fragment {
jieshao = binding.text2; jieshao = binding.text2;
imageView = binding.imageView; imageView = binding.imageView;
binding.cardview.setOnClickListener(v -> { binding.cardview.setOnClickListener(v -> {
File file = new File(wj.filesdri, "user.mq"); File file = new File(wj.filesdri, "user.mq");
// user_logs.USER.user;
if (file.exists()) { if (file.exists()) {
String[] a = new String[]{"退出登录"}; String[] a = new String[]{"退出登录"};
new MaterialAlertDialogBuilder(getContext()) new MaterialAlertDialogBuilder(getContext())
.setItems(a, (dialogInterface, i) -> { .setItems(a, (dialogInterface, i) -> {
file.delete(); file.delete();
setname(getString(R.string.app_name));
setqianming(getString(R.string.app_name));
imageView.setImageResource(R.drawable.ic_launcher_foreground);
new visitor();
new com.muqingbfq.login.user_message(); new com.muqingbfq.login.user_message();
}).show(); }).show();
} else { } else {
startActivity(new Intent(getContext(), user_logs.class)); startActivity(new Intent(getContext(), user_logs.class));
} }
/*
v.setEnabled(false);
new Thread() {
@Override
public void run() {
super.run();
String hq = wl.hq("/login/status?cookie=" + wl.Cookie);
if (hq != null) {
try {
JSONObject jsonObject = new JSONObject(hq);
JSONObject jsonObject1 = jsonObject.getJSONObject("data").getJSONObject("profile");
if (TextUtils.isEmpty(jsonObject1.toString())) {
} else {
main.handler.post(() -> {
});
}
} catch (JSONException e) {
gj.sc(e);
}
}
main.handler.post(() -> v.setEnabled(true));
}
}.start();*/
}); });
// new user_message(); // new user_message();
// int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); // int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f);

View File

@ -45,7 +45,6 @@ public class enroll extends FragmentActivity {
if (null != v) { if (null != v) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0); imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} }
new thread();
} }
private void end() { private void end() {
@ -60,40 +59,4 @@ public class enroll extends FragmentActivity {
setResult(Activity.RESULT_OK, intent); setResult(Activity.RESULT_OK, intent);
finish(); // 结束当前的活动页面 finish(); // 结束当前的活动页面
} }
class thread extends Thread {
public thread() {
account = edit_account.getText().toString();
username = edit_username.getText().toString();
password = edit_password.getText().toString();
email = edit_email.getText().toString();
start();
}
@Override
public void run() {
super.run();
try {
JSONObject jsonpost = wl.jsonpost("/php/user.php?action=register",
new String[]{
"account", "userName", "passWord"
, "email", "appID"
}
, new String[]{
account, username, password, email, appID
});
if (TextUtils.isEmpty(jsonpost.toString())) {
return;
}
int code = jsonpost.getInt("code");
String message = jsonpost.getString("message");
gj.xcts(enroll.this, message);
if (code == 0) {
end();
}
} catch (JSONException e) {
gj.sc(e);
}
}
}
} }

View File

@ -144,50 +144,4 @@ public class user_logs extends AppCompatActivity {
} }
} }
} }
@Deprecated
private void jihuo() {
main.handler.post(new Runnable() {
@Override
public void run() {
EditViewDialog editViewDialog = new EditViewDialog(user_logs.this, "激活用户")
.setMessage("验证码在你账号锁绑定的邮箱绘制垃圾桶中请及时查看");
editViewDialog.setPositive(new View.OnClickListener() {
@Override
public void onClick(View view) {
String editText = editViewDialog.getEditText();
new Thread() {
@Override
public void run() {
super.run();
JSONObject post = wl.jsonpost("/php/user.php?action=enableAccount",
new String[]{
"account", "key"
}
, new String[]{
account, editText
});
if (TextUtils.isEmpty(post.toString())) {
return;
}
try {
int code = post.getInt("code");
gj.xcts(user_logs.this, post.getString("message"));
if (code == 1) {
return;
}
editViewDialog.dismiss();
} catch (JSONException e) {
gj.sc(e);
}
}
}.start();
}
}).setEditinputType("number")
.show();
}
});
}
} }

View File

@ -39,16 +39,17 @@ public class wl {
return null; return null;
} }
public static String post(String str, String[] a, String[] b) { public static String post(String str, String[][] a) {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.build(); .build();
FormBody.Builder builder = new FormBody.Builder(); FormBody.Builder builder = new FormBody.Builder();
for (int i = 0; i < a.length; i++) { for (String[] strings : a) {
builder.add(a[i], b[i]); // gj.sc(strings[0] + ":" + strings[1]);
builder.add(strings[0], strings[1]);
} }
Request request = new Request.Builder() Request request = new Request.Builder()
.url("https://rust.coldmint.top" + str) .url(main.api + str)
.post(builder.build()) .post(builder.build())
.build(); .build();
try { try {
@ -60,9 +61,9 @@ public class wl {
return null; return null;
} }
public static JSONObject jsonpost(String str, String[] a, String[] b) { public static JSONObject jsonpost(String str, String[][] a) {
try { try {
return new JSONObject(post(str, a, b)); return new JSONObject(post(str, a));
} catch (JSONException e) { } catch (JSONException e) {
gj.sc(e); gj.sc(e);
return null; return null;

View File

@ -3,13 +3,17 @@ package com.muqingbfq.view;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
@ -23,6 +27,8 @@ import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.muqingbfq.R; import com.muqingbfq.R;
import com.muqingbfq.databinding.ViewLrcBinding;
import com.muqingbfq.main;
import com.muqingbfq.mq.gj; import com.muqingbfq.mq.gj;
import com.muqingbfq.yc; import com.muqingbfq.yc;
@ -82,6 +88,7 @@ public class LrcView extends RecyclerView {
AttributeSet attrs; AttributeSet attrs;
boolean Lrcline; boolean Lrcline;
LinearLayoutManager linearLayoutManager; LinearLayoutManager linearLayoutManager;
public LrcView(Context context, @Nullable AttributeSet attrs) { public LrcView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.attrs = attrs; this.attrs = attrs;
@ -104,8 +111,37 @@ public class LrcView extends RecyclerView {
public void setLrcline(boolean lrcline) { public void setLrcline(boolean lrcline) {
Lrcline = lrcline; Lrcline = lrcline;
if (lrcline) {
addItemDecoration(new ItemDecoration() {
@Override
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull State state) {
super.onDraw(c, parent, state);
}
});
} else {
addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
view.setOnClickListener(onClickListener);
int parentHeight = parent.getHeight();
int childHeight = view.getHeight();
int topMargin = (parentHeight - childHeight) / 2;
// 设置第一项的顶部间距
if (parent.getChildAdapterPosition(view) == 0) {
outRect.top = topMargin;
}
}
});
}
} }
public android.os.Handler handler = new Handler(Looper.getMainLooper());
@SuppressLint("ClickableViewAccessibility")
private void init() { private void init() {
if (attrs != null) { if (attrs != null) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LrcView); TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LrcView);
@ -129,27 +165,24 @@ public class LrcView extends RecyclerView {
setAdapter(new adaper()); setAdapter(new adaper());
setForeground(null); setForeground(null);
setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER); setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);
if (!Lrcline) { setLrcline(Lrcline);
addItemDecoration(new RecyclerView.ItemDecoration() { addOnScrollListener(new OnScrollListener() {
@Override @Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.getItemOffsets(outRect, view, parent, state); super.onScrollStateChanged(recyclerView, newState);
view.setOnClickListener(onClickListener); // 判断滚动状态
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
int parentHeight = parent.getHeight(); // 正在拖动中
int childHeight = view.getHeight(); // 执行相应的操作
tuodong = true;
int topMargin = (parentHeight - childHeight) / 2; } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
// 停止拖动
// 设置第一项的顶部间距 // 执行相应的操作
if (parent.getChildAdapterPosition(view) == 0) { main.handler.postDelayed(() -> tuodong = false, 3000);
outRect.top = topMargin;
}
} }
}); }
} else { });
setOnTouchListener(null); // setItemAnimator(null);
}
} }
private static class CenterSmoothScroller extends LinearSmoothScroller { private static class CenterSmoothScroller extends LinearSmoothScroller {
@ -212,6 +245,16 @@ public class LrcView extends RecyclerView {
} }
} }
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent e) {
if (!Lrcline) {
return super.onTouchEvent(e);
} else {
return false;
}
}
int index = -1; int index = -1;
int size = 20; int size = 20;
@ -234,12 +277,12 @@ public class LrcView extends RecyclerView {
@Override @Override
public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View inflate = LayoutInflater.from(getContext()).inflate(R.layout.view_lrc, parent, false); View inflate = LayoutInflater.from(getContext()).inflate(R.layout.view_lrc, parent, false);
return new VH(inflate); return new VH(ViewLrcBinding.bind(inflate));
} }
@Override @Override
public void onBindViewHolder(@NonNull VH holder, int position) { public void onBindViewHolder(@NonNull VH holder, int position) {
TextView textView = holder.textView; TextView textView = holder.binding.text;
textView.setTextColor(TextColor); textView.setTextColor(TextColor);
textView.setTextSize( textView.setTextSize(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
@ -249,32 +292,32 @@ public class LrcView extends RecyclerView {
if (Lrcline) { if (Lrcline) {
if (addOnGlobalLayoutListener) { if (addOnGlobalLayoutListener) {
// 注册布局监听器 // 注册布局监听器
holder.textView.getViewTreeObserver().addOnGlobalLayoutListener( textView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() { new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
int height = holder.textView.getHeight(); int height = textView.getHeight();
ViewGroup.LayoutParams layoutParams = LrcView.this.getLayoutParams(); ViewGroup.LayoutParams layoutParams = LrcView.this.getLayoutParams();
layoutParams.height = height * 5; layoutParams.height = height * 5;
LrcView.this.setLayoutParams(layoutParams); LrcView.this.setLayoutParams(layoutParams);
// 移除布局监听器 // 移除布局监听器
holder.textView.getViewTreeObserver().removeOnGlobalLayoutListener(this); textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} }
}); });
} }
if (lrclist.isEmpty()) { if (lrclist.isEmpty()) {
holder.textView.setText("纯音乐,请欣赏"); textView.setText("纯音乐,请欣赏");
return; return;
} }
int currentLineIndex = getCurrentLineIndex(); int currentLineIndex = getCurrentLineIndex();
if (currentLineIndex < lrclist.size()) { if (currentLineIndex < lrclist.size()) {
String text; String text;
if (lrclist.size() <= 3) { if (lrclist.size() <= 5) {
for (LRC a : lrclist) { for (LRC a : lrclist) {
if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) { if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) {
text = "纯音乐,请欣赏"; text = "纯音乐,请欣赏";
holder.textView.setText(text); textView.setText(text);
return; return;
} }
} }
@ -284,11 +327,11 @@ public class LrcView extends RecyclerView {
if (currentLrc.tlyric != null) { if (currentLrc.tlyric != null) {
text += "\n" + currentLrc.tlyric; text += "\n" + currentLrc.tlyric;
} }
holder.textView.setText(text); textView.setText(text);
} }
} else { } else {
if (lrclist.isEmpty()) { if (lrclist.isEmpty()) {
holder.textView.setText("纯音乐,请欣赏"); textView.setText("纯音乐,请欣赏");
return; return;
} }
try { try {
@ -299,11 +342,11 @@ public class LrcView extends RecyclerView {
stringBuffer.append("\n").append(lrc.tlyric); stringBuffer.append("\n").append(lrc.tlyric);
} }
stringBuffer.append("\n"); stringBuffer.append("\n");
holder.textView.setAlpha(0.1f); textView.setAlpha(0.1f);
if (getCurrentLineIndex(time) == position) { if (getCurrentLineIndex(time) == position) {
holder.textView.setAlpha(1.0f); textView.setAlpha(1.0f);
} }
holder.textView.setText(stringBuffer.toString()); textView.setText(stringBuffer.toString());
} catch (Exception e) { } catch (Exception e) {
gj.sc("LrcView.ADAPER.onBindViewHolder" + e); gj.sc("LrcView.ADAPER.onBindViewHolder" + e);
} }
@ -330,11 +373,11 @@ public class LrcView extends RecyclerView {
} }
class VH extends RecyclerView.ViewHolder { class VH extends RecyclerView.ViewHolder {
TextView textView; ViewLrcBinding binding;
public VH(@NonNull View itemView) { public VH(@NonNull ViewLrcBinding itemView) {
super(itemView); super(itemView.getRoot());
textView = itemView.findViewById(R.id.text); binding = itemView;
} }
} }
@ -367,20 +410,39 @@ public class LrcView extends RecyclerView {
int TextColor; int TextColor;
long time; long time;
//是否在拖动
boolean tuodong = false;
Runnable runnable = () -> {
};
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
public void setTimeLrc(long a) { public void setTimeLrc(long a) {
this.time = a; if (tuodong) {
if (!Lrcline) {
int currentLineIndex = getCurrentLineIndex(a);
getAdapter().notifyDataSetChanged();
if (currentLineIndex < 3) {
return;
}
// smoothScrollToPosition(getCurrentLineIndex(a));
linearLayoutManager.smoothScrollToPosition(this,
new RecyclerView.State(), currentLineIndex);
return; return;
} }
getAdapter().notifyDataSetChanged(); try {
this.time = a;
int index = getCurrentLineIndex(a);
if (this.index == index) {
return;
}
if (!Lrcline) {
getAdapter().notifyDataSetChanged();
// smoothScrollToPosition(getCurrentLineIndex(a));
linearLayoutManager.smoothScrollToPosition(this,
new RecyclerView.State(), index);
return;
}
getAdapter().notifyDataSetChanged();
} catch (Exception e) {
gj.sc(e);
}
}
private static long getTime(String min, String sec, String mills) {
return Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000 + Long.parseLong(mills);
} }
} }

View File

@ -7,7 +7,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -48,6 +47,7 @@ public class yc extends AppCompatActivity {
+ "密度DPI" + densityDpi + "\n" + + "密度DPI" + densityDpi + "\n" +
"异常信息: " + exception.toString(); "异常信息: " + exception.toString();
binding.text.setText(wb); binding.text.setText(wb);
binding.button2.setOnClickListener(view -> finish());
} }
public static void start(Object e) { public static void start(Object e) {

View File

@ -22,6 +22,7 @@
android:text="@string/fx"/> android:text="@string/fx"/>
<Button <Button
android:id="@+id/button2"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/quxiao" /> android:text="@string/quxiao" />