优化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.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.GestureDetector;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@ -42,7 +40,6 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
public class gd extends com.muqingbfq.mq.FragmentActivity { public class gd extends com.muqingbfq.mq.FragmentActivity {
public static String gdid; public static String gdid;
@ -115,48 +112,11 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
boolean bool = false; 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.context = context;
this.list = list; this.list = list;
this.bool = bool; 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") @SuppressLint("NotifyDataSetChanged")
public void setonlong(int position) { public void setonlong(int position) {
XM xm = list.get(position); XM xm = list.get(position);
@ -199,7 +159,6 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
try { try {
wj.sc(wj.gd + xm.id); wj.sc(wj.gd + xm.id);
wode.removelist(xm); wode.removelist(xm);
notifyItemRemoved(position);
} catch (Exception e) { } catch (Exception e) {
gj.sc(e); gj.sc(e);
} }
@ -231,6 +190,10 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
if (bool) { if (bool) {
holder.itemView.setOnClickListener(card); holder.itemView.setOnClickListener(card);
holder.bindingB.text2.setText(xm.message); holder.bindingB.text2.setText(xm.message);
holder.itemView.setOnLongClickListener(v -> {
setonlong(position);
return false;
});
} else { } else {
holder.binding.image.setOnClickListener(card); holder.binding.image.setOnClickListener(card);
holder.binding.image.setOnLongClickListener(v -> { holder.binding.image.setOnLongClickListener(v -> {

View File

@ -2,7 +2,6 @@ package com.muqingbfq.fragment;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -10,7 +9,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -88,7 +86,7 @@ public class search extends Fragment {
k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f) / 120; k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f) / 120;
binding.recyclerview.setLayoutManager(new LinearLayoutManager(getContext())); binding.recyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
binding.recyclerview.setAdapter(new gd.baseadapter(getContext(), binding.recyclerview.setAdapter(new gd.baseadapter(getContext(),
xmList, true, binding.recyclerview)); xmList, true));
} }
new start(name); new start(name);

View File

@ -212,7 +212,6 @@ public class wode extends Fragment {
} }
}); });
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return lista.length; return lista.length;
@ -271,33 +270,40 @@ public class wode extends Fragment {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
public void sx() { public void sx() {
try { adaper.list.clear();
adaper.list.clear(); new Thread(){
File file = new File(wj.gd); @Override
for (File a : file.listFiles()) { public void run() {
gj.sc(a); super.run();
String id = a.getName(); try {
if (id.endsWith(".json")) { File file = new File(wj.filesdri + "gd");
return; 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(() ->{ }.start();
adaper.notifyDataSetChanged();
if (adaper.list.isEmpty()) {
binding.recyclerview2Text.setVisibility(View.VISIBLE);
} else {
binding.recyclerview2Text.setVisibility(View.GONE);
}
});
} catch (Exception e) {
gj.sc(e);
}
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")