TViewHolder.java 1.81 KB
Newer Older
konghaorui committed
1 2 3
package com.yidianling.avchatkit.common.adapter;

import android.content.Context;
YKai committed
4
import androidx.fragment.app.Fragment;
konghaorui committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
import android.view.LayoutInflater;
import android.view.View;

public abstract class TViewHolder implements IScrollStateListener {
    /**
     * context
     */
    protected Context context;

    /**
     * fragment
     */
    protected Fragment fragment;

    /**
     * list item view
     */
    protected View view;

    /**
     * adapter providing data
     */
    protected TAdapter adapter;

    /**
     * index of item
     */
    protected int position;

    public TViewHolder() {

    }

    protected void setFragment(Fragment fragment) {
        this.fragment = fragment;
    }

    protected void setContext(Context context) {

        this.context = context;
    }

    protected void setAdapter(TAdapter adapter) {
        this.adapter = adapter;
    }

    protected TAdapter getAdapter() {
        return this.adapter;
    }

    protected void setPosition(int position) {
        this.position = position;
    }

    public View getView(LayoutInflater inflater) {
        int resId = getResId();
        view = inflater.inflate(resId, null);
        inflate();
        return view;
    }

    public boolean isFirstItem() {
        return position == 0;
    }

    public boolean isLastItem() {
        return position == adapter.getCount() - 1;
    }

    protected abstract int getResId();

    protected abstract void inflate();

    protected abstract void refresh(Object item);

    @Override
    public void reclaim() {
    }

    @Override
    public void onImmutable() {
    }

    protected boolean mutable() {
        return adapter.isMutable();
    }

    public void destory() {

    }

    protected <T extends View> T findView(int resId) {
        return (T) (view.findViewById(resId));
    }
}