package com.letv.core.utils;

import android.annotation.SuppressLint;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import com.letv.base.R;
import com.letv.core.BaseApplication;
import com.letv.core.config.LetvConfig;
import com.letv.pp.utils.NetworkUtils;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
import java.util.Locale;
import java.util.TimeZone;
import org.cybergarage.upnp.std.av.server.object.SearchCriteria;

public class StringUtils {
    public static String subZeroAndDot(String s) {
        if (s.indexOf(".") > 0) {
            return s.replaceAll("0+?$", "").replaceAll("[.]$", "");
        }
        return s;
    }

    public static String timeClockString(String format) {
        return new SimpleDateFormat(format).format(new Date());
    }

    public static String timeString(long time) {
        SimpleDateFormat formatTime = new SimpleDateFormat("yyyy-MM-dd");
        formatTime.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
        return formatTime.format(new Date(time));
    }

    public static String timeStringByMinutes(long time) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(time));
    }

    public static String timeStringBySecond(long time) {
        return new SimpleDateFormat("MM-dd HH:mm:ss").format(new Date(1000 * time));
    }

    public static String time2StrBySec(long time) {
        return new SimpleDateFormat("HH:mm").format(new Date(1000 * time));
    }

    public static String timeStringAll(long time) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time));
    }

    public static String getNumberTime(long time_second) {
        Formatter formatter = new Formatter(null, Locale.getDefault());
        try {
            long seconds = time_second % 60;
            long minutes = (time_second / 60) % 60;
            String formatter2 = formatter.format("%02d:%02d:%02d", new Object[]{Long.valueOf(time_second / 3600), Long.valueOf(minutes), Long.valueOf(seconds)}).toString();
            return formatter2;
        } finally {
            formatter.close();
        }
    }

    public static String getNumberTextTime(long time_second) {
        if (time_second <= 0) {
            return "";
        }
        Formatter formatter = new Formatter(null, Locale.getDefault());
        try {
            long seconds = time_second % 60;
            long minutes = (time_second / 60) % 60;
            String formatter2 = formatter.format("%02d%02d%02d", new Object[]{Long.valueOf(time_second / 3600), Long.valueOf(minutes), Long.valueOf(seconds)}).toString();
            return formatter2;
        } finally {
            formatter.close();
        }
    }

    public static String stringForTimeNoHour(long timeMs) {
        String formatter;
        StringBuilder formatBuilder = new StringBuilder();
        Formatter formatter2 = new Formatter(formatBuilder, Locale.getDefault());
        if (timeMs >= 0) {
            try {
                int totalSeconds = (int) (timeMs / 1000);
                int seconds = totalSeconds % 60;
                int minutes = totalSeconds / 60;
                formatBuilder.setLength(0);
                formatter = formatter2.format("%02d:%02d", new Object[]{Integer.valueOf(minutes), Integer.valueOf(seconds)}).toString();
            } finally {
                formatter2.close();
            }
        } else {
            formatter = "00:00";
            formatter2.close();
        }
        return formatter;
    }

    public static long stringToLong2(String str) {
        long i = 0;
        try {
            i = Long.parseLong(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    public static String stringForTime(long timeMs) {
        StringBuilder formatBuilder = new StringBuilder();
        Formatter formatter = new Formatter(formatBuilder, Locale.getDefault());
        try {
            int totalSeconds = (int) (timeMs / 1000);
            int seconds = totalSeconds % 60;
            int minutes = (totalSeconds / 60) % 60;
            int hours = totalSeconds / 3600;
            formatBuilder.setLength(0);
            String formatter2 = formatter.format("%02d:%02d:%02d", new Object[]{Integer.valueOf(hours), Integer.valueOf(minutes), Integer.valueOf(seconds)}).toString();
            return formatter2;
        } finally {
            formatter.close();
        }
    }

    public static String timeFormatter(long timeMs) {
        if (((int) (timeMs / 1000)) >= 3600) {
            return stringForTime(timeMs);
        }
        return stringForTimeNoHour(timeMs);
    }

    public static String getPlayCountsToStr(long playCount) {
        if (playCount < 10000) {
            if (playCount < 1000) {
                return playCount + "";
            }
            if (playCount < 1000 || playCount > 9999) {
                return "";
            }
            String aa = (playCount / 1000) + "";
            String bb = (playCount % 1000) + "";
            if (bb.length() < 3) {
                bb = "0" + bb;
            }
            return aa + "," + bb;
        } else if (playCount < 10000 || playCount >= 100000000) {
            return new DecimalFormat(".#").format((((double) playCount) * 1.0d) / 1.0E8d) + LetvUtils.getString(R.string.hundred_million);
        } else {
            return new DecimalFormat(".#").format((((double) playCount) * 1.0d) / 10000.0d) + LetvUtils.getString(R.string.ten_thousands);
        }
    }

    public static String formatTime(String time, String format) {
        if (!(TextUtils.isEmpty(time) || TextUtils.isEmpty(format))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                time = new SimpleDateFormat(format).format(sdf.parse(time));
            } catch (ParseException e) {
                e.printStackTrace();
            } finally {
            }
        }
        return time;
    }

    public static boolean isToday(Date date) {
        return getDateName(0).equals(new SimpleDateFormat("yyyy-MM-dd").format(date));
    }

    public static boolean isYesterday(Date date) {
        return getDateName(-1).equals(new SimpleDateFormat("yyyy-MM-dd").format(date));
    }

    public static boolean isTomorrow(Date date) {
        return getDateName(1).equals(new SimpleDateFormat("yyyy-MM-dd").format(date));
    }

    public static String getWeekName(String dateString) {
        if (!TextUtils.isEmpty(dateString)) {
            try {
                Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateString);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                dateString = getWeekName(calendar);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return dateString;
    }

    private static String getWeekName(Calendar calendar) {
        String name = calendar.getDisplayName(7, 1, Locale.CHINESE);
        if (TextUtils.isEmpty(name)) {
            return "";
        }
        return name.replace(LetvUtils.getString(R.string.week_xinqi), LetvUtils.getString(R.string.week_zhou));
    }

    public static String getDateName(String dateString) {
        if (TextUtils.isEmpty(dateString)) {
            return dateString;
        }
        try {
            Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateString);
            if (isYesterday(date)) {
                return LetvUtils.getString(R.string.letvutil_week_yesterday);
            }
            if (isToday(date)) {
                return LetvUtils.getString(R.string.letvutil_week_tody);
            }
            if (isTomorrow(date)) {
                return LetvUtils.getString(R.string.letvutil_week_tomorrow);
            }
            return new SimpleDateFormat("MM" + LetvUtils.getString(R.string.month) + "dd" + LetvUtils.getString(R.string.day)).format(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return dateString;
        }
    }

    private static String getDateName(int i) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(6, calendar.get(6) + i);
        return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
    }

    public static String getString(String targetStr, String defaultStr) {
        if (!TextUtils.isEmpty(targetStr)) {
            return targetStr;
        }
        LogInfo.log("getString", "目标String为空, 取默认String : " + defaultStr);
        return defaultStr;
    }

    public static String getString(String targetStr, int defaultStrId) {
        return getString(targetStr, BaseApplication.getInstance().getString(defaultStrId));
    }

    public static long getTimeLong(String date) {
        Date mDate;
        try {
            mDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            mDate = new Date();
        }
        return mDate.getTime();
    }

    public static String getStringTwo(String strIn) {
        String strResult = "";
        if (TextUtils.isEmpty(strIn)) {
            return strResult;
        }
        if (strIn.length() >= 2) {
            return strIn;
        }
        return "0".concat(strIn);
    }

    public static String addUnlinkParams(String url, boolean isPay, String liveid, String uuid, String st) {
        if ((TextUtils.isEmpty(liveid) || TextUtils.equals(liveid, NetworkUtils.DELIMITER_LINE)) && (TextUtils.isEmpty(st) || TextUtils.equals(st, NetworkUtils.DELIMITER_LINE))) {
            st = getStreamIdFromUrl(url);
        }
        String str = "&platid=10&playid=1&termid=2&pay=%s&tm=1411974165&