Search in sources :

Example 1 with BaseActivity

use of im.actor.sdk.controllers.activity.BaseActivity 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 2 with BaseActivity

use of im.actor.sdk.controllers.activity.BaseActivity 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)

Example 3 with BaseActivity

use of im.actor.sdk.controllers.activity.BaseActivity in project actor-platform by actorapp.

the class BaseActorSettingsFragment method updateActionBar.

private void updateActionBar(int offset) {
    if (!animateToolbar) {
        return;
    }
    Activity activity = getActivity();
    if (!(activity instanceof BaseActivity)) {
        return;
    }
    ActionBar bar = ((BaseActivity) getActivity()).getSupportActionBar();
    if (bar == null) {
        return;
    }
    int fullColor = baseColor;
    ActorStyle style = ActorSDK.sharedActor().style;
    if (style.getToolBarColor() != 0) {
        fullColor = style.getToolBarColor();
    }
    if (Math.abs(offset) > Screen.dp(248 - 56)) {
        bar.setBackgroundDrawable(new ColorDrawable(fullColor));
    } else {
        float alpha = Math.abs(offset) / (float) Screen.dp(248 - 56);
        bar.setBackgroundDrawable(new ColorDrawable(Color.argb((int) (255 * alpha), Color.red(fullColor), Color.green(fullColor), Color.blue(fullColor))));
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ActorStyle(im.actor.sdk.ActorStyle) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) ViewAvatarActivity(im.actor.sdk.controllers.fragment.preview.ViewAvatarActivity) HelpActivity(im.actor.sdk.controllers.fragment.help.HelpActivity) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) Activity(android.app.Activity) ActionBar(android.support.v7.app.ActionBar)

Example 4 with BaseActivity

use of im.actor.sdk.controllers.activity.BaseActivity in project actor-platform by actorapp.

the class CallBackgroundAvatarView method bind.

public void bind(Avatar avatar) {
    // Same avatar
    if (avatar != null && getImage(avatar) != null && getImage(avatar).getFileReference().getFileId() == currentId) {
        return;
    }
    fastThumbLoader = new FastThumbLoader(this);
    fastThumbLoader.setBlur(10);
    if (bindedFile != null) {
        bindedFile.detach();
        bindedFile = null;
    }
    setImageURI(null);
    if (avatar == null || getImage(avatar) == null) {
        currentId = 0;
        return;
    }
    currentId = getImage(avatar).getFileReference().getFileId();
    bindedFile = messenger().bindFile(getImage(avatar).getFileReference(), true, new FileVMCallback() {

        @Override
        public void onNotDownloaded() {
        }

        @Override
        public void onDownloading(float progress) {
        }

        @Override
        public void onDownloaded(FileSystemReference reference) {
            blurActor.send(new BlurActor.RequestBlur(reference.getDescriptor(), 10, new BlurActor.BluredListener() {

                @Override
                public void onBlured(final File f) {
                    ((BaseActivity) getContext()).runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(f)).setResizeOptions(new ResizeOptions(Screen.getWidth(), Screen.getHeight())).build();
                            PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder().setOldController(getController()).setImageRequest(request).build();
                            setController(controller);
                        }
                    });
                }
            }));
        }
    });
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) FastThumbLoader(im.actor.sdk.controllers.conversation.view.FastThumbLoader) PipelineDraweeController(com.facebook.drawee.backends.pipeline.PipelineDraweeController) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) File(java.io.File) FileVMCallback(im.actor.core.viewmodel.FileVMCallback)

Example 5 with BaseActivity

use of im.actor.sdk.controllers.activity.BaseActivity in project actor-platform by actorapp.

the class GroupInfoFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    chatId = getArguments().getInt(EXTRA_CHAT_ID);
    groupVM = groups().get(chatId);
    View res = inflater.inflate(R.layout.fragment_group, container, false);
    listView = (RecyclerListView) res.findViewById(R.id.groupList);
    notMemberView = res.findViewById(R.id.notMember);
    res.setBackgroundColor(style.getMainBackgroundColor());
    // listView.setBackgroundColor(style.getMainBackgroundColor());
    notMemberView.setBackgroundColor(style.getMainBackgroundColor());
    ((TextView) notMemberView.findViewById(R.id.not_member_text)).setTextColor(style.getTextPrimaryColor());
    // 
    // Header
    // 
    // Views
    View header = inflater.inflate(R.layout.fragment_group_header, listView, false);
    TextView title = (TextView) header.findViewById(R.id.title);
    TextView subtitle = (TextView) header.findViewById(R.id.subtitle);
    avatarView = (AvatarView) header.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(48), 22);
    TextView aboutTV = (TextView) header.findViewById(R.id.about);
    View shortNameCont = header.findViewById(R.id.shortNameContainer);
    TextView shortNameView = (TextView) header.findViewById(R.id.shortName);
    TextView shortLinkView = (TextView) header.findViewById(R.id.shortNameLink);
    TextView addMember = (TextView) header.findViewById(R.id.addMemberAction);
    addMember.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
    TextView members = (TextView) header.findViewById(R.id.viewMembersAction);
    TextView leaveAction = (TextView) header.findViewById(R.id.leaveAction);
    TextView administrationAction = (TextView) header.findViewById(R.id.administrationAction);
    View descriptionContainer = header.findViewById(R.id.descriptionContainer);
    SwitchCompat isNotificationsEnabled = (SwitchCompat) header.findViewById(R.id.enableNotifications);
    // Styling
    // ((TextView) header.findViewById(R.id.about_hint)).setTextColor(style.getTextSecondaryColor());
    header.setBackgroundColor(style.getMainBackgroundColor());
    header.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
    title.setTextColor(style.getProfileTitleColor());
    subtitle.setTextColor(style.getProfileSubtitleColor());
    aboutTV.setTextColor(style.getTextPrimaryColor());
    shortNameView.setTextColor(style.getTextPrimaryColor());
    shortLinkView.setTextColor(style.getTextSecondaryColor());
    // settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    ((TintImageView) header.findViewById(R.id.settings_notification_icon)).setTint(style.getSettingsIconColor());
    ((TintImageView) header.findViewById(R.id.settings_about_icon)).setTint(style.getSettingsIconColor());
    ((TextView) header.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
    ((TextView) header.findViewById(R.id.addMemberAction)).setTextColor(style.getTextPrimaryColor());
    members.setTextColor(style.getTextPrimaryColor());
    administrationAction.setTextColor(style.getTextPrimaryColor());
    leaveAction.setTextColor(style.getTextDangerColor());
    if (groupVM.getGroupType() == GroupType.CHANNEL) {
        leaveAction.setText(R.string.group_leave_channel);
    } else {
        leaveAction.setText(R.string.group_leave);
    }
    header.findViewById(R.id.after_settings_divider).setBackgroundColor(style.getBackyardBackgroundColor());
    // 
    // Header
    // 
    avatarView.bind(groupVM.getAvatar().get(), groupVM.getName().get(), groupVM.getId());
    avatarView.setOnClickListener(view -> {
        if (groupVM.getAvatar().get() != null) {
            startActivity(ViewAvatarActivity.viewGroupAvatar(chatId, getActivity()));
        }
    });
    bind(groupVM.getName(), name -> {
        title.setText(name);
    });
    bind(groupVM.getMembersCount(), val -> {
        subtitle.setText(messenger().getFormatter().formatGroupMembers(val));
    });
    // About
    bind(groupVM.getAbout(), (about) -> {
        aboutTV.setText(about);
        aboutTV.setVisibility(about != null ? View.VISIBLE : View.GONE);
    });
    bind(groupVM.getShortName(), shortName -> {
        if (shortName != null) {
            shortNameView.setText("@" + shortName);
            String prefix = ActorSDK.sharedActor().getGroupInvitePrefix();
            if (prefix != null) {
                shortLinkView.setText(prefix + shortName);
                shortLinkView.setVisibility(View.VISIBLE);
            } else {
                shortLinkView.setVisibility(View.GONE);
            }
        }
        shortNameCont.setVisibility(shortName != null ? View.VISIBLE : View.GONE);
    });
    final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    shortNameCont.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String link = shortLinkView.getText().toString();
            clipboard.setPrimaryClip(ClipData.newPlainText(null, (link.contains("://") ? "" : "https://") + link));
            Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
        }
    });
    bind(groupVM.getAbout(), groupVM.getShortName(), (about, shortName) -> {
        descriptionContainer.setVisibility(about != null || shortName != null ? View.VISIBLE : View.GONE);
    });
    // Notifications
    isNotificationsEnabled.setChecked(messenger().isNotificationsEnabled(Peer.group(chatId)));
    isNotificationsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> {
        messenger().changeNotificationsEnabled(Peer.group(chatId), isChecked);
    });
    header.findViewById(R.id.notificationsCont).setOnClickListener(v -> {
        isNotificationsEnabled.setChecked(!isNotificationsEnabled.isChecked());
    });
    // Add Member
    bind(groupVM.getIsCanInviteMembers(), (canInvite) -> {
        if (canInvite) {
            addMember.setVisibility(View.VISIBLE);
        } else {
            addMember.setVisibility(View.GONE);
        }
    });
    addMember.setOnClickListener(view -> {
        startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
    });
    // Administration
    if (groupVM.getIsCanEditAdministration().get() || groupVM.getIsCanDelete().get()) {
        administrationAction.setOnClickListener(view -> {
            startActivity(new Intent(getActivity(), GroupAdminActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
        });
    } else {
        administrationAction.setVisibility(View.GONE);
    }
    // Async Members
    // Showing member only when members available and async members is enabled
    bind(groupVM.getIsCanViewMembers(), groupVM.getIsAsyncMembers(), (canViewMembers, vm1, isAsync, vm2) -> {
        if (canViewMembers) {
            if (isAsync) {
                members.setVisibility(View.VISIBLE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
            } else {
                members.setVisibility(View.GONE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.VISIBLE);
            }
        } else {
            members.setVisibility(View.GONE);
            header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
        }
    });
    members.setOnClickListener(view -> {
        startActivity(new Intent(getContext(), MembersActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupVM.getId()));
    });
    // Leave
    bind(groupVM.getIsCanLeave(), canLeave -> {
        if (canLeave) {
            leaveAction.setVisibility(View.VISIBLE);
            leaveAction.setOnClickListener(view1 -> {
                new AlertDialog.Builder(getActivity()).setMessage(getString(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.alert_leave_channel_message : R.string.alert_leave_group_message).replace("%1$s", groupVM.getName().get())).setPositiveButton(R.string.alert_leave_group_yes, (dialog2, which) -> {
                    execute(messenger().leaveAndDeleteGroup(chatId).then(aVoid -> ActorSDK.returnToRoot(getActivity())));
                }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
            });
        } else {
            leaveAction.setVisibility(View.GONE);
        }
    });
    listView.addHeaderView(header, null, false);
    // 
    // Members
    // 
    groupUserAdapter = new MembersAdapter(getActivity(), getArguments().getInt("groupId"));
    listView.setAdapter(groupUserAdapter);
    listView.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()));
                }
            }
        }
    });
    listView.setOnItemLongClickListener((adapterView, view, i, 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) {
                    groupUserAdapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
                    return true;
                }
            }
        }
        return false;
    });
    // 
    // Scroll handling
    // 
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem >= 1) {
                updateBar(Integer.MAX_VALUE);
            } else {
                View top = listView.getChildAt(0);
                if (top != null) {
                    updateBar(-top.getTop());
                } else {
                    updateBar(Integer.MAX_VALUE);
                }
            }
        }
    });
    // 
    // Placeholder
    // 
    bind(groupVM.isMember(), (isMember) -> {
        notMemberView.setVisibility(isMember ? View.GONE : View.VISIBLE);
        getActivity().invalidateOptionsMenu();
    });
    // Menu
    bind(groupVM.getIsCanEditInfo(), canEditInfo -> {
        getActivity().invalidateOptionsMenu();
    });
    return res;
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) Bundle(android.os.Bundle) ViewAvatarActivity(im.actor.sdk.controllers.fragment.preview.ViewAvatarActivity) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) ColorDrawable(android.graphics.drawable.ColorDrawable) Screen(im.actor.sdk.util.Screen) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) ClipboardManager(android.content.ClipboardManager) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Intents(im.actor.sdk.controllers.Intents) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) Void(im.actor.runtime.actors.messages.Void) GroupMember(im.actor.core.entity.GroupMember) UserPhone(im.actor.core.viewmodel.UserPhone) SwitchCompat(android.support.v7.widget.SwitchCompat) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) Peer(im.actor.core.entity.Peer) ActorStyle(im.actor.sdk.ActorStyle) Context(android.content.Context) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) TintImageView(im.actor.sdk.view.TintImageView) Intent(android.content.Intent) GroupVM(im.actor.core.viewmodel.GroupVM) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) AvatarView(im.actor.sdk.view.avatar.AvatarView) ActionBar(android.support.v7.app.ActionBar) GroupType(im.actor.core.entity.GroupType) ActorSDK(im.actor.sdk.ActorSDK) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) AbsListView(android.widget.AbsListView) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) Color(android.graphics.Color) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) GroupMember(im.actor.core.entity.GroupMember) TintImageView(im.actor.sdk.view.TintImageView) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) TextView(android.widget.TextView) TintImageView(im.actor.sdk.view.TintImageView) AvatarView(im.actor.sdk.view.avatar.AvatarView) AbsListView(android.widget.AbsListView) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

BaseActivity (im.actor.sdk.controllers.activity.BaseActivity)5 View (android.view.View)3 TextView (android.widget.TextView)3 GroupMember (im.actor.core.entity.GroupMember)3 GroupVM (im.actor.core.viewmodel.GroupVM)3 UserVM (im.actor.core.viewmodel.UserVM)3 Activity (android.app.Activity)2 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 Intent (android.content.Intent)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 ActionBar (android.support.v7.app.ActionBar)2 ViewGroup (android.view.ViewGroup)2 Toast (android.widget.Toast)2 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)2 PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)2 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)2 CommandCallback (im.actor.core.viewmodel.CommandCallback)2 UserPhone (im.actor.core.viewmodel.UserPhone)2 Void (im.actor.runtime.actors.messages.Void)2