diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index dab4a77..4d44a55 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -18,7 +18,6 @@ import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import com.google.gson.Gson; @@ -76,22 +75,22 @@ public class bfq extends AppCompatActivity { }); } } + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); binding = ActivityBfqBinding.inflate(getLayoutInflater()); + view = binding.getRoot(); setLrc(); new Media(binding); - view = binding.getRoot(); TypedValue typedValue = new TypedValue(); home.appCompatActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true); // 设置背景颜色 view.setBackgroundColor(typedValue.data); setContentView(view); - Toolbar toolbar = binding.toolbar; - toolbar.setNavigationOnClickListener(view1 -> finish()); - toolbar.setOnMenuItemClickListener(item -> { + binding.toolbar.setNavigationOnClickListener(view1 -> finish()); + binding.toolbar.setOnMenuItemClickListener(item -> { if (item.getItemId() == R.id.fx && bfqkz.xm != null) { com.muqingbfq.mq.gj.fx(this, "音乐名称:" + bfqkz.xm.name + @@ -110,7 +109,9 @@ public class bfq extends AppCompatActivity { if (bfqkz.mt != null && bfqkz.mt.isPlaying()) { binding.kg.setImageResource(R.drawable.bf); } - text(); + binding.toolbar.setOnTouchListener(new Touch()); + view.setOnTouchListener(new Touch()); + binding.like.setOnClickListener(view1 -> { try { Gson gson = new Gson(); @@ -208,11 +209,11 @@ public class bfq extends AppCompatActivity { super.onConfigurationChanged(newConfig); } - private float downY, moveY; - @SuppressLint("ClickableViewAccessibility") - public void text() { - binding.toolbar.setOnTouchListener((view, motionEvent) -> { - LinearLayout root = binding.getRoot(); + + public class Touch implements View.OnTouchListener { + private float downY, moveY; + @Override + public boolean onTouch(View view, MotionEvent motionEvent) {LinearLayout root = binding.getRoot(); switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: downY = motionEvent.getRawY(); @@ -248,7 +249,7 @@ public class bfq extends AppCompatActivity { break; } return true; - }); + } } public static void setlike(boolean bool) { if (binding == null) { diff --git a/app/src/main/java/com/muqingbfq/bfqkz.java b/app/src/main/java/com/muqingbfq/bfqkz.java index 08fb333..ad2e79a 100644 --- a/app/src/main/java/com/muqingbfq/bfqkz.java +++ b/app/src/main/java/com/muqingbfq/bfqkz.java @@ -5,7 +5,6 @@ import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.support.v4.media.MediaBrowserCompat; @@ -56,12 +55,11 @@ public class bfqkz extends MediaBrowserServiceCompat { try { if (TextUtils.isEmpty(id)) { //针对错误进行相应的处理 -/* if (bfqkz.list.size() < 1) { + if (bfqkz.list.size() < 1) { return; } bfqkz.list.remove(bfqkz.xm); - bfqkz.xm = bfqkz.list.get(bfqkz.getmti(bfqkz.ms)); - new mp3(id);*/ + bfq_an.xyq(); return; } if (TextUtils.isEmpty(xm.picurl)) { @@ -199,15 +197,6 @@ public class bfqkz extends MediaBrowserServiceCompat { public void onLoadChildren(@NonNull String parentId, @NonNull Result> result) { } -/* - - public class MyBinder extends Binder { - bfqkz getService() { - return bfqkz.this; - } - } -*/ - public static void updateNotification() { try { // 更新通知栏的播放状态 diff --git a/app/src/main/java/com/muqingbfq/clean/fragment_clean.java b/app/src/main/java/com/muqingbfq/clean/fragment_clean.java index 6fd0564..0d771c3 100644 --- a/app/src/main/java/com/muqingbfq/clean/fragment_clean.java +++ b/app/src/main/java/com/muqingbfq/clean/fragment_clean.java @@ -14,6 +14,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.muqingbfq.R; import com.muqingbfq.databinding.CleanBinding; import com.muqingbfq.mq.FragmentActivity; @@ -41,6 +42,9 @@ public class fragment_clean extends FragmentActivity { list.add(new String[]{"下载的音乐", wj.mp3}); list.add(new String[]{"下载的歌单",wj.gd}); list.add(new String[]{"缓存的音乐",wj.filesdri+"hc"}); + list.add(new String[]{"内部缓存", getCacheDir().toString()}); + String s = Glide.getPhotoCacheDir(this).toString(); + list.add(new String[]{"Glide缓存", s}); binding.toolbar.setTitle("储存清理"); binding.recyclerview.setAdapter(adapter); } @@ -70,62 +74,15 @@ public class fragment_clean extends FragmentActivity { } else { holder.checkBox.setEnabled(false); } - -/* GestureDetector gestureDetector=new GestureDetector(fragment_clean.this, - new GestureDetector.OnGestureListener() { - @Override - public boolean onDown(@NonNull MotionEvent motionEvent) { - return true; - } - - @Override - public void onShowPress(@NonNull MotionEvent motionEvent) { - - } - - @Override - public boolean onSingleTapUp(@NonNull MotionEvent motionEvent) { - return false; - } - - @Override - public boolean onScroll(@Nullable MotionEvent motionEvent, @NonNull MotionEvent motionEvent1, float v, float v1) { - return false; - } - - @Override - public void onLongPress(@NonNull MotionEvent motionEvent) { - - } - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - // 计算水平方向滑动的距离 - float deltaX = e2.getX() - e1.getX(); - holder.checkBox.setX(deltaX); - // 判断是否是从左向右滑动,并且滑动距离超过一定阈值 - if (deltaX > 0 && Math.abs(deltaX) > 100) { - // 执行删除操作 - gj.sc("sc"); - return true; - } - return true; - } - });*/ String s1 = Formatter.formatFileSize(fragment_clean.this, leng); holder.checkBox.setText(s[0] + ":" + s1 + " 共计:" + size+" 个文件"); -/* holder.checkBox.setOnTouchListener((view, motionEvent) -> - gestureDetector.onTouchEvent(motionEvent));*/ holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> { if (b) { list_box.add(file.toString()); }else { list_box.remove(file.toString()); } - if (list_box.size() > 0) { - menu_deleat.setVisible(true); - } else { - menu_deleat.setVisible(false); - } + menu_deleat.setVisible(list_box.size() > 0); }); } 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 c6e3a60..aa02c78 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java @@ -1,14 +1,11 @@ package com.muqingbfq.fragment; import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; -import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -16,11 +13,7 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.muqingbfq.R; import com.muqingbfq.api.resource; -import com.muqingbfq.databinding.FragmentWdBinding; -import com.muqingbfq.login.user_editing; -import com.muqingbfq.login.user_logs; import com.muqingbfq.main; import com.muqingbfq.xm; @@ -53,9 +46,8 @@ public class gd_adapter extends Fragment { return layout; } private class sx implements Runnable { - gd.baseadapter baseadapter; - - public sx(gd.baseadapter baseadapter) { + RecyclerView.Adapter baseadapter; + public sx(RecyclerView.Adapter baseadapter) { this.baseadapter = baseadapter; } @SuppressLint("NotifyDataSetChanged") diff --git a/app/src/main/java/com/muqingbfq/fragment/wode.java b/app/src/main/java/com/muqingbfq/fragment/wode.java index 388d04d..4929bdc 100644 --- a/app/src/main/java/com/muqingbfq/fragment/wode.java +++ b/app/src/main/java/com/muqingbfq/fragment/wode.java @@ -39,15 +39,23 @@ public class wode extends Fragment { public static TextView name, jieshao; @SuppressLint("StaticFieldLeak") public static ImageView imageView; - FragmentWdBinding binding; + private 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, "开发中", ""} + }; private final List list = new ArrayList<>(); @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = FragmentWdBinding.inflate(inflater, container, false); - View view = binding.getRoot(); name = binding.text1; jieshao = binding.text2; imageView = binding.imageView; @@ -58,26 +66,16 @@ public class wode extends Fragment { 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(), 4){ + GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 4) { @Override public boolean canScrollVertically() { return false;//禁止滑动 } }; binding.recyclerview1.setLayoutManager(gridLayoutManager); - 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.setFocusable(false); binding.recyclerview1.setAdapter(new RecyclerView.Adapter() { @NonNull @@ -120,7 +118,6 @@ public class wode extends Fragment { return lista.length; } }); - sx(); binding.recyclerview2.setLayoutManager(new LinearLayoutManager(getContext()) { @Override public boolean canScrollVertically() { @@ -129,7 +126,8 @@ public class wode extends Fragment { }); binding.recyclerview2.setFocusable(false); binding.recyclerview2.setAdapter(new gd.baseadapter(getContext(), list, true)); - return view; + sx(); + return binding.getRoot(); } class VH extends RecyclerView.ViewHolder { @@ -146,7 +144,6 @@ public class wode extends Fragment { @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(); ) { @@ -157,9 +154,6 @@ public class wode extends Fragment { String picUrl = jsonObject.getString("picUrl"); list.add(new xm(id, name, picUrl, cz)); } - if (list.equals(a)) { - return; - } main.handler.post(() -> binding.recyclerview2.getAdapter().notifyDataSetChanged()); } catch (Exception e) { gj.sc(e); diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java index 809fda2..a839c83 100644 --- a/app/src/main/java/com/muqingbfq/home.java +++ b/app/src/main/java/com/muqingbfq/home.java @@ -35,6 +35,7 @@ public class home extends AppCompatActivity { ActivityHomeBinding binding; public MediaBrowserCompat mBrowser; + @Override protected void onCreate(Bundle savedInstanceState) { appCompatActivity = this; @@ -61,14 +62,16 @@ public class home extends AppCompatActivity { //初始化播放器组件 // 启动Service - componentName = new ComponentName(this, bfqkz.class); - mBrowser = new MediaBrowserCompat( - this,componentName - ,//绑定服务端 - browserConnectionCallback,//设置连接回调 - null - ); - mBrowser.connect(); + if (componentName == null) { + componentName = new ComponentName(this, bfqkz.class); + mBrowser = new MediaBrowserCompat( + this, componentName + ,//绑定服务端 + browserConnectionCallback,//设置连接回调 + null + ); + mBrowser.connect(); + } //检测更新 new gj.jianchagengxin(this); binding.editView.setOnClickListener(view -> @@ -80,9 +83,11 @@ public class home extends AppCompatActivity { } public static ComponentName componentName; - private final List list = new ArrayList<>(); - private class adaper extends FragmentStateAdapter { - public adaper(@NonNull FragmentActivity fragmentActivity) { + private Adaper adapter; + + private class Adaper extends FragmentStateAdapter { + List list = new ArrayList<>(); + public Adaper(@NonNull FragmentActivity fragmentActivity) { super(fragmentActivity); list.add(new gd_adapter()); list.add(new wode()); @@ -97,9 +102,10 @@ public class home extends AppCompatActivity { return list.size(); } } - public void UI() { - binding.viewPager.setAdapter(new adaper(this)); + adapter = new Adaper(this); + binding.viewPager.setAdapter(adapter); + binding.viewPager.setSaveEnabled(false); // 将 ViewPager2 绑定到 TabLayout binding.tablayout.setOnItemSelectedListener(item -> { int itemId = item.getItemId(); @@ -128,7 +134,7 @@ public class home extends AppCompatActivity { } catch (InterruptedException e) { e.toString(); } - wode fragment = (wode) list.get(position); + wode fragment = (wode) adapter.createFragment(position); fragment.sx(); } }.start(); @@ -137,6 +143,7 @@ public class home extends AppCompatActivity { } }); } + @Override protected void onPause() { super.onPause(); @@ -156,6 +163,7 @@ public class home extends AppCompatActivity { .replace(R.id.bfq_db, new bfq_db()) .commit(); } + private long time; @Override @@ -190,12 +198,11 @@ public class home extends AppCompatActivity { } - /** * 连接状态的回调接口,连接成功时会调用onConnected()方法 */ - private MediaBrowserCompat.ConnectionCallback browserConnectionCallback= - new MediaBrowserCompat.ConnectionCallback(){ + private final MediaBrowserCompat.ConnectionCallback browserConnectionCallback = + new MediaBrowserCompat.ConnectionCallback() { @Override public void onConnected() { //必须在确保连接成功的前提下执行订阅的操作 @@ -233,7 +240,7 @@ public class home extends AppCompatActivity { * 向媒体服务器(MediaBrowserService)发起数据订阅请求的回调接口 */ private final MediaBrowserCompat.SubscriptionCallback browserSubscriptionCallback = - new MediaBrowserCompat.SubscriptionCallback(){ + new MediaBrowserCompat.SubscriptionCallback() { @Override public void onChildrenLoaded(@NonNull String parentId, @NonNull List children) { diff --git a/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java b/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java index 1580560..9fa3870 100644 --- a/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java +++ b/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java @@ -5,17 +5,15 @@ import android.annotation.SuppressLint; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; -import android.app.Service; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.graphics.BitmapFactory; import android.os.Build; -import android.support.v4.media.MediaMetadataCompat; import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; +import androidx.media.MediaBrowserServiceCompat; import com.muqingbfq.MyButtonClickReceiver; import com.muqingbfq.R; @@ -26,12 +24,12 @@ import com.muqingbfq.home; import com.muqingbfq.yc; public class NotificationManagerCompat { - Service context; + MediaBrowserServiceCompat context; public NotificationCompat.Builder notificationBuilder; public androidx.core.app.NotificationManagerCompat notificationManager; private String name, zz; - public NotificationManagerCompat(Service context) { + public NotificationManagerCompat(MediaBrowserServiceCompat context) { this.context = context; name = context.getString(R.string.app_name); zz = context.getString(R.string.zz); @@ -75,7 +73,6 @@ public class NotificationManagerCompat { .setContentIntent(pendingIntent) .setStyle(style); tzl(); -// context.startForeground(1, notificationBuilder.build()); } catch (Exception e) { yc.start(context, e); } @@ -83,7 +80,6 @@ public class NotificationManagerCompat { PendingIntent pendingIntent; androidx.media.app.NotificationCompat.MediaStyle style; - @SuppressLint("RestrictedApi") public void tzl() { if (bfqkz.xm != null) {