Search in sources :

Example 11 with GroupVM

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;
        }
    });
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) GroupVM(im.actor.core.viewmodel.GroupVM) Peer(im.actor.core.entity.Peer) MenuItem(android.view.MenuItem) Avatar(im.actor.core.entity.Avatar) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) UserVM(im.actor.core.viewmodel.UserVM) SearchView(android.support.v7.widget.SearchView) SearchEntity(im.actor.core.entity.SearchEntity) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) ArrayList(java.util.ArrayList) BindedDisplayList(im.actor.runtime.generic.mvvm.BindedDisplayList) List(java.util.List) DisplayList(im.actor.runtime.generic.mvvm.DisplayList) CommandCallback(im.actor.core.viewmodel.CommandCallback)

Example 12 with GroupVM

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;
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) TextView(android.widget.TextView) KeyboardHelper(im.actor.sdk.util.KeyboardHelper) CommandCallback(im.actor.core.viewmodel.CommandCallback) TextView(android.widget.TextView) View(android.view.View)

Example 13 with GroupVM

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);
}
Also used : GroupVM(im.actor.core.viewmodel.GroupVM) JsGroup(im.actor.core.js.entity.JsGroup)

Example 14 with GroupVM

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;
                }
            }
        }
    }
}
Also used : JsMessage(im.actor.core.js.entity.JsMessage) Message(im.actor.core.entity.Message) StickerPack(im.actor.core.entity.StickerPack) JsMessage(im.actor.core.js.entity.JsMessage) Sticker(im.actor.core.entity.Sticker) JsSticker(im.actor.core.js.entity.JsSticker) JsDialog(im.actor.core.js.entity.JsDialog) JsDialog(im.actor.core.js.entity.JsDialog) Dialog(im.actor.core.entity.Dialog) JsUser(im.actor.core.js.entity.JsUser) DialogSmall(im.actor.core.viewmodel.DialogSmall) StickerContent(im.actor.core.entity.content.StickerContent) GroupVM(im.actor.core.viewmodel.GroupVM) JsContact(im.actor.core.js.entity.JsContact) JsContact(im.actor.core.js.entity.JsContact) Contact(im.actor.core.entity.Contact) UserVM(im.actor.core.viewmodel.UserVM) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) DocumentContent(im.actor.core.entity.content.DocumentContent) JsDialogGroup(im.actor.core.js.entity.JsDialogGroup) DialogGroup(im.actor.core.viewmodel.DialogGroup) JsGroup(im.actor.core.js.entity.JsGroup)

Example 15 with GroupVM

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);
}
Also used : GroupVM(im.actor.core.viewmodel.GroupVM) JsOnlineGroup(im.actor.core.js.entity.JsOnlineGroup)

Aggregations

GroupVM (im.actor.core.viewmodel.GroupVM)15 UserVM (im.actor.core.viewmodel.UserVM)11 View (android.view.View)7 TextView (android.widget.TextView)7 Peer (im.actor.core.entity.Peer)5 CommandCallback (im.actor.core.viewmodel.CommandCallback)5 ViewGroup (android.view.ViewGroup)4 ArrayList (java.util.ArrayList)4 Activity (android.app.Activity)3 Context (android.content.Context)3 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 LayoutInflater (android.view.LayoutInflater)3 Toast (android.widget.Toast)3 GroupMember (im.actor.core.entity.GroupMember)3 ActorSDK (im.actor.sdk.ActorSDK)3 R (im.actor.sdk.R)3 ActorSDKMessenger.messenger (im.actor.sdk.util.ActorSDKMessenger.messenger)3 ActorSDKMessenger.users (im.actor.sdk.util.ActorSDKMessenger.users)3 AlertDialog (android.app.AlertDialog)2