mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Manage OTP
This commit is contained in:
@@ -516,7 +516,11 @@ class EntryEditActivity : LockingActivity(),
|
||||
* Set up OTP (HOTP or TOTP) and add it as extra field
|
||||
*/
|
||||
private fun setupOtp() {
|
||||
// TODO Fragment entryEditFragment?.setupOtp()
|
||||
mEntryEditViewModel.setupOtp()
|
||||
}
|
||||
|
||||
override fun onOtpCreated(otpElement: OtpElement) {
|
||||
mEntryEditViewModel.createOtp(otpElement)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -632,10 +636,6 @@ class EntryEditActivity : LockingActivity(),
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onOtpCreated(otpElement: OtpElement) {
|
||||
// TODO fragment entryEditFragment?.onOtpCreated(otpElement)
|
||||
}
|
||||
|
||||
// Launch the date picker
|
||||
private fun selectDate(dateInstant: DateInstant) {
|
||||
val dateTime = DateTime(dateInstant.date)
|
||||
|
||||
@@ -41,14 +41,13 @@ import com.kunzisoft.keepass.model.AttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.StreamDirection
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.view.TemplateView
|
||||
import com.kunzisoft.keepass.view.collapse
|
||||
import com.kunzisoft.keepass.view.expand
|
||||
import com.kunzisoft.keepass.viewmodels.EntryEditViewModel
|
||||
|
||||
class EntryEditFragment: DatabaseFragment(), SetOTPDialogFragment.CreateOtpListener {
|
||||
class EntryEditFragment: DatabaseFragment() {
|
||||
|
||||
private var iconColor: Int = 0
|
||||
|
||||
@@ -178,6 +177,18 @@ class EntryEditFragment: DatabaseFragment(), SetOTPDialogFragment.CreateOtpListe
|
||||
}
|
||||
}
|
||||
|
||||
mEntryEditViewModel.requestSetupOtp.observe(viewLifecycleOwner) {
|
||||
// Retrieve the current otpElement if exists
|
||||
// and open the dialog to set up the OTP
|
||||
SetOTPDialogFragment.build(templateView.getEntryInfo().otpModel)
|
||||
.show(parentFragmentManager, "addOTPDialog")
|
||||
}
|
||||
|
||||
mEntryEditViewModel.onOtpCreated.observe(viewLifecycleOwner) {
|
||||
// Update the otp field with otpauth:// url
|
||||
templateView.putOtpElement(it)
|
||||
}
|
||||
|
||||
mEntryEditViewModel.onBuildNewAttachment.observe(viewLifecycleOwner) {
|
||||
val attachmentToUploadUri = it.attachmentToUploadUri
|
||||
val fileName = it.fileName
|
||||
@@ -283,30 +294,6 @@ class EntryEditFragment: DatabaseFragment(), SetOTPDialogFragment.CreateOtpListe
|
||||
return false
|
||||
}
|
||||
|
||||
/* -------------
|
||||
* OTP
|
||||
* -------------
|
||||
*/
|
||||
|
||||
fun setupOtp() {
|
||||
// Retrieve the current otpElement if exists
|
||||
// and open the dialog to set up the OTP
|
||||
/*
|
||||
SetOTPDialogFragment.build(mEntryInfo.otpModel)
|
||||
.show(parentFragmentManager, "addOTPDialog")
|
||||
TODO OTP
|
||||
*/
|
||||
}
|
||||
|
||||
override fun onOtpCreated(otpElement: OtpElement) {
|
||||
// Update the otp field with otpauth:// url
|
||||
/*
|
||||
TODO OTP
|
||||
val otpField = OtpEntryFields.buildOtpField(otpElement, mEntryInfo.title, mEntryInfo.username)
|
||||
putCustomField(Field(otpField.name, otpField.protectedValue))
|
||||
*/
|
||||
}
|
||||
|
||||
/* -------------
|
||||
* Attachments
|
||||
* -------------
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.database.element.template.*
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import org.joda.time.DateTime
|
||||
@@ -578,6 +579,12 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
retrieveCustomFieldsFromView()
|
||||
}
|
||||
|
||||
fun putOtpElement(otpElement: OtpElement) {
|
||||
val otpField = OtpEntryFields.buildOtpField(otpElement,
|
||||
mEntryInfo?.title, mEntryInfo?.username)
|
||||
putCustomField(Field(otpField.name, otpField.protectedValue))
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(state: Parcelable?) {
|
||||
//begin boilerplate code so parent classes can restore state
|
||||
if (state !is SavedState) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.kunzisoft.keepass.model.AttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.StreamDirection
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.view.TemplateView
|
||||
|
||||
|
||||
@@ -55,6 +56,11 @@ class EntryEditViewModel: ViewModel() {
|
||||
val onTimeSelected : LiveData<TemplateView.Time> get() = _onTimeSelected
|
||||
private val _onTimeSelected = SingleLiveEvent<TemplateView.Time>()
|
||||
|
||||
val requestSetupOtp : LiveData<Void?> get() = _requestSetupOtp
|
||||
private val _requestSetupOtp = SingleLiveEvent<Void?>()
|
||||
val onOtpCreated : LiveData<OtpElement> get() = _onOtpCreated
|
||||
private val _onOtpCreated = SingleLiveEvent<OtpElement>()
|
||||
|
||||
private val mTempAttachments = mutableListOf<EntryAttachmentState>()
|
||||
val onBuildNewAttachment : LiveData<AttachmentBuild> get() = _onBuildNewAttachment
|
||||
private val _onBuildNewAttachment = SingleLiveEvent<AttachmentBuild>()
|
||||
@@ -176,6 +182,14 @@ class EntryEditViewModel: ViewModel() {
|
||||
_onTimeSelected.value = TemplateView.Time(hours, minutes)
|
||||
}
|
||||
|
||||
fun setupOtp() {
|
||||
_requestSetupOtp.call()
|
||||
}
|
||||
|
||||
fun createOtp(otpElement: OtpElement) {
|
||||
_onOtpCreated.value = otpElement
|
||||
}
|
||||
|
||||
fun buildNewAttachment(attachmentToUploadUri: Uri, fileName: String) {
|
||||
_onBuildNewAttachment.value = AttachmentBuild(attachmentToUploadUri, fileName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user