Skip to content

Commit

Permalink
fix crash and improving performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Dkaishu committed Oct 13, 2023
1 parent 9162a95 commit 9f0348a
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.dkaishu.chuckx.internal.data;

import android.net.Uri;
import android.text.TextUtils;

import com.google.gson.reflect.TypeToken;
import com.dkaishu.chuckx.internal.support.FormatUtils;
Expand Down Expand Up @@ -352,7 +353,11 @@ public boolean isSsl() {
private List<HttpHeader> toHttpHeaderList(Headers headers) {
List<HttpHeader> httpHeaders = new ArrayList<>();
for (int i = 0, count = headers.size(); i < count; i++) {
httpHeaders.add(new HttpHeader(headers.name(i), headers.value(i)));
String value = headers.value(i);
if (!TextUtils.isEmpty(value) && value.length() > 1000) {
value = value.substring(0, 1000) + "...";
}
httpHeaders.add(new HttpHeader(headers.name(i), value));
}
return httpHeaders;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ public static String formatHeaders(List<HttpHeader> httpHeaders, boolean withMar
String out = "";
if (httpHeaders != null) {
for (HttpHeader header : httpHeaders) {
String value = header.getValue();
if (!TextUtils.isEmpty(value) && value.length() > 1000) {
value = value.substring(0, 1000) + "...";
}
out += ((withMarkup) ? "<b>" : "") + header.getName() + ": " + ((withMarkup) ? "</b>" : "") +
header.getValue() + ((withMarkup) ? "<br />" : "\n");
value + ((withMarkup) ? "<br />" : "\n");
}
}
return out;
Expand All @@ -55,7 +59,7 @@ public static String formatByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
return String.format(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre);
}

Expand All @@ -77,7 +81,7 @@ public static String formatXml(String xml) {
Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes())));
StreamResult res = new StreamResult(new ByteArrayOutputStream());
serializer.transform(xmlSource, res);
return new String(((ByteArrayOutputStream)res.getOutputStream()).toByteArray());
return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray());
} catch (Exception e) {
return xml;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public View newView(Context context, Cursor cursor, ViewGroup parent) {
public void bindView(View view, final Context context, Cursor cursor) {
final HttpTransaction transaction = LocalCupboard.getInstance().withCursor(cursor).get(HttpTransaction.class);
final ViewHolder holder = (ViewHolder) view.getTag();
holder.path.setText(transaction.getMethod() + " " + transaction.getPath());
String pathText = transaction.getMethod() + " " + transaction.getPath();
holder.path.setText(pathText.length() > 500 ? pathText.substring(0, 500) + "..." : pathText);
holder.host.setText(transaction.getHost());
holder.start.setText(transaction.getRequestStartTimeString());
holder.ssl.setVisibility(transaction.isSsl() ? View.VISIBLE : View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void transactionUpdated(HttpTransaction transaction) {

private void populateUI() {
if (isAdded() && transaction != null) {
url.setText(transaction.getUrl());
String urlText = transaction.getUrl().length() > 20000 ? transaction.getUrl().substring(0, 20000) + "..." : transaction.getUrl();
url.setText(urlText);
method.setText(transaction.getMethod());
protocol.setText(transaction.getProtocol());
status.setText(transaction.getStatus().toString());
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/layout/chuck_activity_transaction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
48 changes: 24 additions & 24 deletions library/src/main/res/layout/chuck_fragment_transaction_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_url"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -50,13 +50,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_method"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -69,13 +69,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_protocol"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/protocol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -88,13 +88,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_status"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -107,13 +107,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_response"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -126,13 +126,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_ssl"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/ssl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -146,13 +146,13 @@
android:layout_height="wrap_content"
android:paddingTop="8dp">

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_request_time"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/request_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -165,13 +165,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_response_time"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/response_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -184,13 +184,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_duration"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -204,13 +204,13 @@
android:layout_height="wrap_content"
android:paddingTop="8dp">

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_request_size"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/request_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -223,13 +223,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_response_size"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/response_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -242,13 +242,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chuck_total_size"
style="@style/Chuck.TextAppearance.Label"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/total_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
android:padding="16dp"
android:orientation="vertical" >

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/headers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
12 changes: 6 additions & 6 deletions library/src/main/res/layout/chuck_list_item_transaction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:padding="12dp"
android:background="?android:attr/selectableItemBackground">

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/code"
android:layout_width="40dp"
android:layout_height="wrap_content"
Expand All @@ -31,7 +31,7 @@
android:textAppearance="@style/Chuck.TextAppearance.ListItem"
tools:text="200"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -41,7 +41,7 @@
android:textAppearance="@style/Chuck.TextAppearance.ListItem"
tools:text="GET /path/to/some/resource?goes=here"/>

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -70,22 +70,22 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/start"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:padding="2dp"
tools:text="18:29:07" />

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/duration"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:padding="2dp"
android:gravity="end"
tools:text="8023 ms" />

<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/size"
android:layout_width="80dp"
android:layout_height="wrap_content"
Expand Down
Binary file added sample/src/main/assets/chuck.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9f0348a

Please sign in to comment.