/**
 * Copyright (C) 2022 - Florindo Smilari (spherIC)
 */
package ch.spherIC.recurvebowsight.ui.calcsight;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import ch.spherIC.recurvebowsight.R;
import ch.spherIC.recurvebowsight.databinding.FragmentCalcsightParametersBinding;

public class CalculateSightParametersFragment extends Fragment {

    private FragmentCalcsightParametersBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentCalcsightParametersBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        loadCalculationAccuracies(root);
        loadCalculationTimeIntervals(root);

        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    private void loadCalculationAccuracies(View root) {
        String[] accuracies = root.getResources().getStringArray(R.array.CalculationAccuracies);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(root.getContext(), android.R.layout.simple_dropdown_item_1line, accuracies);
        AutoCompleteTextView textView = root.findViewById(R.id.calcPrecisionTxt);
        textView.setAdapter(adapter);
    }

    private void loadCalculationTimeIntervals(View root) {
        String[] timeDeltas = root.getResources().getStringArray(R.array.CalculationTimeIntervals);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(root.getContext(), android.R.layout.simple_dropdown_item_1line, timeDeltas);
        AutoCompleteTextView textView = root.findViewById(R.id.deltaTimeTxt);
        textView.setAdapter(adapter);
    }
}