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