package com.sunzee.ui.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunzee.R;
import com.sunzee.adapter.RvAlarmAdapter;
import com.sunzee.base.BaseApplication;
import com.sunzee.base.MvpFragment;
import com.sunzee.model.domain.WarringBean;
import com.sunzee.mvp.alarmrecord.AlarmRecordPresenter;
import com.sunzee.mvp.alarmrecord.AlarmRecordView;
import com.sunzee.utils.CustomDecoration;

import java.util.List;

/**
 * 报警记录界面 fragment
 */
public class AlarmRecordFragment extends MvpFragment<AlarmRecordPresenter> implements AlarmRecordView {

    private RecyclerView mRvAlarm;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_alarm_record, container, false);
        initView(inflate);
        return inflate;
    }

    private void initView(View inflate) {
        mRvAlarm = inflate.findViewById(R.id.rv_alarm);
        LinearLayoutManager layoutManager = new LinearLayoutManager(BaseApplication.getContext());
        mRvAlarm.setLayoutManager(layoutManager);
        mRvAlarm.addItemDecoration(new CustomDecoration(BaseApplication.getContext(), LinearLayoutManager.VERTICAL,2));
    }

    @Override
    public void onStart() {
        super.onStart();
        mvpPresenter.getAlarmData();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }

    @Override
    protected AlarmRecordPresenter createPresenter() {
        return new AlarmRecordPresenter(this);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showData(List<WarringBean> warringBeans) {
        RvAlarmAdapter adapter=new RvAlarmAdapter(warringBeans);
        mRvAlarm.setAdapter(adapter);
    }
}
