diff --git a/app/build.gradle b/app/build.gradle index e04ef4de6..24aabd87a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,14 +37,13 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.23.7' + compile 'com.simplemobiletools:commons:2.23.8' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.google.code.gson:gson:2.8.0' compile 'com.github.chrisbanes:PhotoView:2.1.2' compile 'it.sephiroth.android.exif:library:1.0.1' - compile 'com.andrognito.patternlockview:patternlockview:1.0.0' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index 5b32968ec..b5125dff1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -4,12 +4,13 @@ import android.content.Intent import android.content.res.Resources import android.os.Bundle import com.simplemobiletools.commons.dialogs.RadioGroupDialog +import com.simplemobiletools.commons.dialogs.SecurityDialog +import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.dialogs.SecurityDialog import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.handleHiddenFolderPasswordProtection import com.simplemobiletools.gallery.helpers.* import kotlinx.android.synthetic.main.activity_settings.* diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt deleted file mode 100644 index 4d92c275d..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/PasswordTypesAdapter.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.simplemobiletools.gallery.adapters - -import android.content.Context -import android.support.v4.view.PagerAdapter -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.interfaces.HashListener -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) - (view as SecurityTab).initTab(requiredHash, hashListener) - return view - } - - override fun destroyItem(container: ViewGroup, position: Int, item: Any) { - container.removeView(item as View) - } - - override fun getCount() = 2 - override fun isViewFromObject(view: View, item: Any) = view == item - - private fun layoutSelection(position: Int): Int = when (position) { - 0 -> R.layout.tab_pattern - 1 -> R.layout.tab_pin - else -> throw RuntimeException("Only 2 tabs allowed") - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt deleted file mode 100644 index c732125ee..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.simplemobiletools.gallery.dialogs - -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 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 - viewPager.adapter = PasswordTypesAdapter(context, requiredHash, this@SecurityDialog) - viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { - override fun onPageScrollStateChanged(state: Int) { - } - - override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { - } - - override fun onPageSelected(position: Int) { - 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) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) - } - } - - override fun receivedHash(hash: String, type: Int) { - callback(hash, type) - dialog!!.dismiss() - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 00af3ac71..ddb92198c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -24,7 +24,6 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.dialogs.SecurityDialog import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS @@ -333,16 +332,6 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) { builder.apply(options).into(target) } -fun SimpleActivity.handleHiddenFolderPasswordProtection(callback: () -> Unit) { - if (config.isPasswordProtectionOn) { - SecurityDialog(this, config.passwordHash, config.protectionType) { hash, type -> - callback() - } - } else { - callback() - } -} - fun Activity.getCachedDirectories(): ArrayList { val token = object : TypeToken>() {}.type return Gson().fromJson>(config.directories, token) ?: ArrayList(1) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 89037e81b..b221d32da 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -232,16 +232,4 @@ class Config(context: Context) : BaseConfig(context) { var replaceShare: Boolean get() = prefs.getBoolean(REPLACE_SHARE_WITH_ROTATE, false) set(replaceShare) = prefs.edit().putBoolean(REPLACE_SHARE_WITH_ROTATE, replaceShare).apply() - - var isPasswordProtectionOn: Boolean - get() = prefs.getBoolean(IS_PASSWORD_PROTECTION, false) - set(passwordProtection) = prefs.edit().putBoolean(IS_PASSWORD_PROTECTION, passwordProtection).apply() - - var passwordHash: String - get() = prefs.getString(PASSWORD_HASH, "") - set(passwordHash) = prefs.edit().putString(PASSWORD_HASH, passwordHash).apply() - - var protectionType: Int - get() = prefs.getInt(PROTECTION_TYPE, PROTECTION_PATTERN) - set(protectionType) = prefs.edit().putInt(PROTECTION_TYPE, protectionType).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 5b946fd5d..30af458a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -33,9 +33,6 @@ val ALBUM_COVERS = "album_covers" val SCROLL_HORIZONTALLY = "scroll_horizontally" val HIDE_SYSTEM_UI = "hide_system_ui" val REPLACE_SHARE_WITH_ROTATE = "replace_share_with_rotate" -val IS_PASSWORD_PROTECTION = "password_protection" -val PASSWORD_HASH = "password_hash" -val PROTECTION_TYPE = "protection_type" val NOMEDIA = ".nomedia" @@ -65,12 +62,3 @@ val ORIENT_PORTRAIT = 0 val ORIENT_LANDSCAPE_LEFT = 1 val ORIENT_LANDSCAPE_RIGHT = 2 val ORIENT_UPSIDE_DOWN = 3 - -// security -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt deleted file mode 100644 index 2549eb4db..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.simplemobiletools.gallery.interfaces - -interface HashListener { - fun receivedHash(hash: String, type: Int) -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/SecurityTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/SecurityTab.kt deleted file mode 100644 index 000818e1f..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/SecurityTab.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.simplemobiletools.gallery.interfaces - -interface SecurityTab { - fun initTab(requiredHash: String, listener: HashListener) -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyDialogViewPager.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyDialogViewPager.kt deleted file mode 100644 index 5268e3a07..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyDialogViewPager.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.simplemobiletools.gallery.views - -import android.content.Context -import android.support.v4.view.ViewPager -import android.util.AttributeSet -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 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) { - } - - return false - } - - // https://stackoverflow.com/a/20784791/1967672 - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - var height = 0 - for (i in 0..childCount - 1) { - val child = getChildAt(i) - child.measure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)) - val h = child.measuredHeight - if (h > height) height = h - } - - val newHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY) - super.onMeasure(widthMeasureSpec, newHeightMeasureSpec) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt deleted file mode 100644 index 9200f797e..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.simplemobiletools.gallery.views - -import android.content.Context -import android.os.Handler -import android.util.AttributeSet -import android.widget.RelativeLayout -import com.andrognito.patternlockview.PatternLockView -import com.andrognito.patternlockview.listener.PatternLockViewListener -import com.andrognito.patternlockview.utils.PatternLockUtils -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.updateTextColors -import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.helpers.PROTECTION_PATTERN -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), SecurityTab { - private var hash = "" - private var requiredHash = "" - lateinit var hashListener: HashListener - - override fun onFinishInflate() { - super.onFinishInflate() - val textColor = context.config.textColor - context.updateTextColors(pattern_lock_holder) - pattern_lock_view.correctStateColor = context.config.primaryColor - pattern_lock_view.normalStateColor = textColor - pattern_lock_view.addPatternLockListener(object : PatternLockViewListener { - override fun onComplete(pattern: MutableList?) { - receivedHash(PatternLockUtils.patternToSha1(pattern_lock_view, pattern)) - } - - override fun onCleared() { - } - - override fun onStarted() { - } - - override fun onProgress(progressPattern: MutableList?) { - } - }) - } - - override fun initTab(requiredHash: String, listener: HashListener) { - this.requiredHash = requiredHash - hash = requiredHash - hashListener = listener - } - - private fun receivedHash(newHash: String) { - if (hash.isEmpty()) { - 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, PROTECTION_PATTERN) - }, 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) - } - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt deleted file mode 100644 index 48aa73ada..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.simplemobiletools.gallery.views - -import android.content.Context -import android.graphics.PorterDuff -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.extensions.config -import com.simplemobiletools.gallery.helpers.PROTECTION_PIN -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), SecurityTab { - private var hash = "" - private var requiredHash = "" - private var pin = "" - lateinit var hashListener: HashListener - - override fun onFinishInflate() { - super.onFinishInflate() - context.updateTextColors(pin_lock_holder) - - pin_0.setOnClickListener { addNumber("0") } - pin_1.setOnClickListener { addNumber("1") } - pin_2.setOnClickListener { addNumber("2") } - pin_3.setOnClickListener { addNumber("3") } - pin_4.setOnClickListener { addNumber("4") } - pin_5.setOnClickListener { addNumber("5") } - pin_6.setOnClickListener { addNumber("6") } - pin_7.setOnClickListener { addNumber("7") } - pin_8.setOnClickListener { addNumber("8") } - pin_9.setOnClickListener { addNumber("9") } - pin_c.setOnClickListener { clear() } - pin_ok.setOnClickListener { confirmPIN() } - pin_ok.setColorFilter(context.config.textColor, PorterDuff.Mode.SRC_IN) - } - - 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 - updatePinCode() - } - } - - private fun clear() { - if (pin.isNotEmpty()) { - pin = pin.substring(0, pin.length - 1) - updatePinCode() - } - } - - 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, PROTECTION_PIN) - } 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/dialog_security.xml b/app/src/main/res/layout/dialog_security.xml deleted file mode 100644 index 993c05bfa..000000000 --- a/app/src/main/res/layout/dialog_security.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/tab_pattern.xml b/app/src/main/res/layout/tab_pattern.xml deleted file mode 100644 index 13cae2fcb..000000000 --- a/app/src/main/res/layout/tab_pattern.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/tab_pin.xml b/app/src/main/res/layout/tab_pin.xml deleted file mode 100644 index 8a7c27695..000000000 --- a/app/src/main/res/layout/tab_pin.xml +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 65e4ec22c..78a798255 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -4,8 +4,4 @@ true - - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bc2a7b38e..f7114219d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -16,14 +16,4 @@ @style/AppTheme.ActionBar.TitleTextStyle - - - -