package com.xplora.xpsettings.Adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import com.xplora.xpsettings.Activity.WiFiActivity;
import com.xplora.xpsettings.Model.BaseModel;
import com.xplora.xpsettings.Model.BluetoothModel;
import com.xplora.xpsettings.Model.WifiModel;
import com.xplora.xpsettings.R;
import com.xplora.xpsettings.Utils.Constant;

import java.util.List;

public class BluetoothDevicesAdapter extends ArrayAdapter<BluetoothModel> {

    Handler mHandler;
    Animation animation = null;

    public BluetoothDevicesAdapter(Context context, int textViewResourceId, List<BluetoothModel> objects, Handler handler) {
        super(context, textViewResourceId, objects);
        mHandler = handler;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BluetoothModel model = getItem(position); // 获取当前项的Fruit实例

        View view = null;
        if (model.cellType == Constant.CellType.SWITCH) {
            view = LayoutInflater.from(getContext()).inflate(R.layout.item_switch, null);
        }
        else if (model.cellType == Constant.CellType.REFRESH) {
            view = LayoutInflater.from(getContext()).inflate(R.layout.item_refresh, null);
        }
        else {
            view = LayoutInflater.from(getContext()).inflate(R.layout.item_title, null);
            ImageView itemArrow = view.findViewById(R.id.item_arrow);
            itemArrow.setVisibility(model.isShowArrow ? View.VISIBLE : View.GONE);

            if(animation != null) {
                itemArrow.clearAnimation();
                animation = null;
            }
//            switch (model.status) {
//                case CONNECTED:
//                    itemArrow.setImageResource(R.drawable.ic_checked);
//                    break;
//                case LOCKED:
//                    itemArrow.setImageResource(R.drawable.ic_wifi_locked);
//                    break;
//                case CONNECTING:
//                    itemArrow.setImageResource(R.drawable.ic_syncing);
//                    if (animation == null) {
//                        animation = new RotateAnimation(0f, 360f,
//                                Animation.RELATIVE_TO_SELF, 0.5f,
//                                Animation.RELATIVE_TO_SELF, 0.5f);
//                        animation.setDuration(1000);
//                        animation.setRepeatCount(-1);
//                        animation.setInterpolator(new LinearInterpolator());
//                    }
//                    itemArrow.startAnimation(animation);
//                    break;
//                default:
//                    itemArrow.setImageResource(R.drawable.icon_arrow);
//                    break;
//
//            }
        }
        TextView itemTitle = view.findViewById(R.id.item_title);
        itemTitle.setText(model.title);

        return view;
    }
}
