Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple pub keys per recipient #1523

Merged
merged 39 commits into from
Nov 25, 2021
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
21ca549
Added PublicKeyEntity. Refactored code. WIP.| #1188
DenBond7 Oct 23, 2021
ae23630
Fixed using ContactsDao.getAllContactsWithPgpLD().| #1188
DenBond7 Oct 25, 2021
77c8855
Fixed using ContactsDao.getAllContactsWithPgp()/getAllContactsWithPgp…
DenBond7 Oct 26, 2021
faa2e23
Renamed ContactEntity to RecipientEntity.| #1188
DenBond7 Oct 26, 2021
fda5a76
Renamed ContactsDao to RecipientDao.| #1188
DenBond7 Oct 26, 2021
91de167
Refactored code.| #1188
DenBond7 Oct 26, 2021
905aacf
Renamed ContactsViewModel to RecipientsViewModel.| #1188
DenBond7 Oct 26, 2021
55355f0
Fixed a few methods in RecipientDao. Refactored code.| #1188
DenBond7 Oct 26, 2021
c36f3ad
Fixed RecipientDao.getRecipientByEmail().| #1188
DenBond7 Oct 26, 2021
5803a9e
Fixed some moments with adding/updating a recipient with a pub key.| …
DenBond7 Oct 26, 2021
8f1644a
Made a workable version after switching to use 'recipients' and 'pub_…
DenBond7 Nov 1, 2021
d22ae4c
Fixed tests. Refactored code.| #1188
DenBond7 Nov 5, 2021
81874c2
Modified code to use a new logic to save contacts on the compose scre…
DenBond7 Nov 9, 2021
daa76eb
Modified code to use a new logic to apply colors to recipients(chips)…
DenBond7 Nov 10, 2021
8874988
Added changes to use all recipient's pub keys for ecnryption + use al…
DenBond7 Nov 10, 2021
bd9334f
Fixed signing option.| #1541
DenBond7 Nov 10, 2021
ece204c
Import recipients manually. Refactored code. Added LookUpPubKeysDialo…
DenBond7 Nov 10, 2021
9ec0be6
Added a base realization of importing pub keys manually.| #1542
DenBond7 Nov 12, 2021
1dd39c8
Added ImportAllPubKeysFromSourceDialogFragment.| #1542
DenBond7 Nov 17, 2021
02bbd10
Removed unused source.| #1542
DenBond7 Nov 18, 2021
57bddc7
Improved some classes.| #1566
DenBond7 Nov 19, 2021
4676fc2
Added RecipientDetailsFragment.| #1566
DenBond7 Nov 19, 2021
e69ff95
Fixed opening PublicKeyDetailsFragment. Refactored code.| #1566
DenBond7 Nov 19, 2021
beedaae
Fixed exporting pub key.| #1566
DenBond7 Nov 19, 2021
d12d609
Fixed deleting pub key.| #1566
DenBond7 Nov 19, 2021
13226a9
Fixed editing pub key.| #1566
DenBond7 Nov 23, 2021
44b85c6
Fixed database migration bug.| #1188
DenBond7 Nov 23, 2021
36d1d11
Fixed nav_graph.xml for test.| #1188
DenBond7 Nov 23, 2021
abc45b1
Temporary disabled some tests.| #1188
DenBond7 Nov 23, 2021
a41dcf0
Temporary disabled some tests(step 2).| #1188
DenBond7 Nov 23, 2021
b7fdee2
Fixed Junit tests.| #1188
DenBond7 Nov 23, 2021
09724be
Fixed some UI tests.| #1188
DenBond7 Nov 23, 2021
775f473
Merge remote-tracking branch 'origin/master' into issue_1188_support_…
DenBond7 Nov 25, 2021
c84d571
Fixed merge conflicts.| #1188
DenBond7 Nov 25, 2021
1a76ddd
Fixed some PR comments. Refactored code.| #1188
DenBond7 Nov 25, 2021
e6e08c2
Fixed some PR comments. Refactored code. Step 2.| #1188
DenBond7 Nov 25, 2021
b9a8b9d
Restored some code.| #1188
DenBond7 Nov 25, 2021
35a6e09
Renamed a file.| #1188
DenBond7 Nov 25, 2021
1170e2f
Fixed importing/updating pub keys for PublicKeyMsgBlock.| #1188
DenBond7 Nov 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved some classes.| #1566
DenBond7 committed Nov 19, 2021

Verified

This commit was signed with the committer’s verified signature.
commit 57bddc7a69d9654293650d9b31fdd3ae68957ca6
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import androidx.room.Query
import androidx.room.Transaction
import com.flowcrypt.email.database.entity.RecipientEntity
import com.flowcrypt.email.database.entity.relation.RecipientWithPubKeys
import kotlinx.coroutines.flow.Flow

/**
* This object describes a logic of work with [RecipientEntity].
@@ -30,7 +31,7 @@ interface RecipientDao : BaseDao<RecipientEntity> {
fun getAllRecipientsLD(): LiveData<List<RecipientEntity>>

@Query("SELECT recipients.* FROM recipients INNER JOIN public_keys ON recipients.email = public_keys.recipient GROUP BY recipients.email ORDER BY recipients._id")
DenBond7 marked this conversation as resolved.
Show resolved Hide resolved
fun getAllRecipientsWithPgpLD(): LiveData<List<RecipientEntity>>
fun getAllRecipientsWithPgpFlow(): Flow<List<RecipientEntity>>

@Query("SELECT recipients.* FROM recipients INNER JOIN public_keys ON recipients.email = public_keys.recipient GROUP BY recipients.email ORDER BY recipients._id")
suspend fun getAllRecipientsWithPgp(): List<RecipientEntity>
Original file line number Diff line number Diff line change
@@ -53,12 +53,7 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati

val allContactsLiveData: LiveData<List<RecipientEntity>> =
roomDatabase.recipientDao().getAllRecipientsLD()
val contactsWithPgpLiveData: LiveData<Result<List<RecipientEntity>>> =
Transformations.switchMap(roomDatabase.recipientDao().getAllRecipientsWithPgpLD()) {
liveData {
emit(Result.success(it))
}
}
val recipientsWithPgpFlow = roomDatabase.recipientDao().getAllRecipientsWithPgpFlow()
val contactsWithPgpSearchLiveData: LiveData<Result<List<RecipientEntity>>> =
Transformations.switchMap(searchPatternLiveData) {
liveData {
Original file line number Diff line number Diff line change
@@ -40,14 +40,24 @@ import com.flowcrypt.email.util.UIUtil
* Time: 17:23
* E-mail: [email protected]
*/
class SelectRecipientsActivity : BaseBackStackActivity(),
RecipientsRecyclerViewAdapter.OnContactActionsListener, SearchView.OnQueryTextListener {
class SelectRecipientsActivity : BaseBackStackActivity(), SearchView.OnQueryTextListener {

private var progressBar: View? = null
private var recyclerViewContacts: RecyclerView? = null
private var emptyView: View? = null
private val recipientsRecyclerViewAdapter: RecipientsRecyclerViewAdapter =
RecipientsRecyclerViewAdapter(false)
RecipientsRecyclerViewAdapter(
false,
object : RecipientsRecyclerViewAdapter.OnRecipientActionsListener {
override fun onDeleteRecipient(recipientEntity: RecipientEntity) {}

override fun onRecipientClick(recipientEntity: RecipientEntity) {
val intent = Intent()
intent.putExtra(KEY_EXTRA_PGP_CONTACT, recipientEntity)
setResult(Activity.RESULT_OK, intent)
finish()
}
})
private var searchPattern: String? = null
private val recipientsViewModel: RecipientsViewModel by viewModels()

@@ -65,7 +75,6 @@ class SelectRecipientsActivity : BaseBackStackActivity(),

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
recipientsRecyclerViewAdapter.onContactActionsListener = this
//todo-denbond7 need to fix this in the future. Not urgent
//val isMultiply = intent.getBooleanExtra(KEY_EXTRA_IS_MULTIPLY, false)

@@ -108,15 +117,6 @@ class SelectRecipientsActivity : BaseBackStackActivity(),
return super.onPrepareOptionsMenu(menu)
}

override fun onContactClick(recipientEntity: RecipientEntity) {
val intent = Intent()
intent.putExtra(KEY_EXTRA_PGP_CONTACT, recipientEntity)
setResult(Activity.RESULT_OK, intent)
finish()
}

override fun onDeleteContact(recipientEntity: RecipientEntity) {}

override fun onQueryTextSubmit(query: String): Boolean {
searchPattern = query
recipientsViewModel.filterContacts(searchPattern)
@@ -146,7 +146,7 @@ class SelectRecipientsActivity : BaseBackStackActivity(),
if (it.data.isNullOrEmpty()) {
UIUtil.exchangeViewVisibility(true, emptyView, recyclerViewContacts)
} else {
recipientsRecyclerViewAdapter.swap(it.data)
recipientsRecyclerViewAdapter.submitList(it.data)
UIUtil.exchangeViewVisibility(false, emptyView, recyclerViewContacts)
}
countingIdlingResourceForFilter.decrementSafely()
Original file line number Diff line number Diff line change
@@ -5,24 +5,25 @@

package com.flowcrypt.email.ui.activity.fragment

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.flowcrypt.email.R
import com.flowcrypt.email.api.retrofit.response.base.Result
import com.flowcrypt.email.database.entity.RecipientEntity
import com.flowcrypt.email.databinding.FragmentRecipientsListBinding
import com.flowcrypt.email.extensions.navController
import com.flowcrypt.email.jetpack.viewmodel.RecipientsViewModel
import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment
import com.flowcrypt.email.ui.activity.fragment.base.ListProgressBehaviour
import com.flowcrypt.email.ui.adapter.RecipientsRecyclerViewAdapter
import com.flowcrypt.email.util.UIUtil
import kotlinx.coroutines.flow.collect

/**
* This fragment shows a list of contacts which have a public key.
@@ -32,105 +33,81 @@ import com.flowcrypt.email.util.UIUtil
* Time: 6:11 PM
* E-mail: [email protected]
*/
class RecipientsListFragment : BaseFragment(),
RecipientsRecyclerViewAdapter.OnContactActionsListener {

private var progressBar: View? = null
private var recyclerViewContacts: RecyclerView? = null
private var emptyView: View? = null
class RecipientsListFragment : BaseFragment(), ListProgressBehaviour {
private var binding: FragmentRecipientsListBinding? = null
private val recipientsRecyclerViewAdapter: RecipientsRecyclerViewAdapter =
RecipientsRecyclerViewAdapter(true)
RecipientsRecyclerViewAdapter(
true,
object : RecipientsRecyclerViewAdapter.OnRecipientActionsListener {
override fun onDeleteRecipient(recipientEntity: RecipientEntity) {
recipientsViewModel.deleteContact(recipientEntity)
Toast.makeText(
context, getString(R.string.the_contact_was_deleted, recipientEntity.email),
Toast.LENGTH_SHORT
).show()
}

override fun onRecipientClick(recipientEntity: RecipientEntity) {
navController?.navigate(
RecipientsListFragmentDirections
.actionRecipientsListFragmentToPublicKeyDetailsFragment(recipientEntity)
)
}
})
private val recipientsViewModel: RecipientsViewModel by viewModels()

override val contentResourceId: Int = R.layout.fragment_recipients_list

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
recipientsRecyclerViewAdapter.onContactActionsListener = this
override val emptyView: View?
get() = binding?.emptyView
override val progressView: View?
get() = binding?.pB
override val contentView: View?
get() = binding?.rVRecipients
override val statusView: View?
get() = null

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
binding = FragmentRecipientsListBinding.inflate(inflater, container, false)
return binding?.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
supportActionBar?.setTitle(R.string.contacts)
initViews(view)
setupContactsViewModel()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_CODE_START_IMPORT_PUB_KEY_ACTIVITY -> when (resultCode) {
Activity.RESULT_OK -> Toast.makeText(
context,
R.string.key_successfully_imported,
Toast.LENGTH_SHORT
).show()
}

else -> super.onActivityResult(requestCode, resultCode, data)
}
}

override fun onContactClick(recipientEntity: RecipientEntity) {
navController?.navigate(
RecipientsListFragmentDirections
.actionRecipientsListFragmentToPublicKeyDetailsFragment(recipientEntity)
)
}

override fun onDeleteContact(recipientEntity: RecipientEntity) {
recipientsViewModel.deleteContact(recipientEntity)
Toast.makeText(
context, getString(R.string.the_contact_was_deleted, recipientEntity.email),
Toast.LENGTH_SHORT
).show()
initViews()
setupRecipientsViewModel()
}

private fun initViews(root: View) {
this.progressBar = root.findViewById(R.id.progressBar)
this.emptyView = root.findViewById(R.id.emptyView)

recyclerViewContacts = root.findViewById(R.id.recyclerViewContacts)
private fun initViews() {
val manager = LinearLayoutManager(context)
val decoration = DividerItemDecoration(context, manager.orientation)
val drawable =
ResourcesCompat.getDrawable(resources, R.drawable.divider_1dp_grey, requireContext().theme)
drawable?.let { decoration.setDrawable(drawable) }
recyclerViewContacts?.addItemDecoration(decoration)
recyclerViewContacts?.layoutManager = manager
recyclerViewContacts?.adapter = recipientsRecyclerViewAdapter
binding?.rVRecipients?.addItemDecoration(decoration)
binding?.rVRecipients?.layoutManager = manager
binding?.rVRecipients?.adapter = recipientsRecyclerViewAdapter

root.findViewById<View>(R.id.floatActionButtonImportPublicKey)?.setOnClickListener {
binding?.fABtImportPublicKey?.setOnClickListener {
navController?.navigate(
RecipientsListFragmentDirections
.actionRecipientsListFragmentToImportRecipientsFromSourceFragment()
)
}
}

private fun setupContactsViewModel() {
recipientsViewModel.contactsWithPgpLiveData.observe(viewLifecycleOwner, {
when (it.status) {
Result.Status.LOADING -> {
UIUtil.exchangeViewVisibility(true, progressBar, recyclerViewContacts)
}

Result.Status.SUCCESS -> {
UIUtil.exchangeViewVisibility(false, progressBar, recyclerViewContacts)
if (it.data.isNullOrEmpty()) {
UIUtil.exchangeViewVisibility(true, emptyView, recyclerViewContacts)
} else {
recipientsRecyclerViewAdapter.swap(it.data)
UIUtil.exchangeViewVisibility(false, emptyView, recyclerViewContacts)
}
}

else -> {
private fun setupRecipientsViewModel() {
lifecycleScope.launchWhenStarted {
recipientsViewModel.recipientsWithPgpFlow.collect {
if (it.isNullOrEmpty()) {
showEmptyView()
} else {
recipientsRecyclerViewAdapter.submitList(it)
showContent()
}
}
})
}

companion object {
private const val REQUEST_CODE_START_IMPORT_PUB_KEY_ACTIVITY = 0
}
}
}
Loading