From aa19b08bd99d0edea7c866c864eae2c811a51125 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sun, 27 Mar 2022 20:41:51 +0200 Subject: [PATCH] Fix password entropy and add chips --- .../dialogs/GeneratePasswordDialogFragment.kt | 112 ++--- .../keepass/utils/PasswordEntropy.kt | 63 +-- .../res/layout/fragment_generate_password.xml | 405 ++++++------------ app/src/main/res/layout/view_password.xml | 3 + 4 files changed, 236 insertions(+), 347 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GeneratePasswordDialogFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GeneratePasswordDialogFragment.kt index 8e5107660..ced72a178 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GeneratePasswordDialogFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/GeneratePasswordDialogFragment.kt @@ -19,12 +19,14 @@ */ package com.kunzisoft.keepass.activities.dialogs +import android.annotation.SuppressLint import android.app.Dialog import android.content.Context import android.os.Bundle import android.view.View import android.widget.* import androidx.appcompat.app.AlertDialog +import com.google.android.material.slider.Slider import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.Field import com.kunzisoft.keepass.password.PasswordGenerator @@ -42,15 +44,15 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() { private var mPasswordField: Field? = null - private var uppercaseBox: CompoundButton? = null - private var lowercaseBox: CompoundButton? = null - private var digitsBox: CompoundButton? = null - private var minusBox: CompoundButton? = null - private var underlineBox: CompoundButton? = null - private var spaceBox: CompoundButton? = null - private var specialsBox: CompoundButton? = null - private var bracketsBox: CompoundButton? = null - private var extendedBox: CompoundButton? = null + private var uppercaseCompound: CompoundButton? = null + private var lowercaseCompound: CompoundButton? = null + private var digitsCompound: CompoundButton? = null + private var minusCompound: CompoundButton? = null + private var underlineCompound: CompoundButton? = null + private var spaceCompound: CompoundButton? = null + private var specialsCompound: CompoundButton? = null + private var bracketsCompound: CompoundButton? = null + private var extendedCompound: CompoundButton? = null override fun onAttach(context: Context) { super.onAttach(context) @@ -85,36 +87,36 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() { } lengthTextView = root?.findViewById(R.id.length) - uppercaseBox = root?.findViewById(R.id.cb_uppercase) - lowercaseBox = root?.findViewById(R.id.cb_lowercase) - digitsBox = root?.findViewById(R.id.cb_digits) - minusBox = root?.findViewById(R.id.cb_minus) - underlineBox = root?.findViewById(R.id.cb_underline) - spaceBox = root?.findViewById(R.id.cb_space) - specialsBox = root?.findViewById(R.id.cb_specials) - bracketsBox = root?.findViewById(R.id.cb_brackets) - extendedBox = root?.findViewById(R.id.cb_extended) + uppercaseCompound = root?.findViewById(R.id.upperCase_filter) + lowercaseCompound = root?.findViewById(R.id.lowerCase_filter) + digitsCompound = root?.findViewById(R.id.digits_filter) + minusCompound = root?.findViewById(R.id.minus_filter) + underlineCompound = root?.findViewById(R.id.underline_filter) + spaceCompound = root?.findViewById(R.id.space_filter) + specialsCompound = root?.findViewById(R.id.special_filter) + bracketsCompound = root?.findViewById(R.id.brackets_filter) + extendedCompound = root?.findViewById(R.id.extendedASCII_filter) mPasswordField = arguments?.getParcelable(KEY_PASSWORD_FIELD) assignDefaultCharacters() - val seekBar = root?.findViewById(R.id.seekbar_length) - seekBar?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { - lengthTextView?.setText(progress.toString()) + val sliderLength = root?.findViewById(R.id.slider_length) + sliderLength?.addOnSliderTouchListener(object : Slider.OnSliderTouchListener { + @SuppressLint("RestrictedApi") + override fun onStartTrackingTouch(slider: Slider) { + } + @SuppressLint("RestrictedApi") + override fun onStopTrackingTouch(slider: Slider) { + lengthTextView?.setText(slider.value.toInt().toString()) } - - override fun onStartTrackingTouch(seekBar: SeekBar) {} - - override fun onStopTrackingTouch(seekBar: SeekBar) {} }) context?.let { context -> - seekBar?.progress = PreferencesUtil.getDefaultPasswordLength(context) + sliderLength?.value = PreferencesUtil.getDefaultPasswordLength(context).toFloat() } - root?.findViewById