优化UI,修复BUG

This commit is contained in:
muqing 2024-01-31 12:31:06 +08:00
parent 6201f3f25d
commit e223972408
3 changed files with 38 additions and 71 deletions

View File

@ -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<XM> list, boolean bool, RecyclerView recyclerView) {
public baseadapter(Context context, List<XM> 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 -> {

View File

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

View File

@ -212,7 +212,6 @@ public class wode extends Fragment {
}
});
}
@Override
public int getItemCount() {
return lista.length;
@ -271,14 +270,19 @@ 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);
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")) {
return;
continue;
}
String dqwb = wj.dqwb(a.toString());
JSONObject jsonObject = new JSONObject(dqwb);
@ -299,6 +303,8 @@ public class wode extends Fragment {
gj.sc(e);
}
}
}.start();
}
@SuppressLint("NotifyDataSetChanged")
public static void addlist(XM xm) {