Add Copy without spaces Function
This commit is contained in:
parent
b4e4647bf3
commit
d00be7be59
@ -16,6 +16,8 @@ class MainActivity : AppCompatActivity() {
|
||||
private lateinit var infoTextView: TextView
|
||||
private lateinit var switchWithoutSpaces: com.google.android.material.switchmaterial.SwitchMaterial
|
||||
private lateinit var switchSpecialChars: com.google.android.material.switchmaterial.SwitchMaterial
|
||||
private lateinit var passwordLengthPicker: android.widget.NumberPicker
|
||||
private lateinit var numPasswordsPicker: android.widget.NumberPicker
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -28,6 +30,7 @@ class MainActivity : AppCompatActivity() {
|
||||
switchWithoutSpaces = findViewById(R.id.switchWithoutSpaces)
|
||||
switchSpecialChars = findViewById(R.id.switchSpecialChars)
|
||||
|
||||
|
||||
generateButton.setOnClickListener {
|
||||
generatePassword()
|
||||
}
|
||||
@ -42,6 +45,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun generatePassword() {
|
||||
|
||||
val password = generateRandomWords(6)
|
||||
|
||||
passwordTextView.text = password
|
||||
@ -93,7 +97,13 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun copyToClipboard(text: String, clipboardManager: ClipboardManager) {
|
||||
val clipData = ClipData.newPlainText("Password", text)
|
||||
|
||||
val clipData = if (switchWithoutSpaces.isChecked)
|
||||
{ val textNoSpaces = text.filter { !it.isWhitespace() }
|
||||
ClipData.newPlainText("Password", textNoSpaces)
|
||||
} else {
|
||||
ClipData.newPlainText("Password", text)
|
||||
}
|
||||
clipboardManager.setPrimaryClip(clipData)
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<android.widget.NumberPicker
|
||||
<NumberPicker
|
||||
android:id="@+id/passwordLengthPicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -48,7 +48,7 @@
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="32dp"/>
|
||||
|
||||
<android.widget.NumberPicker
|
||||
<NumberPicker
|
||||
android:id="@+id/numPasswordsPicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user