Search in sources :

Example 1 with GroupVM

use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.

the class PresenceActor method onGroupOnline.

@Verified
private void onGroupOnline(int gid, int count, long updateDate) {
    // Log.d(TAG, "onGroupOnline  #" + gid + " " + count + " at " + updateDate);
    if (lastGidState.containsKey(gid) && lastGidState.get(gid) >= updateDate) {
        // Log.d(TAG, "onGroupOnline:ignored - too old");
        return;
    }
    lastGidState.put(gid, updateDate);
    // Log.d(TAG, "onGroupOnline:updated");
    GroupVM vm = getGroupVM(gid);
    if (vm != null) {
        vm.getPresence().change(count);
    }
}
Also used : GroupVM(im.actor.core.viewmodel.GroupVM) Verified(im.actor.runtime.annotations.Verified)

Example 2 with GroupVM

use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.

the class ChatFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    findInputBar().setText(messenger().loadDraft(peer), true);
    if (peer.getPeerType() == PeerType.PRIVATE) {
        UserVM userVM = users().get(peer.getPeerId());
        if (userVM.isBot()) {
            ConversationVM conversationVM = messenger().getConversationVM(peer);
            bind(conversationVM.getIsEmpty(), conversationVM.getIsLoaded(), (isEmpty, valueModel, isLoaded, valueModel2) -> {
                if (isEmpty) {
                    inputOverlayText.setText(R.string.chat_empty_bot);
                    inputOverlayText.setTextColor(style.getListActionColor());
                    inputOverlayText.setClickable(true);
                    showView(inputOverlayContainer, false);
                    goneView(inputContainer, false);
                } else {
                    goneView(inputOverlayContainer, false);
                    showView(inputContainer, false);
                }
                if (isEmpty && isLoaded) {
                    showView(emptyContainer, false);
                } else {
                    hideView(emptyContainer, false);
                }
            });
            bind(userVM.getAbout(), (val, valueModel) -> {
                if (val == null) {
                    findEmptyPlaceholder().setText(getString(R.string.chat_empty_bot_about));
                } else {
                    findEmptyPlaceholder().setText(val);
                }
            });
        } else {
            bind(userVM.getIsBlocked(), (val, valueModel) -> {
                if (val) {
                    inputOverlayText.setText(R.string.blocked_unblock);
                    inputOverlayText.setTextColor(style.getListActionColor());
                    inputOverlayText.setClickable(true);
                    showView(inputOverlayContainer, false);
                    goneView(inputContainer, false);
                } else {
                    goneView(inputOverlayContainer, false);
                    showView(inputContainer, false);
                }
            });
        }
    } else if (peer.getPeerType() == PeerType.GROUP) {
        GroupVM groupVM = groups().get(peer.getPeerId());
        bind(groupVM.isMember(), groupVM.getIsCanWriteMessage(), (isMember, valueModel, canWriteMessage, valueModel2) -> {
            if (canWriteMessage) {
                goneView(inputOverlayContainer, false);
                showView(inputContainer, false);
            } else if (isMember) {
                if (messenger().isNotificationsEnabled(peer)) {
                    inputOverlayText.setText(getString(R.string.chat_mute));
                } else {
                    inputOverlayText.setText(getString(R.string.chat_unmute));
                }
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(true);
                inputOverlayText.setEnabled(true);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else if (groupVM.getIsCanJoin().get()) {
                inputOverlayText.setText(getString(R.string.join));
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(true);
                inputOverlayText.setEnabled(true);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else if (groupVM.getIsDeleted().get()) {
                inputOverlayText.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_deleted : R.string.group_deleted);
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(false);
                inputOverlayText.setEnabled(false);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else {
                inputOverlayText.setText(R.string.chat_not_member);
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(false);
                inputOverlayText.setEnabled(false);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            }
        });
    }
}
Also used : BaseFragment(im.actor.sdk.controllers.BaseFragment) ConversationVM(im.actor.core.viewmodel.ConversationVM) InputBarFragment(im.actor.sdk.controllers.conversation.inputbar.InputBarFragment) Bundle(android.os.Bundle) ValueDoubleChangedListener(im.actor.runtime.mvvm.ValueDoubleChangedListener) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) ValueListener(im.actor.runtime.mvvm.ValueListener) GroupVM(im.actor.core.viewmodel.GroupVM) QuoteCallback(im.actor.sdk.controllers.conversation.quote.QuoteCallback) AutocompleteFragment(im.actor.sdk.controllers.conversation.mentions.AutocompleteFragment) AttachFragment(im.actor.sdk.controllers.conversation.attach.AttachFragment) Toast(android.widget.Toast) AbsAttachFragment(im.actor.sdk.controllers.conversation.attach.AbsAttachFragment) View(android.view.View) AutocompleteCallback(im.actor.sdk.controllers.conversation.mentions.AutocompleteCallback) GroupType(im.actor.core.entity.GroupType) PeerType(im.actor.core.entity.PeerType) Sticker(im.actor.core.entity.Sticker) ActorSDK(im.actor.sdk.ActorSDK) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) MessagesDefaultFragment(im.actor.sdk.controllers.conversation.messages.MessagesDefaultFragment) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) InputBarCallback(im.actor.sdk.controllers.conversation.inputbar.InputBarCallback) MessagesFragmentCallback(im.actor.sdk.controllers.conversation.messages.MessagesFragmentCallback) ViewGroup(android.view.ViewGroup) RpcException(im.actor.core.network.RpcException) EmptyChatPlaceholder(im.actor.sdk.controllers.conversation.placeholder.EmptyChatPlaceholder) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) TextView(android.widget.TextView) QuoteFragment(im.actor.sdk.controllers.conversation.quote.QuoteFragment) Configuration(android.content.res.Configuration) Peer(im.actor.core.entity.Peer) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) ValueChangedListener(im.actor.runtime.mvvm.ValueChangedListener) Value(im.actor.runtime.mvvm.Value) ChatToolbarFragment(im.actor.sdk.controllers.conversation.toolbar.ChatToolbarFragment) UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) ConversationVM(im.actor.core.viewmodel.ConversationVM)

Example 3 with GroupVM

use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.

the class ChatToolbarFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (peer.getPeerType() == PeerType.PRIVATE) {
        // Loading user
        UserVM user = users().get(peer.getPeerId());
        // Binding User Avatar to Toolbar
        bind(barAvatar, user.getId(), user.getAvatar(), user.getName());
        // Binding User name to Toolbar
        bind(barTitle, user.getName());
        bind(user.getIsVerified(), (val, valueModel) -> {
            barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, val ? new TintDrawable(getResources().getDrawable(R.drawable.ic_verified_user_black_18dp), ActorSDK.sharedActor().style.getVerifiedColor()) : null, null);
        });
        // Binding User presence to Toolbar
        bind(barSubtitle, user);
        // Binding User typing to Toolbar
        bindPrivateTyping(barTyping, barTypingContainer, barSubtitle, messenger().getTyping(user.getId()));
        // Refresh menu on contact state change
        bind(user.isContact(), (val, valueModel) -> {
            getActivity().invalidateOptionsMenu();
        });
    } else if (peer.getPeerType() == PeerType.GROUP) {
        // Loading group
        GroupVM group = groups().get(peer.getPeerId());
        // Binding Group avatar to Toolbar
        bind(barAvatar, group.getId(), group.getAvatar(), group.getName());
        // Binding Group title to Toolbar
        bind(barTitle, group.getName());
        if (group.getGroupType() == GroupType.CHANNEL) {
            barTitle.setCompoundDrawablesWithIntrinsicBounds(new TintDrawable(getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), Color.WHITE), null, null, null);
        } else {
            barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }
        // Subtitle is always visible for Groups
        barSubtitleContainer.setVisibility(View.VISIBLE);
        // Binding group members
        bind(barSubtitle, barSubtitleContainer, group);
        // Binding group typing
        if (group.getGroupType() == GroupType.GROUP) {
            bindGroupTyping(barTyping, barTypingContainer, barSubtitle, messenger().getGroupTyping(group.getId()));
        }
    }
    // Global Counter
    bind(messenger().getGlobalState().getGlobalCounter(), (val, valueModel) -> {
        if (val != null && val > 0) {
            counter.setText(Integer.toString(val));
            showView(counter);
        } else {
            hideView(counter);
        }
    });
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) TintDrawable(im.actor.sdk.view.TintDrawable)

Example 4 with GroupVM

use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.

the class MembersFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View res = inflater.inflate(R.layout.fragment_members, container, false);
    int groupId = getArguments().getInt("groupId");
    adapter = new MembersAdapter(getContext(), groupId);
    GroupVM groupVM = groups().get(groupId);
    RecyclerListView list = (RecyclerListView) res.findViewById(R.id.items);
    Boolean canInvite = groupVM.getIsCanInviteMembers().get();
    Boolean canInviteViaLink = groupVM.getIsCanInviteViaLink().get();
    if (canInvite || canInviteViaLink) {
        LinearLayout header = new LinearLayout(getActivity());
        list.addHeaderView(header);
        if (canInvite) {
            TextView addMmemberTV = new TextView(getContext());
            addMmemberTV.setBackgroundResource(R.drawable.selector);
            addMmemberTV.setTextSize(16);
            addMmemberTV.setPadding(Screen.dp(72), 0, 0, 0);
            addMmemberTV.setGravity(Gravity.CENTER_VERTICAL);
            addMmemberTV.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
            addMmemberTV.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
            addMmemberTV.setOnClickListener(view -> {
                startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupId));
            });
            header.addView(addMmemberTV, ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(58));
        }
        if (canInvite && canInviteViaLink) {
            header.addView(new DividerView(getActivity()), ViewGroup.LayoutParams.MATCH_PARENT, 1);
        }
        if (canInviteViaLink) {
            TextView shareLinkTV = new TextView(getContext());
            shareLinkTV.setBackgroundResource(R.drawable.selector);
            shareLinkTV.setTextSize(16);
            shareLinkTV.setPadding(Screen.dp(72), 0, 0, 0);
            shareLinkTV.setGravity(Gravity.CENTER_VERTICAL);
            shareLinkTV.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
            shareLinkTV.setText(R.string.invite_link_action_share);
            shareLinkTV.setOnClickListener(view -> Intents.inviteLink(groupId, getActivity()));
            header.addView(shareLinkTV, ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(58));
        }
    }
    footer = new LinearLayout(getActivity());
    footer.setVisibility(View.INVISIBLE);
    list.addFooterView(footer);
    CircularProgressBar botProgressView = new CircularProgressBar(getActivity());
    int padding = Screen.dp(16);
    botProgressView.setPadding(padding, padding, padding, padding);
    botProgressView.setIndeterminate(true);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Screen.dp(72), Screen.dp(72));
    params.gravity = Gravity.CENTER;
    FrameLayout cont = new FrameLayout(getActivity());
    cont.addView(botProgressView, params);
    footer.addView(cont, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    list.setAdapter(adapter);
    list.setOnItemClickListener((parent, view, position, id) -> {
        Object item = parent.getItemAtPosition(position);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    startActivity(Intents.openPrivateDialog(userVM.getId(), true, getActivity()));
                }
            }
        }
    });
    list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            Object item = adapterView.getItemAtPosition(i);
            if (item != null && item instanceof GroupMember) {
                GroupMember groupMember = (GroupMember) item;
                if (groupMember.getUid() != myUid()) {
                    UserVM userVM = users().get(groupMember.getUid());
                    if (userVM != null) {
                        adapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
                        return true;
                    }
                }
            }
            return false;
        }
    });
    progressView = (CircularProgressBar) res.findViewById(R.id.loadingProgress);
    progressView.setIndeterminate(true);
    return res;
}
Also used : MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) GroupMember(im.actor.core.entity.GroupMember) GroupVM(im.actor.core.viewmodel.GroupVM) DividerView(im.actor.sdk.view.DividerView) CircularProgressBar(fr.castorflex.android.circularprogressbar.CircularProgressBar) Intent(android.content.Intent) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) AdapterView(android.widget.AdapterView) DividerView(im.actor.sdk.view.DividerView) TextView(android.widget.TextView) UserVM(im.actor.core.viewmodel.UserVM) FrameLayout(android.widget.FrameLayout) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout) Nullable(android.support.annotation.Nullable)

Example 5 with GroupVM

use of im.actor.core.viewmodel.GroupVM in project actor-platform by actorapp.

the class MembersAdapter method onMemberClick.

public void onMemberClick(GroupVM groupVM, UserVM userVM, boolean isAdministrator, boolean isInvitedByMe, BaseActivity activity) {
    AlertListBuilder alertListBuilder = new AlertListBuilder();
    final ArrayList<UserPhone> phones = userVM.getPhones().get();
    alertListBuilder.addItem(activity.getString(R.string.group_context_message).replace("{0}", userVM.getName().get()), () -> activity.startActivity(Intents.openPrivateDialog(userVM.getId(), true, activity)));
    if (phones.size() != 0) {
        alertListBuilder.addItem(activity.getString(R.string.group_context_call).replace("{0}", userVM.getName().get()), () -> {
            if (phones.size() == 1) {
                activity.startActivity(Intents.call(phones.get(0).getPhone()));
            } else {
                CharSequence[] sequences = new CharSequence[phones.size()];
                for (int i = 0; i < sequences.length; i++) {
                    try {
                        Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + phones.get(i).getPhone(), "us");
                        sequences[i] = phones.get(i).getTitle() + ": " + PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
                    } catch (NumberParseException e) {
                        e.printStackTrace();
                        sequences[i] = phones.get(i).getTitle() + ": +" + phones.get(i).getPhone();
                    }
                }
                new AlertDialog.Builder(activity).setItems(sequences, (dialog1, which1) -> {
                    activity.startActivity(Intents.call(phones.get(which1).getPhone()));
                }).show().setCanceledOnTouchOutside(true);
            }
        });
    }
    alertListBuilder.addItem(activity.getString(R.string.group_context_view).replace("{0}", userVM.getName().get()), () -> ActorSDKLauncher.startProfileActivity(activity, userVM.getId()));
    if (groupVM.getIsCanKickAnyone().get() || (groupVM.getIsCanKickInvited().get() && isInvitedByMe)) {
        alertListBuilder.addItem(activity.getString(R.string.group_context_remove).replace("{0}", userVM.getName().get()), () -> {
            new AlertDialog.Builder(activity).setMessage(activity.getString(R.string.alert_group_remove_text).replace("{0}", userVM.getName().get())).setPositiveButton(R.string.alert_group_remove_yes, (dialog2, which1) -> {
                activity.execute(messenger().kickMember(groupVM.getId(), userVM.getId()), R.string.progress_common, new CommandCallback<Void>() {

                    @Override
                    public void onResult(Void res1) {
                    }

                    @Override
                    public void onError(Exception e) {
                        Toast.makeText(activity, R.string.toast_unable_kick, Toast.LENGTH_SHORT).show();
                    }
                });
            }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
        });
    }
    if (groupVM.getIsCanEditAdmins().get() && !userVM.isBot()) {
        alertListBuilder.addItem(!isAdministrator ? activity.getResources().getString(R.string.group_make_admin) : activity.getResources().getString(R.string.group_revoke_admin), () -> {
            if (!isAdministrator) {
                messenger().makeAdmin(groupVM.getId(), userVM.getId()).start(new CommandCallback<Void>() {

                    @Override
                    public void onResult(Void res) {
                    }

                    @Override
                    public void onError(Exception e) {
                    }
                });
            } else {
                messenger().revokeAdmin(groupVM.getId(), userVM.getId()).start(new CommandCallback<Void>() {

                    @Override
                    public void onResult(Void res) {
                    }

                    @Override
                    public void onError(Exception e) {
                    }
                });
            }
        });
    }
    alertListBuilder.build(activity).show().setCanceledOnTouchOutside(true);
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) Arrays(java.util.Arrays) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) GroupVM(im.actor.core.viewmodel.GroupVM) ArrayList(java.util.ArrayList) Screen(im.actor.sdk.util.Screen) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) Toast(android.widget.Toast) AvatarView(im.actor.sdk.view.avatar.AvatarView) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) HolderAdapter(im.actor.sdk.view.adapters.HolderAdapter) Intents(im.actor.sdk.controllers.Intents) ActorSDK(im.actor.sdk.ActorSDK) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) Void(im.actor.runtime.actors.messages.Void) Collection(java.util.Collection) GroupMember(im.actor.core.entity.GroupMember) im.actor.runtime.actors.messages(im.actor.runtime.actors.messages) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) UserPhone(im.actor.core.viewmodel.UserPhone) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) AlertDialog(android.app.AlertDialog) R(im.actor.sdk.R) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Optional(java.util.Optional) Activity(android.app.Activity) ViewHolder(im.actor.sdk.view.adapters.ViewHolder) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) UserPhone(im.actor.core.viewmodel.UserPhone) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) CommandCallback(im.actor.core.viewmodel.CommandCallback) Void(im.actor.runtime.actors.messages.Void) Phonenumber(com.google.i18n.phonenumbers.Phonenumber)

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