From b13afc751dbbce24753d008f1f87d2c5e133a4ad Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期二, 09 七月 2024 15:19:26 +0800 Subject: [PATCH] fix bug --- app/src/main/java/com/dollearn/student/utils/extention/WeparkEx.kt | 48 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 37 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/dollearn/student/utils/extention/WeparkEx.kt b/app/src/main/java/com/dollearn/student/utils/extention/WeparkEx.kt index 256cba1..46f6669 100644 --- a/app/src/main/java/com/dollearn/student/utils/extention/WeparkEx.kt +++ b/app/src/main/java/com/dollearn/student/utils/extention/WeparkEx.kt @@ -5,20 +5,18 @@ import android.util.Log import android.view.View import android.widget.ImageView -import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import cn.sinata.xldutils.activity.BaseActivity import com.bumptech.glide.Glide import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition -import com.github.promeg.pinyinhelper.Pinyin -import com.dollearn.student.utils.interfaces.StringCallback -import com.dollearn.student.network.entity.Grade import com.dollearn.student.utils.OSSUtil import com.dollearn.student.utils.extention.ViewClickDelay.SPACE_TIME import com.dollearn.student.utils.extention.ViewClickDelay.hash import com.dollearn.student.utils.extention.ViewClickDelay.lastClickTime import com.dollearn.student.utils.glide.GlideUtil +import com.dollearn.student.utils.interfaces.StringCallback +import com.github.promeg.pinyinhelper.Pinyin import kotlinx.android.synthetic.main.activity_course_deatil.* import org.jetbrains.anko.toast import top.zibin.luban.Luban @@ -27,15 +25,15 @@ fun String.getInitial():String = if (startsWith("重庆")) "C" else Pinyin.toPinyin(this[0])[0].toString() -fun String.uploadWithCompress(act:BaseActivity,callback: StringCallback){ +fun String.uploadWithCompress(act: BaseActivity, callback: StringCallback){ Luban.with(act).load(File(this)) .ignoreBy(100).setTargetDir(act.getPath()) .filter { path -> path.isNotEmpty() || path.toLowerCase().endsWith(".gif") } - .setCompressListener(object :OnCompressListener{ + .setCompressListener(object : OnCompressListener { override fun onSuccess(file: File) { - Log.e("gwx","压缩完成") + Log.e("gwx", "压缩完成") Thread(Runnable { - OSSUtil(act).uploadSingle(file.path,object :OSSUtil.OSSUploadCallBack(){ + OSSUtil(act).uploadSingle(file.path, object : OSSUtil.OSSUploadCallBack() { override fun onFial(message: String?) { super.onFial(message) act.runOnUiThread { @@ -62,7 +60,7 @@ } override fun onStart() { - Log.e("gwx","压缩开始") + Log.e("gwx", "压缩开始") act.showDialog(canCancel = false) } }).launch() @@ -94,7 +92,7 @@ * 使用Glide计算网络图片的宽高比加载长图 * 父布局必须是ConstraintLayout:使用 dimensionRatio 属性 */ -fun String.loadLongImage(context:Context,imageView: ImageView){ +fun String.loadLongImage(context: Context, imageView: ImageView){ Glide.with(context).asBitmap().load(this) .into(object : SimpleTarget<Bitmap?>() { override fun onResourceReady( @@ -105,7 +103,35 @@ layoutParams.dimensionRatio = "${resource.width}:${resource.height}" imageView.layoutParams = layoutParams - GlideUtil.load(context,this@loadLongImage,imageView,0) + GlideUtil.load(context, this@loadLongImage, imageView, 0) } }) +} + +fun Int.formatToChinese():String{ + var number = this + val DIGITS = arrayListOf('零', '一', '二', '三', '四', '五', '六', '七', '八', '九') + val UNITS = arrayListOf('0', '十', '百', '千', '万') + if (number == 0) { + return DIGITS[0].toString() + } + val chineseNumber = StringBuilder() + var unitPlace = 0 // 位数,从百位开始 + var lastWasZero = false // 前一个数字是否为零 + while (number > 0) { + val digit: Int = number % 10 + lastWasZero = if (digit == 0) { + if (!lastWasZero) { + chineseNumber.insert(0, DIGITS[0]) + } + true + } else { + chineseNumber.insert(0, DIGITS[digit]) + chineseNumber.insert(0, UNITS[unitPlace]) + false + } + number /= 10 + unitPlace++ + } + return chineseNumber.toString().replace("0","") } \ No newline at end of file -- Gitblit v1.7.1