|
@@ -5,6 +5,7 @@ import android.content.Context
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Bitmap
|
|
import android.graphics.BitmapFactory
|
|
import android.graphics.BitmapFactory
|
|
import android.graphics.drawable.Drawable
|
|
import android.graphics.drawable.Drawable
|
|
|
|
+import android.text.TextUtils
|
|
import com.bumptech.glide.Glide
|
|
import com.bumptech.glide.Glide
|
|
import com.bumptech.glide.request.target.CustomTarget
|
|
import com.bumptech.glide.request.target.CustomTarget
|
|
import com.bumptech.glide.request.transition.Transition
|
|
import com.bumptech.glide.request.transition.Transition
|
|
@@ -19,28 +20,33 @@ import java.io.IOException
|
|
|
|
|
|
object BitmapUtils {
|
|
object BitmapUtils {
|
|
|
|
|
|
- fun getBitmapFromPath(url:String?):Bitmap?{
|
|
|
|
- val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile"
|
|
|
|
- val pathFile = File("$path/${url?.substring(url.lastIndexOf("/"))}")
|
|
|
|
- return if (pathFile.exists()) {
|
|
|
|
- BitmapFactory.decodeFile(pathFile.absolutePath)
|
|
|
|
- } else {
|
|
|
|
- null
|
|
|
|
- }
|
|
|
|
|
|
+ fun getBitmapFromPath(url: String?): Bitmap? {
|
|
|
|
+ if (TextUtils.isEmpty(url)) {
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
+ val path = "${AppContext.getContext().getExternalFilesDir(null)!!.path}/swagoFile"
|
|
|
|
+ val pathFile = File("$path/${url?.substring(url.lastIndexOf("/"))}")
|
|
|
|
+ return if (pathFile.exists()) {
|
|
|
|
+ BitmapFactory.decodeFile(pathFile.absolutePath)
|
|
|
|
+ } else {
|
|
|
|
+ null
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- fun loadFile(context: Context, url: String) {
|
|
|
|
- if (context is Activity){
|
|
|
|
|
|
+ fun loadFile(context: Context, url: String,width:Int,height:Int) {
|
|
|
|
+ if (context is Activity) {
|
|
if (context.isDestroyed)
|
|
if (context.isDestroyed)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
Glide.with(context)
|
|
Glide.with(context)
|
|
.asBitmap()
|
|
.asBitmap()
|
|
|
|
+ .override(width,height)
|
|
.load(url)
|
|
.load(url)
|
|
.into(object : CustomTarget<Bitmap>() {
|
|
.into(object : CustomTarget<Bitmap>() {
|
|
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
|
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
|
- val pathFile = File("${UrlConstant.specialResourcePath}/${url.substring(url.lastIndexOf("/"))}")
|
|
|
|
|
|
+ val pathFile =
|
|
|
|
+ File("${UrlConstant.specialResourcePath}/${url.substring(url.lastIndexOf("/"))}")
|
|
var outputStream: FileOutputStream? = null
|
|
var outputStream: FileOutputStream? = null
|
|
try {
|
|
try {
|
|
outputStream = FileOutputStream(pathFile)
|
|
outputStream = FileOutputStream(pathFile)
|
|
@@ -58,31 +64,4 @@ object BitmapUtils {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
- fun downLoadLottie(downloadUrl: String, name: String) {
|
|
|
|
- val pathFile = File(UrlConstant.specialResourcePath)
|
|
|
|
- pathFile.mkdirs()
|
|
|
|
- GlobalScope.launch {
|
|
|
|
- try {
|
|
|
|
- val responseBody = ApiManager.homeApi.downFile(downloadUrl)
|
|
|
|
- dowload(AppContext.getContext(), responseBody) {
|
|
|
|
- hasSelfPath = {
|
|
|
|
- UrlConstant.specialResourcePath
|
|
|
|
- }
|
|
|
|
- setFileName = {
|
|
|
|
- File.separator + name
|
|
|
|
- }
|
|
|
|
- success {
|
|
|
|
- LogUtil.d("资源","下载成功")
|
|
|
|
- }
|
|
|
|
- error {
|
|
|
|
- LogUtil.d("资源","下载失败")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }.startDowload()
|
|
|
|
- } catch (e: Exception) {
|
|
|
|
- LogUtil.d("资源","下载失败")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|