From 69c7cd15b9b46d1d75d0dc7fbee4bc87f5c0256f Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Sat, 30 Dec 2023 20:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG=E4=BC=98=E5=8C=96UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../main/java/com/muqingbfq/MediaPlayer.java | 2 +- .../com/muqingbfq/MyButtonClickReceiver.java | 7 +- .../main/java/com/muqingbfq/api/resource.java | 23 ++- app/src/main/java/com/muqingbfq/bfq.java | 19 +- .../java/com/muqingbfq/fragment/Media.java | 2 +- .../java/com/muqingbfq/fragment/bflb_db.java | 31 +++- .../main/java/com/muqingbfq/fragment/gd.java | 172 ++++++++++-------- .../java/com/muqingbfq/fragment/search.java | 25 ++- .../java/com/muqingbfq/fragment/wode.java | 3 +- .../muqingbfq/mq/FloatingLyricsService.java | 47 +++-- .../java/com/muqingbfq/view/CardImage.java | 11 +- .../main/java/com/muqingbfq/view/LrcView.java | 75 ++++---- app/src/main/java/com/muqingbfq/xm.java | 15 +- app/src/main/res/layout-land/activity_bfq.xml | 5 +- app/src/main/res/layout/activity_bfq.xml | 8 +- app/src/main/res/layout/float_lrcview.xml | 25 ++- app/src/main/res/layout/list_gd.xml | 36 +--- app/src/main/res/layout/list_gd_b.xml | 66 +++---- app/src/main/res/values-night/themes.xml | 9 + app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/colors.xml | 3 +- app/src/main/res/values/themes.xml | 27 +-- 23 files changed, 335 insertions(+), 279 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 729b34c..7b84ebd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ android { //noinspection OldTargetApi targetSdk 31 versionCode 1 - versionName "1.7.8" + versionName "1.8.0" } compileOptions { diff --git a/app/src/main/java/com/muqingbfq/MediaPlayer.java b/app/src/main/java/com/muqingbfq/MediaPlayer.java index aaabe30..cdcbfa3 100644 --- a/app/src/main/java/com/muqingbfq/MediaPlayer.java +++ b/app/src/main/java/com/muqingbfq/MediaPlayer.java @@ -149,7 +149,7 @@ public class MediaPlayer extends android.media.MediaPlayer { BitmapFactory.decodeByteArray(albumImage, 0, albumImage.length); } } catch (Exception a) { - gj.sc(a); + gj.sc("yc:"+a); } bfqkz.notify.setBitmap(); return false; diff --git a/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java b/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java index 6309866..a35fa95 100644 --- a/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java +++ b/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java @@ -90,10 +90,7 @@ public class MyButtonClickReceiver extends BroadcastReceiver { return; } FloatingLyricsService lei = FloatingLyricsService.lei; - gj.sc(lei.setup.i); - if (lei.setup.i == 0) { - lei.show(); - } else if (lei.setup.i == 1) { + if (lei.setup.i == 1) { lei.setyc(); } else { lei.setup.i = 0; @@ -102,6 +99,8 @@ public class MyButtonClickReceiver extends BroadcastReceiver { new Intent(home.appCompatActivity, FloatingLyricsService.class)); } break; + case "like": + break; } // 处理按钮点击事件的逻辑 } diff --git a/app/src/main/java/com/muqingbfq/api/resource.java b/app/src/main/java/com/muqingbfq/api/resource.java index b9907a8..5470388 100644 --- a/app/src/main/java/com/muqingbfq/api/resource.java +++ b/app/src/main/java/com/muqingbfq/api/resource.java @@ -2,19 +2,18 @@ package com.muqingbfq.api; import android.text.TextUtils; -import com.muqingbfq.R; +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.JSONArray; +import org.json.JSONException; import org.json.JSONObject; -import java.util.Iterator; import java.util.List; -import com.muqingbfq.xm; - public class resource { public static void recommend(List list) { @@ -54,6 +53,16 @@ public class resource { } } + + public static xm Playlist_content(String UID) throws JSONException { + String hq = wl.get(main.api + "/playlist/detail?id=" + UID); + JSONObject js = new JSONObject(hq).getJSONObject("playlist"); + String id = js.getString("id"); + String name = js.getString("name"); + String coverImgUrl = js.getString("coverImgUrl"); + return new xm(id, name, coverImgUrl); + } + public static void 排行榜(List list) { String hq; try { @@ -78,9 +87,8 @@ public class resource { if (!TextUtils.isEmpty(description) && !description.equals("null")) { name += description; } - boolean cz = wj.cz(wj.gd + id); String coverImgUrl = get.getString("coverImgUrl"); - list.add(new xm(id, name, coverImgUrl, cz)); + list.add(new xm(id, name, coverImgUrl)); } } } catch (Exception e) { @@ -90,9 +98,8 @@ public class resource { private static void add(JSONObject jsonObject, List list) throws Exception { String id = jsonObject.getString("id"); - boolean cz = wj.cz(wj.gd + id); String name = jsonObject.getString("name"); String picUrl = jsonObject.getString("picUrl"); - list.add(new xm(id, name, picUrl, cz)); + list.add(new xm(id, name, picUrl)); } } diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index bc1c625..aea0cdc 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -12,6 +12,7 @@ import android.os.Bundle; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; import android.view.WindowManager; import android.widget.LinearLayout; @@ -46,19 +47,13 @@ public class bfq extends AppCompatActivity { public static String lrc; public static com.muqingbfq.view.LrcView lrcView; private void setLrc(){ - lrcView = binding.lrcView;/* - lrcview.setCurrentColor(ContextCompat.getColor(this,R.color.text)); - lrcview.setLabel(getString(R.string.app_name)); - lrcview.setCurrentTextSize(TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics())); -// lrcView.setLrcPadding(16); - lrcview.setCurrentTextSize(TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics())); - lrcview.setTimelineTextColor(ContextCompat.getColor(this,R.color.text_tm)); - lrcview.setDraggable(true, (view, time) -> { + lrcView = binding.lrcView; + + ViewGroup.LayoutParams layoutParams = binding.cardview.getLayoutParams(); + layoutParams.height = main.k; + layoutParams.width = main.k; + binding.cardview.setLayoutParams(layoutParams);/* bfqkz.mt.seekTo(Math.toIntExact(time)); - return false; - }); if (!gj.isTablet(this)) { lrcview.setOnTapListener((view, x, y) -> { View kp = binding.kp1; diff --git a/app/src/main/java/com/muqingbfq/fragment/Media.java b/app/src/main/java/com/muqingbfq/fragment/Media.java index 7e18a95..5baae24 100644 --- a/app/src/main/java/com/muqingbfq/fragment/Media.java +++ b/app/src/main/java/com/muqingbfq/fragment/Media.java @@ -100,7 +100,7 @@ public class Media { a = jsonObject.getJSONObject("lrc").getString("lyric"); b = jsonObject.getJSONObject("tlyric").getString("lyric"); } catch (Exception e) { - gj.sc(e); + gj.sc("Media loadLyric "+e); } LrcView.setLrc(a, b); // bfq.lrcView.getLrc(); diff --git a/app/src/main/java/com/muqingbfq/fragment/bflb_db.java b/app/src/main/java/com/muqingbfq/fragment/bflb_db.java index 1e36b56..72a3a26 100644 --- a/app/src/main/java/com/muqingbfq/fragment/bflb_db.java +++ b/app/src/main/java/com/muqingbfq/fragment/bflb_db.java @@ -1,6 +1,8 @@ package com.muqingbfq.fragment; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -11,38 +13,47 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.muqingbfq.MP3; import com.muqingbfq.R; import com.muqingbfq.api.url; import com.muqingbfq.bfqkz; +import com.muqingbfq.databinding.FragmentBflbDbBinding; import com.muqingbfq.list.MyViewHoder; import com.muqingbfq.main; -import com.muqingbfq.mq.gj; -import com.muqingbfq.xm; import com.muqingbfq.yc; public class bflb_db extends BottomSheetDialog { public static RecyclerView.Adapter adapter; - + @SuppressLint("NotifyDataSetChanged") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.fragment_bflb_db); + FragmentBflbDbBinding binding = FragmentBflbDbBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); int height = main.g - main.g / 2 / 2; getBehavior().setPeekHeight(height); getBehavior().setMaxHeight(height); try { - RecyclerView lb = findViewById(R.id.lb); - lb.setAdapter(new spq()); + binding.lb.setAdapter(new spq()); if (bfqkz.xm != null) { - lb.smoothScrollToPosition(getI()); + binding.lb.smoothScrollToPosition(getI()); } - findViewById(R.id.xxbj). - setOnClickListener(v -> { + binding.xxbj.setOnClickListener(v -> { if (bfqkz.xm != null) { - lb.smoothScrollToPosition(getI()); + binding.lb.smoothScrollToPosition(getI()); } }); + binding.sc.setOnClickListener(view -> { + new MaterialAlertDialogBuilder(getContext()) + .setTitle("清空播放列表") + .setPositiveButton("确定", (dialogInterface, i) -> { + bfqkz.list.clear(); + adapter.notifyDataSetChanged(); + }) + .setNegativeButton("取消", null) + .show(); + }); } catch (Exception e) { yc.start(getContext(), e); } diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 6d30271..111cbc7 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -14,31 +14,21 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import androidx.viewpager2.adapter.FragmentStateAdapter; -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.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.muqingbfq.MP3; import com.muqingbfq.R; import com.muqingbfq.api.playlist; import com.muqingbfq.api.resource; import com.muqingbfq.bfq_an; import com.muqingbfq.bfqkz; -import com.muqingbfq.databinding.FragmentGdBinding; import com.muqingbfq.databinding.FragmentMp3Binding; -import com.muqingbfq.list.MyViewHoder; import com.muqingbfq.main; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; import com.muqingbfq.mq.wl; +import com.muqingbfq.view.CardImage; import com.muqingbfq.xm; import org.json.JSONArray; @@ -100,7 +90,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { String id = jsonObject.getString("id"); String name = jsonObject.getString("name"); String coverImgUrl = jsonObject.getString("coverImgUrl"); - list.add(new xm(id, name, coverImgUrl, false)); + list.add(new xm(id, name, coverImgUrl)); } } catch (Exception e) { gj.sc(e); @@ -110,7 +100,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { } } - public static class baseadapter extends RecyclerView.Adapter { + public static class baseadapter extends RecyclerView.Adapter{ Context context; List list; @@ -144,63 +134,14 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { @Override public void onBindViewHolder(@NonNull VH holder, int position) { xm xm = list.get(position); - 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; - }); + CARD card = new CARD(xm); + if (bool) { + holder.itemView.setOnClickListener(card); + holder.itemView.setOnLongClickListener(card); + } else { + holder.image.setOnClickListener(card); + holder.image.setOnLongClickListener(card); + } holder.textView.setText(xm.name); holder.kg.setOnClickListener(view1 -> { ImageView tx = (ImageView) view1; @@ -228,8 +169,8 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { color_kg = ContextCompat.getDrawable(context, R.drawable.bf); } holder.kg.setImageDrawable(color_kg); - Glide.with(context).load(xm.picurl).apply(new RequestOptions().placeholder(R.drawable.icon)) - .into(holder.imageView); +// xm.picurl + holder.image.setImageapply(xm.picurl); } @Override @@ -237,22 +178,99 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { return list.size(); } + class CARD implements View.OnClickListener + , View.OnLongClickListener { + xm xm; + + public CARD(xm xm) { + this.xm = xm; + } + @Override + public void onClick(View 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); + } + + @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=100"); + if (hq != null) { + wj.xrwb(wj.gd + xm.id, hq); + try { + JSONObject jsonObject = new JSONObject(); + if (wj.cz(wj.gd_xz)) { + jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz))); + } + xm fh=resource.Playlist_content(xm.id); + JSONObject json = new JSONObject(); + json.put("name", fh.name); + json.put("picUrl", fh.picurl); + jsonObject.put(fh.id, json); + wj.xrwb(wj.gd_xz, jsonObject.toString()); + main.handler.post(new sx()); + } 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)); + } + 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(new sx()); + } + }.start(); + // 在这里处理菜单项的点击事件 + dialog.dismiss(); + }).show(); + return false; + } + + } + + class sx implements Runnable { + @SuppressLint("NotifyDataSetChanged") + @Override + public void run() { + notifyDataSetChanged(); + } + } + } static class VH extends RecyclerView.ViewHolder { TextView textView; - ImageView imageView, kg; - MaterialCardView cardView; + ImageView kg; + CardImage image; public VH(@NonNull View itemView) { super(itemView); textView = itemView.findViewById(R.id.wb1); - imageView = itemView.findViewById(R.id.fh); - cardView = itemView.findViewById(R.id.cardview); + image = itemView.findViewById(R.id.image); kg = itemView.findViewById(R.id.kg); } } - private class lbspq_sx implements Runnable { @SuppressLint("NotifyDataSetChanged") @Override diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java index 965770a..d27d3ee 100644 --- a/app/src/main/java/com/muqingbfq/fragment/search.java +++ b/app/src/main/java/com/muqingbfq/fragment/search.java @@ -125,6 +125,13 @@ public class search extends Fragment { } private void mp3() { + try { + Long.parseLong(name); + com.muqingbfq.api.playlist.hq(list, name); + return; + } catch (NumberFormatException e) { + gj.sc(e); + } String hq = wl.hq("/search?keywords=" + name + "&type=1"); try { JSONArray jsonArray = new JSONObject(hq).getJSONObject("result") @@ -154,8 +161,21 @@ public class search extends Fragment { } private void gd() { - String hq = wl.hq("/search?keywords=" + name + "&limit=" + (k * 3) + "&type=1000"); try { + Long.parseLong(name); + String hq = wl.hq("/playlist/detail?id=" + name); + JSONObject js = new JSONObject(hq).getJSONObject("playlist"); + String id = js.getString("id"); + String name = js.getString("name"); + String coverImgUrl = js.getString("coverImgUrl"); +// gj.sc(name); + xmList.add(new xm(id, name, coverImgUrl)); + return; + } catch (Exception e) { + gj.sc(e); + } + try { + String hq = wl.hq("/search?keywords=" + name + "&limit=" + (k * 3) + "&type=1000"); JSONArray jsonArray = new JSONObject(hq).getJSONObject("result") .getJSONArray("playlists"); int length = jsonArray.length(); @@ -165,8 +185,7 @@ public class search extends Fragment { String name = jsonObject.getString("name"); String coverImgUrl = jsonObject.getString("coverImgUrl"); // gj.sc(name); - xmList.add(new xm(id, name, coverImgUrl, false)); - + xmList.add(new xm(id, name, coverImgUrl)); } } catch (Exception e) { gj.sc(e); diff --git a/app/src/main/java/com/muqingbfq/fragment/wode.java b/app/src/main/java/com/muqingbfq/fragment/wode.java index 4929bdc..f81b512 100644 --- a/app/src/main/java/com/muqingbfq/fragment/wode.java +++ b/app/src/main/java/com/muqingbfq/fragment/wode.java @@ -148,11 +148,10 @@ public class wode extends Fragment { JSONObject date = new JSONObject(wj.dqwb(wj.gd_xz)); for (Iterator it = date.keys(); it.hasNext(); ) { String id = it.next(); - boolean cz = wj.cz(wj.gd + id); JSONObject jsonObject = date.getJSONObject(id); String name = jsonObject.getString("name"); String picUrl = jsonObject.getString("picUrl"); - list.add(new xm(id, name, picUrl, cz)); + list.add(new xm(id, name, picUrl)); } main.handler.post(() -> binding.recyclerview2.getAdapter().notifyDataSetChanged()); } catch (Exception e) { diff --git a/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java b/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java index 2c28e15..b6a5fc7 100644 --- a/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java +++ b/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java @@ -12,11 +12,13 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; +import android.widget.ImageView; import androidx.annotation.Nullable; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import com.muqingbfq.R; import com.muqingbfq.bfq_an; import com.muqingbfq.bfqkz; import com.muqingbfq.databinding.FloatLrcviewBinding; @@ -52,9 +54,10 @@ public class FloatingLyricsService extends Service implements View.OnClickListen SETUP setup = gson.fromJson(dqwb, type); return setup.i != 0; } else { - return true; + return false; } } + Handler handler = new Handler(); LrcView lrcView; WindowManager.LayoutParams params; @@ -67,8 +70,6 @@ public class FloatingLyricsService extends Service implements View.OnClickListen } public SETUP setup = new SETUP(); - File file; - public int lock() { if (setup != null && setup.i == 2) { return WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE @@ -77,13 +78,12 @@ public class FloatingLyricsService extends Service implements View.OnClickListen return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; } - @Override public void onCreate() { super.onCreate(); lei = this; + File file = new File(wj.filesdri + "FloatingLyricsService.json"); try { - file = new File(wj.filesdri + "FloatingLyricsService.json"); if (file.exists() && file.isFile()) { String dqwb = wj.dqwb(file.toString()); Gson gson = new Gson(); @@ -95,20 +95,15 @@ public class FloatingLyricsService extends Service implements View.OnClickListen setup.TOP = 0; setup.Y = -main.g; } - - } catch (Exception e) { wj.sc(file.toString()); - gj.sc(e); + gj.sc(getClass() + ":" + e); } // 创建悬浮窗歌词的 View // FloatLrcviewBinding FloatLrcviewBinding binding = FloatLrcviewBinding.inflate(LayoutInflater.from(this)); layout = binding.getRoot(); layout.setOnTouchListener(this); -// ViewGroup.LayoutParams layoutParams = layout.getLayoutParams(); -// layout.setLayoutParams(layoutParams); - // int i = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;FLAG_NOT_TOUCH_MODAL params = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, @@ -124,7 +119,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen lrcView = binding.lrcView; bfq_an.kz bfqAn = new bfq_an.kz(); - binding.kg.setOnClickListener(bfqAn); + binding.kg.setOnClickListener(this); binding.syq.setOnClickListener(bfqAn); binding.xyq.setOnClickListener(bfqAn); binding.lock.setOnClickListener(this); @@ -140,7 +135,10 @@ public class FloatingLyricsService extends Service implements View.OnClickListen layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE); } windowManager.addView(layout, params); - gj.sc("添加成功"); + if (setup.i == 0) { + setup.i = 1; + } + baocun(); handler.post(updateSeekBar); // 在播放开始时启动更新进度 } @@ -163,8 +161,8 @@ public class FloatingLyricsService extends Service implements View.OnClickListen } public void baocun() { - String s = new Gson().toJson(setup); - wj.xrwb(new File(wj.filesdri + "FloatingLyricsService.json").toString(), s); + wj.xrwb(new File(wj.filesdri + "FloatingLyricsService.json").toString(), + new Gson().toJson(setup)); } private int initialY; @@ -196,7 +194,24 @@ public class FloatingLyricsService extends Service implements View.OnClickListen @Override public void onClick(View view) { - setyc(); + int id = view.getId(); + if (id == R.id.kg) { + ImageView kg = (ImageView) view; + if (bfqkz.mt == null) { + return; + } + if (bfqkz.mt.isPlaying()) { + bfqkz.mt.pause(); + kg.setImageResource(R.drawable.zt); + } else { + bfqkz.mt.start(); + kg.setImageResource(R.drawable.bf); + } + } else if (id==R.id.lock) { + setyc(); + } else if (id == R.id.like) { +// bfq + } } public void setyc() { diff --git a/app/src/main/java/com/muqingbfq/view/CardImage.java b/app/src/main/java/com/muqingbfq/view/CardImage.java index f79f60c..dacdfa9 100644 --- a/app/src/main/java/com/muqingbfq/view/CardImage.java +++ b/app/src/main/java/com/muqingbfq/view/CardImage.java @@ -1,11 +1,11 @@ package com.muqingbfq.view; import android.content.Context; -import android.graphics.Bitmap; import android.util.AttributeSet; import android.widget.ImageView; import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import com.google.android.material.card.MaterialCardView; import com.muqingbfq.R; @@ -37,6 +37,15 @@ public class CardImage extends MaterialCardView { public void setImage(Object bitmap) { Glide.with(getContext()) .load(bitmap) +// .apply(new RequestOptions().placeholder(R.drawable.icon)) + .into(imageView); + } + + public void setImageapply(Object bitmap) { + Glide.with(getContext()) + .load(bitmap) + .apply(new RequestOptions().placeholder(R.drawable.icon)) +// .error(R.drawable.app_warning) .into(imageView); } } diff --git a/app/src/main/java/com/muqingbfq/view/LrcView.java b/app/src/main/java/com/muqingbfq/view/LrcView.java index 4543759..382e562 100644 --- a/app/src/main/java/com/muqingbfq/view/LrcView.java +++ b/app/src/main/java/com/muqingbfq/view/LrcView.java @@ -3,21 +3,15 @@ package com.muqingbfq.view; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Paint; import android.graphics.Rect; -import android.text.Layout; -import android.text.StaticLayout; -import android.text.TextPaint; import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; +import android.view.ViewTreeObserver; import android.widget.TextView; import androidx.annotation.NonNull; @@ -28,17 +22,12 @@ import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.RecyclerView; import com.muqingbfq.R; -import com.muqingbfq.main; import com.muqingbfq.mq.gj; -import com.muqingbfq.yc; import java.util.ArrayList; import java.util.List; public class LrcView extends RecyclerView { - private void sc(Object obj) { - gj.sc("LRC " + obj); - } static List lrclist = new ArrayList<>(); @@ -91,10 +80,11 @@ public class LrcView extends RecyclerView { TextColor = ta.getColor(R.styleable.LrcView_TextColor, ContextCompat.getColor(getContext(), R.color.text)); Lrcline = ta.getBoolean(R.styleable.LrcView_Lrcline, true); + addOnGlobalLayoutListener = ta. + getBoolean(R.styleable.LrcView_addOnGlobalLayoutListener, false); ta.recycle(); } linearLayoutManager = new LinearLayoutManager(getContext()) { - @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { RecyclerView.SmoothScroller smoothScroller = new CenterSmoothScroller(recyclerView.getContext()); @@ -108,9 +98,9 @@ public class LrcView extends RecyclerView { setForeground(null); setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER); if (!Lrcline) { - addItemDecoration( new RecyclerView.ItemDecoration() { + addItemDecoration(new RecyclerView.ItemDecoration() { @Override - public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int parentHeight = parent.getHeight(); @@ -166,7 +156,6 @@ public class LrcView extends RecyclerView { long time = (long) minute * 60 * 1000 + second * 1000L + millisecond; int currentLineIndex = getCurrentLineIndex(time); lrclist.set(currentLineIndex, lrclist.get(currentLineIndex).setTlyric(lyric)); -// gj.sc(lyric); } } } @@ -195,13 +184,15 @@ public class LrcView extends RecyclerView { int millisecond = Integer.parseInt(secondParts[1]); long time = (long) minute * 60 * 1000 + second * 1000L + millisecond; lrclist.add(new lrc(lyric, time)); -// gj.sc(lyric); } } } } } + int index = -1; + boolean addOnGlobalLayoutListener; + class adaper extends RecyclerView.Adapter { @NonNull @@ -218,11 +209,26 @@ public class LrcView extends RecyclerView { @Override public void onBindViewHolder(@NonNull VH holder, int position) { - if (lrclist.isEmpty()) { - holder.textView.setText("纯音乐,请欣赏"); - return; - } if (Lrcline) { + if (addOnGlobalLayoutListener) { + // 注册布局监听器 + holder.textView.getViewTreeObserver().addOnGlobalLayoutListener( + new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + int height = holder.textView.getHeight(); + ViewGroup.LayoutParams layoutParams = LrcView.this.getLayoutParams(); + layoutParams.height = height * 5; + LrcView.this.setLayoutParams(layoutParams); + // 移除布局监听器 + holder.textView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); + } + if (lrclist.isEmpty()) { + holder.textView.setText("纯音乐,请欣赏"); + return; + } int currentLineIndex = getCurrentLineIndex(); if (currentLineIndex >= 0 && currentLineIndex < lrclist.size()) { @@ -244,6 +250,10 @@ public class LrcView extends RecyclerView { holder.textView.setText(text); } } else { + if (lrclist.isEmpty()) { + holder.textView.setText("纯音乐,请欣赏"); + return; + } try { lrc lrc = lrclist.get(position); StringBuilder stringBuffer = new StringBuilder(); @@ -265,7 +275,6 @@ public class LrcView extends RecyclerView { @Override public int getItemCount() { - gj.sc(lrclist.size()); if (lrclist.size() < 3) { for (lrc a : lrclist) { if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) { @@ -291,14 +300,9 @@ public class LrcView extends RecyclerView { textView = itemView.findViewById(R.id.text); } } -/* @Override - public void onDraw(@NonNull Canvas canvas) { - super.onDraw(canvas); - setTimeLrc(canvas); - }*/ private int getCurrentLineIndex() { - int index = -1; + index = -1; for (int i = 0; i < lrclist.size(); i++) { lrc lineLrc = lrclist.get(i); if (lineLrc.time <= time) { @@ -311,7 +315,7 @@ public class LrcView extends RecyclerView { } private static int getCurrentLineIndex(long time) { - int index = -1; + int index = 0; for (int i = 0; i < lrclist.size(); i++) { lrc lineLrc = lrclist.get(i); if (lineLrc.time <= time) { @@ -331,22 +335,15 @@ public class LrcView extends RecyclerView { this.time = a; if (!Lrcline) { int currentLineIndex = getCurrentLineIndex(a); - if (currentLineIndex == -1) { + getAdapter().notifyDataSetChanged(); + if (currentLineIndex < 3) { return; } +// smoothScrollToPosition(getCurrentLineIndex(a)); linearLayoutManager.smoothScrollToPosition(this, new RecyclerView.State(), currentLineIndex); -// smoothScrollToPosition(getCurrentLineIndex(a)); - getAdapter().notifyItemChanged(--currentLineIndex); - getAdapter().notifyItemChanged(getCurrentLineIndex(a)); return; } getAdapter().notifyDataSetChanged(); } - - public void getLrc() { - for (lrc a : lrclist) { - sc(a.time + ":" + a.lrc + ":" + a.tlyric); - } - } } diff --git a/app/src/main/java/com/muqingbfq/xm.java b/app/src/main/java/com/muqingbfq/xm.java index e8b8f8a..6d3133c 100644 --- a/app/src/main/java/com/muqingbfq/xm.java +++ b/app/src/main/java/com/muqingbfq/xm.java @@ -1,25 +1,16 @@ package com.muqingbfq; public class xm { - public String id, name, zz; + public String id, name; public Object picurl; - public boolean cz; - public xm(String id, String name, String zz, String picurl) { + public xm(String id, String name, String picurl) { this.id = id; this.name = name; - this.zz = zz; this.picurl = picurl; } - public xm(String id, String name, String picurl, boolean cz) { + public xm(String id, String name, int picurl) { this.id = id; this.name = name; this.picurl = picurl; - this.cz = cz; - } - public xm(String id, String name, int picurl, boolean cz) { - this.id = id; - this.name = name; - this.picurl = picurl; - this.cz = cz; } } \ No newline at end of file diff --git a/app/src/main/res/layout-land/activity_bfq.xml b/app/src/main/res/layout-land/activity_bfq.xml index ed3beab..3f7fa0f 100644 --- a/app/src/main/res/layout-land/activity_bfq.xml +++ b/app/src/main/res/layout-land/activity_bfq.xml @@ -30,9 +30,10 @@ diff --git a/app/src/main/res/layout/activity_bfq.xml b/app/src/main/res/layout/activity_bfq.xml index a6ca90c..4e47161 100644 --- a/app/src/main/res/layout/activity_bfq.xml +++ b/app/src/main/res/layout/activity_bfq.xml @@ -29,9 +29,10 @@ @@ -66,7 +67,8 @@ diff --git a/app/src/main/res/layout/float_lrcview.xml b/app/src/main/res/layout/float_lrcview.xml index 78b7cff..9f7812b 100644 --- a/app/src/main/res/layout/float_lrcview.xml +++ b/app/src/main/res/layout/float_lrcview.xml @@ -27,51 +27,56 @@ android:layout_height="36dp" android:src="@drawable/like" android:text="喜欢" + android:tint="@color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + tools:ignore="UseAppTint" /> + tools:ignore="ContentDescription,UseAppTint" /> + tools:ignore="ContentDescription,UseAppTint" /> + app:layout_constraintTop_toTopOf="parent" + tools:ignore="UseAppTint" /> -