pull/1738/head
kunfei 3 years ago
parent 0c50b867ad
commit 9458e1bedd
  1. 22
      app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt
  2. 7
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt

@ -0,0 +1,22 @@
package io.legado.app.ui.config
import android.app.Application
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.help.BookHelp
import io.legado.app.utils.FileUtils
import io.legado.app.utils.toastOnUi
class ConfigViewModel(application: Application) : BaseViewModel(application) {
fun clearCache() {
execute {
BookHelp.clearCache()
FileUtils.delete(context.cacheDir.absolutePath)
}.onSuccess {
context.toastOnUi(R.string.clear_cache_success)
}
}
}

@ -6,6 +6,7 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.preference.ListPreference
import androidx.preference.Preference
import io.legado.app.R
@ -13,7 +14,6 @@ import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.BookHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor
@ -29,6 +29,7 @@ import splitties.init.appCtx
class OtherConfigFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
private val viewModel by activityViewModels<ConfigViewModel>()
private val packageManager = appCtx.packageManager
private val componentName = ComponentName(
appCtx,
@ -185,9 +186,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
messageResource = R.string.sure_del
) {
okButton {
BookHelp.clearCache()
FileUtils.delete(requireActivity().cacheDir.absolutePath)
toastOnUi(R.string.clear_cache_success)
viewModel.clearCache()
}
noButton()
}

Loading…
Cancel
Save