Skip to content

Commit

Permalink
Fix share as text not working Ashok-Varma#28
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiaoming committed Jul 24, 2020
1 parent 94077c4 commit 1ce2ef5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.ashokvarma.gander.R;
import com.ashokvarma.gander.internal.data.HttpHeader;
import com.ashokvarma.gander.internal.ui.HttpTransactionUIHelper;
import com.ashokvarma.gander.internal.ui.details.TransactionDetailsActivity;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -153,8 +154,21 @@ public static CharSequence formatFormEncoded(String formEncoded) {
}
}

public static CharSequence getShareText(Context context, HttpTransactionUIHelper transactionUIHelper) {
SpannableStringBuilder text = new SpannableStringBuilder();
public static CharSequence getShareText(Context context, HttpTransactionUIHelper transactionUIHelper, int position) {
StringBuilder text = new StringBuilder();
if (position == TransactionDetailsActivity.POSITION_OVERVIEW) {
text.append(getOverviewText(context, transactionUIHelper));
} else if (position == TransactionDetailsActivity.POSITION_REQUEST) {
text.append(getRequestText(context, transactionUIHelper));
} else if (position == TransactionDetailsActivity.POSITION_RESPONSE) {
text.append(getResponseText(context, transactionUIHelper));
}
return text;
}

@SuppressWarnings("all")
private static CharSequence getOverviewText(Context context, HttpTransactionUIHelper transactionUIHelper) {
StringBuilder text = new StringBuilder();
text.append(context.getString(R.string.gander_url)).append(": ").append(v(transactionUIHelper.getUrl())).append("\n");
text.append(context.getString(R.string.gander_method)).append(": ").append(v(transactionUIHelper.getMethod())).append("\n");
text.append(context.getString(R.string.gander_protocol)).append(": ").append(v(transactionUIHelper.getProtocol())).append("\n");
Expand All @@ -170,6 +184,12 @@ public static CharSequence getShareText(Context context, HttpTransactionUIHelper
text.append(context.getString(R.string.gander_response_size)).append(": ").append(v(transactionUIHelper.getResponseSizeString())).append("\n");
text.append(context.getString(R.string.gander_total_size)).append(": ").append(v(transactionUIHelper.getTotalSizeString())).append("\n");
text.append("\n");
return text;
}


private static CharSequence getRequestText(Context context, HttpTransactionUIHelper transactionUIHelper) {
StringBuilder text = new StringBuilder();
text.append("---------- ").append(context.getString(R.string.gander_request)).append(" ----------\n\n");
CharSequence headers = formatHeaders(transactionUIHelper.getRequestHeaders(), false);
if (!TextUtil.isNullOrWhiteSpace(headers)) {
Expand All @@ -178,8 +198,14 @@ public static CharSequence getShareText(Context context, HttpTransactionUIHelper
text.append((transactionUIHelper.requestBodyIsPlainText()) ? v(transactionUIHelper.getFormattedRequestBody()) :
context.getString(R.string.gander_body_omitted));
text.append("\n\n");
return text;
}

private static CharSequence getResponseText(Context context, HttpTransactionUIHelper
transactionUIHelper) {
StringBuilder text = new StringBuilder();
text.append("---------- ").append(context.getString(R.string.gander_response)).append(" ----------\n\n");
headers = formatHeaders(transactionUIHelper.getResponseHeaders(), false);
CharSequence headers = formatHeaders(transactionUIHelper.getResponseHeaders(), false);
if (!TextUtil.isNullOrWhiteSpace(headers)) {
text.append(headers).append("\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public static void start(Context context, long transactionId, HttpTransactionUIH
context.startActivity(intent);
}

private static int SELECTED_TAB_POSITION = 0;
public static final int POSITION_OVERVIEW = 0;
public static final int POSITION_REQUEST = 1;
public static final int POSITION_RESPONSE = 2;
private static int SELECTED_TAB_POSITION = POSITION_OVERVIEW;

private TextView mTitleView;
private Adapter mAdapter;
Expand Down Expand Up @@ -122,7 +125,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.share_text) {
if (mTransaction != null)
share(FormatUtils.getShareText(this, mTransaction));
share(FormatUtils.getShareText(this, mTransaction, SELECTED_TAB_POSITION));
return true;
} else if (item.getItemId() == R.id.share_curl) {
if (mTransaction != null)
Expand Down

0 comments on commit 1ce2ef5

Please sign in to comment.