实现我的界面UI交互完整化

删除exoplayer播放器SDK改用android原生player
This commit is contained in:
muqing 2023-12-26 13:49:45 +08:00
parent 22cd5b5e30
commit c7e3897f38
12 changed files with 266 additions and 179 deletions

View File

@ -57,6 +57,7 @@
android:theme="@style/fragment_dialog" />
<activity android:name=".fragment.mp3" />
<activity android:name=".fragment.gd" />
<activity android:name=".activity_about_software" />
<activity android:name=".sz" />
<activity android:name=".mq.llq" />

View File

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

View File

@ -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<xm> list = new ArrayList<>();
public static RecyclerView.Adapter<VH> 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<Fragment> 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<xm> 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<xm> 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();
}
}
}

View File

@ -52,34 +52,6 @@ public class gd_adapter extends Fragment {
}.start();
return layout;
}
public static class paihangbang extends Fragment {
List<xm> 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;

View File

@ -178,7 +178,6 @@ public class search extends Fragment {
xmList.add(new xm(id, name, coverImgUrl, false));
}
} catch (Exception e) {
gj.sc(e);
}

View File

@ -42,6 +42,7 @@ public class wode extends Fragment {
FragmentWdBinding binding;
private final List<com.muqingbfq.xm> 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<VH>() {
@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<xm> a = new ArrayList<>(list);
list.clear();
JSONObject date = new JSONObject(wj.dqwb(wj.gd_xz));
for (Iterator<String> 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) {

View File

@ -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<Fragment> 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

View File

@ -24,33 +24,43 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize">
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/editView"
android:background="@drawable/ui_editview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editview"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:autofillHints=""
android:background="@drawable/ui_editview"
android:hint="@string/search"
android:enabled="false"
android:gravity="center"
android:imeOptions="actionSearch"
android:inputType="text"
android:text="@string/search"
android:minHeight="48dp"
android:paddingStart="3dp"
android:paddingEnd="3dp" />
</LinearLayout>
android:paddingEnd="3dp"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/gd"
android:name="com.muqingbfq.fragment.gd"
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/fragment_gd" />
android:layout_weight="1"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bfq_db"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_bfq_db" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/Playlist"
app:menu="@menu/bottom_gd"/>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.navigation.NavigationView

View File

@ -3,23 +3,27 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.muqingbfq.view.Text
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="26sp"
android:textColor="@color/text"/>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lb"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bfq_db"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.muqingbfq.fragment.bfq_db"
tools:layout="@layout/fragment_bfq_db" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/Playlist"
app:menu="@menu/bottom_gd"/>
</LinearLayout>

View File

@ -8,7 +8,6 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.muqingbfq.view.Text
android:id="@+id/title"
android:layout_width="match_parent"

View File

@ -5,7 +5,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragment.sz"
android:fitsSystemWindows="true"
android:focusable="true">
tools:context=".fragment.sz">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="36sp"
android:text="云音乐"
android:layout_margin="16dp" />
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dividerInsetStart="16dp"
app:dividerInsetEnd="16dp"/>
</androidx.appcompat.widget.LinearLayoutCompat>

View File

@ -4,10 +4,6 @@
android:id="@+id/a"
android:icon="@drawable/zhuye"
android:title="推荐" />
<item
android:id="@+id/b"
android:icon="@drawable/paihangbang"
android:title="排行榜" />
<item
android:id="@+id/c"
android:icon="@drawable/user"