package com.luticate.utils.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.luticate.utils.R;

/**
 * Created by robin on 12/8/15.
 */
public class DefaultPaginationView extends AbstractPaginationView {
    public DefaultPaginationView(Context context) {
        super(context);
        init();
    }

    public DefaultPaginationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DefaultPaginationView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void init()
    {
        inflate(getContext(), R.layout.default_pagination_view_layout, this);
        findViewById(R.id.previousPageView).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                loadPreviousPage();
            }
        });
        findViewById(R.id.nextPageView).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                loadNextPage();
            }
        });
    }

    @Override
    protected void onUpdatePages() {
        ViewGroup layout = (ViewGroup) findViewById(R.id.pagesLayout);
        layout.removeAllViews();
        for (final int page : getPages())
        {
            TextView tv = new TextView(getContext());
            tv.setText(" " + String.valueOf(page + 1) + " ");
            tv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        loadPage(page);
                    }
                });
            tv.setTextAppearance(getContext(), android.R.style.TextAppearance_DeviceDefault_Large);
            layout.addView(tv);
        }
    }
}
