diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 629dbbd..56be7df 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -5,9 +5,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.view.GestureDetector; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -42,7 +40,6 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; public class gd extends com.muqingbfq.mq.FragmentActivity { public static String gdid; @@ -115,48 +112,11 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { boolean bool = false; - public baseadapter(Context context, List list, boolean bool, RecyclerView recyclerView) { + public baseadapter(Context context, List list, boolean bool) { this.context = context; this.list = list; this.bool = bool; - setrecycle(recyclerView); } - - public void setrecycle(RecyclerView recyclerView) { - - recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { - final GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { - @Override - public void onLongPress(@NonNull MotionEvent motionEvent) { - View childView = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY()); - if (childView != null) { - int position = recyclerView.getChildAdapterPosition(childView); - setonlong(position); - // 处理长按事件,使用正确的位置position - // ... - - } - } - }); - - @Override - public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { - return gestureDetector.onTouchEvent(e); - } - - @Override - public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { - - } - - @Override - public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { - - } - - }); - } - @SuppressLint("NotifyDataSetChanged") public void setonlong(int position) { XM xm = list.get(position); @@ -199,7 +159,6 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { try { wj.sc(wj.gd + xm.id); wode.removelist(xm); - notifyItemRemoved(position); } catch (Exception e) { gj.sc(e); } @@ -231,6 +190,10 @@ public class gd extends com.muqingbfq.mq.FragmentActivity { if (bool) { holder.itemView.setOnClickListener(card); holder.bindingB.text2.setText(xm.message); + holder.itemView.setOnLongClickListener(v -> { + setonlong(position); + return false; + }); } else { holder.binding.image.setOnClickListener(card); holder.binding.image.setOnLongClickListener(v -> { diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java index 65fc923..14464a2 100644 --- a/app/src/main/java/com/muqingbfq/fragment/search.java +++ b/app/src/main/java/com/muqingbfq/fragment/search.java @@ -2,7 +2,6 @@ package com.muqingbfq.fragment; import android.annotation.SuppressLint; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,7 +9,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -88,7 +86,7 @@ public class search extends Fragment { k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f) / 120; binding.recyclerview.setLayoutManager(new LinearLayoutManager(getContext())); binding.recyclerview.setAdapter(new gd.baseadapter(getContext(), - xmList, true, binding.recyclerview)); + xmList, true)); } new start(name); diff --git a/app/src/main/java/com/muqingbfq/fragment/wode.java b/app/src/main/java/com/muqingbfq/fragment/wode.java index a164592..e8fc27f 100644 --- a/app/src/main/java/com/muqingbfq/fragment/wode.java +++ b/app/src/main/java/com/muqingbfq/fragment/wode.java @@ -212,7 +212,6 @@ public class wode extends Fragment { } }); } - @Override public int getItemCount() { return lista.length; @@ -271,33 +270,40 @@ public class wode extends Fragment { @SuppressLint("NotifyDataSetChanged") public void sx() { - try { - adaper.list.clear(); - File file = new File(wj.gd); - for (File a : file.listFiles()) { - gj.sc(a); - String id = a.getName(); - if (id.endsWith(".json")) { - return; + adaper.list.clear(); + new Thread(){ + @Override + public void run() { + super.run(); + try { + File file = new File(wj.filesdri + "gd"); + File[] files = file.listFiles(); + gj.sc(files.length); + for (File a : files) { + String id = a.getName(); + if (id.endsWith(".json")) { + continue; + } + String dqwb = wj.dqwb(a.toString()); + JSONObject jsonObject = new JSONObject(dqwb); + String name = jsonObject.getString("name"); + String picUrl = jsonObject.getString("picUrl"); + String message = jsonObject.getString("message"); + adaper.list.add(new XM(id, name, message, picUrl)); + } + main.handler.post(() ->{ + adaper.notifyDataSetChanged(); + if (adaper.list.isEmpty()) { + binding.recyclerview2Text.setVisibility(View.VISIBLE); + } else { + binding.recyclerview2Text.setVisibility(View.GONE); + } + }); + } catch (Exception e) { + gj.sc(e); } - String dqwb = wj.dqwb(a.toString()); - JSONObject jsonObject = new JSONObject(dqwb); - String name = jsonObject.getString("name"); - String picUrl = jsonObject.getString("picUrl"); - String message = jsonObject.getString("message"); - adaper.list.add(new XM(id, name, message, picUrl)); } - main.handler.post(() ->{ - adaper.notifyDataSetChanged(); - if (adaper.list.isEmpty()) { - binding.recyclerview2Text.setVisibility(View.VISIBLE); - } else { - binding.recyclerview2Text.setVisibility(View.GONE); - } - }); - } catch (Exception e) { - gj.sc(e); - } + }.start(); } @SuppressLint("NotifyDataSetChanged")