apptik / MultiSlider

Multi functional slider/seekbar( / rangebar / scrubber) for Android
Apache License 2.0
320 stars 80 forks source link

The Thumb is not updated for the OnThumbValueChangeListener #74

Closed CsabaZz closed 6 years ago

CsabaZz commented 6 years ago

Can we change the order of these calls please, so the thumb is updated and then call we the listener? Thus we will know the new parameters of the Thumb, like the new left/right position of the thumb.

So,

    if (hasOnThumbValueChangeListener()) {
        mOnThumbValueChangeListener.onValueChanged(this, thumb, mThumbs.indexOf(thumb), thumb
                .getValue());
    }
    updateThumb(thumb, getWidth(), getHeight());

Should be

    updateThumb(thumb, getWidth(), getHeight());
    if (hasOnThumbValueChangeListener()) {
        mOnThumbValueChangeListener.onValueChanged(this, thumb, mThumbs.indexOf(thumb), thumb
                .getValue());
    }
bmx666 commented 6 years ago

Hi @CsabaZz, You can change thumb's props before redraw it. For example set min/max values depend on logic of your app.

bmx666 commented 6 years ago

In your case you can extend logic OnValueChangeBefore and OnValueChangeAfter

CsabaZz commented 6 years ago

@bmx666 I don't find those interfaces. Can you help me please? I'm using the v1.3 version.

Anyway, my logic is I have a TextView positioned above the slider, and I'm moving the TextView as how the Thumb is moving. So I added a MultiSlider.OnThumbValueChangeListener to the MultiSlider view, and positioning the TextView inside the listener like this:

        @Override
        public void onValueChanged(MultiSlider multiSlider, MultiSlider.Thumb thumb, int thumbIndex, int value) {
            int left = mBuyInAmountSlider.getThumb(0).getThumb().getBounds().left;
            int width = mBuyInAmountSlider.getThumb(0).getThumb().getBounds().width();
            mBuyInAmountMinText.setText(String.valueOf(mBuyInAmountSlider.getThumb(0).getValue()));
            mBuyInAmountMinText.setTranslationX((left + (width / 2)) - (mBuyInAmountMinText.getMeasuredWidth() / 2));
            // there's a MaxText view as well which uses the getThumb(1)
        }

My problem with this solution is that the listener called before the Thumb is updated, so

            int left = mBuyInAmountSlider.getThumb(0).getThumb().getBounds().left;

will return me the previous value, not the latest one.

bmx666 commented 6 years ago

Maybe you looking something this #50?

bmx666 commented 6 years ago

I merged branch thumb-binder-dev with master, you can check

CsabaZz commented 6 years ago

Sounds similar...

CsabaZz commented 6 years ago

Added

    compile 'io.apptik.widget:multislider:1.3.1-SNAPSHOT'

but does not seem that the underline code has changed, I can compile the project without the need of change the implementation of the listener as you suggested. :(

bmx666 commented 6 years ago

@CsabaZz, download source code of library and include in your app.

CsabaZz commented 6 years ago

OK, thx. I thought it's available as gradle dependency.

Edit: I don't see the new interface neither in master nor in thumb-binder-dev branches. Did you updated the source on Github? The latest changes was made 10 days ago, it was a dependency configuration change and cleanup.

bmx666 commented 6 years ago

@CsabaZz, for thumb-binder-dev branch you don't need change library interface. Just bind textview to thumb (see example)

CsabaZz commented 6 years ago

I'll do it, thanks!

CsabaZz commented 6 years ago

Sorry for not answering earlier. Seems working fine with the binding code, and I could remove the call of translationX method since it is done by the lib - it means much cleaner code. :)