Skip to content

Commit b6290c7

Browse files
committed
add password protection for showing hidden items
1 parent 9d81c1a commit b6290c7

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ android {
3232
}
3333

3434
dependencies {
35-
compile 'com.simplemobiletools:commons:2.22.7'
35+
compile 'com.simplemobiletools:commons:2.25.3'
3636
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
3737
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3838
}

app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,19 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
184184
}
185185

186186
private fun temporarilyShowHidden() {
187-
config.temporarilyShowHidden = true
187+
if (config.temporarilyShowHidden) {
188+
toggleTemporarilyShowHidden(false)
189+
} else {
190+
handleHiddenFolderPasswordProtection {
191+
toggleTemporarilyShowHidden(true)
192+
}
193+
}
194+
}
195+
196+
private fun toggleTemporarilyShowHidden(show: Boolean) {
197+
config.temporarilyShowHidden = show
188198
openPath(currentPath)
199+
invalidateOptionsMenu()
189200
}
190201

191202
private fun launchAbout() {

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package com.simplemobiletools.filemanager.activities
22

33
import android.content.Intent
44
import android.os.Bundle
5+
import com.simplemobiletools.commons.dialogs.SecurityDialog
6+
import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection
57
import com.simplemobiletools.commons.extensions.updateTextColors
8+
import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS
69
import com.simplemobiletools.filemanager.R
710
import com.simplemobiletools.filemanager.extensions.config
811
import kotlinx.android.synthetic.main.activity_settings.*
@@ -19,6 +22,7 @@ class SettingsActivity : SimpleActivity() {
1922
setupCustomizeColors()
2023
setupManageFavorites()
2124
setupShowHidden()
25+
setupPasswordProtection()
2226
updateTextColors(settings_holder)
2327
}
2428

@@ -37,8 +41,32 @@ class SettingsActivity : SimpleActivity() {
3741
private fun setupShowHidden() {
3842
settings_show_hidden.isChecked = config.showHidden
3943
settings_show_hidden_holder.setOnClickListener {
40-
settings_show_hidden.toggle()
41-
config.showHidden = settings_show_hidden.isChecked
44+
if (config.showHidden) {
45+
toggleShowHidden()
46+
} else {
47+
handleHiddenFolderPasswordProtection {
48+
toggleShowHidden()
49+
}
50+
}
51+
}
52+
}
53+
54+
private fun toggleShowHidden() {
55+
settings_show_hidden.toggle()
56+
config.showHidden = settings_show_hidden.isChecked
57+
}
58+
59+
private fun setupPasswordProtection() {
60+
settings_password_protection.isChecked = config.isPasswordProtectionOn
61+
settings_password_protection_holder.setOnClickListener {
62+
val tabToShow = if (config.isPasswordProtectionOn) config.protectionType else SHOW_ALL_TABS
63+
SecurityDialog(this, config.passwordHash, tabToShow) { hash, type ->
64+
val hasPasswordProtection = config.isPasswordProtectionOn
65+
settings_password_protection.isChecked = !hasPasswordProtection
66+
config.isPasswordProtectionOn = !hasPasswordProtection
67+
config.passwordHash = if (hasPasswordProtection) "" else hash
68+
config.protectionType = type
69+
}
4270
}
4371
}
4472
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,25 @@
6868
android:text="@string/show_hidden"/>
6969

7070
</RelativeLayout>
71+
72+
<RelativeLayout
73+
android:id="@+id/settings_password_protection_holder"
74+
android:layout_width="match_parent"
75+
android:layout_height="wrap_content"
76+
android:layout_marginTop="@dimen/medium_margin"
77+
android:background="?attr/selectableItemBackground"
78+
android:padding="@dimen/activity_margin">
79+
80+
<com.simplemobiletools.commons.views.MySwitchCompat
81+
android:id="@+id/settings_password_protection"
82+
android:layout_width="match_parent"
83+
android:layout_height="wrap_content"
84+
android:background="@null"
85+
android:clickable="false"
86+
android:paddingLeft="@dimen/medium_margin"
87+
android:paddingStart="@dimen/medium_margin"
88+
android:text="@string/password_protect_hidden_items"/>
89+
90+
</RelativeLayout>
7191
</LinearLayout>
7292
</ScrollView>

0 commit comments

Comments
 (0)