Search in sources :

Example 1 with AvailableReactionCell

use of org.telegram.ui.Cells.AvailableReactionCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatReactionsEditActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("Reactions", R.string.Reactions));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(LinearLayout.VERTICAL);
    availableReactions.addAll(getMediaDataController().getEnabledReactionsList());
    enableReactionsCell = new TextCheckCell(context);
    enableReactionsCell.setHeight(56);
    enableReactionsCell.setTextAndCheck(LocaleController.getString("EnableReactions", R.string.EnableReactions), !chatReactions.isEmpty(), false);
    enableReactionsCell.setBackgroundColor(Theme.getColor(enableReactionsCell.isChecked() ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked));
    enableReactionsCell.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    enableReactionsCell.setAnimatingToThumbInsteadOfTouch(true);
    enableReactionsCell.setOnClickListener(v -> {
        setCheckedEnableReactionCell(!enableReactionsCell.isChecked());
    });
    ll.addView(enableReactionsCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    listView = new RecyclerListView(context);
    listView.setLayoutManager(new LinearLayoutManager(context));
    listView.setAdapter(listAdapter = new RecyclerView.Adapter() {

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            switch(viewType) {
                default:
                case TYPE_REACTION:
                    {
                        return new RecyclerListView.Holder(new AvailableReactionCell(context, false));
                    }
                case TYPE_INFO:
                    {
                        TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
                        return new RecyclerListView.Holder(infoCell);
                    }
                case TYPE_HEADER:
                    {
                        return new RecyclerListView.Holder(new HeaderCell(context, 23));
                    }
            }
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            switch(getItemViewType(position)) {
                case TYPE_INFO:
                    TextInfoPrivacyCell infoCell = (TextInfoPrivacyCell) holder.itemView;
                    infoCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
                    infoCell.setText(ChatObject.isChannelAndNotMegaGroup(currentChat) ? LocaleController.getString("EnableReactionsChannelInfo", R.string.EnableReactionsChannelInfo) : LocaleController.getString("EnableReactionsGroupInfo", R.string.EnableReactionsGroupInfo));
                    break;
                case TYPE_HEADER:
                    HeaderCell headerCell = (HeaderCell) holder.itemView;
                    headerCell.setText(LocaleController.getString("AvailableReactions", R.string.AvailableReactions));
                    headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    break;
                case TYPE_REACTION:
                    AvailableReactionCell reactionCell = (AvailableReactionCell) holder.itemView;
                    TLRPC.TL_availableReaction react = availableReactions.get(position - 2);
                    reactionCell.bind(react, chatReactions.contains(react.reaction));
                    break;
            }
        }

        @Override
        public int getItemCount() {
            return 1 + (!chatReactions.isEmpty() ? 1 + availableReactions.size() : 0);
        }

        @Override
        public int getItemViewType(int position) {
            return position == 0 ? TYPE_INFO : position == 1 ? TYPE_HEADER : TYPE_REACTION;
        }
    });
    listView.setOnItemClickListener((view, position) -> {
        if (position <= 1)
            return;
        AvailableReactionCell cell = (AvailableReactionCell) view;
        TLRPC.TL_availableReaction react = availableReactions.get(position - 2);
        boolean nc = !chatReactions.contains(react.reaction);
        if (nc) {
            chatReactions.add(react.reaction);
        } else {
            chatReactions.remove(react.reaction);
            if (chatReactions.isEmpty()) {
                setCheckedEnableReactionCell(false);
            }
        }
        cell.setChecked(nc, true);
    });
    ll.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 0, 1f));
    fragmentView = contentView = ll;
    updateColors();
    return contentView;
}
Also used : TextCheckCell(org.telegram.ui.Cells.TextCheckCell) ViewGroup(android.view.ViewGroup) HeaderCell(org.telegram.ui.Cells.HeaderCell) AvailableReactionCell(org.telegram.ui.Cells.AvailableReactionCell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) NonNull(androidx.annotation.NonNull) RecyclerView(androidx.recyclerview.widget.RecyclerView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout)

Example 2 with AvailableReactionCell

use of org.telegram.ui.Cells.AvailableReactionCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ReactionsDoubleTapManageActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("Reactions", R.string.Reactions));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    LinearLayout linaerLayout = new LinearLayout(context);
    linaerLayout.setOrientation(LinearLayout.VERTICAL);
    listView = new RecyclerListView(context);
    listView.setLayoutManager(new LinearLayoutManager(context));
    listView.setAdapter(listAdapter = new RecyclerView.Adapter() {

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view;
            switch(viewType) {
                case 0:
                    ThemePreviewMessagesCell messagesCell = new ThemePreviewMessagesCell(context, parentLayout, ThemePreviewMessagesCell.TYPE_REACTIONS_DOUBLE_TAP);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        messagesCell.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
                    }
                    messagesCell.fragment = ReactionsDoubleTapManageActivity.this;
                    view = messagesCell;
                    break;
                case 2:
                    TextInfoPrivacyCell cell = new TextInfoPrivacyCell(context);
                    cell.setText(LocaleController.getString("DoubleTapPreviewRational", R.string.DoubleTapPreviewRational));
                    view = cell;
                    break;
                default:
                case 1:
                    {
                        view = new AvailableReactionCell(context, true);
                    }
                    break;
            }
            return new RecyclerListView.Holder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            switch(getItemViewType(position)) {
                case 1:
                    AvailableReactionCell reactionCell = (AvailableReactionCell) holder.itemView;
                    TLRPC.TL_availableReaction react = getAvailableReactions().get(position - reactionsStartRow);
                    reactionCell.bind(react, react.reaction.contains(MediaDataController.getInstance(currentAccount).getDoubleTapReaction()));
                    break;
            }
        }

        @Override
        public int getItemCount() {
            return getAvailableReactions().size();
        }

        @Override
        public int getItemViewType(int position) {
            if (position == previewRow) {
                return 0;
            }
            if (position == infoRow) {
                return 2;
            }
            return 1;
        }
    });
    listView.setOnItemClickListener((view, position) -> {
        if (view instanceof AvailableReactionCell) {
            MediaDataController.getInstance(currentAccount).setDoubleTapReaction(((AvailableReactionCell) view).react.reaction);
            AndroidUtilities.updateVisibleRows(listView);
        }
    });
    linaerLayout.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    fragmentView = contentView = linaerLayout;
    updateColors();
    updateRows();
    return contentView;
}
Also used : ThemePreviewMessagesCell(org.telegram.ui.Cells.ThemePreviewMessagesCell) ViewGroup(android.view.ViewGroup) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) AvailableReactionCell(org.telegram.ui.Cells.AvailableReactionCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) NonNull(androidx.annotation.NonNull) RecyclerView(androidx.recyclerview.widget.RecyclerView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 ViewGroup (android.view.ViewGroup)2 LinearLayout (android.widget.LinearLayout)2 NonNull (androidx.annotation.NonNull)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 TLRPC (org.telegram.tgnet.TLRPC)2 ActionBar (org.telegram.ui.ActionBar.ActionBar)2 AvailableReactionCell (org.telegram.ui.Cells.AvailableReactionCell)2 TextInfoPrivacyCell (org.telegram.ui.Cells.TextInfoPrivacyCell)2 RecyclerListView (org.telegram.ui.Components.RecyclerListView)2 View (android.view.View)1 HeaderCell (org.telegram.ui.Cells.HeaderCell)1 TextCheckCell (org.telegram.ui.Cells.TextCheckCell)1 ThemePreviewMessagesCell (org.telegram.ui.Cells.ThemePreviewMessagesCell)1