aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
diff options
context:
space:
mode:
authorDiogenes Molinares <amolinares19@gmail.com>2020-06-10 10:35:03 +0200
committerGitHub <noreply@github.com>2020-06-10 14:05:03 +0530
commit0050deb5012d158f83f04bc6be61a52596fa99c2 (patch)
tree51417971d7b7dbcbeb3d34d688c9a8d45a9c24ca /app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
parent7569d4027081d27a6e3d975c14cfc9bdcd879257 (diff)
downloadHardenedPass-0050deb5012d158f83f04bc6be61a52596fa99c2.tar.gz
HardenedPass-0050deb5012d158f83f04bc6be61a52596fa99c2.zip
Remove Apache Commons dependencies (#840)
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/UserPreference.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.kt16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
index 63c9ce7c..96f23724 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
@@ -36,6 +36,7 @@ import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreferenceCompat
import com.github.ajalt.timberkt.Timber.tag
import com.github.ajalt.timberkt.d
+import com.github.ajalt.timberkt.w
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.zeapo.pwdstore.autofill.AutofillPreferenceActivity
@@ -52,7 +53,6 @@ import com.zeapo.pwdstore.utils.PasswordRepository
import com.zeapo.pwdstore.utils.autofillManager
import com.zeapo.pwdstore.utils.getEncryptedPrefs
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
-import org.apache.commons.io.FileUtils
import java.io.File
import java.io.IOException
import java.time.LocalDateTime
@@ -227,7 +227,7 @@ class UserPreference : AppCompatActivity() {
.setCancelable(false)
.setPositiveButton(R.string.dialog_delete) { dialogInterface, _ ->
try {
- FileUtils.cleanDirectory(PasswordRepository.getRepositoryDirectory(callingActivity.applicationContext))
+ PasswordRepository.getRepositoryDirectory(callingActivity.applicationContext).deleteRecursively()
PasswordRepository.closeRepository()
} catch (ignored: Exception) {
// TODO Handle the different cases of exceptions
@@ -357,8 +357,8 @@ class UserPreference : AppCompatActivity() {
prefIsCustomDict?.onPreferenceChangeListener = ChangeListener { _, newValue ->
if (!(newValue as Boolean)) {
val customDictFile = File(context.filesDir, XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE)
- if (customDictFile.exists()) {
- FileUtils.deleteQuietly(customDictFile)
+ if (customDictFile.exists() && !customDictFile.delete()) {
+ w { "Failed to delete custom XkPassword dictionary: $customDictFile" }
}
prefCustomDictPicker?.setSummary(R.string.xkpwgen_pref_custom_dict_picker_summary)
}
@@ -706,9 +706,11 @@ class UserPreference : AppCompatActivity() {
val customDictPref = prefsFragment.findPreference<Preference>("pref_key_custom_dict")
setCustomDictSummary(customDictPref, uri)
// copy user selected file to internal storage
- val inputStream = this.contentResolver.openInputStream(uri)
- val customDictFile = File(this.filesDir.toString(), XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE)
- FileUtils.copyInputStreamToFile(inputStream, customDictFile)
+ val inputStream = contentResolver.openInputStream(uri)
+ val customDictFile = File(filesDir.toString(), XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE).outputStream()
+ inputStream?.copyTo(customDictFile, 1024)
+ inputStream?.close()
+ customDictFile.close()
setResult(Activity.RESULT_OK)
}