| | |
| | | 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 kotlinx.android.synthetic.main.activity_course_deatil.* |
| | | import com.dollearn.student.utils.interfaces.StringCallback |
| | | import org.jetbrains.anko.toast |
| | | import top.zibin.luban.Luban |
| | | import top.zibin.luban.OnCompressListener |
| | | import java.io.File |
| | | |
| | | 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 { |
| | |
| | | } |
| | | |
| | | override fun onStart() { |
| | | Log.e("gwx","压缩开始") |
| | | Log.e("gwx", "压缩开始") |
| | | act.showDialog(canCancel = false) |
| | | } |
| | | }).launch() |
| | |
| | | * 使用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( |
| | |
| | | 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","") |
| | | } |