From 00c4d08deb1f762b7c54e76547eaca0a81f3484f Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Mon, 11 Apr 2022 12:58:28 +0200 Subject: [PATCH] Add HTTP scroll to request/reply button --- .../adapters/PayloadAdapter.java | 62 ++++++++++++++++++- .../fragments/ConnectionPayload.java | 2 +- .../drawable/ic_subdirectory_arrow_left.xml | 5 ++ app/src/main/res/layout/payload_item.xml | 40 +++++++++--- 4 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/drawable/ic_subdirectory_arrow_left.xml diff --git a/app/src/main/java/com/emanuelef/remote_capture/adapters/PayloadAdapter.java b/app/src/main/java/com/emanuelef/remote_capture/adapters/PayloadAdapter.java index aecdb004..b1869028 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/adapters/PayloadAdapter.java +++ b/app/src/main/java/com/emanuelef/remote_capture/adapters/PayloadAdapter.java @@ -20,6 +20,7 @@ package com.emanuelef.remote_capture.adapters; import android.content.Context; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,6 +29,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.emanuelef.remote_capture.CaptureService; @@ -38,6 +40,7 @@ import com.emanuelef.remote_capture.model.ConnectionDescriptor; import com.emanuelef.remote_capture.model.PayloadChunk; import com.emanuelef.remote_capture.model.PayloadChunk.ChunkType; import com.emanuelef.remote_capture.model.Prefs; +import com.google.android.material.button.MaterialButton; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; @@ -50,6 +53,7 @@ import java.util.Locale; * Since the text of a chunk can be very long (hundreds of KB) and rendering it would freeze the UI, * it is split into pages of VISUAL_PAGE_SIZE. */ public class PayloadAdapter extends RecyclerView.Adapter implements HTTPReassembly.ReassemblyListener { + private static final String TAG = "PayloadAdapter"; public static final int COLLAPSE_CHUNK_SIZE = 1500; public static final int VISUAL_PAGE_SIZE = 4020; // must be a multiple of 67 to avoid splitting the hexdump private final LayoutInflater mLayoutInflater; @@ -57,12 +61,15 @@ public class PayloadAdapter extends RecyclerView.Adapter mChunks = new ArrayList<>(); + private final LinearLayoutManager mLinearLayout; private final HTTPReassembly mHttpReq; private final HTTPReassembly mHttpRes; - public PayloadAdapter(Context context, ConnectionDescriptor conn, ChunkType mode) { + public PayloadAdapter(Context context, LinearLayoutManager linearLayout, ConnectionDescriptor conn, ChunkType mode) { mLayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mLinearLayout = linearLayout; mConn = conn; mContext = context; mMode = mode; @@ -83,6 +90,7 @@ public class PayloadAdapter extends RecyclerView.Adapter { + int pos = holder.getAbsoluteAdapterPosition(); + Page page = getItem(pos); + assert(page.adaptChunk.peer != null); + + int jumpPos = getAdapterPosition(page.adaptChunk.peer); + Log.d(TAG, "jump to " + jumpPos + " (orig_pos=" + page.adaptChunk.peer.originalPos + ")"); + mLinearLayout.scrollToPosition(jumpPos); + }); + return holder; } @@ -252,6 +272,8 @@ public class PayloadAdapter extends RecyclerView.Adapter + + diff --git a/app/src/main/res/layout/payload_item.xml b/app/src/main/res/layout/payload_item.xml index dff30a1f..2fbee8f6 100644 --- a/app/src/main/res/layout/payload_item.xml +++ b/app/src/main/res/layout/payload_item.xml @@ -3,19 +3,43 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:paddingHorizontal="3sp" - android:paddingVertical="10dp"> + android:paddingVertical="8dp"> - + android:gravity="center_vertical" + android:layout_marginBottom="10dp" + android:orientation="horizontal"> + + + + +