package com.swago

import android.content.Context
import android.os.Build
import android.text.BidiFormatter
import android.text.TextDirectionHeuristics
import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import com.bumptech.glide.Glide
import com.swago.baseswago.R
import java.util.*

/**
 *@date 2022/3/29 09:49
 *description:
 */

fun ImageView.loadWebp(context: Context, @DrawableRes resourceId:Int){
    Glide.with(context)
        .load(resourceId)
        .placeholder(R.mipmap.default_avatar)
        .error(R.mipmap.default_avatar)
        .into(this)
}

fun ImageView.loadUrl(context: Context,url:String){
    Glide.with(context)
        .load(url)
        .centerCrop()
        .placeholder(R.mipmap.default_avatar)
        .error(R.mipmap.default_avatar)
        .into(this)
}


fun String.formatAr(): String {
    return BidiFormatter.getInstance(Locale.getDefault())
        .unicodeWrap(this, TextDirectionHeuristics.LOCALE)
}


@RequiresApi(Build.VERSION_CODES.O)
fun CharSequence.formatAr(): CharSequence {
    return BidiFormatter.getInstance(Locale.getDefault()).unicodeWrap(
        this,
        TextDirectionHeuristics.LOCALE
    )
}