@Override public View getView(int i, View view, ViewGroup viewGroup) { int type = getItemViewType(i); if (type == 0) { if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.settings_wallpapers_my_row, viewGroup, false); } View parentView = view.findViewById(R.id.parent); ImageView imageView = (ImageView) view.findViewById(R.id.image); View selection = view.findViewById(R.id.selection); if (i == 0) { if (selectedBackground == -1 || selectedColor != 0 || selectedBackground == 1000001) { imageView.setBackgroundColor(0x5A475866); } else { imageView.setBackgroundColor(0x5A000000); } imageView.setImageResource(R.drawable.ic_gallery_background); if (selectedBackground == -1) { selection.setVisibility(View.VISIBLE); } else { selection.setVisibility(View.INVISIBLE); } } else { imageView.setImageBitmap(null); TLRPC.WallPaper wallPaper = wallPapers.get(i - 1); imageView.setBackgroundColor(0xff000000 | wallPaper.bg_color); if (wallPaper.id == selectedBackground) { selection.setVisibility(View.VISIBLE); } else { selection.setVisibility(View.INVISIBLE); } } } else if (type == 1) { if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.settings_wallpapers_other_row, viewGroup, false); } BackupImageView image = (BackupImageView) view.findViewById(R.id.image); View selection = view.findViewById(R.id.selection); TLRPC.WallPaper wallPaper = wallPapers.get(i - 1); TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100)); if (size != null && size.location != null) { image.setImage(size.location, "100_100", 0); } if (wallPaper.id == selectedBackground) { selection.setVisibility(View.VISIBLE); } else { selection.setVisibility(View.INVISIBLE); } } return view; }
@Override public View getView(int i, View view, ViewGroup viewGroup) { int type = getItemViewType(i); if (type == 0) { MessageObject message = messages.get(i); if (view == null) { LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.media_photo_layout, viewGroup, false); } ViewGroup.LayoutParams params = view.getLayoutParams(); params.width = itemWidth; params.height = itemWidth; view.setLayoutParams(params); BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image); if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) { ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes; boolean set = false; // for (TLRPC.PhotoSize size : sizes) { // if (size.type != null && size.type.equals("m")) { // set = true; // imageView.setImage(size.location, null, R.drawable.photo_placeholder); // break; // } // } if (!set) { if (message.imagePreview != null) { imageView.setImageBitmap(message.imagePreview); } else { imageView.setImage(message.messageOwner.media.photo.sizes.get(0).location, null, R.drawable.photo_placeholder_in); } } } else { imageView.setImageResource(R.drawable.photo_placeholder_in); } } else if (type == 1) { MessageObject message = messages.get(i); if (view == null) { LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.media_video_layout, viewGroup, false); } ViewGroup.LayoutParams params = view.getLayoutParams(); params.width = itemWidth; params.height = itemWidth; view.setLayoutParams(params); TextView textView = (TextView)view.findViewById(R.id.chat_video_time); BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image); if (message.messageOwner.media.video != null && message.messageOwner.media.video.thumb != null) { int duration = message.messageOwner.media.video.duration; int minutes = duration / 60; int seconds = duration - minutes * 60; textView.setText(String.format("%d:%02d", minutes, seconds)); if (message.imagePreview != null) { imageView.setImageBitmap(message.imagePreview); } else { imageView.setImage(message.messageOwner.media.video.thumb.location, null, R.drawable.photo_placeholder_in); } textView.setVisibility(View.VISIBLE); } else { textView.setVisibility(View.GONE); imageView.setImageResource(R.drawable.photo_placeholder_in); } } else if (type == 2) { if (view == null) { LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.media_loading_layout, viewGroup, false); } ViewGroup.LayoutParams params = view.getLayoutParams(); params.width = itemWidth; params.height = itemWidth; view.setLayoutParams(params); } return view; }
@Override public View getView(int i, View view, ViewGroup viewGroup) { int type = getItemViewType(i); if (type == 0) { BackupImageView avatarImage; TextView onlineText; TLRPC.User user = MessagesController.getInstance().users.get(user_id); if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.user_profile_avatar_layout, viewGroup, false); onlineText = (TextView) view.findViewById(R.id.settings_online); avatarImage = (BackupImageView) view.findViewById(R.id.settings_avatar_image); avatarImage.processDetach = false; avatarImage.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { TLRPC.User user = MessagesController.getInstance().users.get(user_id); if (user.photo != null && user.photo.photo_big != null) { PhotoViewer.getInstance() .openPhoto(user.photo.photo_big, UserProfileActivity.this); } } }); } else { avatarImage = (BackupImageView) view.findViewById(R.id.settings_avatar_image); onlineText = (TextView) view.findViewById(R.id.settings_online); } TextView textView = (TextView) view.findViewById(R.id.settings_name); Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf"); textView.setTypeface(typeface); textView.setText(Utilities.formatName(user.first_name, user.last_name)); onlineText.setText(LocaleController.formatUserStatus(user)); TLRPC.FileLocation photo = null; TLRPC.FileLocation photoBig = null; if (user.photo != null) { photo = user.photo.photo_small; photoBig = user.photo.photo_big; } avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id)); avatarImage.imageReceiver.setVisible( !PhotoViewer.getInstance().isShowingImage(photoBig), false); return view; } else if (type == 1) { if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.settings_section_layout, viewGroup, false); } TextView textView = (TextView) view.findViewById(R.id.settings_section_text); if (i == phoneSectionRow) { textView.setText(LocaleController.getString("PHONE", R.string.PHONE)); } else if (i == settingsSectionRow) { textView.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS)); } else if (i == sharedMediaSectionRow) { textView.setText(LocaleController.getString("SHAREDMEDIA", R.string.SHAREDMEDIA)); } } else if (type == 2) { final TLRPC.User user = MessagesController.getInstance().users.get(user_id); if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.user_profile_phone_layout, viewGroup, false); view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (user.phone == null || user.phone.length() == 0 || getParentActivity() == null) { return; } selectedPhone = user.phone; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setItems( new CharSequence[] { LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 1) { try { Intent intent = new Intent( Intent.ACTION_DIAL, Uri.parse("tel:+" + selectedPhone)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == 0) { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText(selectedPhone); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService( Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", selectedPhone); clipboard.setPrimaryClip(clip); } } } }); showAlertDialog(builder); } }); } ImageButton button = (ImageButton) view.findViewById(R.id.settings_edit_name); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { TLRPC.User user = MessagesController.getInstance().users.get(user_id); if (user == null || user instanceof TLRPC.TL_userEmpty) { return; } NotificationCenter.getInstance() .postNotificationName(MessagesController.closeChats); Bundle args = new Bundle(); args.putInt("user_id", user_id); presentFragment(new ChatActivity(args), true); } }); TextView textView = (TextView) view.findViewById(R.id.settings_row_text); TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail); View divider = view.findViewById(R.id.settings_row_divider); if (i == phoneRow) { if (user.phone != null && user.phone.length() != 0) { textView.setText(PhoneFormat.getInstance().format("+" + user.phone)); } else { textView.setText("Unknown"); } divider.setVisibility(View.INVISIBLE); detailTextView.setText(LocaleController.getString("PhoneMobile", R.string.PhoneMobile)); } } else if (type == 3) { if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.user_profile_leftright_row_layout, viewGroup, false); } TextView textView = (TextView) view.findViewById(R.id.settings_row_text); TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail); View divider = view.findViewById(R.id.settings_row_divider); if (i == sharedMediaRow) { textView.setText(LocaleController.getString("SharedMedia", R.string.SharedMedia)); if (totalMediaCount == -1) { detailTextView.setText(LocaleController.getString("Loading", R.string.Loading)); } else { detailTextView.setText(String.format("%d", totalMediaCount)); } divider.setVisibility(View.INVISIBLE); } else if (i == settingsTimerRow) { TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().encryptedChats.get((int) (dialog_id >> 32)); textView.setText(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); divider.setVisibility(View.VISIBLE); if (encryptedChat.ttl == 0) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever)); } else if (encryptedChat.ttl == 2) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetime2s", R.string.ShortMessageLifetime2s)); } else if (encryptedChat.ttl == 5) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetime5s", R.string.ShortMessageLifetime5s)); } else if (encryptedChat.ttl == 60) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetime1m", R.string.ShortMessageLifetime1m)); } else if (encryptedChat.ttl == 60 * 60) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetime1h", R.string.ShortMessageLifetime1h)); } else if (encryptedChat.ttl == 60 * 60 * 24) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetime1d", R.string.ShortMessageLifetime1d)); } else if (encryptedChat.ttl == 60 * 60 * 24 * 7) { detailTextView.setText( LocaleController.getString( "ShortMessageLifetime1w", R.string.ShortMessageLifetime1w)); } else { detailTextView.setText(String.format("%d", encryptedChat.ttl)); } } } else if (type == 4) { if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.user_profile_identicon_layout, viewGroup, false); } TextView textView = (TextView) view.findViewById(R.id.settings_row_text); View divider = view.findViewById(R.id.settings_row_divider); divider.setVisibility(View.VISIBLE); IdenticonView identiconView = (IdenticonView) view.findViewById(R.id.identicon_view); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().encryptedChats.get((int) (dialog_id >> 32)); identiconView.setBytes(encryptedChat.auth_key); textView.setText(LocaleController.getString("EncryptionKey", R.string.EncryptionKey)); } else if (type == 5) { if (view == null) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.settings_row_button_layout, viewGroup, false); } TextView textView = (TextView) view.findViewById(R.id.settings_row_text); View divider = view.findViewById(R.id.settings_row_divider); if (i == settingsNotificationsRow) { textView.setText( LocaleController.getString( "NotificationsAndSounds", R.string.NotificationsAndSounds)); divider.setVisibility(View.INVISIBLE); } } return view; }