aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/adapters/FieldItemAdapter.kt27
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt22
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt20
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/dialogs/BasicBottomSheet.kt10
4 files changed, 38 insertions, 41 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/adapters/FieldItemAdapter.kt b/app/src/main/java/dev/msfjarvis/aps/ui/adapters/FieldItemAdapter.kt
index 030f6056..d019bcae 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/adapters/FieldItemAdapter.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/adapters/FieldItemAdapter.kt
@@ -19,7 +19,7 @@ import dev.msfjarvis.aps.databinding.ItemFieldBinding
class FieldItemAdapter(
private var fieldItemList: List<FieldItem>,
private val showPassword: Boolean,
- private val copyTextToClipBoard: (text: String?) -> Unit,
+ private val copyTextToClipboard: (text: String?) -> Unit,
) : RecyclerView.Adapter<FieldItemAdapter.FieldItemViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FieldItemViewHolder {
@@ -28,7 +28,7 @@ class FieldItemAdapter(
}
override fun onBindViewHolder(holder: FieldItemViewHolder, position: Int) {
- holder.bind(fieldItemList[position], showPassword, copyTextToClipBoard)
+ holder.bind(fieldItemList[position], showPassword, copyTextToClipboard)
}
override fun getItemCount(): Int {
@@ -50,15 +50,10 @@ class FieldItemAdapter(
notifyItemChanged(otpItemPosition)
}
- fun updateItems(itemList: List<FieldItem>) {
- fieldItemList = itemList
- notifyDataSetChanged()
- }
-
class FieldItemViewHolder(itemView: View, val binding: ItemFieldBinding) :
RecyclerView.ViewHolder(itemView) {
- fun bind(fieldItem: FieldItem, showPassword: Boolean, copyTextToClipBoard: (String?) -> Unit) {
+ fun bind(fieldItem: FieldItem, showPassword: Boolean, copyTextToClipboard: (String?) -> Unit) {
with(binding) {
itemText.hint = fieldItem.key
itemTextContainer.hint = fieldItem.key
@@ -70,19 +65,23 @@ class FieldItemAdapter(
endIconDrawable =
ContextCompat.getDrawable(itemView.context, R.drawable.ic_content_copy)
endIconMode = TextInputLayout.END_ICON_CUSTOM
- setEndIconOnClickListener { copyTextToClipBoard(itemText.text.toString()) }
+ setEndIconOnClickListener { copyTextToClipboard(itemText.text.toString()) }
}
+ itemText.transformationMethod = null
}
FieldItem.ActionType.HIDE -> {
itemTextContainer.apply {
endIconMode = TextInputLayout.END_ICON_PASSWORD_TOGGLE
- setOnClickListener { copyTextToClipBoard(itemText.text.toString()) }
+ setOnClickListener { copyTextToClipboard(itemText.text.toString()) }
}
itemText.apply {
- if (!showPassword) {
- transformationMethod = PasswordTransformationMethod.getInstance()
- }
- setOnClickListener { copyTextToClipBoard(itemText.text.toString()) }
+ transformationMethod =
+ if (!showPassword) {
+ PasswordTransformationMethod.getInstance()
+ } else {
+ null
+ }
+ setOnClickListener { copyTextToClipboard(itemText.text.toString()) }
}
}
}
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
index e1ee2195..1e46dfda 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
@@ -179,9 +179,6 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
runCatching {
val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
val entry = passwordEntryFactory.create(lifecycleScope, outputStream.toByteArray())
- val items = arrayListOf<FieldItem>()
- val adapter =
- FieldItemAdapter(emptyList(), showPassword) { text -> copyTextToClipboard(text) }
if (settings.getBoolean(PreferenceKeys.COPY_ON_DECRYPT, false)) {
copyPasswordToClipboard(entry.password)
@@ -190,17 +187,13 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
passwordEntry = entry
invalidateOptionsMenu()
+ val items = arrayListOf<FieldItem>()
if (!entry.password.isNullOrBlank()) {
items.add(FieldItem.createPasswordField(entry.password!!))
}
if (entry.hasTotp()) {
- launch {
- items.add(FieldItem.createOtpField(entry.totp.value))
- entry.totp.collect { code ->
- withContext(Dispatchers.Main) { adapter.updateOTPCode(code) }
- }
- }
+ items.add(FieldItem.createOtpField(entry.totp.value))
}
if (!entry.username.isNullOrBlank()) {
@@ -211,8 +204,17 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
items.add(FieldItem(key, value, FieldItem.ActionType.COPY))
}
+ val adapter =
+ FieldItemAdapter(items, showPassword) { text -> copyTextToClipboard(text) }
binding.recyclerView.adapter = adapter
- adapter.updateItems(items)
+
+ if (entry.hasTotp()) {
+ lifecycleScope.launch {
+ entry.totp.collect { code ->
+ withContext(Dispatchers.Main) { adapter.updateOTPCode(code) }
+ }
+ }
+ }
}
.onFailure { e -> logcat(ERROR) { e.asLog() } }
}
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt
index 403b8191..4b49632d 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivityV2.kt
@@ -20,6 +20,7 @@ import dev.msfjarvis.aps.injection.password.PasswordEntryFactory
import dev.msfjarvis.aps.ui.adapters.FieldItemAdapter
import dev.msfjarvis.aps.util.extensions.unsafeLazy
import dev.msfjarvis.aps.util.extensions.viewBinding
+import dev.msfjarvis.aps.util.settings.PreferenceKeys
import java.io.ByteArrayOutputStream
import java.io.File
import javax.inject.Inject
@@ -142,23 +143,18 @@ class DecryptActivityV2 : BasePgpActivity() {
}
startAutoDismissTimer()
+ val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
val entry = passwordEntryFactory.create(lifecycleScope, result.toByteArray())
passwordEntry = entry
invalidateOptionsMenu()
val items = arrayListOf<FieldItem>()
- val adapter = FieldItemAdapter(emptyList(), true) { text -> copyTextToClipboard(text) }
if (!entry.password.isNullOrBlank()) {
items.add(FieldItem.createPasswordField(entry.password!!))
}
if (entry.hasTotp()) {
- lifecycleScope.launch {
- items.add(FieldItem.createOtpField(entry.totp.value))
- entry.totp.collect { code ->
- withContext(Dispatchers.Main) { adapter.updateOTPCode(code) }
- }
- }
+ items.add(FieldItem.createOtpField(entry.totp.value))
}
if (!entry.username.isNullOrBlank()) {
@@ -169,8 +165,16 @@ class DecryptActivityV2 : BasePgpActivity() {
items.add(FieldItem(key, value, FieldItem.ActionType.COPY))
}
+ val adapter = FieldItemAdapter(items, showPassword) { text -> copyTextToClipboard(text) }
binding.recyclerView.adapter = adapter
- adapter.updateItems(items)
+
+ if (entry.hasTotp()) {
+ lifecycleScope.launch {
+ entry.totp.collect { code ->
+ withContext(Dispatchers.Main) { adapter.updateOTPCode(code) }
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/dialogs/BasicBottomSheet.kt b/app/src/main/java/dev/msfjarvis/aps/ui/dialogs/BasicBottomSheet.kt
index dad86479..53d9a201 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/dialogs/BasicBottomSheet.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/dialogs/BasicBottomSheet.kt
@@ -6,7 +6,6 @@
package dev.msfjarvis.aps.ui.dialogs
import android.content.Context
-import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -20,13 +19,11 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dev.msfjarvis.aps.R
import dev.msfjarvis.aps.databinding.BasicBottomSheetBinding
-import dev.msfjarvis.aps.ui.dialogs.BasicBottomSheet.Builder
-import dev.msfjarvis.aps.util.extensions.resolveAttribute
import dev.msfjarvis.aps.util.extensions.viewBinding
/**
* [BottomSheetDialogFragment] that exposes a simple [androidx.appcompat.app.AlertDialog] like API
- * through [Builder] to create a similar UI, just at the bottom of the screen.
+ * through [BasicBottomSheet.Builder] to create a similar UI, just at the bottom of the screen.
*/
class BasicBottomSheet
private constructor(
@@ -100,11 +97,6 @@ private constructor(
}
}
)
- val gradientDrawable =
- GradientDrawable().apply {
- setColor(requireContext().resolveAttribute(android.R.attr.windowBackground))
- }
- view.background = gradientDrawable
}
override fun dismiss() {