use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.
the class PaymentFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getArguments() != null) {
isShowValueAdded = getArguments().getBoolean(IS_SHOW_VALUE_ADDED, false);
}
paymentViewModel.getGoBack().observe(getViewLifecycleOwner(), paymentResult -> {
if (getActivity() != null && paymentResult != null) {
getActivity().getSupportFragmentManager().popBackStackImmediate();
if (callBack != null) {
callBack.onPaymentFinished(paymentResult);
}
}
});
paymentViewModel.getGoToWebPage().observe(getViewLifecycleOwner(), webLink -> {
if (getActivity() != null && webLink != null) {
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webLink));
Bundle bundle = new Bundle();
bundle.putString("Authorization", TokenContainer.getInstance().getToken());
browserIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(browserIntent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getActivity(), R.string.add_new_account, Toast.LENGTH_LONG).show();
}
/*CustomTabsIntent intent = new CustomTabsIntent.Builder().build();
Bundle bundle = new Bundle();
bundle.putString("Authorization", G.getApiToken());
intent.intent.putExtra(Browser.EXTRA_HEADERS, bundle);
CustomTabsActivityHelper.openCustomTab(getActivity(), intent, Uri.parse(webLink), (activity, uri) -> {
});*/
}
});
binding.paymentFeatureRC.setHasFixedSize(true);
paymentViewModel.getDiscountOption().observe(getViewLifecycleOwner(), new Observer<List<PaymentFeature>>() {
@Override
public void onChanged(List<PaymentFeature> paymentFeatures) {
if (paymentFeatures != null) {
adapter = new PaymentPlansAdapter(paymentFeatures, new PaymentPlansAdapter.PlanListListener() {
@Override
public void onPlanClicked(int position, boolean state) {
if (state)
paymentViewModel.setDiscountPlanPosition(position);
else
paymentViewModel.setDiscountPlanPosition(-1);
}
});
binding.paymentFeatureRC.setAdapter(adapter);
}
}
});
binding.screenshotButton.setOnClickListener(v -> {
try {
HelperPermission.getStoragePermission(getActivity(), new OnGetPermission() {
@Override
public void Allow() {
getScreenshot();
}
@Override
public void deny() {
showDeniedPermissionMessage(G.context.getString(R.string.permission_storage));
}
});
} catch (IOException e) {
FileLog.e(e);
}
});
paymentViewModel.getPrice().observe(getViewLifecycleOwner(), price -> {
if (getContext() != null && price != null) {
DecimalFormat df = new DecimalFormat(",###");
binding.priceTitle.setText(getString(R.string.wallet_amount) + (isShowValueAdded ? (" + " + getString(R.string.value_added)) : "") + ": " + (HelperCalander.isPersianUnicode ? HelperCalander.convertToUnicodeFarsiNumber(df.format(price)) : price) + getString(R.string.rial));
}
});
binding.discountCode.requestFocus();
binding.saveDiscountCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String code = binding.discountCode.getText().toString();
paymentViewModel.checkOrderTokenForDiscount(code);
}
});
paymentViewModel.getErrorMessage().observe(getViewLifecycleOwner(), errorMessage -> {
if (errorMessage != null) {
if (errorMessage.equals("errorPayment")) {
binding.paymentStatus.setText(getContext().getResources().getString(R.string.faild_payment));
} else {
binding.paymentStatus.setText(errorMessage);
}
}
});
}
use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.
the class FragmentSyncRegisteredContacts method onViewCreated.
@Override
public void onViewCreated(@NotNull View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
G.onPhoneContact = this;
G.onContactsGetList = this;
Contacts.localPhoneContactId = 0;
Contacts.getContact = true;
userID = this.getArguments().getLong(ARG_USER_ID);
// Toolbar Initial
LinearLayout toolbarLayout = view.findViewById(R.id.frg_contact_ll_toolbar_layout);
mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setSearchBoxShown(true).setLogoShown(true).setDefaultTitle(getString(R.string.str_frag_sync_contactWelcome));
toolbarLayout.addView(mHelperToolbar.getView());
mHelperToolbar.setListener(this);
prgWaiting = view.findViewById(R.id.prgWaiting_addContact);
AppUtils.setProgresColler(prgWaiting);
Bundle bundle = this.getArguments();
String title = null;
if (bundle != null) {
title = bundle.getString("TITLE");
isCallAction = bundle.getBoolean("ACTION");
}
// My Code H.Amini
// ContactUtils.syncContacts();
realmRecyclerView = view.findViewById(R.id.recycler_view);
realmRecyclerView.setItemViewCacheSize(1000);
realmRecyclerView.setItemAnimator(null);
layoutManager = new LinearLayoutManager(realmRecyclerView.getContext());
realmRecyclerView.setLayoutManager(layoutManager);
// get all the contacts from realm
results = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).findAll().sort("display_name");
});
results.addChangeListener(new RealmChangeListener<RealmResults<RealmContacts>>() {
@Override
public void onChange(@NotNull RealmResults<RealmContacts> realmContacts) {
if (realmContacts.size() > 0) {
fastScroller.setVisibility(View.VISIBLE);
}
contactListAdapter2.notifyDataSetChanged();
}
});
// Load all of the data
// contactListAdapter = new FragmentSyncRegisteredContacts.ContactListAdapter(results);
contactListAdapter2 = new ContactListAdapter2(results);
// realmRecyclerView.setAdapter(contactListAdapter);
realmRecyclerView.setAdapter(contactListAdapter2);
realmRecyclerView.setVisibility(View.VISIBLE);
realmRecyclerView.setLayoutManager(new ScrollingLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false, 1000));
realmRecyclerView.setNestedScrollingEnabled(false);
fastScroller = view.findViewById(R.id.fast_scroller);
fastScroller.setRecyclerView(realmRecyclerView);
fastScroller.setVisibility(View.GONE);
// going to app directly
skipBtn = view.findViewById(R.id.frag_sync_skipbtn);
skipBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getActivity() != null) {
Intent intent = new Intent(getActivity(), ActivityMain.class);
intent.putExtra(ARG_USER_ID, userID);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(intent);
getActivity().finish();
}
}
});
/*FragmentSyncRegisteredContacts.StickyHeader stickyHeader = new FragmentSyncRegisteredContacts.StickyHeader(results);
decoration = new StickyRecyclerHeadersDecoration(stickyHeader);
realmRecyclerView.addItemDecoration(decoration);*/
onCliclRecyclerView = new FragmentSyncRegisteredContacts.onClickRecyclerView() {
@Override
public void onClick(View view, int position) {
if (isMultiSelect) {
}
}
};
// get permission for contacts
try {
if (getPermission) {
getPermission = false;
HelperPermission.getContactPermision(G.fragmentActivity, new OnGetPermission() {
@Override
public void Allow() throws IOException {
/**
* if contacts size is zero send request for get contacts list
* for insuring that contacts not exist really or not
*/
if (results.size() == 0) {
LoginActions.importContact();
}
}
@Override
public void deny() {
/*if (results.size() == 0) {
new RequestUserContactsGetList().userContactGetList();
}*/
if (getActivity() == null || getActivity().isFinishing()) {
return;
}
Intent intent = new Intent(getContext(), ActivityMain.class);
intent.putExtra(ARG_USER_ID, userID);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
G.context.startActivity(intent);
G.fragmentActivity.finish();
}
});
} else {
if (results.size() == 0) {
new RequestUserContactsGetList().userContactGetList();
} else {
hideProgress();
}
/*if (HelperPermission.grantedContactPermission()) {
new Contacts.FetchContactForClient().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
hideProgress();
}*/
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.
the class FragmentProfile method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewModel.getGoToWalletPage().observe(getViewLifecycleOwner(), phoneNumber -> {
if (getActivity() != null && phoneNumber != null) {
// getActivity().startActivityForResult(new HelperWallet().goToWallet(getActivity(), new Intent(getActivity(), WalletActivity.class), phoneNumber, false), WALLET_REQUEST_CODE);
}
});
viewModel.getGoToAddMemberPage().observe(getViewLifecycleOwner(), aBoolean -> {
if (getActivity() != null && aBoolean != null && aBoolean) {
try {
Fragment fragment = RegisteredContactsFragment.newInstance(true, false, RegisteredContactsFragment.ADD);
new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
} catch (Exception e) {
e.getStackTrace();
}
}
});
viewModel.goToChatPage.observe(getViewLifecycleOwner(), data -> {
if (getActivity() != null && data != null) {
new GoToChatActivity(data.getRoomId()).setPeerID(data.getPeerId()).startActivity(getActivity());
}
});
viewModel.goToScannerPage.observe(getViewLifecycleOwner(), go -> {
if (go != null && go) {
try {
HelperPermission.getCameraPermission(getActivity(), new OnGetPermission() {
@Override
public void Allow() throws IllegalStateException {
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setRequestCode(ActivityMain.requestCodeQrCode);
integrator.setBeepEnabled(false);
integrator.setPrompt("");
integrator.initiateScan();
}
@Override
public void deny() {
showDeniedPermissionMessage(G.context.getString(R.string.permission_camera));
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
viewModel.checkLocationPermission.observe(getViewLifecycleOwner(), isCheck -> {
if (isCheck != null && isCheck) {
try {
HelperPermission.getLocationPermission(getActivity(), new OnGetPermission() {
@Override
public void Allow() {
viewModel.haveLocationPermission();
}
@Override
public void deny() {
showDeniedPermissionMessage(G.context.getString(R.string.permission_location));
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
viewModel.shareInviteLink.observe(getViewLifecycleOwner(), link -> {
if (link != null) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, link);
sendIntent.setType("text/plain");
Intent openInChooser = Intent.createChooser(sendIntent, "Open in...");
startActivity(openInChooser);
}
});
viewModel.goToContactsPage.observe(getViewLifecycleOwner(), go -> {
if (getActivity() != null && go != null && go) {
new HelperFragment(getActivity().getSupportFragmentManager(), RegisteredContactsFragment.newInstance(false, false, RegisteredContactsFragment.CONTACTS)).setReplace(false).load();
}
});
viewModel.goToUserScorePage.observe(getViewLifecycleOwner(), go -> {
if (getActivity() != null && go != null && go) {
new HelperFragment(getActivity().getSupportFragmentManager(), new FragmentUserScore()).setReplace(false).load();
}
});
viewModel.goToIGapMapPage.observe(getViewLifecycleOwner(), isGo -> {
if (getActivity() != null && isGo != null && isGo) {
new HelperFragment(getActivity().getSupportFragmentManager(), FragmentiGapMap.getInstance()).setReplace(false).load();
}
});
viewModel.goToFAQPage.observe(getViewLifecycleOwner(), link -> {
if (link != null) {
HelperUrl.openBrowser(link);
}
});
viewModel.goToSettingPage.observe(getViewLifecycleOwner(), go -> {
if (getActivity() != null && go != null && go) {
new HelperFragment(getActivity().getSupportFragmentManager(), new FragmentSetting()).setReplace(false).load();
}
});
viewModel.getUpdateNewTheme().observe(getViewLifecycleOwner(), isUpdate -> {
if (getActivity() != null && isUpdate != null && isUpdate) {
Fragment frg;
frg = getActivity().getSupportFragmentManager().findFragmentByTag(BottomNavigationFragment.class.getName());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
}
});
viewModel.showDialogBeLastVersion.observe(getViewLifecycleOwner(), isShow -> {
if (getActivity() != null && isShow != null && isShow) {
new MaterialDialog.Builder(getActivity()).cancelable(false).title(R.string.app_version_change_log).titleGravity(GravityEnum.CENTER).titleColor(new Theme().getPrimaryColor(getActivity())).content(R.string.updated_version_title).contentGravity(GravityEnum.CENTER).positiveText(R.string.ok).itemsGravity(GravityEnum.START).show();
}
});
viewModel.showDialogUpdate.observe(getViewLifecycleOwner(), body -> {
if (getActivity() != null && body != null) {
new MaterialDialog.Builder(getActivity()).cancelable(false).title(R.string.app_version_change_log).titleGravity(GravityEnum.CENTER).titleColor(new Theme().getPrimaryColor(getActivity())).content(body).contentGravity(GravityEnum.CENTER).positiveText(R.string.startUpdate).itemsGravity(GravityEnum.START).onPositive((dialog, which) -> {
String url = BuildConfig.UPDATE_LINK;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}).negativeText(R.string.cancel).show();
}
});
}
use of net.iGap.observers.interfaces.OnGetPermission in project iGap-Android by KianIranian-STDG.
the class ChatAttachmentPopup method initViews.
private void initViews(View view) {
View camera, photo, video, music, file, contact, location;
View root;
camera = view.findViewById(R.id.camera);
photo = view.findViewById(R.id.picture);
video = view.findViewById(R.id.video);
music = view.findViewById(R.id.music);
file = view.findViewById(R.id.file);
location = view.findViewById(R.id.location);
contact = view.findViewById(R.id.contact);
btnSend = view.findViewById(R.id.close);
icoSend = view.findViewById(R.id.txtSend);
lblSend = view.findViewById(R.id.txtNumberItem);
root = view.findViewById(R.id.root);
root.setOnClickListener(v -> {
dismiss();
});
btnSend.setOnClickListener(v -> {
if (animation != null)
animation.cancel();
if (FragmentEditImage.textImageList.size() > 0) {
dismiss();
clearRecyclerAdapter();
lblSend.setText(mFrgActivity.getString(R.string.icon_close));
lblSend.setText(mFrgActivity.getString(R.string.navigation_drawer_close));
mPopupListener.onAttachPopupSendSelected();
} else {
dismiss();
}
});
camera.setOnClickListener(v -> {
dismiss();
attachFile.showDialogOpenCamera(v, null, mFragment);
});
photo.setOnClickListener(v -> {
dismiss();
openPhotoGallery();
});
video.setOnClickListener(v -> {
dismiss();
openVideoGallery();
});
music.setOnClickListener(v -> {
dismiss();
openMusicGallery();
});
file.setOnClickListener(v -> {
dismiss();
try {
attachFile.requestPickFile((selectedPathList, caption) -> {
mPopupListener.onAttachPopupFilePicked(selectedPathList, caption);
});
} catch (IOException e) {
e.printStackTrace();
}
});
contact.setOnClickListener(v -> {
dismiss();
try {
attachFile.requestPickContact(mFragment);
} catch (IOException e) {
e.printStackTrace();
}
});
location.setOnClickListener(v -> {
dismiss();
try {
attachFile.requestGetPosition((result, messageOne, MessageTow) -> {
mPopupListener.onAttachPopupLocation(messageOne);
}, mFragment);
} catch (IOException e) {
e.printStackTrace();
}
});
// init local pictures
fastItemAdapter = new FastItemAdapter();
onClickCamera = () -> {
try {
dismiss();
new AttachFile(mFrgActivity).requestTakePicture(mFragment);
} catch (IOException e) {
e.printStackTrace();
}
};
onPathAdapterBottomSheet = (path, isCheck, isEdit, mList, id) -> {
if (isEdit) {
dismiss();
new HelperFragment(mFrgActivity.getSupportFragmentManager(), FragmentEditImage.newInstance(null, true, false, id)).setReplace(false).load();
} else {
if (isCheck) {
StructBottomSheet item = new StructBottomSheet();
item.setPath(path);
item.setText("");
item.setId(id);
FragmentEditImage.textImageList.put(path, item);
} else {
FragmentEditImage.textImageList.remove(path);
}
if (FragmentEditImage.textImageList.size() > 0) {
icoSend.setText(mFrgActivity.getString(R.string.icon_send));
lblSend.setText("" + FragmentEditImage.textImageList.size() + " " + mFrgActivity.getString(item));
} else {
icoSend.setText(mFrgActivity.getString(R.string.icon_close));
lblSend.setText(mFrgActivity.getString(R.string.navigation_drawer_close));
}
}
};
mNoCameraPermission = view.findViewById(R.id.no_camera_permission);
rcvBottomSheet = view.findViewById(R.id.rcvContent);
rcvBottomSheet.setLayoutManager(new GridLayoutManager(mFrgActivity, 1, GridLayoutManager.HORIZONTAL, false));
rcvBottomSheet.setAdapter(fastItemAdapter);
mNoCameraPermission.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
HelperPermission.getCameraPermission(G.fragmentActivity, new OnGetPermission() {
@Override
public void Allow() throws IOException {
mNoCameraPermission.setVisibility(View.GONE);
rcvBottomSheet.setVisibility(View.VISIBLE);
}
@Override
public void deny() {
HelperPermission.showDeniedPermissionMessage(G.context.getString(R.string.permission_camera));
}
});
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
});
// disable and enable camera when user scroll on recycler view
rcvBottomSheet.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(final View view) {
if (isPermissionCamera) {
if (rcvBottomSheet.getChildAdapterPosition(view) == 0) {
isCameraAttached = true;
}
if (isCameraAttached) {
enableCamera();
}
}
}
@Override
public void onChildViewDetachedFromWindow(final View view) {
if (isPermissionCamera) {
if (rcvBottomSheet.getChildAdapterPosition(view) == 0) {
isCameraAttached = false;
}
if (!isCameraAttached) {
disableCamera();
}
}
}
});
}
use of net.iGap.observers.interfaces.OnGetPermission 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();
});
}
Aggregations