Added download clear feature

This commit is contained in:
tom5079
2019-06-06 01:06:48 +09:00
parent 9014ad6d77
commit 57e08d2208
5 changed files with 45 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import kotlinx.android.synthetic.main.dialog_default_query.view.*
@@ -95,6 +96,33 @@ class SettingsActivity : AppCompatActivity() {
true
}
}
with(findPreference<Preference>("delete_downloads")) {
this ?: return@with
val dir = File(ContextCompat.getDataDir(context), "images")
summary = getCacheSize(dir)
setOnPreferenceClickListener {
AlertDialog.Builder(context).apply {
setTitle(R.string.warning)
setMessage(R.string.settings_clear_downloads_alert_message)
setPositiveButton(android.R.string.yes) { _, _ ->
if (dir.exists())
dir.deleteRecursively()
val downloads = (activity!!.application as Pupil).downloads
downloads.clear()
summary = getCacheSize(dir)
}
setNegativeButton(android.R.string.no) { _, _ -> }
}.show()
true
}
}
with(findPreference<Preference>("clear_history")) {
this ?: return@with