111 lines
4.1 KiB
Kotlin
111 lines
4.1 KiB
Kotlin
package com.yingmao.clash.act
|
|
|
|
import android.content.ContentValues
|
|
import android.content.Intent
|
|
import android.graphics.Bitmap
|
|
import android.net.Uri
|
|
import android.os.Bundle
|
|
import android.provider.MediaStore
|
|
import android.view.View
|
|
import android.widget.ImageView
|
|
import android.widget.TextView
|
|
import android.widget.Toast
|
|
import androidx.appcompat.widget.AppCompatImageView
|
|
import androidx.core.content.ContentProviderCompat.requireContext
|
|
import androidx.core.graphics.drawable.toBitmap
|
|
import androidx.lifecycle.ViewModelProvider
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.observe
|
|
import com.bumptech.glide.Glide
|
|
import com.yingmao.clash.view.dialog.RxDialogShapeLoading
|
|
|
|
import com.tencent.mmkv.MMKV
|
|
import com.yingmao.clash.BuildConfig
|
|
import com.yingmao.clash.R
|
|
import com.yingmao.clash.base.BaseActivity
|
|
import com.yingmao.clash.conf.BZYConstants
|
|
import com.yingmao.clash.net.http.HttpStatus
|
|
import com.yingmao.clash.net.http.entity.AppShareInfoRsp
|
|
import com.yingmao.clash.view.RxToast
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.MainScope
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.withContext
|
|
|
|
class LossPreventionActivity : BaseActivity() {
|
|
var iv_lossper: ImageView? = null;
|
|
private lateinit var aiBack: AppCompatImageView
|
|
private lateinit var tvSave:TextView
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.layout_activity_losspre)
|
|
initView()
|
|
}
|
|
|
|
private fun initView() {
|
|
aiBack=findViewById(R.id.aiBack)
|
|
aiBack.setOnClickListener {
|
|
finish()
|
|
}
|
|
tvSave= findViewById(R.id.tv_save)
|
|
iv_lossper = findViewById(R.id.iv_gif)
|
|
tvSave.setOnClickListener {
|
|
lifecycleScope.launch {
|
|
saveImage()
|
|
}
|
|
}
|
|
|
|
var fdsUrl = if (BuildConfig.is_ym) {
|
|
"https://yingmao.oss-cn-hongkong.aliyuncs.com/fds/fds_yingmao.jpg"
|
|
} else if (BuildConfig.is_tz) {
|
|
"https://yingmao.oss-cn-hongkong.aliyuncs.com/fds/fds_taizi.png"
|
|
} else {
|
|
"https://yingmao.oss-cn-hongkong.aliyuncs.com/fds/fds_bzy.png"
|
|
}
|
|
Glide.with(this).load(fdsUrl)
|
|
.placeholder(R.drawable.spinner200px200px)
|
|
.fitCenter()
|
|
.into(iv_lossper!!)
|
|
}
|
|
|
|
private suspend fun saveImage() {
|
|
withContext(Dispatchers.IO) {
|
|
val imageUrl = this@LossPreventionActivity.contentResolver.insert(
|
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
|
ContentValues()
|
|
) ?: kotlin.run {
|
|
Toast.makeText(
|
|
this@LossPreventionActivity,
|
|
"存储失败,请使用屏幕截屏功能保存",
|
|
Toast.LENGTH_SHORT
|
|
).show()
|
|
Toast.makeText(this@LossPreventionActivity, resources.getString(R.string.SaveFileError), Toast.LENGTH_SHORT).show()
|
|
}
|
|
this@LossPreventionActivity.contentResolver.openOutputStream(imageUrl as Uri).use { os->
|
|
os?.let {
|
|
iv_lossper?.let { iv ->
|
|
if (iv.drawable.toBitmap().compress(Bitmap.CompressFormat.PNG, 90, os)) {
|
|
MainScope().launch {
|
|
Toast.makeText(
|
|
this@LossPreventionActivity,
|
|
resources.getString(R.string.StorageSuccessful),
|
|
Toast.LENGTH_SHORT
|
|
).show()
|
|
}
|
|
} else {
|
|
MainScope().launch {
|
|
Toast.makeText(
|
|
this@LossPreventionActivity,
|
|
resources.getString(R.string.SaveFileError),
|
|
Toast.LENGTH_SHORT
|
|
).show()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
} |