Skip to content

Commit 028877e

Browse files
committed
added password protection to deleting and moving files
1 parent 82f2a9f commit 028877e

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SettingsActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SettingsActivity : SimpleActivity() {
3131
setupShowHidden()
3232
setupHiddenItemPasswordProtection()
3333
setupAppPasswordProtection()
34+
setupFileDeletionPasswordProtection()
3435
setupKeepLastModified()
3536
setupShowInfoBubble()
3637
setupEnableRootAccess()
@@ -129,6 +130,28 @@ class SettingsActivity : SimpleActivity() {
129130
}
130131
}
131132

133+
private fun setupFileDeletionPasswordProtection() {
134+
settings_file_deletion_password_protection.isChecked = config.isDeletePasswordProtectionOn
135+
settings_file_deletion_password_protection_holder.setOnClickListener {
136+
val tabToShow = if (config.isDeletePasswordProtectionOn) config.deleteProtectionType else SHOW_ALL_TABS
137+
SecurityDialog(this, config.deletePasswordHash, tabToShow) { hash, type, success ->
138+
if (success) {
139+
val hasPasswordProtection = config.isDeletePasswordProtectionOn
140+
settings_file_deletion_password_protection.isChecked = !hasPasswordProtection
141+
config.isDeletePasswordProtectionOn = !hasPasswordProtection
142+
config.deletePasswordHash = if (hasPasswordProtection) "" else hash
143+
config.deleteProtectionType = type
144+
145+
if (config.isDeletePasswordProtectionOn) {
146+
val confirmationTextId = if (config.deleteProtectionType == PROTECTION_FINGERPRINT)
147+
R.string.fingerprint_setup_successfully else R.string.protection_setup_successfully
148+
ConfirmationDialog(this, "", confirmationTextId, R.string.ok, 0) { }
149+
}
150+
}
151+
}
152+
}
153+
}
154+
132155
private fun setupKeepLastModified() {
133156
settings_keep_last_modified.isChecked = config.keepLastModified
134157
settings_keep_last_modified_holder.setOnClickListener {

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
8585
R.id.cab_open_with -> openWith()
8686
R.id.cab_open_as -> openAs()
8787
R.id.cab_copy_to -> copyMoveTo(true)
88-
R.id.cab_move_to -> copyMoveTo(false)
88+
R.id.cab_move_to -> tryMoveFiles()
8989
R.id.cab_compress -> compressSelection()
9090
R.id.cab_decompress -> decompressSelection()
9191
R.id.cab_select_all -> selectAll()
@@ -247,6 +247,12 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
247247
}
248248
}
249249

250+
private fun tryMoveFiles() {
251+
activity.handleDeletePasswordProtection {
252+
copyMoveTo(false)
253+
}
254+
}
255+
250256
private fun copyMoveTo(isCopyOperation: Boolean) {
251257
val files = getSelectedFileDirItems()
252258
val firstFile = files[0]
@@ -479,11 +485,13 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
479485
}
480486

481487
private fun askConfirmDelete() {
482-
val selectionSize = selectedKeys.size
483-
val items = resources.getQuantityString(R.plurals.delete_items, selectionSize, selectionSize)
484-
val question = String.format(resources.getString(R.string.deletion_confirmation), items)
485-
ConfirmationDialog(activity, question) {
486-
deleteFiles()
488+
activity.handleDeletePasswordProtection {
489+
val selectionSize = selectedKeys.size
490+
val items = resources.getQuantityString(R.plurals.delete_items, selectionSize, selectionSize)
491+
val question = String.format(resources.getString(R.string.deletion_confirmation), items)
492+
ConfirmationDialog(activity, question) {
493+
deleteFiles()
494+
}
487495
}
488496
}
489497

app/src/main/res/layout/activity_settings.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,29 @@
262262

263263
</RelativeLayout>
264264

265+
<RelativeLayout
266+
android:id="@+id/settings_file_deletion_password_protection_holder"
267+
android:layout_width="match_parent"
268+
android:layout_height="wrap_content"
269+
android:layout_marginTop="@dimen/medium_margin"
270+
android:background="?attr/selectableItemBackground"
271+
android:paddingLeft="@dimen/normal_margin"
272+
android:paddingTop="@dimen/activity_margin"
273+
android:paddingRight="@dimen/normal_margin"
274+
android:paddingBottom="@dimen/activity_margin">
275+
276+
<com.simplemobiletools.commons.views.MySwitchCompat
277+
android:id="@+id/settings_file_deletion_password_protection"
278+
android:layout_width="match_parent"
279+
android:layout_height="wrap_content"
280+
android:background="@null"
281+
android:clickable="false"
282+
android:paddingStart="@dimen/medium_margin"
283+
android:text="@string/password_protect_file_deletion"
284+
app:switchPadding="@dimen/medium_margin"/>
285+
286+
</RelativeLayout>
287+
265288
<RelativeLayout
266289
android:id="@+id/settings_enable_root_access_holder"
267290
android:layout_width="match_parent"

0 commit comments

Comments
 (0)