Reputation: 6314
I have a special case in my project that relies on MVP pattern.
The use case is that when clicking a button an contact email should be sent. The email is created dynamically, a combination from some input fields and some data from repository and string resources.
The flow starts like this:
Fragment/View:
sendButton.setOnClickListener { presenter.onSendButtonClick(
emailField.text.toString(),
questionField.text.toString(),
getSubjectWithTimeStamp(presenter.getMyObject(), getString(R.string.app_name))
)}
private fun getMailSubjectTimeStamp(object: MyObject? = null, appName: String): String {
val timeStamp = MAIL_SUBJECT_TIMESTAMP_FORMAT.format(Date())
return if (object != null) {
getString(
R.string.help_contactForm_subject_with_data,
appName,
object.someInfo,
timeStamp
)
} else {
getString(
R.string.help_contactForm_subject,
appName,
timeStamp
)
}
}
Presenter:
private var lastKnownObject: MyObject? = null
override fun onBound(view: ContactContract.View) {
super.onBound(view)
scope.launch {
// This is fetched from DB behind the scene via the Interactor.
lastKnownObject = myObjectInteractor.readLastKnownObject()
}
}
override fun getLastKnownObject(): MyObject? {
return lastKnownObject
}
override fun onSendButtonClick(userMail: String, questionText: String, subject: String) {
sendMailAndShowFeedback(userMail, questionText, subject)
}
This works, but I'm not very happy with the fact that I need to expose a variable from my presenter and manually access it before triggering the flow with onSendButtonClick
.
Any other ideas on how to achieve this kind of combination and still have my separation of concerns?
Upvotes: 0
Views: 70