-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Switch Export Settings to Activity Result API #8740
base: main
Are you sure you want to change the base?
Conversation
@@ -195,7 +193,6 @@ class SettingsExportViewModel( | |||
|
|||
companion object { | |||
private const val MIN_PROGRESS_DURATION = 1000L | |||
private const val SETTINGS_MIME_TYPE = "application/octet-stream" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move this to the fragment? Deciding which MIME type to use is not something that should be done in view code.
Besides that, I also don't see how this is related to switching to the activity result API. Please try to keep pull requests as focused as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well, the reason was that the usage of wildcards on ActivityResultContracts.CreateDocument()
is deprecated so you have to specify MIME Type on constructor and you cannot use registerForActivityResult
at runtime. My options were make that constant public or move it to the place of usage instead of passing by action events. I'll revert it and use the first option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. This feels like a design bug in the CreateDocument()
API. We could fix that by using our own implementation:
class CreateDocument : ActivityResultContract<CreateDocument.Arguments, Uri?>() {
override fun createIntent(context: Context, input: Arguments): Intent {
return Intent(Intent.ACTION_CREATE_DOCUMENT)
.setType(input.mimeType)
.putExtra(Intent.EXTRA_TITLE, input.title)
}
override fun getSynchronousResult(context: Context, input: Arguments): SynchronousResult<Uri?>? = null
override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
return intent.takeIf { resultCode == Activity.RESULT_OK }?.data
}
data class Arguments(
val title: String,
val mimeType: String,
)
}
Alternatively, expose the MIME type via a SettingsExportViewModel
property. We don't want to introduce tight coupling between the fragment and the view model. So when changing SettingsExportFragment
, pretend SettingsExportViewModel
was an interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you're right, I should expose through a property and not by changing visibility. Anyway the first option seems to me suitable for future cases, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think the first option would be better. It does raise the question of where to put the code, though. I'd say in the package app.k9mail.core.android.common.activity
.
@wmontwe: Are we fine with adding a dependency on androidx.activity
to :core:android:common
?
e9d6a0a
to
e5b0a81
Compare
e5b0a81
to
dff82bf
Compare
Change related to #7758
Migrate create document result to new API on settings export