use of net.iGap.realm.RealmContacts in project iGap-Android by KianIranian-STDG.
the class FragmentContactsProfileViewModel method mainStart.
private void mainStart() {
if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || roomId == 0) {
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
});
if (realmRoom != null) {
shearedId = realmRoom.getId();
}
} else {
shearedId = roomId;
}
if (!RealmRoom.isNotificationServices(roomId)) {
isShowReportView.set(true);
} else {
isShowReportView.set(false);
}
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
cloudVisibility.postValue(true);
} else
cloudVisibility.postValue(false);
registeredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, userId);
});
if (registeredInfo != null) {
registeredInfo.addChangeListener((RealmObjectChangeListener<RealmRegisteredInfo>) (realmModel, changeSet) -> {
if (changeSet != null) {
for (int i = 0; i < changeSet.getChangedFields().length; i++) {
if (changeSet.getChangedFields()[i].equals("blockUser")) {
userBlockState.set(realmModel.isBlockUser() ? R.string.un_block_user : R.string.block);
}
}
}
});
isBot = registeredInfo.isBot();
if (isBot || userId == AccountManager.getInstance().getCurrentUser().getId()) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
callVisibility.setValue(View.VISIBLE);
menuVisibility.setValue(View.VISIBLE);
videoCallVisibility.setValue(View.VISIBLE);
}
isBlockUser = registeredInfo.isBlockUser();
userBlockState.set(isBlockUser ? R.string.un_block_user : R.string.block);
registeredInfo.addChangeListener(element -> isBlockUser = registeredInfo.isBlockUser());
DbManager.getInstance().doRealmTask(realm -> {
if (registeredInfo.getLastAvatar(realm) != null) {
String mainFilePath = registeredInfo.getLastAvatar(realm).getFile().getLocalFilePath();
if (mainFilePath != null && new File(mainFilePath).exists()) {
// if main image is exist showing that
avatarPath = mainFilePath;
} else {
avatarPath = registeredInfo.getLastAvatar(realm).getFile().getLocalThumbnailPath();
}
avatarList = registeredInfo.getAvatars(realm);
}
});
}
RealmContacts realmUser = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("id", userId).findFirst();
});
if (registeredInfo != null) {
if (registeredInfo.getDisplayName() != null && !registeredInfo.getDisplayName().equals("")) {
contactName.setValue(registeredInfo.getDisplayName());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
if (registeredInfo.getBio() == null || registeredInfo.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(registeredInfo.getBio());
}
username.set(registeredInfo.getUsername());
phone.set(registeredInfo.getPhoneNumber());
phoneNumber = "+" + registeredInfo.getPhoneNumber();
firstName = registeredInfo.getFirstName();
lastName = registeredInfo.getLastName();
lastSeenValue = registeredInfo.getLastSeen();
color = registeredInfo.getColor();
initials = registeredInfo.getInitials();
userStatus = registeredInfo.getStatus();
isVerified = registeredInfo.isVerified();
} else if (realmUser != null) {
if (realmUser.getDisplay_name() != null && !realmUser.getDisplay_name().equals("")) {
contactName.setValue(realmUser.getDisplay_name());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
username.set(realmUser.getUsername());
phone.set(Long.toString(realmUser.getPhone()));
phoneNumber = "+" + realmUser.getPhone();
firstName = realmUser.getFirst_name();
lastName = realmUser.getLast_name();
lastSeenValue = realmUser.getLast_seen();
color = realmUser.getColor();
initials = realmUser.getInitials();
isVerified = realmUser.isVerified();
if (realmUser.getBio() == null || realmUser.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(realmUser.getBio());
}
}
if (isVerified) {
verifyTextVisibility.set(View.VISIBLE);
} else {
verifyTextVisibility.set(View.INVISIBLE);
}
// todo: fixed it two times check it and first and her
if (userId != 134 && AccountManager.getInstance().getCurrentUser().getId() != userId) {
RealmCallConfig callConfig = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmCallConfig.class).findFirst();
});
if (callConfig != null) {
if (isBot) {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
if (callConfig.isVoice_calling()) {
callVisibility.setValue(View.VISIBLE);
}
if (callConfig.isVideo_calling()) {
videoCallVisibility.setValue(View.VISIBLE);
}
}
} else {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
} else {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
RealmContacts realmContacts = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("phone", Long.parseLong(phone.get())).findFirst();
});
/**
* if this user isn't in my contacts don't show phone number
*/
if (realmContacts == null && enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString())) {
showNumber.set(false);
disableDeleteContact = true;
menuVisibility.setValue(View.GONE);
}
if (!G.isAppRtl) {
textsGravity.set(Gravity.LEFT);
} else {
textsGravity.set(Gravity.RIGHT);
}
setUserStatus(userStatus, lastSeenValue);
setAvatar.setValue(userId != AccountManager.getInstance().getCurrentUser().getId());
// todo: change it
FragmentShearedMedia.getCountOfSharedMedia(shearedId);
if (registeredInfo == null) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
}
use of net.iGap.realm.RealmContacts 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.realm.RealmContacts in project iGap-Android by KianIranian-STDG.
the class FragmentChat method itemAdapterBottomSheetForward.
private void itemAdapterBottomSheetForward() {
String[] fieldNames = { "isPinned", "pinId", "updatedTime" };
Sort[] sort = { Sort.DESCENDING, Sort.DESCENDING, Sort.DESCENDING };
results = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("keepRoom", false).equalTo("isDeleted", false).equalTo("readOnly", false).findAll().sort(fieldNames, sort);
});
resultsContact = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).findAll().sort("display_name");
});
List<Long> te = new ArrayList<>();
te.add(chatPeerId);
long identifier = 100L;
for (RealmRoom r : results) {
StructBottomSheetForward item = new StructBottomSheetForward();
item.setId(r.getId());
if (r.getType() == ProtoGlobal.Room.Type.CHAT) {
te.add(r.getChatRoom().getPeerId());
}
item.setDisplayName(r.getTitle());
if (r.getChatRoom() != null)
item.setPeer_id(r.getChatRoom().getPeerId());
item.setType(r.getType());
item.setContactList(false);
item.setNotExistRoom(false);
identifier = identifier + 1;
if (r.getChatRoom() != null && r.getChatRoom().getPeerId() > 0 && r.getChatRoom().getPeerId() == userId) {
fastItemAdapterForward.add(0, new ItemBottomSheetForward(item, avatarHandler).withIdentifier(identifier));
} else {
fastItemAdapterForward.add(new ItemBottomSheetForward(item, avatarHandler).withIdentifier(identifier));
}
}
for (RealmContacts r : resultsContact) {
if (!te.contains(r.getId())) {
StructBottomSheetForward item = new StructBottomSheetForward();
item.setId(r.getId());
item.setDisplayName(r.getDisplay_name());
item.setContactList(true);
item.setNotExistRoom(true);
identifier = identifier + 1;
fastItemAdapterForward.add(new ItemBottomSheetForward(item, avatarHandler).withIdentifier(identifier));
}
}
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
if (isAdded()) {
bottomSheetDialogForward.show();
}
}
}, 100);
}
use of net.iGap.realm.RealmContacts in project iGap-Android by KianIranian-STDG.
the class FragmentChat method showSpamBar.
/**
* manage need showSpamBar for user or no
*/
private void showSpamBar() {
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
RealmContacts realmContacts = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("id", chatPeerId).findFirst();
});
if (realmRegisteredInfo != null && realmRegisteredInfo.getId() != AccountManager.getInstance().getCurrentUser().getId()) {
if (phoneNumber == null) {
if (realmContacts == null && chatType == CHAT && !isChatReadOnly) {
initSpamBarLayout(realmRegisteredInfo);
vgSpamUser.setVisibility(View.VISIBLE);
}
}
if (realmRegisteredInfo.getId() != AccountManager.getInstance().getCurrentUser().getId()) {
if (!realmRegisteredInfo.getDoNotshowSpamBar()) {
if (realmRegisteredInfo.isBlockUser()) {
initSpamBarLayout(realmRegisteredInfo);
blockUser = true;
txtSpamUser.setText(G.fragmentActivity.getResources().getString(R.string.un_block_user));
vgSpamUser.setVisibility(View.VISIBLE);
} else {
if (vgSpamUser != null) {
vgSpamUser.setVisibility(View.GONE);
}
}
}
}
if (realmContacts != null && realmRegisteredInfo.getId() != AccountManager.getInstance().getCurrentUser().getId()) {
if (realmContacts.isBlockUser()) {
initSpamBarLayout(realmRegisteredInfo);
blockUser = true;
txtSpamUser.setText(G.fragmentActivity.getResources().getString(R.string.un_block_user));
vgSpamUser.setVisibility(View.VISIBLE);
} else {
if (vgSpamUser != null) {
vgSpamUser.setVisibility(View.GONE);
}
}
}
}
if (vgSpamUser != null) {
RelativeLayout.LayoutParams spamLayoutParam = (RelativeLayout.LayoutParams) vgSpamUser.getLayoutParams();
if (mediaContainer.getVisibility() == View.VISIBLE) {
chatContainer.removeView(vgSpamUser);
spamLayoutParam.topMargin = LayoutCreator.dp(95);
chatContainer.addView(vgSpamUser);
}
}
}
use of net.iGap.realm.RealmContacts in project iGap-Android by KianIranian-STDG.
the class ContactUtils method syncContacts.
/**
* sync iGap contacts with phone contacts (add iGap Accounts to phone contacts that has iGap)
*/
public static void syncContacts() {
try {
HelperPermission.getContactPermision(G.fragmentActivity, new OnGetPermission() {
@Override
public void Allow() throws IOException {
final MaterialDialog[] dialog = new MaterialDialog[1];
dialog[0] = new MaterialDialog.Builder(G.currentActivity).title(R.string.sync_contact).content(R.string.just_wait_en).progress(false, 0, true).show();
new Thread(() -> {
DbManager.getInstance().doRealmTransaction(realm1 -> {
final RealmResults<RealmContacts> realmContacts = realm1.where(RealmContacts.class).findAll();
final int contactsSize = realmContacts.size();
dialog[0].setMaxProgress(contactsSize);
for (RealmContacts realmContacts1 : realmContacts) {
addContactToPhoneBook(realmContacts1);
if (dialog[0].isCancelled()) {
break;
}
G.handler.post(() -> dialog[0].incrementProgress(1));
}
G.handler.postDelayed(() -> dialog[0].dismiss(), 500);
});
}).start();
}
@Override
public void deny() {
showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
// do nothing
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations