Kaynağa Gözat

1.修改图片缓存策略,不缓存

JaycePC 6 ay önce
ebeveyn
işleme
a147a19c19

+ 2 - 0
HttpCoreLibrary/build.gradle

@@ -44,5 +44,7 @@ dependencies {
     api libs.rx.android
     api libs.gson
 
+    implementation 'com.blankj:utilcodex:1.31.1'
+
 //    implementation dep.luban
 }

+ 38 - 12
HttpCoreLibrary/src/main/java/com/rc/httpcore/HttpClient.kt

@@ -2,6 +2,8 @@ package com.rc.httpcore
 
 import android.content.Context
 import android.util.Log
+import com.blankj.utilcode.util.AppUtils
+import com.blankj.utilcode.util.LogUtils
 import com.rc.httpcore.client.factory.ClientFactory
 import com.rc.httpcore.client.factory.RetrofitFactory
 import com.rc.httpcore.config.OkHttpDNS
@@ -19,13 +21,14 @@ import java.util.logging.Logger
 
 object HttpClient {
 
-//    private const val TIMEOUT_DEFAULT = 3 * 60L
+    //    private const val TIMEOUT_DEFAULT = 3 * 60L
     private const val TIMEOUT_DEFAULT = 10L
 
     private var mAppContext: Context? = null
     private val LOGGER: Logger = Logger.getLogger(HttpClient::class.java.name)
-    var token: String?=null
+    var token: String? = null
     var vName: String = "1.0.0"
+    var httpClient: OkHttpClient? = null
 
 
     fun init(appContext: Context) {
@@ -50,7 +53,7 @@ object HttpClient {
 
     private fun buildRetrofit(
         baseUrl: String = HttpConfig.API_BASE_URL,
-        okHttpClient: OkHttpClient = buildHttpClient()
+        okHttpClient: OkHttpClient? = buildHttpClient()
     ): Retrofit {
         return Retrofit.Builder()
             .client(okHttpClient)
@@ -61,21 +64,44 @@ object HttpClient {
             .build()
     }
 
-    private fun buildHttpClient(): OkHttpClient {
+    private fun buildHttpClient(): OkHttpClient? {
 //        //设置日志打印级别
 //        val interceptor = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { message ->
 //            LOGGER.log(Level.INFO, message)
 //        })
 //        interceptor.level = HttpLoggingInterceptor.Level.BODY
-        return OkHttpClient.Builder()
-            .readTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置读取超时时间
-            .connectTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置请求超时时间
-            .writeTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置写入超时时间
-            .addNetworkInterceptor(TokenHeaderInterceptor())
-            .addInterceptor(LogInterceptor())//添加请求日志
-            .retryOnConnectionFailure(true) // 设置出现错误进行重新连接
+
+        val logPath = "/sdcard/logs/"
+        val config = LogUtils.getConfig()
+        // log开关控制
+        config.setLogSwitch(true)
+        // log控制台开关
+        config.setConsoleSwitch(true)
+        // logTag
+        config.setGlobalTag("Jayce")
+        // log头部信息开关
+        config.setLogHeadSwitch(true)
+        // log文件开关
+        config.setLog2FileSwitch(true)
+        config.setDir(logPath)
+        // log文件前缀
+        config.setFilePrefix(AppUtils.getAppName())
+        // log边框开关
+        config.setBorderSwitch(true)
+        // log文件保存天数
+        config.setSaveDays(7)
+        if (null == httpClient) {
+            return OkHttpClient.Builder()
+                .readTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置读取超时时间
+                .connectTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置请求超时时间
+                .writeTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置写入超时时间
+                .addNetworkInterceptor(TokenHeaderInterceptor())
+                .addInterceptor(LogInterceptor())//添加请求日志
+                .retryOnConnectionFailure(true) // 设置出现错误进行重新连接
 //            .dns(OkHttpDNS())
-            .build()
+                .build()
+        }
+        return httpClient;
     }
 
 }

+ 10 - 11
HttpCoreLibrary/src/main/java/com/rc/httpcore/vo/LogInterceptor.java

@@ -1,6 +1,7 @@
 package com.rc.httpcore.vo;
 
-import android.util.Log;
+
+import com.blankj.utilcode.util.LogUtils;
 
 import java.io.IOException;
 
@@ -18,14 +19,13 @@ public class LogInterceptor implements Interceptor {
         long startTime = System.currentTimeMillis();
         okhttp3.Response response = chain.proceed(chain.request());
         long endTime = System.currentTimeMillis();
-        long duration=endTime-startTime;
+        long duration = endTime - startTime;
         okhttp3.MediaType mediaType = response.body().contentType();
         String content = response.body().string();
-        Log.d(TAG,"\n");
-        Log.d(TAG,"----------Start----------------");
-        Log.d(TAG, "| "+request.toString());
-        String method=request.method();
-        if("POST".equals(method)){
+        String requestString = request.toString();
+        LogUtils.d("----------Start----------------", requestString);
+        String method = request.method();
+        if ("POST".equals(method)) {
             StringBuilder sb = new StringBuilder();
             if (request.body() instanceof FormBody) {
                 FormBody body = (FormBody) request.body();
@@ -33,12 +33,11 @@ public class LogInterceptor implements Interceptor {
                     sb.append(body.encodedName(i) + "=" + body.encodedValue(i) + ",");
                 }
                 sb.delete(sb.length() - 1, sb.length());
-                Log.d(TAG, "| RequestParams:{"+sb.toString()+"}");
+                LogUtils.d("RequestParams", sb.toString());
             }
         }
-        LogUtil.eLength(TAG,"| Response:" + content);
-//        Log.d(TAG, "| Response:" + content);
-        Log.d(TAG,"----------End:"+duration+"毫秒----------");
+        String durationStr = "----------End:" + duration + "毫秒----------";
+        LogUtils.d("Response", content, durationStr);
         return response.newBuilder()
                 .body(okhttp3.ResponseBody.create(mediaType, content))
                 .build();

+ 2 - 1
app/.gitignore

@@ -1 +1,2 @@
-/build
+/build
+/release

+ 1 - 1
app/build.gradle

@@ -12,7 +12,7 @@ android {
         minSdkVersion 24
         targetSdkVersion 34
         versionCode 3
-        versionName "1.04"
+        versionName "1.06"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 

BIN
app/release/Exam_release_v3_1.03_202406211421.apk


+ 0 - 18
app/release/output-metadata.json

@@ -1,18 +0,0 @@
-{
-  "version": 2,
-  "artifactType": {
-    "type": "APK",
-    "kind": "Directory"
-  },
-  "applicationId": "com.dlc.exam",
-  "variantName": "processReleaseResources",
-  "elements": [
-    {
-      "type": "SINGLE",
-      "filters": [],
-      "versionCode": 3,
-      "versionName": "1.03",
-      "outputFile": "Exam_release_v3_1.03_202406211421.apk"
-    }
-  ]
-}

+ 0 - 6
app/src/main/java/com/dlc/exam/ui/SplashActivity.kt

@@ -15,7 +15,6 @@ import com.arcsoft.face.ErrorInfo
 import com.arcsoft.face.FaceEngine
 import com.bumptech.glide.Glide
 import com.bumptech.glide.load.DataSource
-import com.bumptech.glide.load.engine.DiskCacheStrategy
 import com.bumptech.glide.load.engine.GlideException
 import com.bumptech.glide.request.RequestListener
 import com.bumptech.glide.request.target.Target
@@ -192,7 +191,6 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
                         return false
                     }
                 })
-                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                 .preload()
         }
     }
@@ -229,7 +227,6 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
 //                val delayMillis = if (true == mBannerMap[activeIndex]) {
 //                    Glide.with(this@SplashActivity)
 //                        .load(data[activeIndex].imgUrl)
-//                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
 //                        .into(viewBinding.banner)
 //
 //                    3000L
@@ -263,7 +260,6 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
 //                val activeIndex = index % bannerData.size
 //                Glide.with(this@SplashActivity)
 //                    .load(bannerData[activeIndex])
-//                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
 //                    .into(viewBinding.banner)
 //
 //                index++
@@ -626,7 +622,6 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
                     Glide.with(this)
 //                        .load(datas!![activeIndex].imgUrl)
                         .load(url)
-                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                         .into(viewBinding.banner)
 
                     3000L
@@ -671,7 +666,6 @@ class SplashActivity : RcBaseActivity<ActivitySplashBinding>() {
                 Glide.with(this)
 //                    .load(bannerData!![activeIndex])
                     .load(url)
-                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                     .into(viewBinding.banner)
                 index++
                 if (index >= bannerData!!.size) index = 0

+ 3 - 0
app/src/main/java/com/dlc/exam/ui/certificate/CertificatePhotoDialog.kt

@@ -4,6 +4,8 @@ import android.app.Dialog
 import android.content.Context
 import android.os.Bundle
 import android.view.LayoutInflater
+import android.widget.Toast
+import com.blankj.utilcode.util.LogUtils
 import com.bumptech.glide.Glide
 import com.dlc.exam.R
 import com.dlc.exam.databinding.DialogCertificatePhotoBinding
@@ -34,6 +36,7 @@ class CertificatePhotoDialog(context: Context, private val imgUrl: String) :
                 HttpConfig.API_BASE_URL + imgUrl
             }
         }
+        LogUtils.d(imgUrl, url)
         Glide.with(context)
             .load(url)
             .placeholder(R.mipmap.img_bg_jzz)

+ 2 - 1
app/src/main/java/com/dlc/exam/ui/common/FaceMatchingFragment.kt

@@ -4,6 +4,7 @@ import android.app.Activity
 import android.content.Context
 import android.content.DialogInterface
 import android.os.Bundle
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.ViewGroup
 import android.view.ViewTreeObserver
@@ -172,7 +173,7 @@ class FaceMatchingFragment : RcBaseFragment<FragmentFaceMatchingBinding>(),
                 RcLog.info("======SHIBATWO")
                 dismissLoading()
                 callback.invoke(false)
-//                showNetError(throwable)
+                showNetError(throwable)
 
 //                if (!pretreatmentError(throwable)) {
 //                    faceEngineHelper?.stopPreview(false)

+ 3 - 1
app/src/main/java/com/dlc/exam/ui/learn/CourseChapterActivity.kt

@@ -6,6 +6,7 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import androidx.recyclerview.widget.LinearLayoutManager
+import com.blankj.utilcode.util.LogUtils
 import com.chad.library.adapter.base.BaseDelegateMultiAdapter
 import com.chad.library.adapter.base.delegate.BaseMultiTypeDelegate
 import com.chad.library.adapter.base.viewholder.BaseViewHolder
@@ -43,7 +44,7 @@ class CourseChapterActivity : BaseCountDownActivity<ActivityCourseChapterBinding
     override fun initViews(savedInstanceState: Bundle?) {
         super.initViews(savedInstanceState)
         viewBinding.titleBar.setTitleListener(this)
-        viewBinding.titleBar.setUsername(ExamApp.sLearnLoginVo?.nickName)
+        viewBinding.titleBar.setUsername(ExamApp.sLearnLoginVo?.userName)
         mRecord = intent.getBooleanExtra("record", false)
 
         mChapterAdapter.record = mRecord
@@ -163,6 +164,7 @@ class CourseChapterActivity : BaseCountDownActivity<ActivityCourseChapterBinding
 
     @SuppressLint("SetTextI18n")
     private fun updateViews(data: ExamCourseVo?) {
+        LogUtils.json(data)
         data?.let {
             mVideoDraggable = it.videoDraggable
 

+ 1 - 0
app/src/main/java/com/dlc/exam/ui/learn/LearnDetailExoActivity.java

@@ -48,6 +48,7 @@ public class LearnDetailExoActivity extends BaseCountDownActivity<ActivityLearnD
         Intent getIntent = getIntent();
         if (null != getIntent && getIntent.hasExtra("Chapter")) {
             learnChapterBean = getIntent.getParcelableExtra("Chapter");
+            LogUtils.json(learnChapterBean);
             boolean relearn = getIntent.getBooleanExtra("relearn", false);
             if (null == learnChapterBean) {
                 finish();