package com.halo.assistant.fragment.user.region;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gh.gamecenter.common.base.fragment.BaseFragment;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.common.view.VerticalItemDecoration;
import com.gh.gamecenter.R;

import java.util.List;

/**
 * Created by khy on 25/09/17.
 * 修改用户归属地省份
 */
public class RegionProvFragment extends BaseFragment implements OnRegionSelectListener {

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_region;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        RecyclerView recyclerView = view.findViewById(R.id.region_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.addItemDecoration(new VerticalItemDecoration(getContext(), false));

        Bundle arguments = getArguments();
        if (arguments != null && arguments.getStringArrayList(EntranceConsts.KEY_PROLIST) != null) {
            recyclerView.setAdapter(new RegionProvAdapter(getContext(), arguments.getStringArrayList(EntranceConsts.KEY_PROLIST), this));
        }
    }

    @Override
    public void onRegionSelect(String content, List<String> provinceList) {
        if (getParentFragment() instanceof OnRegionSelectListener) {
            ((OnRegionSelectListener) getParentFragment()).onRegionSelect(content, provinceList);
        }
    }
}
