package ch.pizzalemon.android.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import ch.pizzalemon.android.R;

/**
 * Created by cimenmus on 24.10.2017.
 */

public class AppInfoView extends LinearLayout {

    private View rootView;
    private TextView descriptionTextView;
    private TextView textview;
    private String description;
    private String text;

    public AppInfoView(Context context) {
        super(context);
        init(context);
    }

    public AppInfoView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AppInfoView, 0, 0);
        try {
            description = a.getString(R.styleable.AppInfoView_description);
            text = a.getString(R.styleable.AppInfoView_infoText);
        } finally {
            a.recycle();
        }
        init(context);
    }

    private void init(Context context) {
        rootView = inflate(context, R.layout.layout_pizzalink_view, this);
        descriptionTextView = (TextView) rootView.findViewById(R.id.descriptionTextView);
        textview = (TextView) rootView.findViewById(R.id.infoTextView);
        if(description == null)
            description = "";
        if(text == null)
            text = "";
        descriptionTextView.setText(description);
        textview.setText(text);
    }

    public String getText(){
        return textview.getText().toString().trim();
    }

    public void setText(String text){
        textview.setText(text);
    }
}