Search in sources :

Example 1 with TrendingStickersLayout

use of org.telegram.ui.Components.TrendingStickersLayout in project Telegram-FOSS by Telegram-FOSS-Team.

the class StickersActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setAllowOverlayTitle(true);
    if (currentType == MediaDataController.TYPE_IMAGE) {
        actionBar.setTitle(LocaleController.getString("StickersName", R.string.StickersName));
    } else {
        actionBar.setTitle(LocaleController.getString("Masks", R.string.Masks));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (onBackPressed()) {
                    finishFragment();
                }
            } else if (id == MENU_ARCHIVE || id == MENU_DELETE || id == MENU_SHARE) {
                if (!needReorder) {
                    if (activeReorderingRequests == 0) {
                        listAdapter.processSelectionMenu(id);
                    }
                } else {
                    sendReorder();
                }
            }
        }
    });
    final ActionBarMenu actionMode = actionBar.createActionMode();
    selectedCountTextView = new NumberTextView(actionMode.getContext());
    selectedCountTextView.setTextSize(18);
    selectedCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
    actionMode.addView(selectedCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 72, 0, 0, 0));
    selectedCountTextView.setOnTouchListener((v, event) -> true);
    shareMenuItem = actionMode.addItemWithWidth(MENU_SHARE, R.drawable.msg_share, AndroidUtilities.dp(54));
    archiveMenuItem = actionMode.addItemWithWidth(MENU_ARCHIVE, R.drawable.msg_archive, AndroidUtilities.dp(54));
    deleteMenuItem = actionMode.addItemWithWidth(MENU_DELETE, R.drawable.msg_delete, AndroidUtilities.dp(54));
    listAdapter = new ListAdapter(context, MediaDataController.getInstance(currentAccount).getStickerSets(currentType));
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setFocusable(true);
    listView.setTag(7);
    layoutManager = new LinearLayoutManager(context) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }

        @Override
        protected void calculateExtraLayoutSpace(@NonNull RecyclerView.State state, @NonNull int[] extraLayoutSpace) {
            extraLayoutSpace[1] = listView.getHeight();
        }
    };
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    listView.setLayoutManager(layoutManager);
    itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
    itemTouchHelper.attachToRecyclerView(listView);
    itemAnimator = (DefaultItemAnimator) listView.getItemAnimator();
    itemAnimator.setSupportsChangeAnimations(false);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (position >= stickersStartRow && position < stickersEndRow && getParentActivity() != null) {
            if (!listAdapter.hasSelected()) {
                final TLRPC.TL_messages_stickerSet stickerSet = listAdapter.stickerSets.get(position - stickersStartRow);
                ArrayList<TLRPC.Document> stickers = stickerSet.documents;
                if (stickers == null || stickers.isEmpty()) {
                    return;
                }
                showDialog(new StickersAlert(getParentActivity(), StickersActivity.this, null, stickerSet, null));
            } else {
                listAdapter.toggleSelected(position);
            }
        } else if (position == featuredRow) {
            final TrendingStickersLayout.Delegate trendingDelegate = new TrendingStickersLayout.Delegate() {

                @Override
                public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet, boolean primary) {
                    MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 2, StickersActivity.this, false, false);
                }

                @Override
                public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
                    MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 0, StickersActivity.this, false, false);
                }
            };
            trendingStickersAlert = new TrendingStickersAlert(context, this, new TrendingStickersLayout(context, trendingDelegate), null);
            trendingStickersAlert.show();
        } else if (position == archivedRow) {
            presentFragment(new ArchivedStickersActivity(currentType));
        } else if (position == masksRow) {
            presentFragment(new StickersActivity(MediaDataController.TYPE_MASK));
        } else if (position == suggestRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("SuggestStickers", R.string.SuggestStickers));
            String[] items = new String[] { LocaleController.getString("SuggestStickersAll", R.string.SuggestStickersAll), LocaleController.getString("SuggestStickersInstalled", R.string.SuggestStickersInstalled), LocaleController.getString("SuggestStickersNone", R.string.SuggestStickersNone) };
            final LinearLayout linearLayout = new LinearLayout(getParentActivity());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            builder.setView(linearLayout);
            for (int a = 0; a < items.length; a++) {
                RadioColorCell cell = new RadioColorCell(getParentActivity());
                cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                cell.setTag(a);
                cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
                cell.setTextAndValue(items[a], SharedConfig.suggestStickers == a);
                linearLayout.addView(cell);
                cell.setOnClickListener(v -> {
                    Integer which = (Integer) v.getTag();
                    SharedConfig.setSuggestStickers(which);
                    listAdapter.notifyItemChanged(suggestRow);
                    builder.getDismissRunnable().run();
                });
            }
            showDialog(builder.create());
        } else if (position == loopRow) {
            SharedConfig.toggleLoopStickers();
            listAdapter.notifyItemChanged(loopRow, ListAdapter.UPDATE_LOOP_STICKERS);
        }
    });
    listView.setOnItemLongClickListener((view, position) -> {
        if (!listAdapter.hasSelected() && position >= stickersStartRow && position < stickersEndRow) {
            listAdapter.toggleSelected(position);
            return true;
        } else {
            return false;
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) NumberTextView(org.telegram.ui.Components.NumberTextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) TrendingStickersLayout(org.telegram.ui.Components.TrendingStickersLayout) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) SuppressLint(android.annotation.SuppressLint) StickersAlert(org.telegram.ui.Components.StickersAlert) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) RadioColorCell(org.telegram.ui.Cells.RadioColorCell) LinearLayout(android.widget.LinearLayout)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 TLRPC (org.telegram.tgnet.TLRPC)1 ActionBar (org.telegram.ui.ActionBar.ActionBar)1 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)1 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)1 BackDrawable (org.telegram.ui.ActionBar.BackDrawable)1 RadioColorCell (org.telegram.ui.Cells.RadioColorCell)1 NumberTextView (org.telegram.ui.Components.NumberTextView)1 RecyclerListView (org.telegram.ui.Components.RecyclerListView)1 StickersAlert (org.telegram.ui.Components.StickersAlert)1 TrendingStickersAlert (org.telegram.ui.Components.TrendingStickersAlert)1 TrendingStickersLayout (org.telegram.ui.Components.TrendingStickersLayout)1