package com.example.lfrmobileapp.ui.home;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.lfrmobileapp.Communication;
import com.example.lfrmobileapp.databinding.FragmentManuellBinding;

import io.github.controlwear.virtual.joystick.android.JoystickView;

public class HomeFragment extends Fragment {

    private FragmentManuellBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        HomeViewModel homeViewModel =
                new ViewModelProvider(this).get(HomeViewModel.class);

        binding = FragmentManuellBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        final TextView textView = binding.textHome;
        homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);

        JoystickView joystick = (JoystickView) binding.joystick;
        Communication com = new Communication();
        joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
            @Override
            public void onMove(int angle, int strength) {
                homeViewModel.setText(Integer.toString(angle), Integer.toString(strength));
                com.sendData("Vanessa stinkt, Baran nicht");
            }
        });

        return root;
    }

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


}