-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some UI and logic. Refactored code.| #1251
- Loading branch information
Showing
15 changed files
with
443 additions
and
14 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...t/src/main/java/com/flowcrypt/email/jetpack/viewmodel/KeysWithEmptyPassphraseViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected] | ||
* Contributors: DenBond7 | ||
*/ | ||
|
||
package com.flowcrypt.email.jetpack.viewmodel | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MediatorLiveData | ||
import androidx.lifecycle.liveData | ||
import androidx.lifecycle.switchMap | ||
import com.flowcrypt.email.api.retrofit.response.base.Result | ||
import com.flowcrypt.email.extensions.org.bouncycastle.openpgp.toPgpKeyDetails | ||
import com.flowcrypt.email.security.KeysStorageImpl | ||
import com.flowcrypt.email.security.model.PgpKeyDetails | ||
|
||
/** | ||
* @author Denis Bondarenko | ||
* Date: 6/1/21 | ||
* Time: 9:59 AM | ||
* E-mail: [email protected] | ||
*/ | ||
class KeysWithEmptyPassphraseViewModel(application: Application) : AccountViewModel(application) { | ||
private val keysStorage: KeysStorageImpl = KeysStorageImpl.getInstance(getApplication()) | ||
|
||
val keysWithEmptyPassphrasesLiveData: MediatorLiveData<Result<List<PgpKeyDetails>>> = | ||
MediatorLiveData() | ||
|
||
private val pgpKeyDetailsLiveData: LiveData<Result<List<PgpKeyDetails>>> = | ||
keysStorage.secretKeyRingsLiveData.switchMap { list -> | ||
liveData { | ||
emit(Result.loading()) | ||
emit(Result.success(list | ||
.map { it.toPgpKeyDetails() } | ||
.filter { keysStorage.getPassphraseByFingerprint(it.fingerprint)?.isEmpty == true }) | ||
) | ||
} | ||
} | ||
|
||
private val afterPassphraseUpdatedKeyDetailsLiveData: LiveData<Result<List<PgpKeyDetails>>> = | ||
keysStorage.passphrasesUpdatesLiveData.switchMap { | ||
liveData { | ||
emit(Result.loading()) | ||
emit( | ||
Result.success(keysStorage.getPgpKeyDetailsList() | ||
.filter { keysStorage.getPassphraseByFingerprint(it.fingerprint)?.isEmpty == true }) | ||
) | ||
} | ||
} | ||
|
||
init { | ||
keysWithEmptyPassphrasesLiveData.addSource(pgpKeyDetailsLiveData) { | ||
keysWithEmptyPassphrasesLiveData.value = it | ||
} | ||
keysWithEmptyPassphrasesLiveData.addSource(afterPassphraseUpdatedKeyDetailsLiveData) { | ||
keysWithEmptyPassphrasesLiveData.value = it | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
.../java/com/flowcrypt/email/ui/activity/fragment/dialog/FixEmptyPassphraseDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected] | ||
* Contributors: DenBond7 | ||
*/ | ||
|
||
package com.flowcrypt.email.ui.activity.fragment.dialog | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Dialog | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.fragment.app.viewModels | ||
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.extensions.decrementSafely | ||
import com.flowcrypt.email.extensions.gone | ||
import com.flowcrypt.email.extensions.incrementSafely | ||
import com.flowcrypt.email.extensions.visible | ||
import com.flowcrypt.email.jetpack.viewmodel.KeysWithEmptyPassphraseViewModel | ||
import com.flowcrypt.email.ui.adapter.PrvKeysRecyclerViewAdapter | ||
import com.flowcrypt.email.ui.adapter.recyclerview.itemdecoration.MarginItemDecoration | ||
import com.google.android.gms.common.util.CollectionUtils | ||
|
||
/** | ||
* @author Denis Bondarenko | ||
* Date: 5/28/21 | ||
* Time: 2:50 PM | ||
* E-mail: [email protected] | ||
*/ | ||
class FixEmptyPassphraseDialogFragment : BaseDialogFragment() { | ||
private var rVKeys: RecyclerView? = null | ||
private var tVStatusMessage: TextView? = null | ||
private var pBLoading: View? = null | ||
private var gCheckPassphrase: View? = null | ||
private val prvKeysRecyclerViewAdapter = PrvKeysRecyclerViewAdapter() | ||
|
||
private val keysWithEmptyPassphraseViewModel: KeysWithEmptyPassphraseViewModel by viewModels() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
isCancelable = false | ||
setupKeysWithEmptyPassphraseLiveData() | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val view = LayoutInflater.from(context).inflate( | ||
R.layout.fragment_fix_empty_passphrase, | ||
if ((view != null) and (view is ViewGroup)) view as ViewGroup? else null, false | ||
) | ||
|
||
gCheckPassphrase = view.findViewById(R.id.gCheckPassphrase) | ||
tVStatusMessage = view.findViewById(R.id.tVStatusMessage) | ||
pBLoading = view.findViewById(R.id.pBLoading) | ||
rVKeys = view.findViewById(R.id.rVKeys) | ||
|
||
rVKeys?.apply { | ||
layoutManager = LinearLayoutManager(context) | ||
addItemDecoration( | ||
MarginItemDecoration( | ||
marginBottom = resources.getDimensionPixelSize(R.dimen.default_margin_content_small) | ||
) | ||
) | ||
adapter = prvKeysRecyclerViewAdapter | ||
} | ||
|
||
val builder = AlertDialog.Builder(requireContext()).apply { | ||
setView(view) | ||
setNegativeButton(R.string.cancel) { _, _ -> } | ||
} | ||
|
||
return builder.create() | ||
} | ||
|
||
@SuppressLint("FragmentLiveDataObserve") | ||
private fun setupKeysWithEmptyPassphraseLiveData() { | ||
keysWithEmptyPassphraseViewModel.keysWithEmptyPassphrasesLiveData.observe(this, { | ||
when (it.status) { | ||
Result.Status.LOADING -> { | ||
baseActivity?.countingIdlingResource?.incrementSafely() | ||
pBLoading?.visible() | ||
} | ||
|
||
Result.Status.SUCCESS -> { | ||
pBLoading?.gone() | ||
val keyDetailsList = it.data ?: emptyList() | ||
if (CollectionUtils.isEmpty(keyDetailsList)) { | ||
tVStatusMessage?.text = getString(R.string.no_pub_keys) | ||
} else { | ||
gCheckPassphrase?.visible() | ||
tVStatusMessage?.text = requireContext().resources.getQuantityString( | ||
R.plurals.please_provide_passphrase_for_following_keys, keyDetailsList.size | ||
) | ||
|
||
prvKeysRecyclerViewAdapter.submitList(keyDetailsList) | ||
} | ||
baseActivity?.countingIdlingResource?.decrementSafely() | ||
} | ||
|
||
Result.Status.EXCEPTION -> { | ||
pBLoading?.gone() | ||
tVStatusMessage?.visible() | ||
tVStatusMessage?.text = it.exception?.message | ||
baseActivity?.countingIdlingResource?.decrementSafely() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
companion object { | ||
fun newInstance(): FixEmptyPassphraseDialogFragment { | ||
return FixEmptyPassphraseDialogFragment() | ||
} | ||
} | ||
} |
Oops, something went wrong.