diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 702d8a5..c8d82b9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -57,6 +57,7 @@ android:theme="@style/fragment_dialog" /> + diff --git a/app/src/main/java/com/muqingbfq/MediaPlayer.java b/app/src/main/java/com/muqingbfq/MediaPlayer.java index 1f1fc4e..121c35b 100644 --- a/app/src/main/java/com/muqingbfq/MediaPlayer.java +++ b/app/src/main/java/com/muqingbfq/MediaPlayer.java @@ -171,6 +171,7 @@ public class MediaPlayer extends android.media.MediaPlayer { Media.setProgress(0); Media.setname(name); Media.setzz(zz); + bfq_an.islike(); } bfq_db.setname(name + "/" + zz); if (com.muqingbfq.fragment.mp3.lbspq != null) { diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 1cb3d37..6d30271 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -12,9 +12,12 @@ import android.widget.ImageView; 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; @@ -23,17 +26,22 @@ 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.xm; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -42,76 +50,63 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -public class gd extends Fragment { +public class gd extends com.muqingbfq.mq.FragmentActivity { public static String gdid; - FragmentGdBinding binding; + private final List list = new ArrayList<>(); + public static RecyclerView.Adapter adapter; + int k; @Override - public void onResume() { - super.onResume(); - getActivity().getSupportFragmentManager().beginTransaction() - .replace(R.id.bfq_db, new bfq_db()) - .commit(); + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + FragmentMp3Binding binding = FragmentMp3Binding.inflate(getLayoutInflater()); + Intent intent = getIntent(); + binding.title.setText(intent.getStringExtra("name")); +// inflate.toolbar.setTitle(intent.getStringExtra("name")); + setContentView(binding.getRoot()); + 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); + binding.lb.setAdapter(adapter); + String id = intent.getStringExtra("id"); +// inflate.bfqDb.setBackground(gd.color); + new start(id); } + @SuppressLint("NotifyDataSetChanged") + class start extends Thread { + String id; + public start(String id) { + this.id = id; + list.clear(); + adapter.notifyDataSetChanged(); + start(); + } - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - binding = FragmentGdBinding.inflate(inflater, container, false); - binding.viewPager.setAdapter(new adaper(getActivity())); - -// 将 ViewPager2 绑定到 TabLayout - binding.tablayout.setOnItemSelectedListener(item -> { - int itemId = item.getItemId(); - if (itemId == R.id.a) { - binding.viewPager.setCurrentItem(0); - } else if (itemId == R.id.b) { - binding.viewPager.setCurrentItem(1); - } else if (itemId == R.id.c) { - binding.viewPager.setCurrentItem(2); - } - return true; - }); - binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { - @Override - public void onPageSelected(int position) { - switch (position) { - case 0: - binding.tablayout.setSelectedItemId(R.id.a); - break; - case 1: - binding.tablayout.setSelectedItemId(R.id.b); - break; - case 2: - binding.tablayout.setSelectedItemId(R.id.c); - wode fragment = (wode) list.get(position); - fragment.sx(); - break; + @Override + public void run() { + super.run(); + if (id.equals("排行榜")) { + resource.排行榜(list); + } else { + String hq = wl.hq("/search?keywords=" + id + "&limit=" + (k * 3) + "&type=1000"); + try { + 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"); + String name = jsonObject.getString("name"); + String coverImgUrl = jsonObject.getString("coverImgUrl"); + list.add(new xm(id, name, coverImgUrl, false)); + } + } catch (Exception e) { + gj.sc(e); } } - }); - return binding.getRoot(); - } - - List list = new ArrayList<>(); - - private class adaper extends FragmentStateAdapter { - public adaper(@NonNull FragmentActivity fragmentActivity) { - super(fragmentActivity); - list.add(new gd_adapter()); - list.add(new gd_adapter.paihangbang()); - list.add(new wode()); - } - - @NonNull - @Override - public Fragment createFragment(int position) { - return list.get(position); - } - @Override - public int getItemCount() { - return list.size(); + main.handler.post(new lbspq_sx()); } } @@ -124,12 +119,22 @@ public class gd extends Fragment { this.list = list; } + boolean bool = false; + public baseadapter(Context context, List list,boolean bool) { + this.context = context; + this.list = list; + this.bool = bool; + } + @NonNull @Override public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(context) - .inflate(R.layout.list_gd, parent, false); - return new VH(view); + if (bool) { + return new VH(LayoutInflater.from(context) + .inflate(R.layout.list_gd_b, parent, false)); + } + return new VH(LayoutInflater.from(context) + .inflate(R.layout.list_gd, parent, false)); } public void setList(List list) { @@ -247,4 +252,12 @@ public class gd extends Fragment { kg = itemView.findViewById(R.id.kg); } } + + private class lbspq_sx implements Runnable { + @SuppressLint("NotifyDataSetChanged") + @Override + public void run() { + adapter.notifyDataSetChanged(); + } + } } \ No newline at end of file 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 92caf04..4022bb2 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java @@ -52,34 +52,6 @@ public class gd_adapter extends Fragment { }.start(); return layout; } - - public static class paihangbang extends Fragment { - List list = new ArrayList<>(); - gd.baseadapter baseadapter; - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - FrameLayout layout = new FrameLayout(getContext()); - RecyclerView recyclerView = new RecyclerView(layout.getContext()); - int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); - GridLayoutManager gridLayoutManager = new GridLayoutManager(layout.getContext(), k / 120); - recyclerView.setLayoutManager(gridLayoutManager); - layout.addView(recyclerView); - baseadapter = new gd.baseadapter(getContext(), list); - recyclerView.setAdapter(baseadapter); - new Thread() { - @SuppressLint("NotifyDataSetChanged") - @Override - public void run() { - super.run(); - resource.排行榜(list); - main.handler.postDelayed(new sx(baseadapter),500); - } - }.start(); - return layout; - } - } private static class sx implements Runnable { gd.baseadapter baseadapter; diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java index cdce3c0..65a1826 100644 --- a/app/src/main/java/com/muqingbfq/fragment/search.java +++ b/app/src/main/java/com/muqingbfq/fragment/search.java @@ -178,7 +178,6 @@ public class search extends Fragment { xmList.add(new xm(id, name, coverImgUrl, false)); } - } 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 3a965f1..9c3635f 100644 --- a/app/src/main/java/com/muqingbfq/fragment/wode.java +++ b/app/src/main/java/com/muqingbfq/fragment/wode.java @@ -42,6 +42,7 @@ public class wode extends Fragment { FragmentWdBinding binding; private final List list = new ArrayList<>(); + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -51,26 +52,26 @@ public class wode extends Fragment { jieshao = binding.text2; imageView = binding.imageView; binding.cardview.setOnClickListener(v -> { - if (main.getToken() == null) { - startActivity(new Intent(getContext(), user_logs.class)); - } else { - startActivity(new Intent(getContext(), user_editing.class)); - } - }); + if (main.getToken() == null) { + startActivity(new Intent(getContext(), user_logs.class)); + } else { + startActivity(new Intent(getContext(), user_editing.class)); + } + }); new user_message(); - int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); - GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), k / 120); +// int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); + GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 4); binding.recyclerview1.setLayoutManager(gridLayoutManager); - final Object[][] lista ={ - {R.drawable.bf,"最近播放"}, - {R.drawable.download,"下载音乐"}, - {R.drawable.like,"喜欢音乐"}, - {R.drawable.icon,"本地搜索"}, - {R.drawable.icon,"我的歌单"}, - {R.drawable.icon,"导入歌单"}, - {R.drawable.icon,"开发中"}, - {R.drawable.icon,"开发者"} + final Object[][] lista = { + {R.drawable.bf, "最近播放", "mp3_hc.json"}, + {R.drawable.download, "下载音乐", "mp3_xz.json"}, + {R.drawable.like, "喜欢音乐", "mp3_like.json"}, + {R.drawable.icon, "本地搜索", ""}, + {R.drawable.icon, "我的歌单", ""}, + {R.drawable.icon, "导入歌单", ""}, + {R.drawable.paihangbang, "排行榜", "排行榜"}, + {R.drawable.icon, "开发中", ""} }; binding.recyclerview1.setAdapter(new RecyclerView.Adapter() { @NonNull @@ -87,27 +88,23 @@ public class wode extends Fragment { Glide.with(getContext()) .load(lista[position][0]) .into(holder.imageView); + String data = lista[position][2].toString(); holder.itemView.setOnClickListener(view -> { - Intent a = new Intent(getContext(), com.muqingbfq.fragment.mp3.class); - switch (position) { - case 0: - a.putExtra("id", "mp3_hc.json"); + switch (data) { + case "mp3_hc.json": + case "mp3_xz.json": + case "mp3_like.json": + Intent a = new Intent(getContext(), com.muqingbfq.fragment.mp3.class); + a.putExtra("id", data); a.putExtra("name", s); getContext().startActivity(a); break; - case 1: - a.putExtra("id", "mp3_xz.json"); - a.putExtra("name", s); - getContext().startActivity(a); + case "排行榜": + Intent b = new Intent(getContext(), com.muqingbfq.fragment.gd.class); + b.putExtra("id", data); + b.putExtra("name", s); + getContext().startActivity(b); break; - case 2: - a.putExtra("id", "mp3_like.json"); - a.putExtra("name", s); - getContext().startActivity(a); - break; - case 3: - break; - } }); } @@ -118,20 +115,21 @@ public class wode extends Fragment { } }); sx(); - binding.recyclerview2.setLayoutManager(new LinearLayoutManager(getContext()){ + binding.recyclerview2.setLayoutManager(new LinearLayoutManager(getContext()) { @Override public boolean canScrollVertically() { return false;//禁止滑动 } }); binding.recyclerview2.setFocusable(false); - binding.recyclerview2.setAdapter(new gd.baseadapter(getContext(),list)); + binding.recyclerview2.setAdapter(new gd.baseadapter(getContext(), list, true)); return view; } class VH extends RecyclerView.ViewHolder { public ImageView imageView; public TextView textView; + public VH(@NonNull View itemView) { super(itemView); imageView = itemView.findViewById(R.id.image); @@ -139,8 +137,10 @@ public class wode extends Fragment { } } - public void sx(){ + @SuppressLint("NotifyDataSetChanged") + public void sx() { try { + List a = new ArrayList<>(list); list.clear(); JSONObject date = new JSONObject(wj.dqwb(wj.gd_xz)); for (Iterator it = date.keys(); it.hasNext(); ) { @@ -151,14 +151,19 @@ public class wode extends Fragment { String picUrl = jsonObject.getString("picUrl"); list.add(new xm(id, name, picUrl, cz)); } - binding.recyclerview2.getAdapter().notifyDataSetChanged(); + if (list.equals(a)) { + return; + } + main.handler.post(() -> binding.recyclerview2.getAdapter().notifyDataSetChanged()); } catch (Exception e) { gj.sc(e); } } + public static void setname(String string) { main.handler.post(() -> name.setText(string)); } + public static void setqianming(String string) { main.handler.post(() -> { if (string == null) { diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java index 452614c..e0c7db3 100644 --- a/app/src/main/java/com/muqingbfq/home.java +++ b/app/src/main/java/com/muqingbfq/home.java @@ -11,20 +11,27 @@ import android.view.Menu; import android.view.MenuItem; import android.widget.ImageView; +import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; -import com.google.android.material.navigation.NavigationView; +import com.muqingbfq.databinding.ActivityHomeBinding; import com.muqingbfq.fragment.Media; import com.muqingbfq.fragment.bfq_db; import com.muqingbfq.fragment.gd; +import com.muqingbfq.fragment.gd_adapter; +import com.muqingbfq.fragment.wode; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; -import java.io.FileOutputStream; -import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; import me.wcy.lrcview.LrcView; @@ -33,16 +40,18 @@ public class home extends AppCompatActivity { public static AppCompatActivity appCompatActivity; @SuppressLint("StaticFieldLeak") public static ImageView imageView; + ActivityHomeBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { appCompatActivity = this; setTheme(R.style.Theme_muqing); super.onCreate(savedInstanceState); - if (true) { + if (false) { com.muqingbfq.mq.floating.start(this); } - setContentView(R.layout.activity_home); + binding = ActivityHomeBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); DisplayMetrics dm = getResources().getDisplayMetrics(); main.k = dm.widthPixels; main.g = dm.heightPixels; @@ -60,27 +69,25 @@ public class home extends AppCompatActivity { Media.lrcview = new LrcView(this); // 请将Context替换为实际的上下文对象 // 设置LrcView的属性 - Media.lrcview.setCurrentColor(getResources().getColor(R.color.text)); + Media.lrcview.setCurrentColor(ContextCompat.getColor(this,R.color.text)); Media.lrcview.setLabel(getString(R.string.app_name)); Media.lrcview.setCurrentTextSize(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics())); // lrcView.setLrcPadding(16); Media.lrcview.setCurrentTextSize(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics())); - Media.lrcview.setTimelineTextColor(getResources().getColor(R.color.text_tm)); + Media.lrcview.setTimelineTextColor(ContextCompat.getColor(this,R.color.text_tm)); } try { //初始化工具栏 - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); DrawerLayout drawerLayout = findViewById(R.id.chct); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( - this, drawerLayout, toolbar, R.string.app_name, R.string.app_name); + this, drawerLayout, binding.toolbar, R.string.app_name, R.string.app_name); drawerLayout.addDrawerListener(toggle); toggle.syncState(); //初始化侧滑 - NavigationView chb = findViewById(R.id.chb); - chb.setNavigationItemSelectedListener(item -> { + binding.chb.setNavigationItemSelectedListener(item -> { com.muqingbfq.fragment.sz.switch_sz(home.this, item.getItemId()); return false; }); @@ -92,12 +99,75 @@ public class home extends AppCompatActivity { } //检测更新 new gj.jianchagengxin(this); - + binding.editView.setOnClickListener(view -> + startActivity(new Intent(this, activity_search.class))); + UI(); } catch (Exception e) { yc.tc(this, e); } } + List list = new ArrayList<>(); + + private class adaper extends FragmentStateAdapter { + public adaper(@NonNull FragmentActivity fragmentActivity) { + super(fragmentActivity); + list.add(new gd_adapter()); + list.add(new wode()); + } + + @NonNull + @Override + public Fragment createFragment(int position) { + return list.get(position); + } + @Override + public int getItemCount() { + return list.size(); + } + } + + public void UI() { + binding.viewPager.setAdapter(new adaper(this)); + +// 将 ViewPager2 绑定到 TabLayout + binding.tablayout.setOnItemSelectedListener(item -> { + int itemId = item.getItemId(); + if (itemId == R.id.a) { + binding.viewPager.setCurrentItem(0); + } else if (itemId == R.id.c) { + binding.viewPager.setCurrentItem(1); + } + return true; + }); + binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { + @Override + public void onPageSelected(int position) { + switch (position) { + case 0: + binding.tablayout.setSelectedItemId(R.id.a); + break; + case 1: + binding.tablayout.setSelectedItemId(R.id.c); + new Thread() { + @Override + public void run() { + super.run(); + try { + sleep(1000); + } catch (InterruptedException e) { + e.toString(); + } + wode fragment = (wode) list.get(position); + fragment.sx(); + } + }.start(); + break; + } + } + }); + } + private static Intent serviceIntent; @Override @@ -114,6 +184,13 @@ public class home extends AppCompatActivity { } + @Override + public void onResume() { + super.onResume(); + getSupportFragmentManager().beginTransaction() + .replace(R.id.bfq_db, new bfq_db()) + .commit(); + } private long time; @Override diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index bebda5f..01d8ebc 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -24,33 +24,43 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize"> - - + - + android:paddingEnd="3dp" + app:layout_constraintTop_toTopOf="parent" /> + - + android:layout_weight="1"/> + + + - + + + - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_mp3.xml b/app/src/main/res/layout/fragment_mp3.xml index 88f0993..959eb9a 100644 --- a/app/src/main/res/layout/fragment_mp3.xml +++ b/app/src/main/res/layout/fragment_mp3.xml @@ -8,7 +8,6 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content"> - + tools:context=".fragment.sz"> + + + diff --git a/app/src/main/res/menu/bottom_gd.xml b/app/src/main/res/menu/bottom_gd.xml index d8571f4..f737f00 100644 --- a/app/src/main/res/menu/bottom_gd.xml +++ b/app/src/main/res/menu/bottom_gd.xml @@ -4,10 +4,6 @@ android:id="@+id/a" android:icon="@drawable/zhuye" android:title="推荐" /> -