package com.example.tabulation;

import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

public class Q3 implements TextView.OnEditorActionListener {

    private final TextView rouge;
    private final TextView vert;
    private final TextView bleu;
    private String ancienRouge;
    private String ancienVert;
    private String ancienBleu;

    public Q3(View couleur, TextView rouge, TextView vert, TextView bleu){
        this.couleur = couleur;
        this.rouge = rouge;
        this.vert = vert;
        this.bleu = bleu;
        this.ancienRouge = (String) rouge.getText();
        this.ancienVert = (String) vert.getText();
        this.ancienBleu = (String) bleu.getText();
    }

    @Override
    public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
        Log.v("test","entrer");
        TextView source = (TextView) textView;
        String texteSource = String.valueOf(source.getText());
        if (source.getId() == this.degreC.getId()){
            degreF.setText(Evenement.convertionCToF(texteSource));
            return true;
        }
        if (source.getId() == this.degreF.getId()){
            degreC.setText(Evenement.convertionFToC(texteSource));
            return true;
        }
        return false;
    }

    private static String convertionCToF(String c){
        double cDouble = Double.parseDouble(c);
        double fDouble = cDouble*9d/5d + 32d;
        return fDouble+"";
    }

    private static String convertionFToC(String f){
        double fDouble = Double.parseDouble(f);
        double cDouble = ((fDouble-32d)*5d)/9d;
        return cDouble+"";
    }
}
