package com.baoshi.swms.activity.changeView;

import android.app.Activity;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.baoshi.swms.R;

/**
 * 调度时的视图变更
 *
 * @author Zhendong Zhou
 * @date 2021/12/6 10:14
 */
public class ListViewFooterChange {
    public LinearLayout mLoadLayout;
    private final Activity activity;
    private final ListView listView;
    private final LinearLayout.LayoutParams mProgressBarLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    private final LinearLayout.LayoutParams mTipContentLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    public ListViewFooterChange(Activity activity, ListView listView){
        this.activity = activity;
        this.listView = listView;
    }
    //设置加载footer
    public void addLoadFooter()
    {
        //"加载项"布局，此布局被添加到ListView的Footer中。
        mLoadLayout = new LinearLayout(activity);
        mLoadLayout.setMinimumHeight(60);
        mLoadLayout.setGravity(Gravity.CENTER);
        mLoadLayout.setOrientation(LinearLayout.HORIZONTAL);
        //向"加载项"布局中添加一个圆型进度条。
        ProgressBar mProgressBar = new ProgressBar(activity);
        mProgressBar.setPadding(0, 0, 15, 0);
        mLoadLayout.addView(mProgressBar, mProgressBarLayoutParams);
        //向"加载项"布局中添加提示信息。
        TextView mTipContent = new TextView(activity);
        mTipContent.setText("加载中...");
        mLoadLayout.addView(mTipContent, mTipContentLayoutParams);
        //获取ListView组件，并将"加载项"布局添加到ListView组件的Footer中。
        listView.addFooterView(mLoadLayout);
    }
    public void addLoadStopFooter()
    {
        mLoadLayout = new LinearLayout(activity);
        mLoadLayout.setMinimumHeight(60);
        mLoadLayout.setGravity(Gravity.CENTER);
        mLoadLayout.setOrientation(LinearLayout.HORIZONTAL);
        TextView mTipContent = new TextView(activity);
        mTipContent.setText("已经到底了~");
        mTipContent.setTextColor(activity.getResources().getColor(R.color.dark_gray));
        mLoadLayout.addView(mTipContent, mTipContentLayoutParams);
        listView.addFooterView(mLoadLayout);
    }
    public void addLoadNoneFooter()
    {
        mLoadLayout = new LinearLayout(activity);
        mLoadLayout.setGravity(Gravity.CENTER);
        mLoadLayout.setMinimumHeight(500);
        mLoadLayout.setOrientation(LinearLayout.HORIZONTAL);
        TextView mTipContent = new TextView(activity);
        mTipContent.setText("暂无数据......");
        mTipContent.setTextColor(activity.getResources().getColor(R.color.dark_gray));
        mLoadLayout.addView(mTipContent, mTipContentLayoutParams);
        listView.addFooterView(mLoadLayout);
    }
}
