Kaynağa Gözat

feat: 清除缓存

tongmengxiao 6 ay önce
ebeveyn
işleme
20dd70a90f

+ 17 - 0
baseswago/src/main/java/com/swago/baseswago/UserVm.kt

@@ -11,6 +11,10 @@ import com.swago.baseswago.model.mine.LevelModel
 import com.swago.baseswago.model.mine.RoomBlack
 import com.swago.baseswago.model.mine.RoomBlackItem
 import com.swago.baseswago.util.*
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
 import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import okhttp3.MultipartBody
 import okhttp3.RequestBody
@@ -322,4 +326,17 @@ class UserVm(application: Application) : BaseViewModel(application) {
         }
 
     }
+
+    fun clearCache(){
+        CoroutineScope(Dispatchers.Main).launch {
+            withContext(Dispatchers.IO){
+                FileUtil.clearCache(AppContext.getContext())
+            }
+            Toast.makeText(
+                AppContext.getContext(),
+                AppContext.getContext().resources.getString(R.string.clear_cache_success),
+                Toast.LENGTH_SHORT
+            ).show()
+        }
+    }
 }

+ 14 - 0
baseswago/src/main/java/com/swago/baseswago/util/FileUtil.kt

@@ -1,5 +1,6 @@
 package com.swago.baseswago.util
 
+import android.app.Application
 import java.io.*
 import java.lang.Exception
 import java.util.*
@@ -99,4 +100,17 @@ object FileUtil {
         }
     }
 
+    fun clearCache(context : Application){
+        deleteFile(File(AppContext.getContext().cacheDir.absolutePath))
+        deleteFile(File(AppContext.getContext().filesDir.absolutePath))
+        val externalFile = context.getExternalFilesDir("")
+        if (externalFile != null){
+            deleteFile(File(externalFile.absolutePath))
+        }
+        val externalCache = context.externalCacheDir
+        if (externalCache != null){
+            deleteFile(File(externalCache.absolutePath))
+        }
+    }
+
 }

+ 2 - 0
baseswago/src/main/res/values-ar/strings.xml

@@ -329,4 +329,6 @@
     <string name="loading">تحميل...</string>
     <string name="modify_success">حفظ بنجاح</string>
     <string name="Password_rooms_do_not_count_as_hours">أوقات غرفة القفل لم يتم احتسابها في المدة</string>
+    <string name="clear_cache">مسح ذاكرة التخزين المؤقت</string>
+    <string name="clear_cache_success">مسح ذاكرة التخزين المؤقت بنجاح</string>
 </resources>

+ 2 - 0
baseswago/src/main/res/values-in/strings.xml

@@ -341,4 +341,6 @@
     <string name="loading">loading...</string>
     <string name="modify_success">Berhasil dimodifikasi</string>
     <string name="Password_rooms_do_not_count_as_hours">Ruang kata sandi tidak tambah durasi</string>
+    <string name="clear_cache">Bersihkan cache</string>
+    <string name="clear_cache_success">Hapus sukses</string>
 </resources>

+ 3 - 0
baseswago/src/main/res/values-ms/strings.xml

@@ -341,4 +341,7 @@
     <string name="loading">loading...</string>
     <string name="modify_success">Berhasil dimodifikasi</string>
     <string name="Password_rooms_do_not_count_as_hours">Ruang kata sandi tidak tambah durasi</string>
+    <string name="clear_cache">Bersihkan cache</string>
+    <string name="clear_cache_success">Hapus sukses</string>
+
 </resources>

+ 2 - 0
baseswago/src/main/res/values-zh/strings.xml

@@ -329,4 +329,6 @@
     <string name="loading">loading...</string>
     <string name="modify_success">修改成功</string>
     <string name="Password_rooms_do_not_count_as_hours">密码房不计入时长</string>
+    <string name="clear_cache">清除缓存</string>
+    <string name="clear_cache_success">清除成功</string>
 </resources>

+ 2 - 0
baseswago/src/main/res/values/strings.xml

@@ -361,4 +361,6 @@
     <string name="loading">loading...</string>
     <string name="modify_success">Modify success</string>
     <string name="Password_rooms_do_not_count_as_hours">Lock room times didn\'t count into</string>
+    <string name="clear_cache">clear cache</string>
+    <string name="clear_cache_success">Clearance successful</string>
 </resources>

+ 6 - 0
user/src/main/java/com/swago/user/SettingActivity.kt

@@ -55,6 +55,12 @@ class SettingActivity : BaseXActivity<ActivitySettingBinding>() {
                 userVm.logout()
             }
         })
+
+        binding.tvClearCache.setOnClickListener(object : NoDoubleClickListener() {
+            override fun onClick() {
+                userVm.clearCache()
+            }
+        })
     }
 
     override fun initLiveData() {

+ 13 - 2
user/src/main/res/layout/activity_setting.xml

@@ -52,10 +52,21 @@
             android:layout_width="match_parent"
             android:layout_height="60dp"/>
 
+        <com.swago.baseswago.cusview.MediumTextView
+            android:id="@+id/tvClearCache"
+            app:layout_constraintTop_toBottomOf="@+id/tvUserPrivacy"
+            android:gravity="center_vertical"
+            android:padding="20dp"
+            android:textSize="16dp"
+            android:textColor="@color/black"
+            android:drawableEnd="@mipmap/more_small"
+            android:text="@string/clear_cache"
+            android:layout_width="match_parent"
+            android:layout_height="60dp"/>
 
         <com.swago.baseswago.cusview.MediumTextView
             android:id="@+id/tvCurrentVersion"
-            app:layout_constraintTop_toBottomOf="@+id/tvUserPrivacy"
+            app:layout_constraintTop_toBottomOf="@+id/tvClearCache"
             android:gravity="center_vertical"
             android:padding="20dp"
             android:textSize="16dp"
@@ -70,7 +81,7 @@
 
         <com.swago.baseswago.cusview.RegularTextView
             android:id="@+id/tvVersion"
-            app:layout_constraintTop_toBottomOf="@+id/tvUserPrivacy"
+            app:layout_constraintTop_toBottomOf="@+id/tvClearCache"
             android:gravity="center_vertical"
             android:padding="20dp"
             android:textSize="16dp"