package ch.spherIC.recurvebowsight.ui.about;

import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import ch.spherIC.recurvebowsight.database.RBSDatabaseHelper;
import ch.spherIC.recurvebowsight.databinding.FragmentAboutBinding;

public class AboutFragment extends Fragment {

    private FragmentAboutBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        String versionName = "";
        String dbVersionName = "";
        String androidVersionName = "";
        this.binding = FragmentAboutBinding.inflate(inflater, container, false);
        View root = this.binding.getRoot();

        androidVersionName = Build.VERSION.RELEASE;
        dbVersionName = Integer.toString(RBSDatabaseHelper.getInstance().getReadableDatabase().getVersion());
        try {
            versionName = root.getContext().getPackageManager().getPackageInfo("ch.spherIC.recurvebowsight", PackageManager.GET_CONFIGURATIONS).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            versionName = "-";
        }
        this.binding.versionTextVal.setText(versionName);
        this.binding.androidVersionTextVal.setText(androidVersionName);
        this.binding.dbVersionTextVal.setText(dbVersionName);

        return root;
    }

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