From 70a2a4e8b1b3861cdceb51a01fee104ad78cf53a Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Fri, 26 Jan 2024 18:00:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=85=A5=E6=AD=8C?= =?UTF-8?q?=E5=8D=95=E6=93=8D=E4=BD=9C=E4=BC=98=E5=8C=96=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E6=98=BE=E7=A4=BAUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- app/src/main/java/com/muqingbfq/MP3.java | 4 - .../main/java/com/muqingbfq/MediaPlayer.java | 50 ++-- app/src/main/java/com/muqingbfq/XM.java | 8 +- .../java/com/muqingbfq/activity_search.java | 29 +-- .../com/muqingbfq/api/FileDownloader.java | 1 + .../main/java/com/muqingbfq/api/playlist.java | 27 ++- app/src/main/java/com/muqingbfq/api/url.java | 13 +- app/src/main/java/com/muqingbfq/bfqkz.java | 2 - .../java/com/muqingbfq/fragment/Media.java | 3 - .../java/com/muqingbfq/fragment/bflb_db.java | 14 +- .../main/java/com/muqingbfq/fragment/gd.java | 57 +++-- .../com/muqingbfq/fragment/gd_adapter.java | 12 +- .../main/java/com/muqingbfq/fragment/mp3.java | 215 ++++++++++++++---- .../java/com/muqingbfq/fragment/search.java | 50 ++-- .../main/java/com/muqingbfq/fragment/sz.java | 3 - .../java/com/muqingbfq/fragment/wode.java | 66 +++++- app/src/main/java/com/muqingbfq/home.java | 5 +- .../java/com/muqingbfq/list/MyViewHoder.java | 10 +- .../main/java/com/muqingbfq/login/cookie.java | 71 +----- .../com/muqingbfq/login/user_editing.java | 66 ------ .../java/com/muqingbfq/login/user_logs.java | 126 +++++++--- app/src/main/java/com/muqingbfq/main.java | 27 +-- app/src/main/java/com/muqingbfq/mq/gj.java | 28 ++- app/src/main/java/com/muqingbfq/mq/wl.java | 27 ++- .../java/com/muqingbfq/view/CardImage.java | 1 + .../main/java/com/muqingbfq/view/LrcView.java | 41 ++-- app/src/main/res/drawable/gd.xml | 9 + app/src/main/res/drawable/icon.xml | 4 +- app/src/main/res/drawable/paihangbang.xml | 2 +- app/src/main/res/layout/activity_cookie.xml | 9 - .../main/res/layout/activity_user_logs.xml | 209 ++++++++++------- app/src/main/res/layout/fragment_mp3.xml | 30 ++- app/src/main/res/layout/list_gd.xml | 1 - app/src/main/res/layout/list_gd_b.xml | 58 +++-- app/src/main/res/layout/list_mp3.xml | 30 ++- app/src/main/res/menu/sz.xml | 4 - 37 files changed, 784 insertions(+), 530 deletions(-) create mode 100644 app/src/main/res/drawable/gd.xml diff --git a/app/build.gradle b/app/build.gradle index 7e0b303..b8a887f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ android { //noinspection OldTargetApi targetSdk 31 versionCode 1 - versionName "1.9.3" + versionName "1.9.5" } compileOptions { diff --git a/app/src/main/java/com/muqingbfq/MP3.java b/app/src/main/java/com/muqingbfq/MP3.java index 45a1749..f690ceb 100644 --- a/app/src/main/java/com/muqingbfq/MP3.java +++ b/app/src/main/java/com/muqingbfq/MP3.java @@ -1,10 +1,6 @@ package com.muqingbfq; -import static android.support.v4.media.session.MediaSessionCompat.*; - -import android.support.v4.media.session.MediaSessionCompat; import java.util.Objects; -import java.util.Queue; public class MP3 { public String id, name, zz; diff --git a/app/src/main/java/com/muqingbfq/MediaPlayer.java b/app/src/main/java/com/muqingbfq/MediaPlayer.java index 16c0c4a..e98aec7 100644 --- a/app/src/main/java/com/muqingbfq/MediaPlayer.java +++ b/app/src/main/java/com/muqingbfq/MediaPlayer.java @@ -21,6 +21,7 @@ import com.mpatric.mp3agic.Mp3File; import com.muqingbfq.fragment.Media; import com.muqingbfq.fragment.bflb_db; import com.muqingbfq.fragment.bfq_db; +import com.muqingbfq.fragment.mp3; import com.muqingbfq.fragment.search; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; @@ -60,7 +61,6 @@ public class MediaPlayer extends android.media.MediaPlayer { } bfq_an.xyq(); }); -// setAudioStreamType(AudioManager.STREAM_MUSIC); setAudioAttributes(new AudioAttributes .Builder() .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) @@ -87,9 +87,6 @@ public class MediaPlayer extends android.media.MediaPlayer { super.start(); Media.setbf(true); } - - // 创建 MediaItem 列表 -// public static List list = new ArrayList<>(); @Override public void setDataSource(String path) throws IOException { reset(); @@ -132,7 +129,6 @@ public class MediaPlayer extends android.media.MediaPlayer { prepare(); setTX(); } - public void setTX() { Glide.with(main.application) .asBitmap() @@ -171,30 +167,30 @@ public class MediaPlayer extends android.media.MediaPlayer { bfqkz.notify.tzl(); } Media.setImageBitmap(); - return false; - } - }) - .submit(); - } - @SuppressLint("NotifyDataSetChanged") - public void bfui() { - String name = xm.name, zz = bfqkz.xm.zz; - setTX(); - if (bfq.view != null) { - Media.setProgress(0); - bfq.setname(name); - bfq.setzz(zz); - bfq_an.islike(); - } - bfq_db.setname(name + "/" + zz); - if (com.muqingbfq.fragment.mp3.lbspq != null) { - com.muqingbfq.fragment.mp3.lbspq.notifyDataSetChanged(); - } - if (search.lbspq != null) { - search.lbspq.notifyDataSetChanged(); - } if (bflb_db.adapter != null) { bflb_db.adapter.notifyDataSetChanged(); } + return false; + } +}) + .submit(); + } +@SuppressLint("NotifyDataSetChanged") +public void bfui() { + String name = xm.name, zz = bfqkz.xm.zz; + setTX(); + if (bfq.view != null) { + Media.setProgress(0); + bfq.setname(name); + bfq.setzz(zz); + bfq_an.islike(); + } + bfq_db.setname(name + "/" + zz); + if (com.muqingbfq.fragment.mp3.lbspq != null) { + new mp3.lbspq_sx(); + } + if (search.lbspq != null) { + search.lbspq.notifyDataSetChanged(); + } } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/XM.java b/app/src/main/java/com/muqingbfq/XM.java index 6f8c74e..5f44994 100644 --- a/app/src/main/java/com/muqingbfq/XM.java +++ b/app/src/main/java/com/muqingbfq/XM.java @@ -1,13 +1,19 @@ package com.muqingbfq; public class XM { - public String id, name; + public String id, name, message; public Object picurl; public XM(String id, String name, String picurl) { this.id = id; this.name = name; this.picurl = picurl; } + public XM(String id, String name,String message, String picurl) { + this.id = id; + this.name = name; + this.picurl = picurl; + this.message = message; + } public XM(String id, String name, int picurl) { this.id = id; this.name = name; diff --git a/app/src/main/java/com/muqingbfq/activity_search.java b/app/src/main/java/com/muqingbfq/activity_search.java index 5548035..7dd9f0b 100644 --- a/app/src/main/java/com/muqingbfq/activity_search.java +++ b/app/src/main/java/com/muqingbfq/activity_search.java @@ -1,7 +1,6 @@ package com.muqingbfq; import android.annotation.SuppressLint; -import android.content.Context; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; @@ -13,7 +12,6 @@ import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; -import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; @@ -41,7 +39,6 @@ import java.util.ArrayList; import java.util.List; public class activity_search extends FragmentActivity { - private EditText editText; private ArrayAdapter adapter; private List json_list = new ArrayList<>(); private final List list = new ArrayList<>(); @@ -63,8 +60,7 @@ public class activity_search extends FragmentActivity { binding.listRecycler.setLayoutManager(manager); binding.listRecycler.setAdapter(new SearchRecordAdapter()); - editText = findViewById(R.id.editview); - editText.setOnEditorActionListener((v, actionId, event) -> { + binding.editview.setOnEditorActionListener((v, actionId, event) -> { if (actionId == EditorInfo.IME_ACTION_SEARCH) { String str = v.getText().toString(); if (!str.equals("")) { @@ -93,19 +89,19 @@ public class activity_search extends FragmentActivity { //设置项点击监听 listPopupWindow.setOnItemClickListener((adapterView, view, i, l) -> { - editText.clearFocus(); + view.clearFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); View v = getWindow().peekDecorView(); if (null != v) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } - editText.setText(list.get(i));//把选择的选项内容展示在EditText上 + binding.editview.setText(list.get(i));//把选择的选项内容展示在EditText上 dismiss();//如果已经选择了,隐藏起来 - start(editText.getText().toString()); + start(binding.editview.getText().toString()); }); Object o = new Object(); - editText.addTextChangedListener(new TextWatcher() { + binding.editview.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -147,20 +143,13 @@ public class activity_search extends FragmentActivity { public void afterTextChanged(Editable s) { } }); - - binding.editview.requestFocus();//获取焦点 - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - //if (!imm.isActive()) //没有显示键盘,弹出 - imm.showSoftInput(binding.editview, 0); + gj.tcjp(binding.editview); } public void dismiss() { binding.editview.clearFocus(); listPopupWindow.setVisibility(View.GONE); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm.isActive()) //有显示键盘,隐藏 - imm.hideSoftInputFromWindow(binding.editview.getWindowToken(), - InputMethodManager.HIDE_NOT_ALWAYS); + gj.ycjp(binding.editview); } @SuppressLint("NotifyDataSetChanged") @@ -190,7 +179,7 @@ public class activity_search extends FragmentActivity { if (itemId == android.R.id.home) { finish(); } else if (itemId == R.id.menu_search) { - start(editText.getText().toString()); + start(binding.editview.getText().toString()); } return super.onOptionsItemSelected(item); } @@ -238,7 +227,7 @@ public class activity_search extends FragmentActivity { String keyword = json_list.get(position); holder.recordTextView.setText(keyword); holder.recordTextView.setOnClickListener(v -> { - editText.setText(keyword); + binding.editview.setText(keyword); start(keyword); }); holder.recordTextView.setOnLongClickListener(view -> { diff --git a/app/src/main/java/com/muqingbfq/api/FileDownloader.java b/app/src/main/java/com/muqingbfq/api/FileDownloader.java index 1762bf3..c861970 100644 --- a/app/src/main/java/com/muqingbfq/api/FileDownloader.java +++ b/app/src/main/java/com/muqingbfq/api/FileDownloader.java @@ -122,6 +122,7 @@ public class FileDownloader { outputStream = new FileOutputStream(outputFile); int read; + fileSizeDownloaded = 0; while ((read = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, read); fileSizeDownloaded += read; diff --git a/app/src/main/java/com/muqingbfq/api/playlist.java b/app/src/main/java/com/muqingbfq/api/playlist.java index 507176b..78a9dfa 100644 --- a/app/src/main/java/com/muqingbfq/api/playlist.java +++ b/app/src/main/java/com/muqingbfq/api/playlist.java @@ -23,6 +23,14 @@ import java.util.List; public class playlist extends Thread { public static final String api = "/playlist/track/all?id="; + public static String gethq(String uid) { + if (wj.cz(wj.filesdri + "user.mq")) { + return wl.hq(api + uid + "&limit=100" + "&cookie=" + wl.Cookie); +// gj.sc(hq); + } else { + return wl.hq(api + uid + "&limit=100"); + } + } @SuppressLint("NotifyDataSetChanged") public static boolean hq(List list, String uid) { switch (uid) { @@ -39,11 +47,7 @@ public class playlist extends Thread { if (wj.cz(wj.gd + uid)) { hq = wj.dqwb(wj.gd + uid); } else { - 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"); - } + hq = gethq(uid); } JSONObject json = new JSONObject(hq); JSONArray songs = json.getJSONArray("songs"); @@ -52,7 +56,14 @@ public class playlist extends Thread { JSONObject jsonObject = songs.getJSONObject(i); String id = jsonObject.getString("id"); String name = jsonObject.getString("name"); - + try { + String tns = jsonObject.getString("tns"); + tns = tns.replace("[\"", "("); + tns = tns.replace("\"]", ")"); + name += tns; + } catch (Exception e) { + gj.sc(e); + } JSONObject al = jsonObject.getJSONObject("al"); JSONArray ar = jsonObject.getJSONArray("ar"); StringBuilder zz = new StringBuilder(); @@ -95,13 +106,15 @@ public class playlist extends Thread { try { File file = new File(wj.filesdri + "mp3"); File[] files = file.listFiles(); + int i = 0; for (File value : files) { ID3v2 mp3File = new Mp3File(value).getId3v2Tag(); String id = value.getName(); String name = mp3File.getTitle(); String zz = mp3File.getArtist(); String picUrl = mp3File.getUrl(); - list.add(new MP3(id, name, zz, picUrl)); + list.add(new MP3(id, name, zz.toString(), picUrl)); + i++; } return true; } catch (Exception e) { diff --git a/app/src/main/java/com/muqingbfq/api/url.java b/app/src/main/java/com/muqingbfq/api/url.java index b311485..1b92c64 100644 --- a/app/src/main/java/com/muqingbfq/api/url.java +++ b/app/src/main/java/com/muqingbfq/api/url.java @@ -29,6 +29,8 @@ public class url extends Thread { } public static String hq(MP3 x) { + getLrc(x.id); + Media.loadLyric(); try { if (wj.cz(wj.mp3 + x.id)) { return wj.mp3 + x.id; @@ -47,7 +49,7 @@ public class url extends Thread { return null; } JSONObject json = new JSONObject(hq); - gj.sc(json); +// gj.sc(json); if (json.getInt("code") == -460) { String message = json.getString("message"); main.handler.post(() -> { @@ -57,15 +59,10 @@ public class url extends Thread { }); return null; } - getLrc(x.id); - Media.loadLyric(); JSONArray data = json.getJSONArray("data"); JSONObject jsonObject = data.getJSONObject(0); - String url = jsonObject.getString("url"); - if (wiFiConnected) { - new FileDownloader(url, x,true); - } - return url; + gj.sc(jsonObject.getString("url")); + return jsonObject.getString("url"); } catch (JSONException e) { yc.start("url hq :" + e); } diff --git a/app/src/main/java/com/muqingbfq/bfqkz.java b/app/src/main/java/com/muqingbfq/bfqkz.java index 665c42e..5a5ce09 100644 --- a/app/src/main/java/com/muqingbfq/bfqkz.java +++ b/app/src/main/java/com/muqingbfq/bfqkz.java @@ -27,7 +27,6 @@ import java.util.List; public class bfqkz extends MediaBrowserServiceCompat { public static MediaPlayer mt = new MediaPlayer(); public static List list = new ArrayList<>(); - //保存原始list顺序 public static List list_baocun = new ArrayList<>(); public static List lishi_list = new ArrayList<>(); @@ -52,7 +51,6 @@ public class bfqkz extends MediaBrowserServiceCompat { if (id == null) { return; } - if (TextUtils.isEmpty(id)) { //针对错误进行相应的处理 bfqkz.list.remove(bfqkz.xm); diff --git a/app/src/main/java/com/muqingbfq/fragment/Media.java b/app/src/main/java/com/muqingbfq/fragment/Media.java index 9a19b88..2b58410 100644 --- a/app/src/main/java/com/muqingbfq/fragment/Media.java +++ b/app/src/main/java/com/muqingbfq/fragment/Media.java @@ -136,9 +136,6 @@ public class Media { if (bfq.view == null) { return; } - if (bfq.bitmap == null) { - bfq.bitmap= BitmapFactory.decodeResource(bfq.view.getResources(), R.drawable.icon); - } main.handler.post(() -> bfq.binding.cardview.setImage(com.muqingbfq.bfq.bitmap)); } } 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 72a3a26..dfdcf46 100644 --- a/app/src/main/java/com/muqingbfq/fragment/bflb_db.java +++ b/app/src/main/java/com/muqingbfq/fragment/bflb_db.java @@ -19,6 +19,7 @@ import com.muqingbfq.R; import com.muqingbfq.api.url; import com.muqingbfq.bfqkz; import com.muqingbfq.databinding.FragmentBflbDbBinding; +import com.muqingbfq.databinding.ListMp3Binding; import com.muqingbfq.list.MyViewHoder; import com.muqingbfq.main; import com.muqingbfq.yc; @@ -82,21 +83,22 @@ public class bflb_db extends BottomSheetDialog { @NonNull @Override public MyViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_mp3, parent, false); - return new MyViewHoder(view); +// View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_mp3, parent, false); + return new MyViewHoder(ListMp3Binding. + inflate(getLayoutInflater(),parent,false)); } @Override public void onBindViewHolder(@NonNull MyViewHoder holder, int position) { MP3 x = bfqkz.list.get(position); - holder.name.setText(x.name); - holder.zz.setText(x.zz); + holder.binding.name.setText(x.name); + holder.binding.zz.setText(x.zz); int color = ContextCompat.getColor(holder.getContext(), R.color.text); if (bfqkz.xm != null && x.id.equals(bfqkz.xm.id)) { color = ContextCompat.getColor(holder.getContext(), R.color.text_cz); } - holder.name.setTextColor(color); - holder.zz.setTextColor(color); + holder.binding.name.setTextColor(color); + holder.binding.zz.setTextColor(color); holder.itemView.setOnClickListener(view -> { if (bfqkz.xm != x) { bfqkz.xm = x; diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 4cdf713..11184f4 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -25,6 +25,8 @@ import com.muqingbfq.api.resource; import com.muqingbfq.bfq_an; import com.muqingbfq.bfqkz; import com.muqingbfq.databinding.FragmentMp3Binding; +import com.muqingbfq.databinding.ListGdBBinding; +import com.muqingbfq.databinding.ListGdBinding; import com.muqingbfq.main; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; @@ -45,6 +47,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { private final List list = new ArrayList<>(); public static RecyclerView.Adapter adapter; int k; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -52,7 +55,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { setContentView(binding.getRoot()); Intent intent = getIntent(); binding.title.setText(intent.getStringExtra("name")); - adapter = new baseadapter(this,list); + adapter = new baseadapter(this, list); k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); GridLayoutManager gridLayoutManager = new GridLayoutManager(this, k / 120); binding.lb.setLayoutManager(gridLayoutManager); @@ -64,6 +67,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { @SuppressLint("NotifyDataSetChanged") class start extends Thread { String id; + public start(String id) { this.id = id; list.clear(); @@ -97,7 +101,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; @@ -107,6 +111,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { } boolean bool = false; + public baseadapter(Context context, List list, boolean bool) { this.context = context; this.list = list; @@ -117,11 +122,11 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { @Override public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (bool) { - return new VH(LayoutInflater.from(context) - .inflate(R.layout.list_gd_b, parent, false)); + return new VH(ListGdBBinding.bind(LayoutInflater.from(context) + .inflate(R.layout.list_gd_b, parent, false))); } - return new VH(LayoutInflater.from(context) - .inflate(R.layout.list_gd, parent, false)); + return new VH(ListGdBinding.bind(LayoutInflater.from(context) + .inflate(R.layout.list_gd, parent, false))); } public void setList(List list) { @@ -134,12 +139,13 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { CARD card = new CARD(position); if (bool) { holder.itemView.setOnClickListener(card); + holder.bindingB.text2.setText(xm.message); holder.itemView.setOnLongClickListener(card); } else { - holder.image.setOnClickListener(card); - holder.image.setOnLongClickListener(card); + holder.binding.image.setOnClickListener(card); + holder.binding.image.setOnLongClickListener(card); } - holder.textView.setText(xm.name); + holder.title.setText(xm.name); holder.kg.setOnClickListener(view1 -> { ImageView tx = (ImageView) view1; new Thread() { @@ -208,7 +214,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { @Override public void run() { if (id == 0) { - String hq = wl.hq(playlist.api + xm.id + "&limit=100"); + String hq = playlist.gethq(xm.id); if (hq != null) { wj.xrwb(wj.gd + xm.id, hq); try { @@ -235,15 +241,14 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { jsonObject.remove(xm.id); list.remove(xm); wj.xrwb(wj.gd_xz, jsonObject.toString()); + main.handler.post(() -> notifyItemChanged(position)); } catch (JSONException e) { gj.sc(e); } } - main.handler.post(() -> notifyItemChanged(position)); } }.start(); // 在这里处理菜单项的点击事件 - dialog.dismiss(); }).show(); return false; } @@ -253,17 +258,29 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { } static class VH extends RecyclerView.ViewHolder { - TextView textView; - ImageView kg; - CardImage image; + public ListGdBinding binding; + public ImageView kg; + public CardImage image; + public TextView title; + public VH(@NonNull ListGdBinding itemView) { + super(itemView.getRoot()); + binding = itemView; + title = binding.wb1; + kg = binding.kg; + image = binding.image; + } - public VH(@NonNull View itemView) { - super(itemView); - textView = itemView.findViewById(R.id.wb1); - image = itemView.findViewById(R.id.image); - kg = itemView.findViewById(R.id.kg); + ListGdBBinding bindingB; + + public VH(@NonNull ListGdBBinding itemView) { + super(itemView.getRoot()); + bindingB = itemView; + title = bindingB.text1; + kg = bindingB.kg; + image = bindingB.image; } } + private class lbspq_sx implements Runnable { @SuppressLint("NotifyDataSetChanged") @Override diff --git a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java index cab6046..d283880 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java @@ -19,12 +19,12 @@ import com.muqingbfq.R; import com.muqingbfq.XM; import com.muqingbfq.api.resource; import com.muqingbfq.api.url; -import com.muqingbfq.bfq; import com.muqingbfq.bfqkz; import com.muqingbfq.databinding.FragmentGdBinding; import com.muqingbfq.databinding.ListMp3ImageBinding; import com.muqingbfq.main; import com.muqingbfq.mq.gj; +import com.muqingbfq.mq.wj; import com.muqingbfq.mq.wl; import org.json.JSONArray; @@ -91,8 +91,12 @@ public class gd_adapter extends Fragment { bfqkz.xm = x; new url(x); notifyDataSetChanged(); + } else if (!bfqkz.mt.isPlaying()) { + bfqkz.mt.start(); + } + if (!bfqkz.list.contains(x)) { + bfqkz.list.add(0, x); } - bfqkz.list.add(0, x); // bfqkz.list.addAll(list); // bfq.start(getContext()); }); @@ -134,6 +138,9 @@ public class gd_adapter extends Fragment { public void run() { super.run(); String hq = wl.hq("/recommend/songs" + "?cookie=" + wl.Cookie); + if (hq == null) { + hq = wj.dqwb(wj.filesdri + "songs.josn"); + } try { JSONObject jsonObject = new JSONObject(hq); JSONObject data = jsonObject.getJSONObject("data"); @@ -151,6 +158,7 @@ public class gd_adapter extends Fragment { String picUrl = al.getString("picUrl"); listmp3.add(new MP3(id, name, zz.toString(), picUrl)); } + wj.xrwb(wj.filesdri + "songs.josn", hq); main.handler.post(() -> binding.recyclerview2.getAdapter().notifyDataSetChanged()); } catch (Exception e) { gj.sc(e); diff --git a/app/src/main/java/com/muqingbfq/fragment/mp3.java b/app/src/main/java/com/muqingbfq/fragment/mp3.java index a3aea1e..607335c 100644 --- a/app/src/main/java/com/muqingbfq/fragment/mp3.java +++ b/app/src/main/java/com/muqingbfq/fragment/mp3.java @@ -4,84 +4,132 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.Filter; +import android.widget.Filterable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.muqingbfq.MP3; import com.muqingbfq.R; +import com.muqingbfq.XM; import com.muqingbfq.api.FileDownloader; import com.muqingbfq.api.playlist; +import com.muqingbfq.api.resource; import com.muqingbfq.api.url; import com.muqingbfq.bfq; import com.muqingbfq.bfqkz; import com.muqingbfq.databinding.FragmentMp3Binding; +import com.muqingbfq.databinding.ListMp3Binding; import com.muqingbfq.list.MyViewHoder; import com.muqingbfq.main; import com.muqingbfq.mq.FragmentActivity; import com.muqingbfq.mq.gj; +import com.muqingbfq.mq.wj; +import org.json.JSONException; +import org.json.JSONObject; + +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class mp3 extends FragmentActivity { - private final List list = new ArrayList<>(); - public static RecyclerView.Adapter lbspq; - + private List list = new ArrayList<>(); + private List list_ys = new ArrayList<>(); + public static adaper lbspq; + FragmentMp3Binding binding; +// private static String id; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - FragmentMp3Binding inflate = FragmentMp3Binding.inflate(getLayoutInflater()); + binding = FragmentMp3Binding.inflate(getLayoutInflater()); Intent intent = getIntent(); - inflate.title.setText(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); - lb.setLayoutManager(layoutManager); - lb.setAdapter(lbspq); + binding.title.setText(intent.getStringExtra("name")); String id = intent.getStringExtra("id"); - -// inflate.bfqDb.setBackground(gd.color); + setContentView(binding.getRoot()); + lbspq = new adaper(list); + binding.lb.setLayoutManager(new LinearLayoutManager(this)); + binding.lb.setAdapter(lbspq); new start(id); + binding.edittext.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + if (binding.edittext.getVisibility() == View.VISIBLE) { + lbspq.getFilter().filter(charSequence); + } + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }); + //添加Android自带的分割线 + binding.lb.addItemDecoration( + new DividerItemDecoration(this,DividerItemDecoration.VERTICAL)); } @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuItem itemA = menu.add("下载所有歌曲"); - itemA.setTitle("下载所有歌曲"); - itemA.setIcon(R.drawable.download); + MenuItem itemA = menu.add("搜索"); + itemA.setTitle("搜索"); + itemA.setIcon(R.drawable.sousuo); itemA.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); - gj.sc(itemA.getItemId()); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == 0) { - FileDownloader fileDownloader = new FileDownloader( - mp3. - this); - for (MP3 mp3 : list) { - new Thread(){ - @Override - public void run() { - super.run(); - fileDownloader.downloadFile(mp3); - } - }.start(); + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + if (binding.edittext.getVisibility() == View.VISIBLE) { + binding.title.setVisibility(View.VISIBLE); + binding.edittext.setVisibility(View.GONE); + } else { + finish(); } + gj.ycjp(binding.edittext); + lbspq.getFilter().filter(""); + } else if (itemId == 0) { + binding.title.setVisibility(View.GONE); + binding.edittext.setVisibility(View.VISIBLE); + gj.tcjp(binding.edittext); } - return super.onOptionsItemSelected(item); + return true; + } + + @Override + public void onBackPressed() { + if (binding.edittext.getVisibility() == View.VISIBLE) { + binding.title.setVisibility(View.VISIBLE); + binding.edittext.setVisibility(View.GONE); + } else { + finish(); + } + gj.ycjp(binding.edittext); + lbspq.getFilter().filter(""); } @SuppressLint("NotifyDataSetChanged") @@ -91,7 +139,7 @@ public class mp3 extends FragmentActivity { public start(String id) { this.id = id; list.clear(); - mp3.lbspq.notifyDataSetChanged(); + list_ys.clear(); start(); } @@ -105,6 +153,7 @@ public class mp3 extends FragmentActivity { } else { playlist.hq(list, id); } + list_ys = list; main.handler.post(new lbspq_sx()); } } @@ -117,25 +166,34 @@ public class mp3 extends FragmentActivity { } } - class spq extends RecyclerView.Adapter { + public static class adaper extends RecyclerView.Adapter implements Filterable { + + private List list; + private List list_ys; + public adaper(List list) { + this.list = list; + list_ys = list; + } @NonNull @Override public MyViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_mp3, parent, false); - return new MyViewHoder(view); + return new MyViewHoder(ListMp3Binding.bind(LayoutInflater.from(parent.getContext()). + inflate(R.layout.list_mp3, + parent, false))); } @Override public void onBindViewHolder(@NonNull MyViewHoder holder, int position) { MP3 x = list.get(position); - holder.name.setText(x.name); - holder.zz.setText(x.zz); + holder.binding.text1.setText(String.valueOf(position + 1)); + holder.binding.name.setText(x.name); + holder.binding.zz.setText(x.zz); int color = ContextCompat.getColor(holder.getContext(), R.color.text); if (bfqkz.xm != null && x.id.equals(bfqkz.xm.id)) { color = ContextCompat.getColor(holder.getContext(), R.color.text_cz); } - holder.name.setTextColor(color); - holder.zz.setTextColor(color); + holder.binding.name.setTextColor(color); + holder.binding.zz.setTextColor(color); holder.itemView.setOnClickListener(view -> { if (bfqkz.xm == null || !bfqkz.xm.id.equals(x.id)) { bfqkz.xm = x; @@ -143,7 +201,48 @@ public class mp3 extends FragmentActivity { } bfqkz.list.clear(); bfqkz.list.addAll(list); - bfq.start(mp3.this); + bfq.start(holder.getContext()); + }); + holder.itemView.setOnLongClickListener(view -> { + String a[] = new String[]{"喜欢歌曲", "下载歌曲", "复制名字"}; + new MaterialAlertDialogBuilder(view.getContext()). + setItems(a, (dialog, id) -> { + String title = a[id]; + switch (title) { + case "下载歌曲": + new FileDownloader(view.getContext()).downloadFile(x); + break; + case "喜欢歌曲": + try { + Gson gson = new Gson(); + Type type = new TypeToken>() { + }.getType(); + List list = gson.fromJson(wj.dqwb(wj.gd + "mp3_like.json"), type); + if (list == null) { + list = new ArrayList<>(); + } + if (bfqkz.like_bool) { + list.remove(bfqkz.xm); + bfq.setlike(false); + } else { + if (!list.contains(bfqkz.xm)) { + list.add(bfqkz.xm); + bfq.setlike(true); + } + } + bfqkz.like_bool = !bfqkz.like_bool; + wj.xrwb(wj.gd + "mp3_like.json", gson.toJson(list)); + } catch (Exception e) { + e.printStackTrace(); + } + break; + case "复制名字": + gj.fz(view.getContext(), x.name); + break; + + } + }).show(); + return false; }); } @@ -151,6 +250,42 @@ public class mp3 extends FragmentActivity { public int getItemCount() { return list.size(); } + + @Override + public Filter getFilter() { + return new Filter() { + @Override + protected FilterResults performFiltering(CharSequence charSequence) { + String charString = charSequence.toString(); + if (charString.isEmpty()) { + //没有过滤的内容,则使用源数据 + list = list_ys; + } else { + List filteredList = new ArrayList<>(); + for (int i = 0; i < list_ys.size(); i++) { + MP3 mp3 = list_ys.get(i); + if (mp3.name.contains(charString) + || mp3.zz.contains(charString)) { + filteredList.add(list_ys.get(i)); + } + } + list = filteredList; + } + + FilterResults filterResults = new FilterResults(); + filterResults.values = list; + return filterResults; + } + + @SuppressLint("NotifyDataSetChanged") + @SuppressWarnings("unchecked") + @Override + protected void publishResults(CharSequence charSequence, FilterResults filterResults) { + list = (List) filterResults.values; + notifyDataSetChanged(); + } + }; + } } diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java index 34fade6..7247bc3 100644 --- a/app/src/main/java/com/muqingbfq/fragment/search.java +++ b/app/src/main/java/com/muqingbfq/fragment/search.java @@ -9,7 +9,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -17,20 +16,17 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.tabs.TabLayout; import com.muqingbfq.MP3; -import com.muqingbfq.R; -import com.muqingbfq.api.url; -import com.muqingbfq.bfq; -import com.muqingbfq.bfqkz; +import com.muqingbfq.XM; import com.muqingbfq.databinding.FragmentSearchBinding; import com.muqingbfq.list.MyViewHoder; import com.muqingbfq.main; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wl; -import com.muqingbfq.XM; import org.json.JSONArray; import org.json.JSONObject; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; @@ -48,7 +44,7 @@ public class search extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { inflate = FragmentSearchBinding.inflate(inflater, container, false); - lbspq = new spq(); + lbspq = new mp3.adaper(list); View view = inflate.getRoot(); TypedValue typedValue = new TypedValue(); requireContext().getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true); @@ -90,15 +86,13 @@ public class search extends Fragment { public void setStart(String name) { if (i == 0) { - new spq(); + new mp3.adaper(list); inflate.recyclerview.setLayoutManager(new LinearLayoutManager(getContext())); inflate.recyclerview.setAdapter(lbspq); } else if (i == 1) { k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f) / 120; - GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), - k); - inflate.recyclerview.setLayoutManager(gridLayoutManager); - inflate.recyclerview.setAdapter(new gd.baseadapter(getContext(), xmList)); + inflate.recyclerview.setLayoutManager(new LinearLayoutManager(getContext())); + inflate.recyclerview.setAdapter(new gd.baseadapter(getContext(), xmList, true)); } new start(name); } @@ -175,23 +169,34 @@ public class search extends Fragment { gj.sc(e); } try { - String hq = wl.hq("/search?keywords=" + name + "&limit=" + (k * 3) + "&type=1000"); + String hq = wl.hq("/search?keywords=" + name +"&type=1000"); JSONArray jsonArray = new JSONObject(hq).getJSONObject("result") .getJSONArray("playlists"); int length = jsonArray.length(); for (int i = 0; i < length; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String id = jsonObject.getString("id"); + int trackCount = jsonObject.getInt("trackCount"); + + String nickname = "by " + jsonObject.getJSONObject("creator") + .getString("nickname"); + long playCount = jsonObject.getLong("playCount"); String name = jsonObject.getString("name"); String coverImgUrl = jsonObject.getString("coverImgUrl"); // gj.sc(name); - xmList.add(new XM(id, name, coverImgUrl)); + String formattedNumber = String.valueOf(playCount); + if (playCount > 9999) { + DecimalFormat df = new DecimalFormat("#,###.0万"); + formattedNumber = df.format(playCount / 10000); + } + xmList.add(new XM(id, name, trackCount + "首," + nickname + ",播放" + + formattedNumber + "次", coverImgUrl)); } } catch (Exception e) { gj.sc(e); } } - +/* class spq extends RecyclerView.Adapter { public spq() { lbspq = this; @@ -200,22 +205,21 @@ public class search extends Fragment { @NonNull @Override public MyViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater. - from(parent.getContext()).inflate(R.layout.list_mp3, parent, false); - return new MyViewHoder(view); + return new MyViewHoder(ListMp3Binding. + inflate(getLayoutInflater(),parent,false)); } @Override public void onBindViewHolder(@NonNull MyViewHoder holder, int position) { MP3 x = list.get(position); - holder.name.setText(x.name); - holder.zz.setText(x.zz); + holder.binding.name.setText(x.name); + holder.binding.zz.setText(x.zz); int color = ContextCompat.getColor(holder.getContext(), R.color.text); if (bfqkz.xm != null && x.id.equals(bfqkz.xm.id)) { color = ContextCompat.getColor(holder.getContext(), R.color.text_cz); } - holder.name.setTextColor(color); - holder.zz.setTextColor(color); + holder.binding.name.setTextColor(color); + holder.binding.zz.setTextColor(color); holder.itemView.setOnClickListener(view1 -> { if (bfqkz.xm == null || !bfqkz.xm.id.equals(x.id)) { bfqkz.xm = x; @@ -233,5 +237,5 @@ public class search extends Fragment { public int getItemCount() { return list.size(); } - } + }*/ } diff --git a/app/src/main/java/com/muqingbfq/fragment/sz.java b/app/src/main/java/com/muqingbfq/fragment/sz.java index 2d75e9a..f549a37 100644 --- a/app/src/main/java/com/muqingbfq/fragment/sz.java +++ b/app/src/main/java/com/muqingbfq/fragment/sz.java @@ -47,9 +47,6 @@ public class sz { } else if (id == R.id.f) { context.startActivity(new Intent(context, activity_about_software.class)); // 关于软件 - } else if (id == R.id.g) { - context.startActivity(new Intent(context, cookie.class)); - //绑定网易云 } } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/fragment/wode.java b/app/src/main/java/com/muqingbfq/fragment/wode.java index e8810a2..506a017 100644 --- a/app/src/main/java/com/muqingbfq/fragment/wode.java +++ b/app/src/main/java/com/muqingbfq/fragment/wode.java @@ -2,7 +2,6 @@ package com.muqingbfq.fragment; import android.annotation.SuppressLint; import android.content.Intent; -import android.content.res.ColorStateList; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -12,7 +11,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -23,6 +21,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.gson.Gson; import com.muqingbfq.R; import com.muqingbfq.XM; +import com.muqingbfq.api.playlist; +import com.muqingbfq.api.resource; import com.muqingbfq.databinding.FragmentWdBinding; import com.muqingbfq.login.user_logs; import com.muqingbfq.login.visitor; @@ -31,13 +31,16 @@ import com.muqingbfq.mq.EditViewDialog; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; +import org.json.JSONException; import org.json.JSONObject; import java.io.File; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class wode extends Fragment { @@ -52,7 +55,7 @@ public class wode extends Fragment { {R.drawable.like, "喜欢音乐", "mp3_like.json"}, {R.drawable.icon, "本地搜索", ""}, {R.drawable.fuwuzhongxing, "更换接口", "API"}, - {R.drawable.icon, "导入歌单", ""}, + {R.drawable.gd, "导入歌单", "gd"}, {R.drawable.paihangbang, "排行榜", "排行榜"}, {R.drawable.icon, "开发中", ""} }; @@ -83,8 +86,6 @@ public class wode extends Fragment { startActivity(new Intent(getContext(), user_logs.class)); } }); -// new user_message(); -// int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 4) { @Override public boolean canScrollVertically() { @@ -105,10 +106,7 @@ public class wode extends Fragment { public void onBindViewHolder(@NonNull VH holder, int position) { String s = lista[position][1].toString(); holder.textView.setText(s); - holder.imageView.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.text))); - Glide.with(getContext()) - .load(lista[position][0]) - .into(holder.imageView); + holder.imageView.setImageResource((Integer) lista[position][0]); String data = lista[position][2].toString(); holder.itemView.setOnClickListener(view -> { switch (data) { @@ -142,6 +140,53 @@ public class wode extends Fragment { } }).show(); break; + case "gd": + EditViewDialog editViewDialog1 = new EditViewDialog(getContext(), + "导入歌单") + .setMessage("请用网易云https链接来进行导入或者歌单id"); + editViewDialog1.setPositive(view1 -> { + String str = editViewDialog1.getEditText(); + // 使用正则表达式提取链接 + Pattern pattern = Pattern.compile("https?://[\\w./?=&]+"); + Matcher matcher = pattern.matcher(str); + if (matcher.find()) + str = matcher.group(); + if (!str.isEmpty()) { + // 使用截取方法获取歌单 ID + str = str.substring(str.indexOf("id=") + 3, str.indexOf("&")); + } + String finalStr = str; + gj.ts(getContext(), "导入中"); + new Thread(){ + @Override + public void run() { + super.run(); + String hq = playlist.gethq(finalStr); + if (hq != null) { + wj.xrwb(wj.gd + finalStr, 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(finalStr); + 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()); + sx(); + gj.xcts(getContext(), "成功"); + } catch (JSONException e) { + gj.sc("list gd onclick thear " + e); + gj.xcts(getContext(), "失败"); + } + } + } + }.start(); + editViewDialog1.dismiss(); + }).show(); + break; } }); @@ -218,6 +263,7 @@ public class wode extends Fragment { setqianming(user.qianming); Glide.with(getContext()) .load(user.picUrl) + .error(R.drawable.ic_launcher_foreground) .into(binding.imageView); } } diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java index f88c7c1..e7637f6 100644 --- a/app/src/main/java/com/muqingbfq/home.java +++ b/app/src/main/java/com/muqingbfq/home.java @@ -250,7 +250,6 @@ public class home extends AppCompatActivity { @Override public void onChildrenLoaded(@NonNull String parentId, @NonNull List children) { - gj.sc("onChildrenLoaded------"); } }; @@ -262,7 +261,7 @@ public class home extends AppCompatActivity { if (mBrowser != null && mBrowser.isConnected()) { mBrowser.disconnect(); } - int i = Process.myPid(); - android.os.Process.killProcess(i); +// int i = Process.myPid(); +// android.os.Process.killProcess(i); } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/list/MyViewHoder.java b/app/src/main/java/com/muqingbfq/list/MyViewHoder.java index fbbf279..f087f5d 100644 --- a/app/src/main/java/com/muqingbfq/list/MyViewHoder.java +++ b/app/src/main/java/com/muqingbfq/list/MyViewHoder.java @@ -8,13 +8,13 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.muqingbfq.R; +import com.muqingbfq.databinding.ListMp3Binding; public class MyViewHoder extends RecyclerView.ViewHolder { - public TextView name, zz; - public MyViewHoder(@NonNull View itemView) { - super(itemView); - name = itemView.findViewById(R.id.wb1); - zz = itemView.findViewById(R.id.zz); + public ListMp3Binding binding; + public MyViewHoder(@NonNull ListMp3Binding itemView) { + super(itemView.getRoot()); + binding = itemView; } public Context getContext() { return itemView.getContext(); diff --git a/app/src/main/java/com/muqingbfq/login/cookie.java b/app/src/main/java/com/muqingbfq/login/cookie.java index 52b817b..346afd7 100644 --- a/app/src/main/java/com/muqingbfq/login/cookie.java +++ b/app/src/main/java/com/muqingbfq/login/cookie.java @@ -33,76 +33,7 @@ public class cookie extends FragmentActivity { //view2 里面的控件 textView = findViewById(R.id.textView); imageView = findViewById(R.id.imageView); - new erweima(); - } - - class erweima extends Thread { - int code = 800; - String unikey, qrimg, hq; - private long time = 0; - public erweima() { - textView.setText("请使用网易云音乐扫码"); - start(); - } - @Override - public void run() { - super.run(); - while (code != 0) { - try { - hq = wl.hq("/login/qr/check?key=" + unikey + Time()); - if (hq != null) { - JSONObject json = new JSONObject(hq); - code = json.getInt("code"); - switch (code) { - case 800: - case 400: - setwb("二维码过期"); - hqkey(); - break; - case 801: - setwb("等待扫码"); - break; - case 802: - setwb("等待确认"); - break; - case 803: - setwb("登录成功"); - wl.setcookie(json.getString("cookie")); - code = 0; - cookie.this.finish(); - break; - default: - code = 0; - // 默认情况下的操作 - break; - } - } - sleep(1000); - } catch (Exception e) { - gj.sc(e); - } - } - } - - private void hqkey() throws Exception { - unikey = new JSONObject(Objects.requireNonNull(wl.hq("/login/qr/key"))). - getJSONObject("data").getString("unikey"); - JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wl.hq("/login/qr/create?key=" + - unikey + - "&qrimg=base64"))); - qrimg = jsonObject.getJSONObject("data").getString("qrimg"); - main.handler.post(() -> imageView.setImageBitmap(user_logs.stringToBitmap(qrimg))); - } - - private String Time() { - if (time < System.currentTimeMillis() - 1000) { - time = System.currentTimeMillis(); - } - return "×tamp" + time; - } - private void setwb(String wb) { - main.handler.post(() -> textView.setText(wb)); - } +// new erweima(); } 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 1ac9e8a..5ffcc04 100644 --- a/app/src/main/java/com/muqingbfq/login/user_editing.java +++ b/app/src/main/java/com/muqingbfq/login/user_editing.java @@ -154,72 +154,6 @@ public class user_editing extends FragmentActivity { com.muqingbfq.fragment.wode.setqianming(null); com.muqingbfq.fragment.wode.imageView.setImageResource(R.drawable.icon); }); - findViewById(R.id.button1).setOnClickListener(view -> { - // 创建OkHttpClient实例 - OkHttpClient client = new OkHttpClient(); - -// 创建MultipartBody.Builder来构建请求体 - MultipartBody.Builder builder = new MultipartBody.Builder() - .setType(MultipartBody.FORM); - if (file_a != null) { - File file = new File(file_a); - RequestBody requestBody = RequestBody.create(file, MediaType.parse("image/*")); - builder.addFormDataPart("icon", file.getName(), requestBody); - } - if (file_b != null) { - File file = new File(file_b); - RequestBody requestBody = RequestBody.create(file, MediaType.parse("image/*")); - builder.addFormDataPart("cover", file.getName(), requestBody); - } - builder.addFormDataPart("token", main.token) - .addFormDataPart("userName", edit_name.getText().toString()) - .addFormDataPart("introduce", edit_qianming.getText().toString()) - .addFormDataPart("gender", "1") - .addFormDataPart("dynamicColor", ""); -// 构建请求体 - Request request = new Request.Builder() - .url("https://rust.coldmint.top/php/user.php?action=updateSpaceInfo") - .post(builder.build()) - .build(); -// 发起请求 - client.newCall(request).enqueue(new Callback() { - @Override - public void onFailure(@NonNull Call call, @NonNull IOException e) { - gj.sc(e); - // 请求失败处理 - } - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { - // 请求成功处理 - String responseData = response.body().string(); - gj.sc(responseData); - if (TextUtils.isEmpty(responseData)) { - return; - } - try { - JSONObject jsonObject = new JSONObject(responseData); - int code = jsonObject.getInt("code"); - if (code == 1) { - String data = jsonObject.getString("data"); - switch (data) { - case "@event:用户名占用": - break; - case "introduce": - break; - } - } else if (code == 0) { -// new user_message(); - } - gj.xcts(user_editing.this, jsonObject.getString("message")); - } catch (JSONException e) { - gj.sc(e); - } - // 处理响应数据 - } - }); - - }); } // 获取图片的实际路径 diff --git a/app/src/main/java/com/muqingbfq/login/user_logs.java b/app/src/main/java/com/muqingbfq/login/user_logs.java index 0ab3523..c7c081a 100644 --- a/app/src/main/java/com/muqingbfq/login/user_logs.java +++ b/app/src/main/java/com/muqingbfq/login/user_logs.java @@ -1,6 +1,5 @@ package com.muqingbfq.login; -import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; @@ -9,22 +8,18 @@ import android.util.Base64; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import com.muqingbfq.databinding.ActivityUserLogsBinding; import com.muqingbfq.main; -import com.muqingbfq.mq.EditViewDialog; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wl; -import org.json.JSONException; import org.json.JSONObject; +import java.util.Objects; public class user_logs extends AppCompatActivity { @@ -38,24 +33,9 @@ public class user_logs extends AppCompatActivity { this.picUrl = picUrl; } } - EditText edituser, editpassword; - public static String UUID; - ActivityResultLauncher enroll = - registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), - result -> { - if (result.getResultCode() == RESULT_OK) { - Intent data = result.getData(); - if (data != null) { - Bundle bundle = data.getExtras(); - String user = bundle.getString("user"); - String password = bundle.getString("password"); - edituser.setText(user); - editpassword.setText(password); - } - } - }); ActivityUserLogsBinding binding; + erweima thread; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -63,17 +43,21 @@ public class user_logs extends AppCompatActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - -// UUID = Settings.Secure.getString(getContentResolver(), -// Settings.Secure.ANDROID_ID); binding.login.setOnClickListener(view -> new CloudUser()); -/* findViewById(R.id.enroll).setOnClickListener(view -> { - Intent intent = new Intent(user_logs.this, enroll.class); - intent.putExtra("user", edituser.getText().toString()); - intent.putExtra("appID", UUID); - enroll.launch(intent); - });*/ + binding.button1.setOnClickListener(view -> { + if (binding.layout1.getVisibility() == View.VISIBLE) { + binding.layout1.setVisibility(View.GONE); + binding.layout2.setVisibility(View.VISIBLE); + binding.button1.setText("账号"); + thread = new erweima(); + thread.start(); + } else { + thread.interrupt(); + binding.button1.setText("二维码"); + binding.layout1.setVisibility(View.VISIBLE); + binding.layout2.setVisibility(View.GONE); + } + }); } //some statement @@ -102,6 +86,7 @@ public class user_logs extends AppCompatActivity { } public String account, password; + class CloudUser extends Thread { public CloudUser() { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); @@ -132,7 +117,7 @@ public class user_logs extends AppCompatActivity { String cookie = jsonObject.getString("cookie"); gj.xcts(user_logs.this, "登录成功"); wl.setcookie(cookie); - new user_message(nickname,signature,avatarUrl); + new user_message(nickname, signature, avatarUrl); user_logs.this.finish(); } else if (code == 502) { gj.xcts(user_logs.this, jsonObject.getString("message")); @@ -144,4 +129,79 @@ public class user_logs extends AppCompatActivity { } } } + + + class erweima extends Thread { + int code = 800; + String unikey, qrimg, hq; + private long time = 0; + + public erweima() { + binding.text1.setText("请使用网易云音乐扫码"); + } + + @Override + public void run() { + super.run(); + while (code != 0 && !Thread.currentThread().isInterrupted()) { + gj.sc(code); + try { + hq = wl.hq("/login/qr/check?key=" + unikey + Time()); + if (hq != null) { + JSONObject json = new JSONObject(hq); + code = json.getInt("code"); + switch (code) { + case 800: + case 400: + setwb("二维码过期"); + hqkey(); + break; + case 801: + setwb("等待扫码"); + break; + case 802: + setwb("等待确认"); + break; + case 803: + setwb("登录成功"); + wl.setcookie(json.getString("cookie")); + code = 0; + user_logs.this.finish(); + break; + default: + code = 0; + // 默认情况下的操作 + break; + } + } + sleep(1000); + } catch (Exception e) { + Thread.currentThread().interrupt(); + gj.sc(e); + } + } + } + + private void hqkey() throws Exception { + unikey = new JSONObject(Objects.requireNonNull(wl.hq("/login/qr/key"))). + getJSONObject("data").getString("unikey"); + JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wl.hq("/login/qr/create?key=" + + unikey + + "&qrimg=base64"))); + qrimg = jsonObject.getJSONObject("data").getString("qrimg"); + main.handler.post(() -> binding.image.setImageBitmap(user_logs.stringToBitmap(qrimg))); + } + + private String Time() { + if (time < System.currentTimeMillis() - 1000) { + time = System.currentTimeMillis(); + } + return "×tamp" + time; + } + + private void setwb(String wb) { + main.handler.post(() -> binding.text1.setText(wb)); + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/main.java b/app/src/main/java/com/muqingbfq/main.java index cafeda8..002b378 100644 --- a/app/src/main/java/com/muqingbfq/main.java +++ b/app/src/main/java/com/muqingbfq/main.java @@ -5,20 +5,17 @@ import android.app.Activity; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.provider.Settings; import android.text.TextUtils; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatDelegate; import com.muqingbfq.login.visitor; import com.muqingbfq.mq.FloatingLyricsService; -import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; import com.muqingbfq.mq.wl; @@ -33,10 +30,8 @@ public class main extends Application { public static int k, g; public static SharedPreferences sp; public static SharedPreferences.Editor edit; - - public static String account,token; - public int count = 0; + public static long item = System.currentTimeMillis(); @SuppressLint("HardwareIds") @Override public void onCreate() { @@ -56,7 +51,6 @@ public class main extends Application { wj.xrwb(file.toString(), main.api); } application = this; -// UUID.randomUUID().toString(); sp = getSharedPreferences("Set_up", MODE_PRIVATE); edit = sp.edit(); boolean bj = false; @@ -95,13 +89,12 @@ public class main extends Application { registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) { + public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) { } @Override - public void onActivityStarted(Activity activity) { + public void onActivityStarted(@NonNull Activity activity) { if (count == 0) { //后台切换到前台 - gj.sc(">>>>>>>>>>>>>>>>>>>App切到前台"); if (FloatingLyricsService.lei != null) { stopService(new Intent(main.this, FloatingLyricsService.class)); } @@ -110,19 +103,19 @@ public class main extends Application { } @Override - public void onActivityResumed(Activity activity) { + public void onActivityResumed(@NonNull Activity activity) { } @Override - public void onActivityPaused(Activity activity) { + public void onActivityPaused(@NonNull Activity activity) { } @Override - public void onActivityStopped(Activity activity) { + public void onActivityStopped(@NonNull Activity activity) { count--; if (count == 0) { //后台切换到前台 - gj.sc(">>>>>>>>>>>>>>>>>>>App切到后台"); +// gj.sc(">>>>>>>>>>>>>>>>>>>App切到后台"); new Thread(){ @Override public void run() { @@ -148,11 +141,11 @@ public class main extends Application { } @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { } @Override - public void onActivityDestroyed(Activity activity) { + public void onActivityDestroyed(@NonNull Activity activity) { } }); } diff --git a/app/src/main/java/com/muqingbfq/mq/gj.java b/app/src/main/java/com/muqingbfq/mq/gj.java index 5d358b4..14045a0 100644 --- a/app/src/main/java/com/muqingbfq/mq/gj.java +++ b/app/src/main/java/com/muqingbfq/mq/gj.java @@ -11,6 +11,8 @@ import android.content.Intent; import android.net.Uri; import android.util.DisplayMetrics; import android.util.Log; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; import android.widget.Toast; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -33,6 +35,7 @@ public class gj { main.handler.post(() -> Toast.makeText(context, b.toString(), Toast.LENGTH_SHORT).show()); } + public static boolean isAppInForeground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Service.ACTIVITY_SERVICE); List runningAppProcessInfoList = activityManager.getRunningAppProcesses(); @@ -48,6 +51,7 @@ public class gj { } return false; } + public static boolean isTablet(Context context) { boolean b; DisplayMetrics dm = context.getResources().getDisplayMetrics(); @@ -56,6 +60,7 @@ public class gj { b = main.k > main.g; return b; } + public static void sc(Object a) { if (a == null) { a = "null"; @@ -74,11 +79,13 @@ public class gj { shareIntent.putExtra(Intent.EXTRA_TEXT, str); context.startActivity(shareIntent); } + /** * 复制文字到剪切板 + * * @param text */ - public static void fz(Context context,String text){ + public static void fz(Context context, String text) { ClipboardManager systemService = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); // 创建能够存入剪贴板的ClipData对象 @@ -86,6 +93,7 @@ public class gj { ClipData mClipData = ClipData.newPlainText("Label", text); //将ClipData数据复制到剪贴板: systemService.setPrimaryClip(mClipData); + gj.ts(context, "复制成功"); } public static boolean isWiFiConnected() { @@ -135,7 +143,7 @@ public class gj { String bb = jsonObject.getString("bb"); main.handler.post(() -> new MaterialAlertDialogBuilder(context) .setTitle("更新" + bb) - .setMessage(msg+"\n"+"取消后不再提示更新你需要到关于软件手动检测") + .setMessage(msg + "\n" + "取消后不再提示更新你需要到关于软件手动检测") .setNegativeButton("取消", (dialogInterface, i) -> wj.xrwb(wj.filesdri + "gx.mq", null)) .setPositiveButton("更新", (dialogInterface, i) -> context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)))) @@ -149,4 +157,20 @@ public class gj { } return 400; } + + public static void tcjp(EditText editText) { + editText.requestFocus();//获取焦点 + InputMethodManager imm = (InputMethodManager) + editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); +// gj.sc(imm.isActive()); + //没有显示键盘,弹出 + imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); + } + public static void ycjp(EditText editText) { + InputMethodManager imm = (InputMethodManager) + editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm.isActive()) //有显示键盘,隐藏 + imm.hideSoftInputFromWindow(editText.getWindowToken(), + InputMethodManager.HIDE_NOT_ALWAYS); + } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/mq/wl.java b/app/src/main/java/com/muqingbfq/mq/wl.java index 0312207..61bfe5b 100644 --- a/app/src/main/java/com/muqingbfq/mq/wl.java +++ b/app/src/main/java/com/muqingbfq/mq/wl.java @@ -1,15 +1,15 @@ package com.muqingbfq.mq; -import com.muqingbfq.main; import com.muqingbfq.XM; +import com.muqingbfq.main; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; -import okhttp3.FormBody; +import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -40,22 +40,29 @@ public class wl { } public static String post(String str, String[][] a) { - OkHttpClient client = new OkHttpClient().newBuilder() .build(); - FormBody.Builder builder = new FormBody.Builder(); - for (String[] strings : a) { -// gj.sc(strings[0] + ":" + strings[1]); - builder.add(strings[0], strings[1]); +// MediaType mediaType = MediaType.parse("text/plain"); + MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); + for (String[] b : a) { + builder.addFormDataPart(b[0], b[1]); } + builder.addFormDataPart("cookie", Cookie); + Request request = new Request.Builder() .url(main.api + str) - .post(builder.build()) + .method("POST", builder.build()) + .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)") + .addHeader("Accept", "*/*") + .addHeader("Host", "139.196.224.229:3000") + .addHeader("Connection", "keep-alive") .build(); try { Response response = client.newCall(request).execute(); - return response.body().string(); - } catch (IOException e) { + if (response.body() != null) { + return response.body().string(); + } + } catch (Exception e) { gj.sc(e); } return null; diff --git a/app/src/main/java/com/muqingbfq/view/CardImage.java b/app/src/main/java/com/muqingbfq/view/CardImage.java index 4d35faf..5b7fb1d 100644 --- a/app/src/main/java/com/muqingbfq/view/CardImage.java +++ b/app/src/main/java/com/muqingbfq/view/CardImage.java @@ -42,6 +42,7 @@ public class CardImage extends MaterialCardView { Glide.with(this) .load(bitmap) // .apply(new RequestOptions().placeholder(R.drawable.icon)) + .error(R.drawable.ic_launcher_foreground) .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 587f2af..738f340 100644 --- a/app/src/main/java/com/muqingbfq/view/LrcView.java +++ b/app/src/main/java/com/muqingbfq/view/LrcView.java @@ -3,7 +3,6 @@ package com.muqingbfq.view; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; -import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Rect; import android.os.Handler; @@ -112,33 +111,35 @@ public class LrcView extends RecyclerView { public void setLrcline(boolean lrcline) { Lrcline = lrcline; if (lrcline) { - addItemDecoration(new ItemDecoration() { + removeItemDecoration(ItemDecoration); +/* 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; - } - } - }); + addItemDecoration(ItemDecoration); } } + private final RecyclerView.ItemDecoration ItemDecoration = new 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") diff --git a/app/src/main/res/drawable/gd.xml b/app/src/main/res/drawable/gd.xml new file mode 100644 index 0000000..f83aeca --- /dev/null +++ b/app/src/main/res/drawable/gd.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/icon.xml b/app/src/main/res/drawable/icon.xml index ae0caa1..f51187c 100644 --- a/app/src/main/res/drawable/icon.xml +++ b/app/src/main/res/drawable/icon.xml @@ -5,8 +5,8 @@ android:viewportHeight="1024"> + android:fillColor="@color/text"/> + android:fillColor="@color/text"/> diff --git a/app/src/main/res/drawable/paihangbang.xml b/app/src/main/res/drawable/paihangbang.xml index 005e55b..c1e5566 100644 --- a/app/src/main/res/drawable/paihangbang.xml +++ b/app/src/main/res/drawable/paihangbang.xml @@ -5,5 +5,5 @@ android:viewportHeight="1024"> + android:fillColor="@color/text"/> diff --git a/app/src/main/res/layout/activity_cookie.xml b/app/src/main/res/layout/activity_cookie.xml index 698b225..e851bf4 100644 --- a/app/src/main/res/layout/activity_cookie.xml +++ b/app/src/main/res/layout/activity_cookie.xml @@ -85,13 +85,4 @@ - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_user_logs.xml b/app/src/main/res/layout/activity_user_logs.xml index b1693f9..437cd63 100644 --- a/app/src/main/res/layout/activity_user_logs.xml +++ b/app/src/main/res/layout/activity_user_logs.xml @@ -11,85 +11,136 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:title="@string/login" /> - + + + + + + + + + + + + + + + + + + + + + + + + +