use of net.iGap.helper.avatar.ParamWithAvatarType in project iGap-Android by KianIranian-STDG.
the class FragmentContactsProfile method onViewCreated.
@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initialToolbar();
DbManager.getInstance().doRealmTask(realm -> {
realmRoom = realm.where(RealmRoom.class).equalTo("id", viewModel.roomId).findFirst();
if (realmRoom != null) {
roomType = realmRoom.getType();
action = realmRoom.getActionState();
}
});
G.onSetAction = this;
if (peerId == AccountManager.getInstance().getCurrentUser().getId()) {
binding.toolbarTxtStatusExpanded.setText(requireContext().getResources().getString(R.string.chat_with_yourself));
} else {
viewModel.lastSeen.observe(getViewLifecycleOwner(), lastSeen -> {
if (action != null && realmRoom != null)
binding.toolbarTxtStatusExpanded.setText(action);
else
binding.toolbarTxtStatusExpanded.setText(HelperCalander.unicodeManage(lastSeen));
});
}
userAvatarImageView = binding.toolbarAvatar;
userAvatarImageView.setOnClickListener(v -> viewModel.onImageClick());
binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
binding.toolbarMore.setOnClickListener(v -> viewModel.onMoreButtonClick());
binding.toolbarCall.setOnClickListener(v -> onCallButtonClick());
viewModel.copyUserNameToClipBoard.observe(getViewLifecycleOwner(), userName -> {
if (userName == null)
return;
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("LINK_USER", Config.IGAP_LINK_PREFIX + userName);
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), getString(R.string.username_copied), Toast.LENGTH_SHORT).show();
});
viewModel.getCloudVisibility().observe(getViewLifecycleOwner(), thisMyCloud -> {
if (thisMyCloud != null) {
if (thisMyCloud) {
binding.report.setVisibility(View.GONE);
binding.block.setVisibility(View.GONE);
binding.enableNotificationLyt.setVisibility(View.GONE);
binding.line1.setVisibility(View.GONE);
binding.customNotification.setVisibility(View.GONE);
} else {
binding.report.setVisibility(View.VISIBLE);
binding.block.setVisibility(View.VISIBLE);
binding.line1.setVisibility(View.VISIBLE);
binding.enableNotificationLyt.setVisibility(View.VISIBLE);
binding.customNotification.setVisibility(View.VISIBLE);
}
}
});
viewModel.menuVisibility.observe(getViewLifecycleOwner(), visible -> {
if (visible != null)
binding.toolbarMore.setVisibility(visible);
});
viewModel.videoCallVisibility.observe(getViewLifecycleOwner(), visible -> {
if (visible != null)
binding.toolbarCall.setVisibility(visible);
});
viewModel.isMuteNotificationChangeListener.observe(getViewLifecycleOwner(), isChecked -> {
binding.enableNotification.setChecked(isChecked);
getRoomController().clientMuteRoom(viewModel.roomId, isChecked);
});
viewModel.contactName.observe(getViewLifecycleOwner(), name -> {
if (name != null) {
binding.toolbarTxtNameCollapsed.setText(EmojiManager.getInstance().replaceEmoji(name, binding.toolbarTxtNameCollapsed.getPaint().getFontMetricsInt()));
binding.toolbarTxtNameExpanded.setText(EmojiManager.getInstance().replaceEmoji(name, binding.toolbarTxtNameExpanded.getPaint().getFontMetricsInt()));
binding.toolbarTxtNameExpanded.setSelected(true);
}
});
viewModel.goToChatPage.observe(getViewLifecycleOwner(), userRoomId -> {
if (getActivity() != null && userRoomId != null) {
if (G.twoPaneMode) {
((ActivityMain) getActivity()).removeAllFragment();
} else {
((ActivityMain) getActivity()).removeAllFragmentFromMain();
}
new GoToChatActivity(userRoomId).startActivity(getActivity());
}
});
viewModel.goBack.observe(getViewLifecycleOwner(), isBack -> {
if (isBack != null && isBack) {
popBackStackFragment();
}
});
viewModel.goToShearedMediaPage.observe(getViewLifecycleOwner(), data -> {
if (getActivity() != null && data != null) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(data)).setReplace(false).load();
}
});
if (viewModel.phone != null && (!viewModel.phone.get().equals("0") || viewModel.showNumber.get())) {
if (viewModel.phone.get().equals("0")) {
binding.toolbarTxtTelExpanded.setVisibility(View.GONE);
viewModel.menuVisibility.setValue(View.GONE);
} else {
binding.toolbarTxtTelExpanded.setText(viewModel.phone.get());
binding.toolbarTxtTelExpanded.setOnClickListener(v -> viewModel.onPhoneNumberClick());
}
} else {
binding.toolbarTxtTelExpanded.setVisibility(View.GONE);
}
/*binding.toolbarTxtUsernameExpanded.setText(viewModel.username.get());*/
binding.toolbarFabChat.setOnClickListener(v -> {
viewModel.onClickGoToChat();
});
/*binding.chiFabSetPic.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom)));
binding.chiFabSetPic.setColorFilter(Color.WHITE);
binding.chiFabSetPic.setOnClickListener(new View.OnClickListener() { //fab button
@Override
public void onClick(View view) {
if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || enterFrom.equals("Others")) { // Others is from FragmentMapUsers adapter
final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
if (realmRoom != null) {
new HelperFragment().removeAll(true);
new GoToChatActivity(realmRoom.getId()).startActivity();
} else {
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
G.handler.post(new Runnable() {
@Override
public void run() {
new HelperFragment().removeAll(true);
new GoToChatActivity(room.getId()).setPeerID(userId).startActivity();
G.onChatGetRoom = null;
}
});
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(userId);
}
} else {
popBackStackFragment();
}
}
});*/
/*if (viewModel.showNumber.get()) {
binding.chiLayoutNickname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (viewModel.contactName.get() == null) {
return;
}
final LinearLayout layoutNickname = new LinearLayout(G.fragmentActivity);
layoutNickname.setOrientation(LinearLayout.VERTICAL);
String splitNickname[] = viewModel.contactName.get().split(" ");
String firsName = "";
String lastName = "";
StringBuilder stringBuilder = null;
if (splitNickname.length > 1) {
lastName = splitNickname[splitNickname.length - 1];
stringBuilder = new StringBuilder();
for (int i = 0; i < splitNickname.length - 1; i++) {
stringBuilder.append(splitNickname[i]).append(" ");
}
firsName = stringBuilder.toString();
} else {
firsName = splitNickname[0];
}
final View viewFirstName = new View(G.fragmentActivity);
viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
LinearLayout.LayoutParams viewParams = new AppBarLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2);
TextInputLayout inputFirstName = new TextInputLayout(G.fragmentActivity);
final EmojiEditTextE edtFirstName = new EmojiEditTextE(G.fragmentActivity);
edtFirstName.setHint(R.string.first_name);
edtFirstName.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
edtFirstName.setTypeface(G.typeface_IRANSansMobile);
edtFirstName.setText(firsName);
edtFirstName.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14));
edtFirstName.setTextColor(G.context.getResources().getColor(R.color.text_edit_text));
edtFirstName.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text));
edtFirstName.setPadding(0, 8, 0, 8);
edtFirstName.setSingleLine(true);
inputFirstName.addView(edtFirstName);
inputFirstName.addView(viewFirstName, viewParams);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
edtFirstName.setBackground(G.context.getResources().getDrawable(android.R.color.transparent));
}
final View viewLastName = new View(G.fragmentActivity);
viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
TextInputLayout inputLastName = new TextInputLayout(G.fragmentActivity);
final MEditText edtLastName = new MEditText(G.fragmentActivity);
edtLastName.setHint(R.string.last_name);
edtLastName.setTypeface(G.typeface_IRANSansMobile);
edtLastName.setText(lastName);
edtLastName.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14));
edtLastName.setTextColor(G.context.getResources().getColor(R.color.text_edit_text));
edtLastName.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text));
edtLastName.setPadding(0, 8, 0, 8);
edtLastName.setSingleLine(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
edtLastName.setBackground(G.context.getResources().getDrawable(android.R.color.transparent));
}
inputLastName.addView(edtLastName);
inputLastName.addView(viewLastName, viewParams);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 0, 0, 15);
LinearLayout.LayoutParams lastNameLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lastNameLayoutParams.setMargins(0, 15, 0, 10);
layoutNickname.addView(inputFirstName, layoutParams);
layoutNickname.addView(inputLastName, lastNameLayoutParams);
final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.pu_nikname_profileUser))
.positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok))
.customView(layoutNickname, true)
.widgetColor(Color.parseColor(G.appBarColor))
.negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel))
.build();
final View positive = dialog.getActionButton(DialogAction.POSITIVE);
positive.setEnabled(false);
edtFirstName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b) {
viewFirstName.setBackgroundColor(Color.parseColor(G.appBarColor));
} else {
viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
}
}
});
edtLastName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b) {
viewLastName.setBackgroundColor(Color.parseColor(G.appBarColor));
} else {
viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
}
}
});
final String finalFirsName = firsName;
edtFirstName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (!edtFirstName.getText().toString().equals(finalFirsName)) {
positive.setEnabled(true);
} else {
positive.setEnabled(false);
}
}
});
final String finalLastName = lastName;
edtLastName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (!edtLastName.getText().toString().equals(finalLastName)) {
positive.setEnabled(true);
} else {
positive.setEnabled(false);
}
}
});
positive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
long po = Long.parseLong(viewModel.phone.get());
String firstName = edtFirstName.getText().toString().trim();
String lastName = edtLastName.getText().toString().trim();
new RequestUserContactsEdit().contactsEdit(userId, po, firstName, lastName);
dialog.dismiss();
}
});
dialog.show();
}
});
}*/
/*binding.chiAppbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
ViewGroup viewGroup = binding.chiRootCircleImage;
if (verticalOffset < -5) {
viewGroup.animate().alpha(0).setDuration(700);
viewGroup.setVisibility(View.GONE);
binding.chiTxtTitleToolbarDisplayName.setVisibility(View.VISIBLE);
binding.chiTxtTitleToolbarDisplayName.animate().alpha(1).setDuration(300);
binding.chiTxtTitleToolbarLastSeen.setVisibility(View.VISIBLE);
binding.chiTxtTitleToolbarLastSeen.animate().alpha(1).setDuration(300);
} else {
viewGroup.setVisibility(View.VISIBLE);
viewGroup.animate().alpha(1).setDuration(700);
binding.chiTxtTitleToolbarDisplayName.setVisibility(View.GONE);
binding.chiTxtTitleToolbarDisplayName.animate().alpha(0).setDuration(500);
binding.chiTxtTitleToolbarLastSeen.setVisibility(View.GONE);
binding.chiTxtTitleToolbarLastSeen.animate().alpha(0).setDuration(500);
}
}
});*/
viewModel.showMenu.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && aBoolean) {
showPopUp();
}
});
viewModel.showPhoneNumberDialog.observe(getViewLifecycleOwner(), new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean aBoolean) {
if (aBoolean != null && aBoolean) {
try {
HelperPermission.getContactPermision(G.fragmentActivity, new OnGetPermission() {
@Override
public void Allow() {
showPopupPhoneNumber(/*t.getProfileTell()*/
null, viewModel.phone.get());
}
@Override
public void deny() {
showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
/*binding.chiLayoutSharedMedia.setOnClickListener(new View.OnClickListener() {// go to the ActivityMediaChanel
@Override
public void onClick(View view) {
new HelperFragment(FragmentShearedMedia.newInstance(viewModel.shearedId)).setReplace(false).load();
}
});*/
viewModel.showClearChatDialog.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && aBoolean) {
showAlertDialog(getString(R.string.clear_this_chat), getString(R.string.clear), getString(R.string.cancel));
}
});
viewModel.goToCustomNotificationPage.observe(getViewLifecycleOwner(), aBoolean -> {
if (getActivity() != null && aBoolean != null && aBoolean) {
FragmentNotification fragmentNotification = new FragmentNotification();
Bundle bundle = new Bundle();
bundle.putString("PAGE", "CONTACT");
bundle.putLong("ID", viewModel.roomId);
fragmentNotification.setArguments(bundle);
new HelperFragment(getActivity().getSupportFragmentManager(), fragmentNotification).setReplace(false).load();
}
});
viewModel.setAvatar.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null) {
if (aBoolean) {
avatarHandler.getAvatar(new ParamWithAvatarType(userAvatarImageView, viewModel.userId).avatarSize(R.dimen.dp100).avatarType(AvatarHandler.AvatarType.USER).showMain());
} else {
userAvatarImageView.setImageResource(R.drawable.ic_cloud_space_blue);
}
}
});
viewModel.showDeleteContactDialog.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && aBoolean) {
new MaterialDialog.Builder(G.fragmentActivity).title(R.string.to_delete_contact).content(R.string.delete_text).positiveText(R.string.B_ok).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
viewModel.deleteContact();
}
}).negativeText(R.string.B_cancel).show();
}
});
viewModel.showDialogReportContact.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && aBoolean) {
openDialogReport();
}
});
viewModel.showDialogStartSecretChat.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && aBoolean) {
Toast.makeText(getContext(), "secret chat", Toast.LENGTH_LONG).show();
}
});
viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), isCurrentUser -> {
if (getActivity() != null && isCurrentUser != null) {
Log.wtf(this.getClass().getName(), "goToShowAvatarPage observe");
FragmentShowAvatars fragment;
if (isCurrentUser) {
fragment = FragmentShowAvatars.newInstance(viewModel.userId, FragmentShowAvatars.From.setting);
} else {
fragment = FragmentShowAvatars.newInstance(viewModel.userId, FragmentShowAvatars.From.chat);
}
new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
}
});
viewModel.blockDialogListener.observe(getViewLifecycleOwner(), isBlockUser -> {
if (isBlockUser == null)
return;
if (isBlockUser) {
new MaterialDialog.Builder(getContext()).title(R.string.unblock_the_user).content(R.string.unblock_the_user_text).positiveText(R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
new RequestUserContactsUnblock().userContactsUnblock(viewModel.userId);
}
}).negativeText(R.string.cancel).dismissListener(dialog -> checkViewsState()).showListener(dialog -> checkViewsState()).show();
} else {
new MaterialDialog.Builder(getContext()).title(R.string.block_the_user).content(R.string.block_the_user_text).positiveText(R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
new RequestUserContactsBlock().userContactsBlock(viewModel.userId);
}
}).negativeText(R.string.cancel).dismissListener(dialog -> checkViewsState()).showListener(dialog -> checkViewsState()).show();
}
});
viewModel.editContactListener.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean == null)
return;
FragmentAddContact fragment = FragmentAddContact.newInstance(viewModel.userId, viewModel.phoneNumber, viewModel.firstName, viewModel.lastName, FragmentAddContact.ContactMode.EDIT, (name, family) -> {
viewModel.contactName.setValue(name + " " + family);
viewModel.firstName = name;
viewModel.lastName = family;
if (getActivity() != null) {
((ActivityMain) getActivity()).onUpdateContacts();
}
});
if (getActivity() != null)
new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
});
}
use of net.iGap.helper.avatar.ParamWithAvatarType in project iGap-Android by KianIranian-STDG.
the class EditChannelFragment method receivedEvent.
@Override
public void receivedEvent(int id, int account, Object... args) {
if (id == EventManager.AVATAR_UPDATE) {
G.runOnUiThread(() -> {
viewModel.getShowUploadProgressLiveData().postValue(View.GONE);
long roomId = (long) args[0];
if (roomId == this.roomId) {
avatarHandler.getAvatar(new ParamWithAvatarType(binding.channelAvatar, viewModel.roomId).avatarType(AvatarHandler.AvatarType.ROOM).showMain());
}
}, 500);
} else if (id == EventManager.FILE_UPLOAD_FAILED) {
String fileId = (String) args[0];
if (uploadAvatarId != null && uploadAvatarId.equals(fileId)) {
G.runOnUiThread(() -> viewModel.getShowUploadProgressLiveData().postValue(View.GONE));
}
}
}
use of net.iGap.helper.avatar.ParamWithAvatarType in project iGap-Android by KianIranian-STDG.
the class FragmentGroupProfile method initComponent.
/**
* ************************************** methods **************************************
*/
private void initComponent() {
AppUtils.setProgresColler(binding.loading);
FragmentShowAvatars.onComplete = new OnComplete() {
@Override
public void complete(boolean result, String messageOne, String MessageTwo) {
long mAvatarId = 0;
if (messageOne != null && !messageOne.equals("")) {
mAvatarId = Long.parseLong(messageOne);
}
avatarHandler.avatarDelete(new ParamWithAvatarType(imvGroupAvatar, viewModel.roomId).avatarType(AvatarHandler.AvatarType.ROOM), mAvatarId);
}
};
showAvatar();
}
use of net.iGap.helper.avatar.ParamWithAvatarType in project iGap-Android by KianIranian-STDG.
the class FragmentUserProfile method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getContext() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StatusBarUtil.setColor(getActivity(), new Theme().getPrimaryDarkColor(getContext()), 50);
}
viewModel.getCloseKeyboard().observe(getViewLifecycleOwner(), aBoolean -> {
closeKeyboard((binding.getRoot()));
});
viewModel.openAccountsDialog.observe(getViewLifecycleOwner(), show -> {
if (show == null)
return;
if (show) {
openAccountsDialog();
}
});
viewModel.setCurrentFragment.observe(getViewLifecycleOwner(), isEdit -> {
if (isEdit != null) {
if (isEdit) {
getChildFragmentManager().beginTransaction().setReorderingAllowed(true).add(R.id.frame_edit, FragmentEditProfile.class, null).addToBackStack(FragmentEditProfile.class.getName()).commit();
} else {
getChildFragmentManager().beginTransaction().setReorderingAllowed(true).replace(R.id.frame_edit, FragmentProfile.class, null).addToBackStack(FragmentProfile.class.getName()).commit();
}
}
});
viewModel.changeUserProfileWallpaperPath.observe(getViewLifecycleOwner(), path -> {
if (path != null && new File(path).exists()) {
ImageLoadingServiceInjector.inject().loadImage(binding.fupBgAvatar, path);
} else {
binding.fupBgAvatar.setImageResource(R.drawable.test_bg);
}
});
viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), userId -> {
if (getActivity() != null && userId != null) {
FragmentShowAvatars fragment = FragmentShowAvatars.newInstance(userId, FragmentShowAvatars.From.setting);
new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
}
});
viewModel.setUserAvatar.observe(getViewLifecycleOwner(), userId -> {
if (userId != null) {
avatarHandler.getAvatar(new ParamWithAvatarType(binding.fupUserImage, userId).avatarType(AvatarHandler.AvatarType.USER).showMain());
}
});
viewModel.deleteAvatar.observe(getViewLifecycleOwner(), deleteAvatarModel -> {
if (deleteAvatarModel != null) {
avatarHandler.avatarDelete(new ParamWithAvatarType(binding.fupUserImage, deleteAvatarModel.getUserId()).avatarType(AvatarHandler.AvatarType.USER), deleteAvatarModel.getAvatarId());
}
});
viewModel.setUserAvatarPath.observe(getViewLifecycleOwner(), changeImageModel -> {
if (changeImageModel != null) {
if (changeImageModel.getImagePath() == null || !new File(changeImageModel.getImagePath()).exists()) {
binding.fupUserImage.setImageBitmap(HelperImageBackColor.drawAlphabetOnPicture((int) binding.fupUserImage.getContext().getResources().getDimension(R.dimen.dp100), changeImageModel.getInitials(), changeImageModel.getColor()));
} else {
G.imageLoader.displayImage(AndroidUtils.suitablePath(changeImageModel.getImagePath()), binding.fupUserImage);
}
}
});
viewModel.showDialogChooseImage.observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean != null && aBoolean) {
startDialog();
}
});
viewModel.showError.observe(getViewLifecycleOwner(), message -> {
if (message != null) {
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
}
});
viewModel.getUpdateTwoPaneView().observe(getViewLifecycleOwner(), isUpdate -> {
if (getActivity() != null && isUpdate != null && isUpdate) {
Fragment frg;
frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.mainFrame);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
}
});
viewModel.getPopBackStack().observe(getViewLifecycleOwner(), isPopBackStack -> {
if (isPopBackStack != null && isPopBackStack) {
getChildFragmentManager().popBackStack();
}
});
viewModel.getCheckClick().observe(getViewLifecycleOwner(), isClick -> {
if (isClick) {
viewModel.getToastId().observe(getViewLifecycleOwner(), toastId -> {
if (toastId != R.string.empty_error_message) {
Toast.makeText(getContext(), getResources().getString(toastId), Toast.LENGTH_SHORT).show();
viewModel.getToastId().setValue(R.string.empty_error_message);
}
});
}
});
}
use of net.iGap.helper.avatar.ParamWithAvatarType in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method bindView.
@Override
@CallSuper
public void bindView(final VH holder, List<Object> payloads) {
super.bindView(holder, payloads);
if (messageObject == null) {
return;
}
NewChatItemHolder mHolder;
if (holder instanceof NewChatItemHolder) {
mHolder = (NewChatItemHolder) holder;
} else if (holder instanceof LogItem.ViewHolder || holder instanceof LogWalletCardToCard.ViewHolder || holder instanceof LogWalletBill.ViewHolder || holder instanceof LogWalletTopup.ViewHolder || holder instanceof LogWallet.ViewHolder) {
messageClickListener.onItemShowingMessageId(messageObject);
return;
} else {
return;
}
this.holder = holder;
if (messageObject.forwardedMessage == null && messageObject.isSenderMe() && attachment != null && messageObject.status == MessageObject.STATUS_SENDING) {
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_PROGRESS, this);
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPRESS, this);
if (!Uploader.getInstance().isCompressingOrUploading(messageObject.id + "")) {
// TODO: 12/29/20 MESSAGE_REFACTOR
UploadObject fileObject = UploadObject.createForMessage(messageObject, type);
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
} else {
MessageProgress messageProgress = ((IProgress) holder).getProgress();
int progress = Uploader.getInstance().getUploadProgress(messageObject.id + "");
messageProgress.withProgress(progress);
receivedEvent(EventManager.ON_UPLOAD_PROGRESS, AccountManager.selectedAccount, String.valueOf(messageObject.id), progress);
}
} else {
EventManager.getInstance(currentAccount).removeObserver(EventManager.ON_UPLOAD_PROGRESS, this);
EventManager.getInstance(currentAccount).removeObserver(EventManager.ON_UPLOAD_COMPRESS, this);
}
if (attachment != null) {
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPRESS, this);
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPLETED, this);
EventManager.getInstance(currentAccount).addObserver(EventManager.ON_FILE_DOWNLOAD_COMPLETED, this);
}
// TODO: 12/29/20 MESSAGE_REFACTOR
mHolder.getItemContainer().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OnClickRow(mHolder, view);
}
});
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OnClickRow(mHolder, view);
}
});
if (holder instanceof CardToCardItem.ViewHolder) {
CardToCardItem.ViewHolder cardToCardHolder = (CardToCardItem.ViewHolder) holder;
cardToCardHolder.getRootView().setMinWidth(G.maxChatBox - i_Dp(R.dimen.dp100));
cardToCardHolder.getInnerLayout().setMinimumWidth(G.maxChatBox - i_Dp(R.dimen.dp100));
if (messageObject.forwardedMessage == null && messageObject.additionalData != null && messageObject.additionalType == AdditionalType.CARD_TO_CARD_MESSAGE) {
CardToCardValue value = new CardToCardValue();
try {
JSONArray rootJsonArray = new JSONArray(messageObject.additionalData);
for (int i = 0; i < rootJsonArray.length(); i++) {
JSONArray valuJsonArray = rootJsonArray.getJSONArray(i);
for (int j = 0; j < valuJsonArray.length(); j++) {
JSONObject rootJsonObject = new JSONObject(valuJsonArray.getJSONObject(i).toString());
JSONObject valueObject = rootJsonObject.getJSONObject("value");
String cardNumber = valueObject.getString("cardNumber");
int amount = valueObject.getInt("amount");
long userId = valueObject.getLong("userId");
value.setAmount(amount);
value.setCardNumber(cardNumber);
value.setUserId(userId);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
cardToCardHolder.setValue(value);
}
cardToCardHolder.setOnCardToCard(cardToCard -> {
CardToCardHelper.NewCallCardToCard(G.currentActivity, cardToCard.getUserId(), cardToCard.getAmount(), cardToCard.getCardNumber());
});
}
if (holder instanceof ChatItemWithTextHolder) {
ChatItemWithTextHolder withTextHolder = (ChatItemWithTextHolder) holder;
// withTextHolder.messageView.setHasEmoji(structMessage.hasEmojiInText());
int maxsize = 0;
withTextHolder.removeButtonLayout();
if ((type == ProtoGlobal.Room.Type.CHANNEL) || (type == ProtoGlobal.Room.Type.CHAT) && messageObject.forwardedMessage != null) {
maxsize = G.maxChatBox - 16;
}
if (maxsize > 0)
withTextHolder.messageView.setMaxWidth(maxsize);
if (messageObject.hasLink) {
try {
BetterLinkMovementMethod.linkify(Linkify.ALL, withTextHolder.messageView).setOnLinkClickListener((tv, url) -> {
return FragmentChat.isInSelectionMode;
}).setOnLinkLongClickListener((tv, url) -> {
if (!FragmentChat.isInSelectionMode) {
if (HelperUrl.isTextLink(url)) {
G.isLinkClicked = true;
messageClickListener.onOpenLinkDialog(url);
}
}
return true;
});
} catch (AndroidRuntimeException runtimeException) {
/**
*this try-catch added to fixing bug following bug:
* this bug happens because the "Android System WebView" started being
* installed as its own application from Android 5.0 and greater and this
* code happens to be running while "Android System WebView" is being updated.
* While its being updated the package doesn't exist so it causes this exception
*/
Toast.makeText(context, R.string.please_try_again, Toast.LENGTH_LONG).show();
}
} else {
// remove BetterLinkMovementMethod
}
try {
if (messageObject.forwardedMessage == null && messageObject.additionalData != null && messageObject.additionalType == AdditionalType.UNDER_MESSAGE_BUTTON) {
HashMap<Integer, JSONArray> buttonList = MakeButtons.parseData(messageObject.additionalData);
int rowSize = buttonList.size();
for (int i = 0; i < rowSize; i++) {
int columSize = buttonList.get(i).length();
LinearLayout childLayout = MakeButtons.createLayout(((ChatItemWithTextHolder) holder).getContext());
for (int j = 0; j < columSize; j++) {
ButtonEntity buttonEntity = new Gson().fromJson(buttonList.get(i).get(j).toString(), ButtonEntity.class);
buttonEntity.setJsonObject(buttonList.get(i).get(j).toString());
childLayout = MakeButtons.addButtons(theme, buttonEntity, buttonList.get(i).length(), 1f, childLayout, (view, btnEntity) -> {
if (FragmentChat.isInSelectionMode) {
holder.itemView.performLongClick();
return;
}
mAdapter.onBotButtonClicked(() -> onBotBtnClick(view, btnEntity));
});
}
withTextHolder.addButtonLayout(childLayout);
}
}
} catch (Exception e) {
e.printStackTrace();
}
((LinearLayout.LayoutParams) ((LinearLayout) withTextHolder.messageView.getParent()).getLayoutParams()).gravity = AndroidUtils.isTextRtl(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.message : messageObject.message) ? Gravity.RIGHT : Gravity.LEFT;
}
/**
* for return message that start showing to view
*/
messageClickListener.onItemShowingMessageId(messageObject);
if (isSelected() || messageObject.isSelected) {
((FrameLayout) holder.itemView).setForeground(new ColorDrawable(G.context.getResources().getColor(R.color.colorChatMessageSelectableItemBg)));
} else {
((FrameLayout) holder.itemView).setForeground(new ColorDrawable(Color.TRANSPARENT));
}
/**
* only will be called when message layout is directional-base (e.g. single chat)
*/
if (directionalBased) {
if (!messageObject.isSenderMe() || type == ProtoGlobal.Room.Type.CHANNEL) {
updateLayoutForReceive(holder);
} else if (messageObject.isSenderMe()) {
updateLayoutForSend(holder);
}
}
if (!messageObject.isTimeOrLogMessage()) {
/**
* check failed state ,because if is failed we want show to user even is in channel
*/
if (mAdapter.getRealmRoom() != null && mAdapter.getRealmRoom().isValid() && mAdapter.getRealmRoom().getType() == ProtoGlobal.Room.Type.CHANNEL && ProtoGlobal.RoomMessageStatus.FAILED != ProtoGlobal.RoomMessageStatus.valueOf(messageObject.status)) {
mHolder.getMessageStatusTv().setVisibility(View.GONE);
} else {
mHolder.getMessageStatusTv().setVisibility(View.VISIBLE);
AppUtils.rightMessageStatus(mHolder.getMessageStatusTv(), ProtoGlobal.RoomMessageStatus.forNumber(messageObject.status), ProtoGlobal.RoomMessageType.forNumber(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType), messageObject.isSenderMe());
}
}
if (// TODO: 12/29/20 MESSAGE_REFACTOR
messageObject.edited)
if (messageObject.channelExtra != null && messageObject.channelExtra.getSignature() != null && messageObject.forwardedMessage.channelExtra.getSignature().length() > 0)
mHolder.getSignatureTv().setText(mHolder.getResources().getString(R.string.edited) + " " + messageObject.forwardedMessage.channelExtra.getSignature());
else {
mHolder.getSignatureTv().setText(mHolder.getResources().getString(R.string.edited));
}
else
mHolder.getSignatureTv().setText("");
/**
* display user avatar only if chat type is GROUP
*/
View messageSenderAvatar = mHolder.getItemContainer().findViewById(R.id.messageSenderAvatar);
if (messageSenderAvatar != null) {
messageSenderAvatar.setVisibility(View.GONE);
}
replyMessageIfNeeded(holder);
forwardMessageIfNeeded(holder);
View messageSenderName = mHolder.getContentBloke().findViewById(R.id.messageSenderName);
if (messageSenderName != null) {
messageSenderName.setVisibility(View.GONE);
}
if (type == ProtoGlobal.Room.Type.GROUP) {
if (!messageObject.isSenderMe()) {
addSenderNameToGroupIfNeed(mHolder);
if (messageSenderAvatar == null) {
messageSenderAvatar = ViewMaker.makeCircleImageView();
mHolder.getItemContainer().addView(messageSenderAvatar, 0);
}
messageSenderAvatar.setVisibility(View.VISIBLE);
messageSenderAvatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (FragmentChat.isInSelectionMode) {
holder.itemView.performLongClick();
return;
}
messageClickListener.onSenderAvatarClick(v, messageObject, holder.getAdapterPosition());
}
});
messageSenderAvatar.setOnLongClickListener(getLongClickPerform(holder));
final ImageView copyMessageSenderAvatar = (ImageView) messageSenderAvatar;
mAdapter.avatarHandler.getAvatar(new ParamWithAvatarType(copyMessageSenderAvatar, messageObject.userId).avatarType(AvatarHandler.AvatarType.USER));
}
} else {
FrameLayout forwardContainer = mHolder.getItemContainer().findViewById(R.id.messageForwardContainer);
ContextThemeWrapper wrapper = new ContextThemeWrapper(holder.itemView.getContext(), Theme.getInstance().getTheme(holder.itemView.getContext()));
if (forwardContainer == null) {
forwardContainer = new FrameLayout(holder.itemView.getContext());
forwardContainer.setId(R.id.messageForwardContainer);
if (mAdapter.getRealmRoom() != null && mAdapter.getRealmRoom().getChatRoom() != null && mAdapter.getRealmRoom().getChatRoom().getPeerId() == AccountManager.getInstance().getCurrentUser().getId()) {
mHolder.getItemContainer().addView(forwardContainer, 0, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.MATCH_PARENT, Gravity.BOTTOM));
} else {
mHolder.getItemContainer().addView(forwardContainer, 1, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.MATCH_PARENT, Gravity.BOTTOM));
}
forwardContainer.addView(mHolder.getChannelForwardIv(), LayoutCreator.createFrame(26, 26, Gravity.BOTTOM, 4, 4, 8, 4));
forwardContainer.setVisibility(View.GONE);
}
if (type == ProtoGlobal.Room.Type.CHANNEL) {
mHolder.getChannelForwardIv().setImageDrawable(VectorDrawableCompat.create(holder.itemView.getContext().getResources(), R.drawable.ic_channel_forward_light, wrapper.getTheme()));
forwardContainer.setVisibility(View.VISIBLE);
mHolder.getChannelForwardIv().setOnClickListener(v -> {
if (isAllowToForward(messageObject))
messageClickListener.onForwardClick(messageObject);
});
}
if (type == ProtoGlobal.Room.Type.CHAT && mAdapter.getRealmRoom().getChatRoom() != null && mAdapter.getRealmRoom().getChatRoom().getPeerId() == AccountManager.getInstance().getCurrentUser().getId() && !messageObject.isGiftSticker()) {
mHolder.getChannelForwardIv().setImageDrawable(VectorDrawableCompat.create(holder.itemView.getContext().getResources(), R.drawable.ic_cloud_forward, wrapper.getTheme()));
forwardContainer.setVisibility(View.VISIBLE);
mHolder.getChannelForwardIv().setOnClickListener(v -> {
if (isAllowToForward(messageObject))
messageClickListener.onForwardFromCloudClick(messageObject);
});
}
}
/**
* set message time
*/
String time = HelperCalander.getClocktime(messageObject.createTime, false);
if (HelperCalander.isPersianUnicode) {
mHolder.getMessageTimeTv().setText(HelperCalander.convertToUnicodeFarsiNumber(time));
} else {
mHolder.getMessageTimeTv().setText(time);
}
prepareAttachmentIfNeeded(holder, messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType);
/**
* show vote layout for channel otherwise hide layout also get message state for channel
*/
mHolder.getVoteContainer().setVisibility(View.GONE);
mHolder.getViewContainer().setVisibility(View.GONE);
if (!(holder instanceof StickerItem.ViewHolder)) {
if ((type == ProtoGlobal.Room.Type.CHANNEL)) {
showSeenContainer(holder);
}
}
// TODO: 12/29/20 MESSAGE_REFACTOR
if (messageObject.channelExtra != null && messageObject.channelExtra.getSignature() != null && messageObject.channelExtra.getSignature().length() > 0) {
mHolder.getContentBloke().setMinimumWidth(LayoutCreator.dp(200));
} else if (messageObject.edited) {
mHolder.getContentBloke().setMinimumWidth(LayoutCreator.dp(100));
}
}
Aggregations