Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setDismissOnLongPressStop don't work on my adapter #8

Open
pishguy opened this issue Jul 15, 2017 · 15 comments
Open

setDismissOnLongPressStop don't work on my adapter #8

pishguy opened this issue Jul 15, 2017 · 15 comments

Comments

@pishguy
Copy link

pishguy commented Jul 15, 2017

Thanks to release this useful library, unfortunately in my adapter setDismissOnLongPressStop don't work, could you check this code please?

    public class UserChannelsViewHolder extends RecyclerView.ViewHolder
            implements PopupInflaterListener, View.OnClickListener, PopupStateListener, PopupOnHoverListener {
        ...
        private LongPressPopup mPopup;
        private ImageView      mPopupImg;
        private TextView       mPopupTitle;

        public UserChannelsViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

            title.setTextSize(AndroidUtilities.dp(15));
            description.setTextSize(AndroidUtilities.dp(11));

            iconCafeWebUserCount.setTextSize(AndroidUtilities.dp(11));
            iconVisitCafeWeb.setTextSize(AndroidUtilities.dp(11));

            title.setTypeface(FontManager.getInstance(context).loadFont("fonts/vazir_bold.ttf"));
            description.setTypeface(FontManager.getInstance(context).loadFont("fonts/vazir.ttf"));

            mPopup = new LongPressPopupBuilder(itemView.getContext())
                    .setTarget(imageAvatar)
                    .setPopupView(R.layout.popup_layout, this)
                    .setAnimationType(LongPressPopup.ANIMATION_TYPE_FROM_CENTER)
                    .setPopupListener(this)
                    .setOnHoverListener(this)
                    .setLongPressDuration(750)
                    .setDismissOnLongPressStop(true)
                    .setDismissOnTouchOutside(true)
                    .setDismissOnBackPressed(true)
                    .setCancelTouchOnDragOutsideView(true)
                    .setLongPressReleaseListener(this)
                    .build();
            mPopup.register();
        }

        @Override
        public void onClick(View v) {

        }

        @Override
        public void onHoverChanged(View view, boolean isHovered) {
            if (isHovered) {
                if (view.getId() == mPopupTitle.getId()) {
                } else if (view.getId() == mPopupImg.getId()) {
                }
            }
        }

        @Override
        public void onPopupShow(@Nullable String popupTag) {
            if (mPopupImg != null) {
                Picasso.with(context)
                        .load("http://cdn.time.ir/App_Themes/Default-fa-IR/Images/summerHeader.jpg")
                        .networkPolicy(NetworkPolicy.OFFLINE)
                        .into(mPopupImg);
            }

            if (mPopupTitle != null) {
                mPopupTitle.setText(list.get(getAdapterPosition()).getCafeName());
            }
        }

        @Override
        public void onPopupDismiss(@Nullable String popupTag) {

        }

        @Override
        public void onViewInflated(@Nullable String popupTag, View root) {
            mPopupImg = (ImageView) root.findViewById(R.id.popup_img);
            mPopupTitle = (TextView) root.findViewById(R.id.popup_title);

            mPopupTitle.setOnClickListener(this);
        }
    }
}

@RiccardoMoro
Copy link
Owner

Hi! Thanks for using this library!

Try to remove this four lines
.setDismissOnLongPressStop(true)
.setDismissOnTouchOutside(true)
.setDismissOnBackPressed(true)
.setCancelTouchOnDragOutsideView(true)

If I understood correctly, the behaviour you're trying to achieve is the default of this library, you don't need to set anything particular in the builder

If you set
.setDismissOnTouchOutside(true) and/or
.setDismissOnBackPressed(true)
They override the .setDismissOnLongPressStop(true) setting it to false, because they can happen only if the popup isn't dismissed on long press stop

Let me know if this solves your problem

Riccardo

@pishguy
Copy link
Author

pishguy commented Jul 17, 2017

@RiccardoMoro thanks to reply, i'm not sure whats problem, i change code to

mPopup = new LongPressPopupBuilder(itemView.getContext())
            .setTarget(imageAvatar)
            .setPopupView(R.layout.popup_layout, this)
            .setAnimationType(LongPressPopup.ANIMATION_TYPE_FROM_CENTER)
            .setPopupListener(this)
            .setOnHoverListener(this)
            .setLongPressDuration(400)
            .setLongPressReleaseListener(this)
            .build();
mPopup.register();

problem is, after showing popup, i have to click outside dialog to dismiss that

@RiccardoMoro
Copy link
Owner

I guess that if you just set .setDismissOnLongPressStop(true) the result is the same right?

@pishguy
Copy link
Author

pishguy commented Jul 17, 2017

@RiccardoMoro no, this link is my complete adapter source code

http://paste.debian.net/976931/

@RiccardoMoro
Copy link
Owner

RiccardoMoro commented Jul 17, 2017

Mmm I can see that you did this -> .setDismissOnLongPressStop(false)
Now I'm not sure what you're trying to achieve..
You want the popup to be dismissed when the long press action that creates it stops or not?
( in other words, you want the same behaviour in the initial list in the sample app of this library? )

@pishguy
Copy link
Author

pishguy commented Jul 17, 2017

@RiccardoMoro i added .setDismissOnLongPressStop(false) after your comment, yes i would like to dismiss popup after stop touch, like with your sample code

@RiccardoMoro
Copy link
Owner

You've also tried to set it to true but without the other setters? (Like it's now, but with true instead of false)

@RiccardoMoro
Copy link
Owner

I've tried to replicate what happened to you, but if I paste the exact configuration ( the one without the setters and the one just with .setDismissOnLongPressStop(true) ) and it works as it should
What is the container of your RecyclerView in the layout?

@pishguy
Copy link
Author

pishguy commented Jul 17, 2017

@RiccardoMoro

That's small image view as avatar. See this screen shot

http://rupload.ir/upload/6mr6nxa0p99barqdzw15.jpg

@pishguy
Copy link
Author

pishguy commented Jul 18, 2017

@RiccardoMoro setting true for .setDismissOnLongPressStop, dont any change, and popup dont close after stop and release touch, i have that on screen any time and i have to click on back button or touch out of popup to dismiss that, do you want to share simple screen capture by me?

@RiccardoMoro
Copy link
Owner

RiccardoMoro commented Jul 21, 2017

@MahdiPishguy What is the parent of the RecyclerView? is there some custom touch-handling logic inside it?

@pishguy
Copy link
Author

pishguy commented Jul 21, 2017

@RiccardoMoro no sir, my xml layout is:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="-20dp"
    android:layout_marginRight="-20dp"
    android:background="#eeeeee">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@drawable/content_background">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/userChannelsList"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingTop="45dp"/>
        </LinearLayout>
    </FrameLayout>

    <TextView
        android:id="@+id/defaultPort"
        android:layout_width="match_parent"
        android:layout_height="@dimen/default_textview_height"
        android:visibility="gone"/>
</FrameLayout>

@RiccardoMoro
Copy link
Owner

This is very strange...
Later I'll try to replicate your issue using a layout just like yours

@pishguy
Copy link
Author

pishguy commented Jul 21, 2017

@RiccardoMoro i'm trying to separate this part of application and send it for you, yeah that's very strange

@pishguy
Copy link
Author

pishguy commented Jan 6, 2019

@RiccardoMoro problem is when i set itemView in ViewHolder, dismising dialog work fine when i set itemView on setTarget , for example:

.setTarget(itemView)

that means i can't set other view in that, for example

.setTarget(page_thumbnail_avatar) //page_thumbnail_avatar is an imageView

dismising dialog don't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants