package ch.pizzalemon.android.helper;

import android.text.Html;
import android.widget.TextView;

public class TextHelper {

    public static String parseDate(String pureDate, boolean shouldShowTime){

        if(pureDate == null || pureDate.trim().isEmpty())
            return "";
        // 2017-03-07 11:00:00.000000 9:0:0

        String[] pureDateArray = pureDate.split(" ");
        String date = pureDateArray[0];

        String[] dateArray = date.split("-");
        String year = dateArray[0];
        String month = dateArray[1];
        String day = dateArray[2];

        if(!shouldShowTime)
            return day + "." + month + "." + year;

        String time = pureDateArray[1];
        time = time.substring(0, 5);

        return day + "." + month + "." + year + "    " + "Saat  " + time;
    }

    @SuppressWarnings("deprecation")
    public static void setTextFromHTML(TextView textView, String html) {

        if (android.os.Build.VERSION.SDK_INT >= 24)
            textView.setText(Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY));
        else
            textView.setText(Html.fromHtml(html));

    }

}
