Skip to content
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

Add arrow shape #492

Merged
merged 14 commits into from
Jan 17, 2023
Merged

Add arrow shape #492

merged 14 commits into from
Jan 17, 2023

Conversation

wasky
Copy link
Contributor

@wasky wasky commented Jan 4, 2023

No description provided.

@wasky wasky mentioned this pull request Jan 4, 2023
wasky added 8 commits January 5, 2023 21:33
Change meaning of ArrowPointerLocation.START and
ArrowPointerLocation.END. START point is first touched point and END
is the last touched. This was inverted in initial commit.

After few days of testing I realised that it's easier to draw arrow
when pointer is placed on arrow's START, so I decided to change
default pointer location. Because START and END meaning was changed
in the commit, default pointer location value in ShapeType.Arrow()
don't have to be changed.

Also "pointer location" sounds better than "pointer position" so the
name was also changed.
@burhanrashid52
Copy link
Owner

@wasky Are you planning any more changes or is it ready for review?

@wasky
Copy link
Contributor Author

wasky commented Jan 11, 2023

It's ready!

@burhanrashid52
Copy link
Owner

@wasky Need to resolve conflicts.

@@ -0,0 +1,3 @@
package ja.burhanrashid52.photoeditor.shape

enum class ArrowPointerLocation { START, END, BOTH }
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is just one Enum, Can we move this enum to LineShape file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand the code correctly, LineShape is rather internal file for the library. We need to have access to ArrowPointerLocation from API so LineShape is not the best place for this enum:

ShapeBuilder.withShapeType(ShapeType.Arrow(ArrowPointerLocation.BOTH))

For that reason I put ArrowPointerLocation in separate file. But maybe I will put this enum in Arrow shape type and rename it to PointerLocation? This would look like this:

ShapeBuilder.withShapeType(ShapeType.Arrow(ShapeType.Arrow.PointerLocation.BOTH))

@@ -11,11 +11,6 @@ class EnumTest {
assertEquals(ViewType.values().size.toLong(), 4)
}

@Test
fun testNumberOfShapeTypes() {
Copy link
Owner

@burhanrashid52 burhanrashid52 Jan 14, 2023

Choose a reason for hiding this comment

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

Is there an alternative way to check how many shapes we support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In new Kotlin version (which I plan to update after #497) when expression must be exhaustive. That means if some shape will be added or removed, there will be compilation error in DrawingView:createShape():141 with message 'when' expression must be exhaustive, add necessary 'NewShapeName' branch or 'else' branch instead or in case of shape removal: Unresolved reference: Brush.

There is a possibility to obtain how many elements has sealed class but we need to use a reflection for this. To use reflection in Kotlin we need org.jetbrains.kotlin:kotlin-reflect dependency.

For this reasons I think this test is no longer needed and not worth the effort of adding new dependency only for this.

Copy link
Owner

@burhanrashid52 burhanrashid52 left a comment

Choose a reason for hiding this comment

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

Added some feedback

@burhanrashid52 burhanrashid52 linked an issue Jan 16, 2023 that may be closed by this pull request
wasky added 2 commits January 16, 2023 10:21
# Conflicts:
#	photoeditor/src/main/java/ja/burhanrashid52/photoeditor/DrawingView.kt
@burhanrashid52
Copy link
Owner

burhanrashid52 commented Jan 17, 2023

@wasky I tested this in my local. It works great!!. Thanks for the contribution you made. I really appreciated it.
One UX thing I notice is that the default arrow is set to start which feels reverse while drawing the arrow. I think making it END would feel better.

sealed interface ShapeType {
    class Arrow(val pointerLocation: ArrowPointerLocation = ArrowPointerLocation.END) : ShapeType
}

Copy link
Owner

@burhanrashid52 burhanrashid52 left a comment

Choose a reason for hiding this comment

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

LGTM!!

# Conflicts:
#	photoeditor/src/main/java/ja/burhanrashid52/photoeditor/DrawingView.kt
#	photoeditor/src/main/java/ja/burhanrashid52/photoeditor/shape/ShapeBuilder.kt
@wasky
Copy link
Contributor Author

wasky commented Jan 17, 2023

@wasky I tested this in my local. It works great!!. Thanks for the contribution you made. I really appreciated it.

Thanks! :)

One UX thing I notice is that the default arrow is set to start which feels reverse while drawing the arrow. I think making it END would feel better.

It was intentional. I'm using it for 2 weeks now in my app and I think it's easier with arrow pointer at START position. That's because when you have pointer location as END, you don't see where exactly the pointer will be - you don't see the screen under the finger.

Considering the above, are you sure do you want me to change default position to END? Or maybe you need more time to test?

Also I don't know what about the ArrowPointerLocation or ShapeType.Arrow.PointerLocation? I have a commit already prepared so it's up to you what do you prefer? In this case I'm not able to choose which would be better.

@burhanrashid52
Copy link
Owner

It was intentional. I'm using it for 2 weeks now in my app and I think it's easier with arrow pointer at START position. That's because when you have pointer location as END, you don't see where exactly the pointer will be - you don't see the screen under the finger.

Let's keep it as it is. If needed, we can point to this conversation.

Also I don't know what about the ArrowPointerLocation or ShapeType.Arrow.PointerLocation? I have a commit already prepared so it's up to you what do you prefer? In this case, I'm not able to choose which would be better.

Oh, I missed that. After reading ShapeType.Arrow.PointerLocation I would prefer the earlier one.

@wasky
Copy link
Contributor Author

wasky commented Jan 17, 2023

So it's ready to merge :)

@burhanrashid52 burhanrashid52 merged commit fed472b into burhanrashid52:master Jan 17, 2023
@wasky wasky deleted the PE-491 branch January 17, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arrow shape
2 participants