Skip to content

Commit

Permalink
Fixed deleting pub key.| #1566
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Nov 19, 2021
1 parent beedaae commit d12d609
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.flowcrypt.email.database.entity.PublicKeyEntity
import com.flowcrypt.email.database.entity.RecipientEntity
import com.flowcrypt.email.security.pgp.PgpKey
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.mapLatest
Expand All @@ -29,7 +30,8 @@ class RecipientDetailsViewModel(
private val pureRecipientPubKeysFlow =
roomDatabase.pubKeyDao().getPublicKeysByRecipientFlow(recipientEntity.email)

val recipientPubKeysFlow: StateFlow<List<PublicKeyEntity>> =
@ExperimentalCoroutinesApi
val recipientPubKeysFlow: StateFlow<List<PublicKeyEntity>?> =
pureRecipientPubKeysFlow.mapLatest { fullList ->
fullList.forEach {
withContext(Dispatchers.IO) {
Expand All @@ -46,6 +48,6 @@ class RecipientDetailsViewModel(
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = emptyList()
initialValue = null
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class PublicKeyDetailsFragment : BaseFragment(), ProgressBehaviour {
R.id.menuActionDelete -> {
lifecycleScope.launch {
val roomDatabase = FlowCryptRoomDatabase.getDatabase(requireContext())
roomDatabase.recipientDao().deleteSuspend(args.recipientEntity)
roomDatabase.pubKeyDao().deleteSuspend(args.publicKeyEntity)
navController?.navigateUp()
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ class RecipientDetailsFragment : BaseFragment(), ListProgressBehaviour {
private fun setupRecipientDetailsViewModel() {
lifecycleScope.launchWhenStarted {
recipientDetailsViewModel.recipientPubKeysFlow.collect {
it ?: return@collect
if (it.isNullOrEmpty()) {
showEmptyView()
showEmptyView(resourcesId = R.drawable.ic_no_result_grey_24dp)
} else {
pubKeysRecyclerViewAdapter.submitList(it)
showContent()
Expand Down
54 changes: 24 additions & 30 deletions FlowCrypt/src/main/res/layout/fragment_recipient_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iVPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin_content"
android:layout_marginTop="@dimen/default_margin_content"
android:contentDescription="@string/recipient_detail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_person_green_24" />

<TextView
android:id="@+id/tVName"
android:layout_width="0dp"
Expand All @@ -24,6 +35,17 @@
app:layout_constraintTop_toTopOf="@+id/iVPerson"
tools:text="Den at FlowCrypt" />

<ImageView
android:id="@+id/iVEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin_content"
android:layout_marginTop="@dimen/default_margin_content_small"
android:contentDescription="@string/recipient_detail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iVPerson"
app:srcCompat="@drawable/ic_email_encrypted" />

<TextView
android:id="@+id/tVEmail"
android:layout_width="0dp"
Expand Down Expand Up @@ -79,7 +101,7 @@
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/rVPubKeys"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tVPubKeys" />

Expand All @@ -90,36 +112,8 @@
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/rVPubKeys"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tVPubKeys" />

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="left" />

<ImageView
android:id="@+id/iVPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin_content"
android:layout_marginTop="@dimen/default_margin_content"
android:contentDescription="@string/recipient_detail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_person_green_24" />

<ImageView
android:id="@+id/iVEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin_content"
android:layout_marginTop="@dimen/default_margin_content_small"
android:contentDescription="@string/recipient_detail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iVPerson"
app:srcCompat="@drawable/ic_email_encrypted" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit d12d609

Please sign in to comment.