package com.getbubblenow.android.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;

import com.getbubblenow.android.R;
import com.getbubblenow.android.fragment.NetworkListRecyclerViewAdapter.ItemClickListener;
import com.getbubblenow.android.model.Network;

import java.util.List;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.Adapter;

public class NetworkListDialogFragment extends DialogFragment {

    private final List<Network> networks;
    private final ItemClickListener listener;

    public NetworkListDialogFragment(final List<Network> networks, final ItemClickListener listener) {
        this.networks = networks;
        this.listener = listener;
    }

    @Override
    public Dialog onCreateDialog(final Bundle savedInstanceState) {

        final LayoutInflater inflater = getLayoutInflater();
        final RecyclerView dialogView = (RecyclerView) inflater.inflate(R.layout.network_list_dialog_fragment, null);
        final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        final Adapter adapter = new NetworkListRecyclerViewAdapter(getContext(), networks, listener);

        dialogView.setLayoutManager(layoutManager);
        dialogView.setHasFixedSize(true);
        dialogView.setAdapter(adapter);

        return new AlertDialog.Builder(getActivity())
                .setTitle(R.string.select_your_bubble)
                .setView(dialogView)
                .create();
    }
}