Skip to content

Map Device List#76

Merged
runningcode merged 8 commits into
runningcode:masterfrom
zlippard:map-devices
Nov 7, 2019
Merged

Map Device List#76
runningcode merged 8 commits into
runningcode:masterfrom
zlippard:map-devices

Conversation

@zlippard

@zlippard zlippard commented Oct 31, 2019

Copy link
Copy Markdown
Contributor

Updated devices to support a different API using a list of maps for setting up devices rather than requiring the Device class to be referenced in Gradle.

In reference to: #31

Usage:

fladle {
  ...
  devices = [
/*  No longer allowed  */
//    new Device("Nexus5", 28)
/*  Use this instead  */
    [ "model": "Nexus5", "version": "28" ]
  ]
}

@runningcode

Copy link
Copy Markdown
Owner

Hey, thanks for the contribution. I really like this new api design. Can we deprecate the old one and only allow the new one to be used? Also, can we only allow one of the two to be set from the fladle extension? (Throw an exception if both are set)

@zlippard

zlippard commented Nov 6, 2019

Copy link
Copy Markdown
Contributor Author

@runningcode sure thing! I'll add the deprecation and force only one to be used in the extension.

@zlippard

zlippard commented Nov 6, 2019

Copy link
Copy Markdown
Contributor Author

@runningcode Do you think it would be better to simply replace devices with the list map implementation instead of a list of Devices? Otherwise, we're requiring the users of this to switch over to mapDevices. I had gone back and forth on this, but I'm wondering if now it makes more sense to simply change devices to be the list map implementation. It is a breaking change this way, but maybe this would be a major minor version change to 0.8.0?

Thoughts?

@runningcode

Copy link
Copy Markdown
Owner

Yeah, you know what? Fladle is still a 0.x library so we reserve the right to make these changes. Let's go ahead and do that. I think the importing of the Device has been a really confusing API for some time now. Let's clean this up and have a single opinionated way of doing this. Let's have the new map field only.

@zlippard

zlippard commented Nov 7, 2019

Copy link
Copy Markdown
Contributor Author

Sounds good to me, will change the minor version to 0.8.0 and require the new map implementation of devices 👍

@zlippard

zlippard commented Nov 7, 2019

Copy link
Copy Markdown
Contributor Author

@runningcode Done deal! I figured bumping to 0.8.0 made sense, if not, I can revert that back to 0.7.2 (or remove that version change entirely). This PR is rebased on top of the other recent PR merged in.

@zlippard zlippard changed the title HashMap Device List Map Device List Nov 7, 2019

@runningcode runningcode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a small nit.

appendln(" - model: ${device.model}")
appendln(" version: ${device.version}")
device.orientation?.let {
val model = device["model"]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val model = device["model"]
val model = device["model"]!!

I believe model and version are required fields. Rather than printing - model: null, let's fail fast here.
Maybe we can write a test for this case too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, will fix this 👍

@zlippard zlippard Nov 7, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I added a RequiredDeviceKeyMissingException and throw that when "model" or "version" are null: 4764435


@VisibleForTesting
internal fun createDeviceString(devices: List<Device>): String = buildString {
internal fun createDeviceString(devices: List<Map<String, String?>>): String = buildString {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About to merge, but I need to talk this out. :) Is it possible for the value to be null here? For example if we have orientation in the map, the value for orientation must be non-null. Same goes for model?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what, that's a good point haha. I'll remove the ? that's unnecessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :) 8b63694

@runningcode

Copy link
Copy Markdown
Owner

Thanks for helping out and fixing all those nitpicks. I've realized a lot of people are using this library so we want to make this API as nice as possible.

@runningcode
runningcode merged commit 27dc06a into runningcode:master Nov 7, 2019
@zlippard

zlippard commented Nov 7, 2019

Copy link
Copy Markdown
Contributor Author

Happy to help! It's a great plugin to use alongside Flank :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants