Skip to content

Commit

Permalink
style: Improved messages JSON appearance
Browse files Browse the repository at this point in the history
Co-authored-by: arsLan4k1390 <[email protected]>
  • Loading branch information
omg-xtao and arsLan4k1390 committed Mar 5, 2024
1 parent 635e705 commit b3a78c2
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Base64;
import android.view.Gravity;
Expand All @@ -17,6 +19,8 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
Expand All @@ -31,6 +35,7 @@

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.CodeHighlighting;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
Expand All @@ -50,12 +55,14 @@
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextDetailSettingsCell;
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Components.BulletinFactory;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.RecyclerListView;
import org.telegram.ui.Components.UndoView;
import org.telegram.ui.ProfileActivity;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -90,6 +97,7 @@ public class MessageDetailsActivity extends BaseFragment implements Notification
private int dcRow;
private int buttonsRow;
private int emptyRow;
private int jsonTextRow;
private int exportRow;
private int endRow;

Expand Down Expand Up @@ -207,15 +215,15 @@ public void onItemClick(int id) {
if (position == exportRow) {
try {
AndroidUtilities.addToClipboard(gson.toJson(messageObject.messageOwner));
copyTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null);
BulletinFactory.of(this).createCopyBulletin(LocaleController.formatString("TextCopied", R.string.TextCopied)).show();
} catch (Exception e) {
FileLog.e(e);
}
} else if (position != endRow && position != emptyRow) {
TextDetailSettingsCell textCell = (TextDetailSettingsCell) view;
try {
AndroidUtilities.addToClipboard(textCell.getValueTextView().getText());
copyTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null);
BulletinFactory.of(this).createCopyBulletin(LocaleController.formatString("TextCopied", R.string.TextCopied)).show();
} catch (Exception e) {
FileLog.e(e);
}
Expand Down Expand Up @@ -300,6 +308,7 @@ private void updateRows() {
}
buttonsRow = messageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup ? rowCount++ : -1;
emptyRow = rowCount++;
jsonTextRow = rowCount++;
exportRow = rowCount++;
endRow = rowCount++;
if (listAdapter != null) {
Expand Down Expand Up @@ -479,6 +488,27 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
textCell.setTextAndValue("Scheduled", "Yes", divider);
} else if (position == buttonsRow) {
textCell.setTextAndValue("Buttons", gson.toJson(messageObject.messageOwner.reply_markup), divider);
} else if (position == jsonTextRow) {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
String jsonString = mapper.writeValueAsString(messageObject.messageOwner);

final SpannableString[] sb = new SpannableString[1];
new CountDownTimer(300, 100) {
@Override
public void onTick(long millisUntilFinished) {
sb[0] = CodeHighlighting.getHighlighted(jsonString, "json");
}

@Override
public void onFinish() {
textCell.setTextAndValue("JSON", sb[0], divider);
}
}.start();
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
Expand Down

0 comments on commit b3a78c2

Please sign in to comment.