package com.example.weighttracker;

import com.google.android.material.textfield.TextInputEditText;

// I separated input cleanup so the activities do not repeat the same text parsing logic.
public class InputHelper {

    // Pulls text safely from a field and trims extra spaces.
    public static String getText(TextInputEditText input) {
        if (input.getText() == null) {
            return "";
        }

        return input.getText().toString().trim();
    }

    // Converts text into a number without crashing if the user types bad input.
    public static Double parseDouble(String value) {
        try {
            return Double.parseDouble(value);
        } catch (Exception e) {
            return null;
        }
    }
}