
package com.itude.mobile.mobbl.core.view.components;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;

import com.itude.mobile.mobbl.core.services.MBLocalizationService;

public class MBLocalizedButton extends Button {

    public MBLocalizedButton(Context context) {
        super(context);
    }

    public MBLocalizedButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MBLocalizedButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        super.setText(getValue(text.toString()), type);
    }

    protected String getValue(String text) {
        if (isInEditMode()) {
            // We're previewing the XML file. Therefore, there is no MOBBL configuration loaded: just show the key
            return text;
        } else {
            return MBLocalizationService.getInstance().getTextForKey(text.toString());
        }
    }

}
