eneim / toro

Video list auto playback made simple, specially built for RecyclerView
Apache License 2.0
1.42k stars 253 forks source link

How can I implement Toro without using ToroAdapter? #177

Closed johnernest02 closed 7 years ago

johnernest02 commented 7 years ago

I am using the FlexibleAdapter library and it is impossible for me to extend another type of adapter as my models already work around the said library. Is there any way to implement Toro without extending from ToroAdapter?

eneim commented 7 years ago

What does that "FlexibleAdapter" looks like?

johnernest02 commented 7 years ago

Sorry, here is the link to the library: https://github.com/davideas/FlexibleAdapter

And I am using it quite simply:

public class SampleFlexibleAdapter extends FlexibleAdapter<SampleFlexible> {
    private boolean mIsSelectionMode;

    private HttpProxyCacheServer mProxy;

    public SampleFlexibleAdapter (@Nullable List<SampleFlexible> items, @Nullable Object listeners, HttpProxyCacheServer proxy) {
        super(items, listeners);
        mProxy = proxy;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payloads) {
        SampleFlexible item = getItem(position);

        item.setProxy(mProxy);
        super.onBindViewHolder(holder, position, payloads);
    }

    public boolean isSelectionMode() {
        return mIsSelectionMode;
    }

    public void setIsSelectionMode(boolean isSelectionMode) {
        mIsSelectionMode = isSelectionMode;
    }
}

I am using it this way as everything else has been handled by FlexibleAdapter. I also plan on using the HttpProxyCacheServer from https://github.com/danikula/AndroidVideoCache/ so that I can cache the videos to be played.

The SampleFlexible class minimally looks like this


public class SampleFlexible extends Sample implements IFlexible<SampleFlexible.SampleViewHolder> {

    private boolean mIsEnabled = true;

    private boolean mIsHidden;

    private boolean mIsSelectable = true;

    private boolean mIsDraggable;

    private boolean mIsSwipeable;

    public SampleFlexible(Sample sample) {
        super();
        setText(sample.getText());
    }

    @Override
    public boolean isEnabled() {
        return mIsEnabled;
    }

    @Override
    public void setEnabled(boolean enabled) {
        mIsEnabled = enabled;
    }

    @Override
    public boolean isHidden() {
        return mIsHidden;
    }

    @Override
    public void setHidden(boolean hidden) {
        mIsHidden = hidden;
    }

    @Override
    public boolean isSelectable() {
        return mIsSelectable;
    }

    @Override
    public void setSelectable(boolean selectable) {
        mIsSelectable = selectable;
    }

    @Override
    public boolean isDraggable() {
        return mIsDraggable;
    }

    @Override
    public void setDraggable(boolean draggable) {
        mIsDraggable = draggable;
    }

    @Override
    public boolean isSwipeable() {
        return mIsSwipeable;
    }

    @Override
    public void setSwipeable(boolean swipeable) {
        mIsSwipeable = swipeable;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Sample) {
            Sample otherObj = (Sample) obj;
            return otherObj.getText().equals(getText());
        }
        return false;
    }

    @Override
    public int hashCode() {
        return getText().hashCode();
    }

    @Override
    public int getLayoutRes() {
            return R.layout.item_sample;
    }

    @Override
    public SampleViewHolder createViewHolder(FlexibleAdapter adapter, LayoutInflater inflater, ViewGroup parent) {
        return new SampleViewHolder(inflater.inflate(getLayoutRes(), parent, false), adapter);
    }

    @Override
    public void bindViewHolder(FlexibleAdapter adapter, SampleViewHolder holder, int position, List payloads) {
        Context context = holder.itemView.getContext();

        holder.text.setText(getText());
    }

    private HttpProxyCacheServer mProxy;

    public void setProxy(HttpProxyCacheServer proxy) {
        mProxy = proxy;
    }

    public static class SampleComparator implements Comparator<Sample> {

        @Override
        public int compare(Sample sample, Sample t1) {
            return sample.getText().compareTo(t1.getText());
        }
    }

    public static class SampleViewHolder extends FlexibleViewHolder {

        @BindView(R.id.text)
        public TextView text;

        public SampleViewHolder(View view, FlexibleAdapter adapter) {
            super(view, adapter);
            ButterKnife.bind(this, itemView);
        }
    }

}

Basically the binding of the data is done on the model SampleFlexible which extends from Sample which is my POJO which contains all the actual data.

The SampleViewHolder also extends from FlexibleViewHolder and all of the other viewHolders need to extend from it to make it work as well.

I am looking for a way to implement Toro without changing the extension. If there is an interface or anything that I could do to implement video playback on the list I would really appreciate it as I think Toro also handles everything else that is concerned with Video playback

johnernest02 commented 7 years ago

Hi Are there any updates?

eneim commented 7 years ago

@dev-JE02 I'm afraid there is no way I can adapt that FlexibleAdapter (I have never written an Adapter that huge ...). My BaseAdapter need a few addition methods to correctly watch the ViewHolder when it is attached/detached/recycled an so on. In short: you may need a separated adapter ...

eneim commented 7 years ago

Please wait to see if I can do something on Toro v3.

johnernest02 commented 7 years ago

Gosh thank you very much!