| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.annotation.SuppressLint; |
| 4 | import android.content.Context; |
| 5 | import android.content.Intent; |
| 6 | import android.net.Uri; |
| 7 | import android.os.Build; |
| 8 | import android.os.Bundle; |
| 9 | import android.text.TextUtils; |
| 10 | import android.util.Base64; |
| 11 | import android.view.Gravity; |
| 12 | import android.view.View; |
| 13 | import android.view.ViewGroup; |
| 14 | import android.widget.FrameLayout; |
| 15 | |
| 16 | import androidx.core.content.FileProvider; |
| 17 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 18 | import androidx.recyclerview.widget.RecyclerView; |
| 19 | |
| 20 | import com.google.gson.ExclusionStrategy; |
| 21 | import com.google.gson.FieldAttributes; |
| 22 | import com.google.gson.Gson; |
| 23 | import com.google.gson.GsonBuilder; |
| 24 | import com.google.gson.JsonDeserializationContext; |
| 25 | import com.google.gson.JsonDeserializer; |
| 26 | import com.google.gson.JsonElement; |
| 27 | import com.google.gson.JsonParseException; |
| 28 | import com.google.gson.JsonPrimitive; |
| 29 | import com.google.gson.JsonSerializationContext; |
| 30 | import com.google.gson.JsonSerializer; |
| 31 | |
| 32 | import org.telegram.messenger.AndroidUtilities; |
| 33 | import org.telegram.messenger.BuildConfig; |
| 34 | import org.telegram.messenger.ContactsController; |
| 35 | import org.telegram.messenger.FileLoader; |
| 36 | import org.telegram.messenger.FileLog; |
| 37 | import org.telegram.messenger.LocaleController; |
| 38 | import org.telegram.messenger.MessageObject; |
| 39 | import org.telegram.messenger.NotificationCenter; |
| 40 | import org.telegram.messenger.R; |
| 41 | import org.telegram.tgnet.TLRPC; |
| 42 | import org.telegram.ui.ActionBar.ActionBar; |
| 43 | import org.telegram.ui.ActionBar.BaseFragment; |
| 44 | import org.telegram.ui.ActionBar.Theme; |
| 45 | import org.telegram.ui.ActionBar.ThemeDescription; |
| 46 | import org.telegram.ui.Cells.EmptyCell; |
| 47 | import org.telegram.ui.Cells.HeaderCell; |
| 48 | import org.telegram.ui.Cells.NotificationsCheckCell; |
| 49 | import org.telegram.ui.Cells.ShadowSectionCell; |
| 50 | import org.telegram.ui.Cells.TextCheckCell; |
| 51 | import org.telegram.ui.Cells.TextDetailSettingsCell; |
| 52 | import org.telegram.ui.Cells.TextSettingsCell; |
| 53 | import org.telegram.ui.Components.LayoutHelper; |
| 54 | import org.telegram.ui.Components.RecyclerListView; |
| 55 | import org.telegram.ui.Components.UndoView; |
| 56 | import org.telegram.ui.ProfileActivity; |
| 57 | |
| 58 | import java.io.File; |
| 59 | import java.lang.reflect.Type; |
| 60 | import java.util.ArrayList; |
| 61 | import java.util.Date; |
| 62 | |
| 63 | public class MessageDetailsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { |
| 64 | |
| 65 | private RecyclerListView listView; |
| 66 | private ListAdapter listAdapter; |
| 67 | |
| 68 | private MessageObject messageObject; |
| 69 | private TLRPC.Chat fromChat; |
| 70 | private TLRPC.User fromUser; |
| 71 | private String filePath; |
| 72 | private String fileName; |
| 73 | |
| 74 | private int rowCount; |
| 75 | |
| 76 | private int idRow; |
| 77 | private int scheduledRow; |
| 78 | private int messageRow; |
| 79 | private int captionRow; |
| 80 | private int groupRow; |
| 81 | private int channelRow; |
| 82 | private int fromRow; |
| 83 | private int botRow; |
| 84 | private int dateRow; |
| 85 | private int editedRow; |
| 86 | private int forwardRow; |
| 87 | private int fileNameRow; |
| 88 | private int filePathRow; |
| 89 | private int fileSizeRow; |
| 90 | private int dcRow; |
| 91 | private int buttonsRow; |
| 92 | private int emptyRow; |
| 93 | private int exportRow; |
| 94 | private int endRow; |
| 95 | |
| 96 | private UndoView copyTooltip; |
| 97 | |
| 98 | public static final Gson gson = new GsonBuilder() |
| 99 | .setExclusionStrategies(new Exclusion()) |
| 100 | .registerTypeHierarchyAdapter(byte[].class, new ByteArrayToBase64TypeAdapter()).create(); |
| 101 | |
| 102 | private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> { |
| 103 | public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { |
| 104 | return Base64.decode(json.getAsString(), Base64.NO_WRAP); |
| 105 | } |
| 106 | |
| 107 | public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) { |
| 108 | return new JsonPrimitive(Base64.encodeToString(src, Base64.NO_WRAP)); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | public static class Exclusion implements ExclusionStrategy { |
| 113 | public boolean shouldSkipClass(Class<?> arg0) { |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | public boolean shouldSkipField(FieldAttributes f) { |
| 118 | return f.getName().equals("disableFree") || f.getName().equals("networkType"); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | public MessageDetailsActivity(MessageObject messageObject) { |
| 123 | this.messageObject = messageObject; |
| 124 | if (messageObject.messageOwner.peer_id != null && messageObject.messageOwner.peer_id.channel_id != 0) { |
| 125 | fromChat = getMessagesController().getChat(messageObject.messageOwner.peer_id.channel_id); |
| 126 | } else if (messageObject.messageOwner.peer_id != null && messageObject.messageOwner.peer_id.chat_id != 0) { |
| 127 | fromChat = getMessagesController().getChat(messageObject.messageOwner.peer_id.chat_id); |
| 128 | } |
| 129 | if (messageObject.messageOwner.from_id.user_id != 0) { |
| 130 | fromUser = getMessagesController().getUser(messageObject.messageOwner.from_id.user_id); |
| 131 | } |
| 132 | filePath = messageObject.messageOwner.attachPath; |
| 133 | if (!TextUtils.isEmpty(filePath)) { |
| 134 | File temp = new File(filePath); |
| 135 | if (!temp.exists()) { |
| 136 | filePath = null; |
| 137 | } |
| 138 | } |
| 139 | if (TextUtils.isEmpty(filePath)) { |
| 140 | filePath = FileLoader.getPathToMessage(messageObject.messageOwner).toString(); |
| 141 | File temp = new File(filePath); |
| 142 | if (!temp.exists()) { |
| 143 | filePath = null; |
| 144 | } |
| 145 | } |
| 146 | if (TextUtils.isEmpty(filePath)) { |
| 147 | filePath = FileLoader.getPathToAttach(messageObject.getDocument(), true).toString(); |
| 148 | File temp = new File(filePath); |
| 149 | if (!temp.isFile()) { |
| 150 | filePath = null; |
| 151 | } |
| 152 | } |
| 153 | if (messageObject.messageOwner.media != null && messageObject.messageOwner.media.document != null) { |
| 154 | if (TextUtils.isEmpty(messageObject.messageOwner.media.document.file_name)) { |
| 155 | for (int a = 0; a < messageObject.messageOwner.media.document.attributes.size(); a++) { |
| 156 | if (messageObject.messageOwner.media.document.attributes.get(a) instanceof TLRPC.TL_documentAttributeFilename) { |
| 157 | fileName = messageObject.messageOwner.media.document.attributes.get(a).file_name; |
| 158 | } |
| 159 | } |
| 160 | } else { |
| 161 | fileName = messageObject.messageOwner.media.document.file_name; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public boolean onFragmentCreate() { |
| 169 | super.onFragmentCreate(); |
| 170 | |
| 171 | // NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoad); |
| 172 | updateRows(); |
| 173 | |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | @SuppressLint({"NewApi", "RtlHardcoded"}) |
| 178 | @Override |
| 179 | public View createView(Context context) { |
| 180 | actionBar.setBackButtonImage(R.drawable.ic_ab_back); |
| 181 | actionBar.setTitle(LocaleController.getString("MessageDetails", R.string.MessageDetails)); |
| 182 | |
| 183 | if (AndroidUtilities.isTablet()) { |
| 184 | actionBar.setOccupyStatusBar(false); |
| 185 | } |
| 186 | actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { |
| 187 | @Override |
| 188 | public void onItemClick(int id) { |
| 189 | if (id == -1) { |
| 190 | finishFragment(); |
| 191 | } |
| 192 | } |
| 193 | }); |
| 194 | |
| 195 | listAdapter = new ListAdapter(context); |
| 196 | |
| 197 | fragmentView = new FrameLayout(context); |
| 198 | fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); |
| 199 | FrameLayout frameLayout = (FrameLayout) fragmentView; |
| 200 | |
| 201 | listView = new RecyclerListView(context); |
| 202 | listView.setVerticalScrollBarEnabled(false); |
| 203 | listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); |
| 204 | frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); |
| 205 | listView.setAdapter(listAdapter); |
| 206 | listView.setOnItemClickListener((view, position, x, y) -> { |
| 207 | if (position == exportRow) { |
| 208 | try { |
| 209 | AndroidUtilities.addToClipboard(gson.toJson(messageObject.messageOwner)); |
| 210 | copyTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null); |
| 211 | } catch (Exception e) { |
| 212 | FileLog.e(e); |
| 213 | } |
| 214 | } else if (position != endRow && position != emptyRow) { |
| 215 | TextDetailSettingsCell textCell = (TextDetailSettingsCell) view; |
| 216 | try { |
| 217 | AndroidUtilities.addToClipboard(textCell.getValueTextView().getText()); |
| 218 | copyTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null); |
| 219 | } catch (Exception e) { |
| 220 | FileLog.e(e); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | }); |
| 225 | listView.setOnItemLongClickListener((view, position) -> { |
| 226 | if (position == filePathRow) { |
| 227 | AndroidUtilities.runOnUIThread(() -> { |
| 228 | Intent intent = new Intent(Intent.ACTION_SEND); |
| 229 | intent.setType("application/octet-stream"); |
| 230 | if (Build.VERSION.SDK_INT >= 24) { |
| 231 | try { |
| 232 | intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", new File(filePath))); |
| 233 | intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 234 | } catch (Exception ignore) { |
| 235 | intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath))); |
| 236 | } |
| 237 | } else { |
| 238 | intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath))); |
| 239 | } |
| 240 | startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500); |
| 241 | }); |
| 242 | } else if (position == channelRow || position == groupRow) { |
| 243 | if (fromChat != null) { |
| 244 | Bundle args = new Bundle(); |
| 245 | args.putInt("chat_id", fromChat.id); |
| 246 | ProfileActivity fragment = new ProfileActivity(args); |
| 247 | presentFragment(fragment); |
| 248 | } |
| 249 | } else if (position == fromRow) { |
| 250 | if (fromUser != null) { |
| 251 | Bundle args = new Bundle(); |
| 252 | args.putInt("user_id", fromUser.id); |
| 253 | ProfileActivity fragment = new ProfileActivity(args); |
| 254 | presentFragment(fragment); |
| 255 | } |
| 256 | } else { |
| 257 | return false; |
| 258 | } |
| 259 | return true; |
| 260 | }); |
| 261 | |
| 262 | copyTooltip = new UndoView(context); |
| 263 | copyTooltip.setInfoText(LocaleController.getString("TextCopied", R.string.TextCopied)); |
| 264 | frameLayout.addView(copyTooltip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8)); |
| 265 | |
| 266 | return fragmentView; |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void onResume() { |
| 271 | super.onResume(); |
| 272 | if (listAdapter != null) { |
| 273 | listAdapter.notifyDataSetChanged(); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | private void updateRows() { |
| 278 | rowCount = 0; |
| 279 | idRow = rowCount++; |
| 280 | scheduledRow = messageObject.scheduled ? rowCount++ : -1; |
| 281 | messageRow = TextUtils.isEmpty(messageObject.messageText) ? -1 : rowCount++; |
| 282 | captionRow = TextUtils.isEmpty(messageObject.caption) ? -1 : rowCount++; |
| 283 | groupRow = fromChat != null && !fromChat.broadcast ? rowCount++ : -1; |
| 284 | channelRow = fromChat != null && fromChat.broadcast ? rowCount++ : -1; |
| 285 | fromRow = fromUser != null || messageObject.messageOwner.post_author != null ? rowCount++ : -1; |
| 286 | botRow = fromUser != null && fromUser.bot ? rowCount++ : -1; |
| 287 | dateRow = messageObject.messageOwner.date != 0 ? rowCount++ : -1; |
| 288 | editedRow = messageObject.messageOwner.edit_date != 0 ? rowCount++ : -1; |
| 289 | forwardRow = messageObject.isForwarded() ? rowCount++ : -1; |
| 290 | fileNameRow = TextUtils.isEmpty(fileName) ? -1 : rowCount++; |
| 291 | filePathRow = TextUtils.isEmpty(filePath) ? -1 : rowCount++; |
| 292 | fileSizeRow = messageObject.getSize() != 0 ? rowCount++ : -1; |
| 293 | if (messageObject.messageOwner.media != null && ( |
| 294 | (messageObject.messageOwner.media.photo != null && messageObject.messageOwner.media.photo.dc_id > 0) || |
| 295 | (messageObject.messageOwner.media.document != null && messageObject.messageOwner.media.document.dc_id > 0) |
| 296 | )) { |
| 297 | dcRow = rowCount++; |
| 298 | } else { |
| 299 | dcRow = -1; |
| 300 | } |
| 301 | buttonsRow = messageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup ? rowCount++ : -1; |
| 302 | emptyRow = rowCount++; |
| 303 | exportRow = rowCount++; |
| 304 | endRow = rowCount++; |
| 305 | if (listAdapter != null) { |
| 306 | listAdapter.notifyDataSetChanged(); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public ArrayList<ThemeDescription> getThemeDescriptions() { |
| 312 | ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>(); |
| 313 | themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{EmptyCell.class, TextSettingsCell.class, TextCheckCell.class, HeaderCell.class, TextDetailSettingsCell.class, NotificationsCheckCell.class}, null, null, null, Theme.key_windowBackgroundWhite)); |
| 314 | themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray)); |
| 315 | |
| 316 | themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue)); |
| 317 | themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue)); |
| 318 | themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue)); |
| 319 | themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle)); |
| 320 | themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue)); |
| 321 | themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground)); |
| 322 | themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem)); |
| 323 | |
| 324 | themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector)); |
| 325 | |
| 326 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider)); |
| 327 | |
| 328 | themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow)); |
| 329 | |
| 330 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText)); |
| 331 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText)); |
| 332 | |
| 333 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText)); |
| 334 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2)); |
| 335 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack)); |
| 336 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked)); |
| 337 | |
| 338 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText)); |
| 339 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2)); |
| 340 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack)); |
| 341 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked)); |
| 342 | |
| 343 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader)); |
| 344 | |
| 345 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText)); |
| 346 | themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2)); |
| 347 | |
| 348 | return themeDescriptions; |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public void didReceivedNotification(int id, int account, Object... args) { |
| 353 | /* if (id == NotificationCenter.emojiDidLoad) { |
| 354 | if (listView != null) { |
| 355 | listView.invalidateViews(); |
| 356 | } |
| 357 | }*/ |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void onFragmentDestroy() { |
| 362 | super.onFragmentDestroy(); |
| 363 | // NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiDidLoad); |
| 364 | } |
| 365 | |
| 366 | private class ListAdapter extends RecyclerListView.SelectionAdapter { |
| 367 | |
| 368 | private Context mContext; |
| 369 | |
| 370 | public ListAdapter(Context context) { |
| 371 | mContext = context; |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public int getItemCount() { |
| 376 | return rowCount; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
| 381 | switch (holder.getItemViewType()) { |
| 382 | case 1: { |
| 383 | if (position == endRow) { |
| 384 | holder.itemView.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); |
| 385 | } else { |
| 386 | holder.itemView.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); |
| 387 | } |
| 388 | break; |
| 389 | } |
| 390 | case 2: { |
| 391 | TextDetailSettingsCell textCell = (TextDetailSettingsCell) holder.itemView; |
| 392 | textCell.setMultilineDetail(true); |
| 393 | boolean divider = position + 1 != emptyRow; |
| 394 | if (position == idRow) { |
| 395 | textCell.setTextAndValue("ID", String.valueOf(messageObject.messageOwner.id), divider); |
| 396 | } else if (position == messageRow) { |
| 397 | textCell.setTextAndValue("Message", messageObject.messageText, divider); |
| 398 | } else if (position == captionRow) { |
| 399 | textCell.setTextAndValue("Caption", messageObject.caption, divider); |
| 400 | } else if (position == channelRow || position == groupRow) { |
| 401 | StringBuilder builder = new StringBuilder(); |
| 402 | builder.append(fromChat.title); |
| 403 | builder.append("\n"); |
| 404 | if (!TextUtils.isEmpty(fromChat.username)) { |
| 405 | builder.append("@"); |
| 406 | builder.append(fromChat.username); |
| 407 | builder.append("\n"); |
| 408 | } |
| 409 | builder.append(fromChat.id); |
| 410 | textCell.setTextAndValue(position == channelRow ? "Channel" : "Group", builder.toString(), divider); |
| 411 | } else if (position == fromRow) { |
| 412 | StringBuilder builder = new StringBuilder(); |
| 413 | if (fromUser != null) { |
| 414 | builder.append(ContactsController.formatName(fromUser.first_name, fromUser.last_name)); |
| 415 | builder.append("\n"); |
| 416 | if (!TextUtils.isEmpty(fromUser.username)) { |
| 417 | builder.append("@"); |
| 418 | builder.append(fromUser.username); |
| 419 | builder.append("\n"); |
| 420 | } |
| 421 | builder.append(fromUser.id); |
| 422 | } else { |
| 423 | builder.append(messageObject.messageOwner.post_author); |
| 424 | } |
| 425 | textCell.setTextAndValue("From", builder.toString(), divider); |
| 426 | } else if (position == botRow) { |
| 427 | textCell.setTextAndValue("Bot", "Yes", divider); |
| 428 | } else if (position == dateRow) { |
| 429 | long date = (long) messageObject.messageOwner.date * 1000; |
| 430 | textCell.setTextAndValue(messageObject.scheduled ? "Scheduled date" : "Date", messageObject.messageOwner.date == 0x7ffffffe ? "When online" : LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format( |
| 431 | } else if (position == editedRow) { |
| 432 | long date = (long) messageObject.messageOwner.edit_date * 1000; |
| 433 | textCell.setTextAndValue("Edited", LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date))), divider); |
| 434 | } else if (position == forwardRow) { |
| 435 | StringBuilder builder = new StringBuilder(); |
| 436 | if (messageObject.messageOwner.fwd_from.from_id.channel_id != 0) { |
| 437 | TLRPC.Chat chat = getMessagesController().getChat(messageObject.messageOwner.fwd_from.from_id.channel_id); |
| 438 | builder.append(chat.title); |
| 439 | builder.append("\n"); |
| 440 | if (!TextUtils.isEmpty(chat.username)) { |
| 441 | builder.append("@"); |
| 442 | builder.append(chat.username); |
| 443 | builder.append("\n"); |
| 444 | } |
| 445 | builder.append(chat.id); |
| 446 | } else if (messageObject.messageOwner.fwd_from.from_id.user_id != 0) { |
| 447 | TLRPC.User user = getMessagesController().getUser(messageObject.messageOwner.fwd_from.from_id.channel_id); |
| 448 | builder.append(ContactsController.formatName(user.first_name, user.last_name)); |
| 449 | builder.append("\n"); |
| 450 | if (!TextUtils.isEmpty(user.username)) { |
| 451 | builder.append("@"); |
| 452 | builder.append(user.username); |
| 453 | builder.append("\n"); |
| 454 | } |
| 455 | builder.append(user.id); |
| 456 | } else if (!TextUtils.isEmpty(messageObject.messageOwner.fwd_from.from_name)) { |
| 457 | builder.append(messageObject.messageOwner.fwd_from.from_name); |
| 458 | } |
| 459 | textCell.setTextAndValue("Forward from", builder.toString(), divider); |
| 460 | } else if (position == fileNameRow) { |
| 461 | textCell.setTextAndValue("File name", fileName, divider); |
| 462 | } else if (position == filePathRow) { |
| 463 | textCell.setTextAndValue("File path", filePath, divider); |
| 464 | } else if (position == fileSizeRow) { |
| 465 | textCell.setTextAndValue("File size", AndroidUtilities.formatFileSize(messageObject.getSize()), divider); |
| 466 | } else if (position == dcRow) { |
| 467 | if (messageObject.messageOwner.media.photo != null && messageObject.messageOwner.media.photo.dc_id > 0) { |
| 468 | textCell.setTextAndValue("DC", String.valueOf(messageObject.messageOwner.media.photo.dc_id), divider); |
| 469 | } else if (messageObject.messageOwner.media.document != null && messageObject.messageOwner.media.document.dc_id > 0) { |
| 470 | textCell.setTextAndValue("DC", String.valueOf(messageObject.messageOwner.media.document.dc_id), divider); |
| 471 | } |
| 472 | } else if (position == scheduledRow) { |
| 473 | textCell.setTextAndValue("Scheduled", "Yes", divider); |
| 474 | } else if (position == buttonsRow) { |
| 475 | textCell.setTextAndValue("Buttons", gson.toJson(messageObject.messageOwner.reply_markup), divider); |
| 476 | } |
| 477 | break; |
| 478 | } |
| 479 | case 3: { |
| 480 | TextSettingsCell textCell = (TextSettingsCell) holder.itemView; |
| 481 | if (position == exportRow) { |
| 482 | textCell.setText(LocaleController.getString("ExportAsJson", R.string.ExportAsJson), false); |
| 483 | textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText)); |
| 484 | } |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public boolean isEnabled(RecyclerView.ViewHolder holder) { |
| 492 | int position = holder.getAdapterPosition(); |
| 493 | return position != endRow && position != emptyRow; |
| 494 | } |
| 495 | |
| 496 | @Override |
| 497 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 498 | View view = null; |
| 499 | switch (viewType) { |
| 500 | case 1: |
| 501 | view = new ShadowSectionCell(mContext); |
| 502 | break; |
| 503 | case 2: |
| 504 | view = new TextDetailSettingsCell(mContext); |
| 505 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 506 | break; |
| 507 | case 3: |
| 508 | view = new TextSettingsCell(mContext); |
| 509 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 510 | break; |
| 511 | } |
| 512 | //noinspection ConstantConditions |
| 513 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); |
| 514 | return new RecyclerListView.Holder(view); |
| 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public int getItemViewType(int position) { |
| 519 | if (position == endRow || position == emptyRow) { |
| 520 | return 1; |
| 521 | } else if (position == exportRow) { |
| 522 | return 3; |
| 523 | } else { |
| 524 | return 2; |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |