mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
do not allow swiping the protection viewpager when a password is set
This commit is contained in:
parent
45e1fba535
commit
6e1f56f864
5 changed files with 44 additions and 27 deletions
|
@ -155,12 +155,13 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun setupPasswordProtection() {
|
||||
settings_password_protection.isChecked = config.isPasswordProtectionOn
|
||||
settings_password_protection_holder.setOnClickListener {
|
||||
SecurityDialog(this, config.passwordHash) { hash, type ->
|
||||
val tabToShow = if (config.isPasswordProtectionOn) config.protectionType else SHOW_ALL_TABS
|
||||
SecurityDialog(this, config.passwordHash, tabToShow) { hash, type ->
|
||||
val hasPasswordProtection = config.isPasswordProtectionOn
|
||||
settings_password_protection.isChecked = !hasPasswordProtection
|
||||
config.isPasswordProtectionOn = !hasPasswordProtection
|
||||
config.passwordHash = if (hasPasswordProtection) "" else hash
|
||||
config.protectionType = PROTECTION_PATTERN
|
||||
config.protectionType = type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,41 +4,24 @@ import android.support.design.widget.TabLayout
|
|||
import android.support.v4.view.ViewPager
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.adapters.PasswordTypesAdapter
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.helpers.SHOW_ALL_TABS
|
||||
import com.simplemobiletools.gallery.interfaces.HashListener
|
||||
import com.simplemobiletools.gallery.views.MyDialogViewPager
|
||||
import kotlinx.android.synthetic.main.dialog_security.view.*
|
||||
|
||||
class SecurityDialog(val activity: SimpleActivity, val requiredHash: String, val callback: (hash: String, type: Int) -> Unit) : HashListener {
|
||||
class SecurityDialog(val activity: SimpleActivity, val requiredHash: String, val showTabIndex: Int, val callback: (hash: String, type: Int) -> Unit) : HashListener {
|
||||
var dialog: AlertDialog? = null
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_security, null)
|
||||
|
||||
init {
|
||||
view.apply {
|
||||
val viewPager = findViewById(R.id.dialog_tab_view_pager) as MyDialogViewPager
|
||||
val textColor = context.config.textColor
|
||||
dialog_tab_layout.setTabTextColors(textColor, textColor)
|
||||
dialog_tab_layout.setSelectedTabIndicatorColor(context.config.primaryColor)
|
||||
dialog_tab_layout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
override fun onTabReselected(tab: TabLayout.Tab?) {
|
||||
}
|
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab) {
|
||||
}
|
||||
|
||||
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||
if (tab.text.toString().equals(resources.getString(R.string.pattern), true)) {
|
||||
viewPager.currentItem = 0
|
||||
} else {
|
||||
viewPager.currentItem = 1
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
viewPager.adapter = PasswordTypesAdapter(context, requiredHash, this@SecurityDialog)
|
||||
viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
|
@ -51,6 +34,31 @@ class SecurityDialog(val activity: SimpleActivity, val requiredHash: String, val
|
|||
dialog_tab_layout.getTabAt(position)!!.select()
|
||||
}
|
||||
})
|
||||
|
||||
if (showTabIndex == SHOW_ALL_TABS) {
|
||||
val textColor = context.config.textColor
|
||||
dialog_tab_layout.setTabTextColors(textColor, textColor)
|
||||
dialog_tab_layout.setSelectedTabIndicatorColor(context.config.primaryColor)
|
||||
dialog_tab_layout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||
override fun onTabReselected(tab: TabLayout.Tab?) {
|
||||
}
|
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab) {
|
||||
}
|
||||
|
||||
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||
if (tab.text.toString().equals(resources.getString(R.string.pattern), true)) {
|
||||
viewPager.currentItem = 0
|
||||
} else {
|
||||
viewPager.currentItem = 1
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
dialog_tab_layout.beGone()
|
||||
viewPager.currentItem = showTabIndex
|
||||
viewPager.allowSwiping = false
|
||||
}
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
|
|
|
@ -335,7 +335,7 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) {
|
|||
|
||||
fun SimpleActivity.handleHiddenFolderPasswordProtection(callback: () -> Unit) {
|
||||
if (config.isPasswordProtectionOn) {
|
||||
SecurityDialog(this, config.passwordHash) { hash, type ->
|
||||
SecurityDialog(this, config.passwordHash, config.protectionType) { hash, type ->
|
||||
callback()
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -67,6 +67,10 @@ val ORIENT_LANDSCAPE_RIGHT = 2
|
|||
val ORIENT_UPSIDE_DOWN = 3
|
||||
|
||||
// security
|
||||
val PROTECTION_PATTERN = 1
|
||||
val PROTECTION_PIN = 2
|
||||
val PROTECTION_FINGERPRINT = 3
|
||||
val PROTECTION_PATTERN = 0
|
||||
val PROTECTION_PIN = 1
|
||||
val PROTECTION_FINGERPRINT = 2
|
||||
|
||||
val SHOW_ALL_TABS = -1
|
||||
val SHOW_PATTERN = 0
|
||||
val SHOW_PIN = 1
|
||||
|
|
|
@ -7,17 +7,21 @@ import android.view.MotionEvent
|
|||
import android.view.View
|
||||
|
||||
class MyDialogViewPager : ViewPager {
|
||||
var allowSwiping = true
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
// disable manual swiping of viewpager at the dialog
|
||||
// disable manual swiping of viewpager at the dialog by swiping over the pattern
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onTouchEvent(ev: MotionEvent): Boolean {
|
||||
if (!allowSwiping)
|
||||
return false
|
||||
|
||||
try {
|
||||
return super.onTouchEvent(ev)
|
||||
} catch (ignored: Exception) {
|
||||
|
|
Loading…
Reference in a new issue