package com.cheng.blzb.utils

import android.text.TextUtils
import com.example.base.utils.L

object UIUtils {

    fun checkVersion(version: String, origin: String): Boolean {
        if (TextUtils.isEmpty(version) || TextUtils.isEmpty(origin)) {
            return false
        }
        val versions = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        val origins = origin.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        if (versions.size != 3) {
            return false
        }
        if (origins.size != 3) {
            return false
        }
        for (i in 0..2) {
            L.e(versions[i])
            L.e(origins[i])
            if (versions[i].toInt() > origins[i].toInt()) {
                return true
            } else if (versions[i].toInt() < origins[i].toInt()) {
                return false
            }
        }
        return false
    }

    fun getFileNameFromUrl(url: String): String {
        return url.substring(url.lastIndexOf('/') + 1)
    }
}