Skip to content

Commit

Permalink
Improved logic and UI.| #1251
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Jun 3, 2021
1 parent f8e1d43 commit b4aae51
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class FixEmptyPassphraseDialogFragment : BaseDialogFragment() {
private var tVStatusMessage: TextView? = null
private var pBLoading: View? = null
private var pBCheckPassphrase: View? = null
private var gCheckPassphrase: View? = null
private var tILKeyPassword: View? = null
private var eTKeyPassword: EditText? = null
private var btnUpdatePassphrase: View? = null

private val prvKeysRecyclerViewAdapter = PrvKeysRecyclerViewAdapter()
private val checkPrivateKeysViewModel: CheckPrivateKeysViewModel by viewModels()

Expand Down Expand Up @@ -78,12 +80,13 @@ class FixEmptyPassphraseDialogFragment : BaseDialogFragment() {
}

private fun initViews(view: View) {
gCheckPassphrase = view.findViewById(R.id.gCheckPassphrase)
tVStatusMessage = view.findViewById(R.id.tVStatusMessage)
pBLoading = view.findViewById(R.id.pBLoading)
pBCheckPassphrase = view.findViewById(R.id.pBCheckPassphrase)
tILKeyPassword = view.findViewById(R.id.tILKeyPassword)
rVKeys = view.findViewById(R.id.rVKeys)
eTKeyPassword = view.findViewById(R.id.eTKeyPassword)
btnUpdatePassphrase = view.findViewById(R.id.btnUpdatePassphrase)

eTKeyPassword?.setOnEditorActionListener { _, actionId, _ ->
return@setOnEditorActionListener when (actionId) {
Expand All @@ -105,7 +108,7 @@ class FixEmptyPassphraseDialogFragment : BaseDialogFragment() {
adapter = prvKeysRecyclerViewAdapter
}

view.findViewById<View>(R.id.btnUpdatePassphrase)?.setOnClickListener {
btnUpdatePassphrase?.setOnClickListener {
checkPassphrase()
}
}
Expand All @@ -115,7 +118,6 @@ class FixEmptyPassphraseDialogFragment : BaseDialogFragment() {
if (typedText.isNullOrEmpty()) {
toast(getString(R.string.passphrase_must_be_non_empty))
} else {
UIUtil.hideSoftInput(requireContext(), eTKeyPassword)
eTKeyPassword?.let {
val passPhrase = Passphrase.fromPassword(typedText)
val keys = keysWithEmptyPassphraseViewModel.keysWithEmptyPassphrasesLiveData
Expand Down Expand Up @@ -143,7 +145,9 @@ class FixEmptyPassphraseDialogFragment : BaseDialogFragment() {
if (CollectionUtils.isEmpty(keyDetailsList)) {
tVStatusMessage?.text = getString(R.string.error_no_keys)
} else {
gCheckPassphrase?.visible()
btnUpdatePassphrase?.visible()
tILKeyPassword?.visible()
rVKeys?.visible()
if (checkPrivateKeysViewModel.checkPrvKeysLiveData.value == null) {
tVStatusMessage?.text = resources.getQuantityString(
R.plurals.please_provide_passphrase_for_following_keys, keyDetailsList.size
Expand Down Expand Up @@ -210,6 +214,8 @@ class FixEmptyPassphraseDialogFragment : BaseDialogFragment() {
countOfMatchedPassphrases,
countOfMatchedPassphrases
)
eTKeyPassword?.text = null
UIUtil.hideSoftInput(requireContext(), eTKeyPassword)
}

isWrongPassphraseExceptionFound -> {
Expand Down
170 changes: 62 additions & 108 deletions FlowCrypt/src/main/res/layout/fragment_fix_empty_passphrase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,123 +2,77 @@
~ © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
~ Contributors: DenBond7
-->

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="@dimen/default_margin_content"
android:paddingTop="@dimen/default_margin_content"
android:paddingEnd="@dimen/default_margin_content">

<androidx.constraintlayout.widget.ConstraintLayout
<TextView
android:id="@+id/tVStatusMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:text="@string/loading"
android:textAlignment="center"
android:textSize="@dimen/default_text_size_big" />

<TextView
android:id="@+id/tVStatusMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_content"
android:paddingLeft="@dimen/default_margin_content_small"
android:paddingRight="@dimen/default_margin_content_small"
android:text="@string/loading"
android:textAlignment="center"
android:textSize="@dimen/default_text_size_big"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<ProgressBar
android:id="@+id/pBLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/default_margin_content_small" />

<ProgressBar
android:id="@+id/pBLoading"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_content_small"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/tVStatusMessage" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rVKeys"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_content_small"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/pBLoading"
tools:itemCount="3"
tools:listitem="@layout/prv_key_item" />

<ProgressBar
android:id="@+id/pBCheckPassphrase"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateBehavior="repeat"
android:indeterminateOnly="true"
android:indeterminateTint="@color/colorPrimary"
android:visibility="invisible"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/rVKeys" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tILKeyPassword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/your_passphrase"
app:counterEnabled="false"
app:errorEnabled="false"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/pBCheckPassphrase"
app:passwordToggleContentDescription="description"
app:passwordToggleEnabled="true">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/eTKeyPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/btnUpdatePassphrase"
style="@style/AppWidget.Button.Green"
android:layout_width="0dp"
android:layout_marginTop="@dimen/default_margin_content"
android:text="@string/check_passphrase"
android:textAllCaps="true"
android:theme="@style/AppWidget.Button.Green"
app:layout_constraintEnd_toStartOf="@+id/guidelineRight"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@+id/tILKeyPassword" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rVKeys"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/default_margin_content_small"
android:layout_weight="1"
android:visibility="gone"
tools:itemCount="3"
tools:listitem="@layout/prv_key_item" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/default_margin_content" />
<ProgressBar
android:id="@+id/pBCheckPassphrase"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateBehavior="repeat"
android:indeterminateOnly="true"
android:indeterminateTint="@color/colorPrimary"
android:visibility="invisible" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="@dimen/default_margin_content" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tILKeyPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/your_passphrase"
android:visibility="gone"
app:counterEnabled="false"
app:errorEnabled="false"
app:passwordToggleContentDescription="description"
app:passwordToggleEnabled="true">

<androidx.constraintlayout.widget.Group
android:id="@+id/gCheckPassphrase"
android:layout_width="wrap_content"
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/eTKeyPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="btnUpdatePassphrase,tILKeyPassword,rVKeys"
tools:visibility="visible" />
android:ems="10"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<Button
android:id="@+id/btnUpdatePassphrase"
style="@style/AppWidget.Button.Green"
android:layout_width="match_parent"
android:text="@string/check_passphrase"
android:textAllCaps="true"
android:theme="@style/AppWidget.Button.Green"
android:visibility="gone" />
</LinearLayout>
10 changes: 5 additions & 5 deletions FlowCrypt/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,13 @@
<string name="active_passphrase_session">Active pass phrase session</string>
<string name="silent">Silent</string>
<string name="silent_notifications_notification_channel">The silent notifications channel</string>
<string name="passphrase_type_undefined">Passphrase type is undefined</string>
<string name="passphrase_type_undefined">Pass phrase type is undefined</string>
<plurals name="please_provide_passphrase_for_following_keys">
<item quantity="one">Please provide a passphrase for the following key</item>
<item quantity="other">Please provide a passphrase for the following keys</item>
<item quantity="one">Please provide a pass phrase for the following key</item>
<item quantity="other">Please provide a pass phrase for the following keys</item>
</plurals>
<plurals name="you_have_unlocked_keys">
<item quantity="one">You have unlocked one key. Please use a different passphrase to unlock the remaining keys</item>
<item quantity="other">You have unlocked %1$d keys. Please use a different passphrase to unlock the remaining keys</item>
<item quantity="one">You have unlocked one key. Please use a different pass phrase to unlock the remaining keys</item>
<item quantity="other">You have unlocked %1$d keys. Please use a different pass phrase to unlock the remaining keys</item>
</plurals>
</resources>

0 comments on commit b4aae51

Please sign in to comment.