use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class GlobalSearchBaseFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_global_search, menu);
searchMenu = menu.findItem(R.id.search);
if (messenger().getAppState().getIsAppEmpty().get()) {
searchMenu.setVisible(false);
} else {
searchMenu.setVisible(true);
}
searchView = (SearchView) searchMenu.getActionView();
searchView.setIconifiedByDefault(true);
MenuItemCompat.setOnActionExpandListener(searchMenu, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
showSearch();
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
hideSearch();
return true;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
searchQuery = s.trim();
if (isSearchVisible) {
if (s.trim().length() > 0) {
String activeSearchQuery = searchQuery;
searchDisplay.initSearch(s.trim().toLowerCase(), false);
scrolledToEnd = false;
searchAdapter.setQuery(s.trim().toLowerCase());
globalSearchResults.clear();
messenger().findPeers(s).start(new CommandCallback<List<PeerSearchEntity>>() {
@Override
public void onResult(List<PeerSearchEntity> res) {
if (searchQuery.equals(activeSearchQuery)) {
int order = 0;
outer: for (PeerSearchEntity pse : res) {
for (int i = 0; i < searchDisplay.getSize(); i++) {
if (searchDisplay.getItem(i).getPeer().equals(pse.getPeer())) {
continue outer;
}
}
Avatar avatar;
Peer peer = pse.getPeer();
String name;
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM userVM = users().get(peer.getPeerId());
name = userVM.getName().get();
avatar = userVM.getAvatar().get();
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM groupVM = groups().get(peer.getPeerId());
name = groupVM.getName().get();
avatar = groupVM.getAvatar().get();
} else {
continue;
}
String optMatchString = pse.getOptMatchString();
globalSearchResults.add(new SearchEntity(pse.getPeer(), order++, avatar, optMatchString == null ? name : optMatchString));
}
if (globalSearchResults.size() > 0) {
globalSearchResults.add(new SearchEntityHeader(order++));
}
checkGlobalSearch();
onSearchChanged();
}
}
@Override
public void onError(Exception e) {
}
});
} else {
searchDisplay.initEmpty();
}
}
return false;
}
});
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class EditAboutFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
type = getArguments().getInt("EXTRA_TYPE");
id = getArguments().getInt("EXTRA_ID");
helper = new KeyboardHelper(getActivity());
View res = inflater.inflate(R.layout.fragment_edit_about, container, false);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
aboutEdit = (EditText) res.findViewById(R.id.nameEdit);
aboutEdit.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
hintTv = (TextView) res.findViewById(R.id.hint);
hintTv.setTextColor(ActorSDK.sharedActor().style.getTextHintColor());
if (type == EditAboutActivity.TYPE_ME) {
UserVM userModel = users().get(myUid());
aboutEdit.setText(userModel.getAbout().get());
aboutEdit.setHint(getString(R.string.edit_about_edittext_hint));
} else if (type == EditAboutActivity.TYPE_GROUP) {
GroupVM group = groups().get(id);
aboutEdit.setText(group.getAbout().get());
}
res.findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
res.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
((TextView) res.findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
res.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String about = aboutEdit.getText().toString().trim();
if (about.length() == 0) {
about = null;
}
if (type == EditAboutActivity.TYPE_ME) {
execute(messenger().editMyAbout(about), R.string.progress_common, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT).show();
}
});
//TODO: set group about
}
}
});
((TextView) res.findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
return res;
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class JsBindingModule method getGroup.
public JsBindedValue<JsGroup> getGroup(int gid) {
if (!groups.containsKey(gid)) {
final GroupVM groupVM = context().getGroupsModule().getGroupsCollection().get(gid);
final JsBindedValue<JsGroup> value = new JsBindedValue<>(JsGroup.fromGroupVM(groupVM, messenger));
// Bind updates
groupVM.subscribe(new ModelChangedListener<GroupVM>() {
@Override
public void onChanged(GroupVM model) {
value.changeValue(JsGroup.fromGroupVM(groupVM, messenger));
}
}, false);
groups.put(gid, value);
}
return groups.get(gid);
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class JsBindingModule method onFileLoaded.
@Override
public void onFileLoaded(HashSet<Long> fileId) {
if (dialogsList != null) {
for (JsDisplayListBind<JsDialog, Dialog> b : dialogsList.getActiveBinds()) {
b.startReconverting();
for (Dialog dialog : b.getRawItems()) {
if (checkAvatar(dialog.getDialogAvatar(), fileId)) {
b.forceReconvert(dialog.getEngineId());
}
}
b.stopReconverting();
}
}
if (dialogsGroupedList != null) {
ArrayList<DialogGroup> groups = context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().get();
if (groups != null) {
outer: for (DialogGroup g : groups) {
for (DialogSmall ds : g.getDialogs()) {
if (checkAvatar(ds.getAvatar(), fileId)) {
context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().forceNotify();
break outer;
}
}
}
}
}
if (contactsList != null) {
for (JsDisplayListBind<JsContact, Contact> b : contactsList.getActiveBinds()) {
b.startReconverting();
for (Contact contact : b.getRawItems()) {
if (checkAvatar(contact.getAvatar(), fileId)) {
b.forceReconvert(contact.getEngineId());
}
}
b.stopReconverting();
}
}
for (JsDisplayList<JsMessage, Message> messageList : messageLists.values()) {
for (JsDisplayListBind<JsMessage, Message> b : messageList.getActiveBinds()) {
b.startReconverting();
for (Message message : b.getRawItems()) {
UserVM user = context().getUsersModule().getUsers().get(message.getSenderId());
if (checkAvatar(user.getAvatar().get(), fileId)) {
b.forceReconvert(message.getEngineId());
continue;
}
if (message.getContent() instanceof DocumentContent) {
DocumentContent doc = (DocumentContent) message.getContent();
if (doc.getSource() instanceof FileRemoteSource) {
if (fileId.contains(((FileRemoteSource) doc.getSource()).getFileReference().getFileId())) {
b.forceReconvert(message.getEngineId());
}
}
}
if (message.getContent() instanceof StickerContent) {
StickerContent content = (StickerContent) message.getContent();
if (content.getImage512() != null) {
long stickerFileId = content.getImage512().getReference().getFileId();
if (fileId.contains(stickerFileId)) {
b.forceReconvert(message.getEngineId());
}
} else if (content.getImage256() != null) {
long stickerFileId = content.getImage256().getReference().getFileId();
if (fileId.contains(stickerFileId)) {
b.forceReconvert(message.getEngineId());
}
}
}
}
b.stopReconverting();
}
}
for (JsBindedValue<JsUser> u : users.values()) {
int uid = u.get().getUid();
UserVM userVM = context().getUsersModule().getUsers().get(uid);
if (checkAvatar(userVM.getAvatar().get(), fileId)) {
u.changeValue(JsUser.fromUserVM(userVM, messenger));
}
}
for (JsBindedValue<JsGroup> g : groups.values()) {
int gid = g.get().getGid();
GroupVM groupVM = context().getGroupsModule().getGroupsCollection().get(gid);
if (checkAvatar(groupVM.getAvatar().get(), fileId)) {
g.changeValue(JsGroup.fromGroupVM(groupVM, messenger));
}
}
//
if (stickers != null) {
outer: for (StickerPack stickerPack : messenger.getAvailableStickersVM().getOwnStickerPacks().get()) {
for (Sticker s : stickerPack.getStickers()) {
if (s.getImage256() != null && fileId.contains(s.getImage256().getFileId())) {
messenger.getAvailableStickersVM().getOwnStickerPacks().forceNotify();
break outer;
}
}
}
}
}
use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.
the class JsBindingModule method getGroupOnline.
public JsBindedValue<JsOnlineGroup> getGroupOnline(int gid) {
if (!groupOnlines.containsKey(gid)) {
final JsBindedValue<JsOnlineGroup> value = new JsBindedValue<>();
final GroupVM groupVM = context().getGroupsModule().getGroupsCollection().get(gid);
groupVM.getPresence().subscribe(new ValueChangedListener<Integer>() {
@Override
public void onChanged(Integer val, Value<Integer> valueModel) {
if (groupVM.isMember().get()) {
if (val == null) {
value.changeValue(null);
return;
}
String presence = messenger.getFormatter().formatGroupMembers(groupVM.getMembersCount().get());
if (val > 0) {
presence += ", " + messenger.getFormatter().formatGroupOnline(val);
}
value.changeValue(JsOnlineGroup.create(groupVM.getMembersCount().get(), val, presence, false));
} else {
value.changeValue(JsOnlineGroup.create(0, 0, "Not member", false));
}
}
});
groupOnlines.put(gid, value);
}
return groupOnlines.get(gid);
}
Aggregations