代码拉取完成,页面将自动刷新
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' }
}
}
implementation 'com.gitee.ice_king:iceframework:1.0.8'
IceApplication.statusBarColor=0xff000000.toInt()//设置全局状态栏颜色
IceApplication.init(this)
BaseActivity.activityTasks
fun getHtmlData(htmlBody: String?): String
binding.textView
binding.textView
toastMsg.value=""
showProgressBar.value=true
adapter.list=arrayListOf()
adapter.selectPosition
adapter.selectPositions
adapter.onItemClickListener={}
viewHolder.binding.textView.text=""
http = Http.config(baseUrl){
val headers=HashMap<String,String>()
return@config headers
}
class ApiResponse<T>(
var data: T?,
var code: Int,
var msg: String
)
@GET("demo/demo")
suspend fun test(): ApiResponse<Any>
suspend fun <T> BaseViewModel.call(isBackground:Boolean=false, job:suspend ()->T):T{
if(!isBackground){
this.showProgressBar.value=true
}
var apiResponse: ApiResponse<*>?=null
if(!NetworkUtils.isConnected()){
apiResponse=ApiResponse(null,201,"当前网络未连接")
}
withContext(Dispatchers.IO){
if(!NetworkUtils.isAvailable()){
apiResponse=ApiResponse(null,201,"网络链接不可用")
}
}
if(apiResponse!=null){
if(!isBackground){
this.showProgressBar.value=false
}
return apiResponse as T
}
try {
val res=job()
if(res is ApiResponse<*>){
apiResponse=res
if(apiResponse!!.code==401){
apiResponse!!.msg="请登录"
App.needLogin()
}
if(apiResponse!!.code==402){
apiResponse!!.msg="登录状态过期,请重新登录"
App.needLogin()
}
}else{
apiResponse=ApiResponse(null,201,"Server Error")
}
}catch (e:Exception){
e.printStackTrace()
//对异常进行判断,这个是我随便写的一点,可以写一个工具类给封装起来
val msg = when (e) {
is SocketTimeoutException -> "time out"
is HttpException -> {
when (e.code()) {
404 -> "Did not find suitable resources"
500 -> "Server internal error"
else -> e.message()
}
}
is JsonSyntaxException -> "json parsing exception"
is UnknownHostException -> "network anomaly"
else -> e.message
}
this.toastMsg.value=msg!!
apiResponse=ApiResponse(null,201, msg)
}
if(!isBackground){
this.showProgressBar.value=false
}
return apiResponse as T
}
private val api = App.http.instance<Api>()
viewModelScope.launch {
val res=call {
api.test()
}
}
RetrofitUtils.file2MultiPartBody(file)
fun ImageView.load(context:Context,url:String){
...
}
fun ImageView.loadBlur(context:Context, url:String){
...
}
fun Date.format(format:String):String{
...
}
fun String.toDate(format:String):Date{
...
}
fun View.setOnNotDoubleClickListener(block:(v:View)->Unit){
...
}
//版本号
fun packageCode(context: Context):Int{
...
}
//版本名称
fun packageName(context: Context):String{
...
}
//缓存大小,返回的是格式化后的大小
fun getTotalCacheSize(context: Context): String {
...
}
//清理所有缓存
fun clearAllCache(context: Context) {
...
}
//开始倒计时
fun countDown(lifecycleScope:LifecycleCoroutineScope, tv: TextView) {
...
}
fun requestPermissions(permission:Array<String>,success:()->Unit,fail:()->Unit){
...
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型