diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt
index ca462f8b6..4d92c275d 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt
@@ -7,15 +7,14 @@ import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.interfaces.HashListener
-import com.simplemobiletools.gallery.views.PatternTab
+import com.simplemobiletools.gallery.interfaces.SecurityTab
class PasswordTypesAdapter(val context: Context, val requiredHash: String, val hashListener: HashListener) : PagerAdapter() {
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val view = LayoutInflater.from(context).inflate(layoutSelection(position), container, false)
container.addView(view)
- if (position == 0)
- (view as PatternTab).initTab(requiredHash, hashListener)
+ (view as SecurityTab).initTab(requiredHash, hashListener)
return view
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/SecurityTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/SecurityTab.kt
new file mode 100644
index 000000000..000818e1f
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/SecurityTab.kt
@@ -0,0 +1,5 @@
+package com.simplemobiletools.gallery.interfaces
+
+interface SecurityTab {
+ fun initTab(requiredHash: String, listener: HashListener)
+}
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt
index 304974d98..0ca2b3aab 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt
@@ -12,11 +12,12 @@ import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.interfaces.HashListener
+import com.simplemobiletools.gallery.interfaces.SecurityTab
import kotlinx.android.synthetic.main.tab_pattern.view.*
-class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs) {
- var hash = ""
- var requiredHash = ""
+class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs), SecurityTab {
+ private var hash = ""
+ private var requiredHash = ""
lateinit var hashListener: HashListener
override fun onFinishInflate() {
@@ -41,7 +42,7 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context
})
}
- fun initTab(requiredHash: String, listener: HashListener) {
+ override fun initTab(requiredHash: String, listener: HashListener) {
this.requiredHash = requiredHash
hash = requiredHash
hashListener = listener
@@ -52,23 +53,21 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context
hash = newHash
pattern_lock_view.clearPattern()
pattern_lock_title.setText(R.string.repeat_pattern)
+ } else if (hash == newHash) {
+ pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT)
+ Handler().postDelayed({
+ hashListener.receivedHash(hash)
+ }, 300)
} else {
- if (hash == newHash) {
- pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT)
- Handler().postDelayed({
- hashListener.receivedHash(hash)
- }, 300)
- } else {
- pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG)
- context.toast(R.string.wrong_pattern)
- Handler().postDelayed({
- pattern_lock_view.clearPattern()
- if (requiredHash.isEmpty()) {
- hash = ""
- pattern_lock_title.setText(R.string.insert_pattern)
- }
- }, 1000)
- }
+ pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG)
+ context.toast(R.string.wrong_pattern)
+ Handler().postDelayed({
+ pattern_lock_view.clearPattern()
+ if (requiredHash.isEmpty()) {
+ hash = ""
+ pattern_lock_title.setText(R.string.insert_pattern)
+ }
+ }, 1000)
}
}
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt
index a800834fb..a7b7a24f2 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt
@@ -3,11 +3,21 @@ package com.simplemobiletools.gallery.views
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
+import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
+import com.simplemobiletools.gallery.R
+import com.simplemobiletools.gallery.interfaces.HashListener
+import com.simplemobiletools.gallery.interfaces.SecurityTab
import kotlinx.android.synthetic.main.tab_pin.view.*
+import java.math.BigInteger
+import java.security.MessageDigest
+import java.util.*
-class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs) {
- var pin = ""
+class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, attrs), SecurityTab {
+ private var hash = ""
+ private var requiredHash = ""
+ private var pin = ""
+ lateinit var hashListener: HashListener
override fun onFinishInflate() {
super.onFinishInflate()
@@ -27,6 +37,12 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
pin_ok.setOnClickListener { confirmPIN() }
}
+ override fun initTab(requiredHash: String, listener: HashListener) {
+ this.requiredHash = requiredHash
+ hash = requiredHash
+ hashListener = listener
+ }
+
private fun addNumber(number: String) {
if (pin.length < 10) {
pin += number
@@ -42,10 +58,39 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at
}
private fun confirmPIN() {
+ val newHash = getHashedPin()
+ if (pin.isEmpty()) {
+ context.toast(R.string.please_enter_pin)
+ } else if (hash.isEmpty()) {
+ hash = newHash
+ resetPin()
+ pin_lock_title.setText(R.string.repeat_pin)
+ } else if (hash == newHash) {
+ hashListener.receivedHash(hash)
+ } else {
+ resetPin()
+ context.toast(R.string.wrong_pin)
+ if (requiredHash.isEmpty()) {
+ hash = ""
+ pin_lock_title.setText(R.string.enter_pin)
+ }
+ }
+ }
+ private fun resetPin() {
+ pin = ""
+ pin_lock_current_pin.text = ""
}
private fun updatePinCode() {
pin_lock_current_pin.text = "*".repeat(pin.length)
}
+
+ private fun getHashedPin(): String {
+ val messageDigest = MessageDigest.getInstance("SHA-1")
+ messageDigest.update(pin.toByteArray(charset("UTF-8")))
+ val digest = messageDigest.digest()
+ val bigInteger = BigInteger(1, digest)
+ return String.format(Locale.getDefault(), "%0${digest.size * 2}x", bigInteger).toLowerCase()
+ }
}
diff --git a/app/src/main/res/layout/tab_pin.xml b/app/src/main/res/layout/tab_pin.xml
index 9645647ae..8a7c27695 100644
--- a/app/src/main/res/layout/tab_pin.xml
+++ b/app/src/main/res/layout/tab_pin.xml
@@ -45,7 +45,7 @@
android:id="@+id/pin_1"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="1"/>
@@ -53,7 +53,7 @@
android:id="@+id/pin_2"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="2"/>
@@ -61,7 +61,7 @@
android:id="@+id/pin_3"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="3"/>
@@ -76,7 +76,7 @@
android:id="@+id/pin_4"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="4"/>
@@ -84,7 +84,7 @@
android:id="@+id/pin_5"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="5"/>
@@ -92,7 +92,7 @@
android:id="@+id/pin_6"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="6"/>
@@ -107,7 +107,7 @@
android:id="@+id/pin_7"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="7"/>
@@ -115,7 +115,7 @@
android:id="@+id/pin_8"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="8"/>
@@ -123,7 +123,7 @@
android:id="@+id/pin_9"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="9"/>
@@ -138,7 +138,7 @@
android:id="@+id/pin_c"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="C"/>
@@ -146,7 +146,7 @@
android:id="@+id/pin_0"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
android:text="0"/>
@@ -154,8 +154,9 @@
android:id="@+id/pin_ok"
style="@style/PinNumberStyle"
android:layout_width="0dp"
- android:layout_height="wrap_content"
+ android:layout_height="match_parent"
android:layout_weight="1"
+ android:padding="@dimen/activity_margin"
android:src="@drawable/ic_check"/>
diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml
index 73053a373..90067954a 100644
--- a/app/src/main/res/values-cs/strings.xml
+++ b/app/src/main/res/values-cs/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 01261c7dc..0562ca799 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 7dba19efd..be65972a7 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index f1fd9704e..7a7f80b52 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml
index 4ac31db20..60164e60a 100644
--- a/app/src/main/res/values-hu/strings.xml
+++ b/app/src/main/res/values-hu/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 9195f6eb3..8f24b2f65 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 80e7abac5..6ca1e4fee 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index 9242085a7..157bdd30c 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 0d504ea11..9405ca4eb 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -76,12 +76,13 @@
Aplicativo não encontrado
Definindo como papel de parede;
Papel de parede com sucesso
- Retrato
- Paisagem
+ Retrato
+ Paisagem
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index 60919649b..d2a173d8b 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index fde9bbde2..0e1aa9b87 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml
index 23781cf9e..d7edc2cb6 100644
--- a/app/src/main/res/values-sk/strings.xml
+++ b/app/src/main/res/values-sk/strings.xml
@@ -82,6 +82,7 @@
PIN
Zadajte PIN
+ Prosím zadajte PIN
Nesprávny PIN
Zopakujte PIN
Vzor
diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml
index d567a7964..8b3e840ec 100644
--- a/app/src/main/res/values-sv/strings.xml
+++ b/app/src/main/res/values-sv/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml
index e1c255b99..fad2fcdcd 100644
--- a/app/src/main/res/values-tr/strings.xml
+++ b/app/src/main/res/values-tr/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 552305e1a..0ed778250 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 02e71ea97..35f323e3c 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e8352b0cd..ee31aee06 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -82,6 +82,7 @@
PIN
Enter PIN
+ Please enter a PIN
Wrong PIN
Repeat PIN
Pattern