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

Convert CropImageOptions to data class with proper default parameters. #396

Closed
wants to merge 8 commits into from
Closed

Convert CropImageOptions to data class with proper default parameters. #396

wants to merge 8 commits into from

Conversation

vanniktech
Copy link
Contributor

What do you think of this?

  • It's way less code.
  • We don't need to do the Parcelable dance ourselves.
  • CropImageContractOptions would get much simpler too
  • Unifies the API Consistent names #387

Wanted to get your opinion first, before continuing

@vanniktech vanniktech requested a review from a team as a code owner June 25, 2022 22:47
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 29 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 29 potential problems in the proposed changes. Check the Files changed tab for more details.


/**
* The radius of the touchable area around the handle. (in pixels)<br></br>
* We are basing this value off of the recommended 48dp Rhythm.<br></br>
* See: http://developer.android.com/design/style/metrics-grids.html#48dp-rhythm
*/
@JvmField
var touchRadius: Float
val touchRadius: Float = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, Resources.getSystem().displayMetrics),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should never be used as it might be different from the current window.
Alternatively I'd just rename this to touchRadiusDp, set 24 as the default value and do the conversion at a later stage.

Copy link
Member

Choose a reason for hiding this comment

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

agreed, but would suggest another PR to do the changes, so we keep it self contained

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I just inlined the previous defaults. I'd change that in a follow up. Also there's the #387


/**
* The radius of the touchable area around the handle. (in pixels)<br></br>
* We are basing this value off of the recommended 48dp Rhythm.<br></br>
* See: http://developer.android.com/design/style/metrics-grids.html#48dp-rhythm
*/
@JvmField
var touchRadius: Float
val touchRadius: Float = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, Resources.getSystem().displayMetrics),

/** whether the guidelines should be on, off, or only showing when resizing. */
@JvmField
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the benefit of JvmField here.

Copy link
Member

Choose a reason for hiding this comment

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

I believe we need this to work on Java, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you're with Java you'd need to call getGuideliness here without it

Copy link
Contributor

Choose a reason for hiding this comment

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

For java it's also a best practice to use a getter in order to be able to change the implementation without needing to change the api.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Up to you. I can remove all JvmFields.

Copy link
Member

@Canato Canato left a comment

Choose a reason for hiding this comment

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

This is a great PR, thanks for the work. Will help everyone who uses and maintain the library.

Keep the good work 🚀


/**
* The radius of the touchable area around the handle. (in pixels)<br></br>
* We are basing this value off of the recommended 48dp Rhythm.<br></br>
* See: http://developer.android.com/design/style/metrics-grids.html#48dp-rhythm
*/
@JvmField
var touchRadius: Float
val touchRadius: Float = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, Resources.getSystem().displayMetrics),

/** whether the guidelines should be on, off, or only showing when resizing. */
@JvmField
Copy link
Member

Choose a reason for hiding this comment

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

I believe we need this to work on Java, right?


/**
* The radius of the touchable area around the handle. (in pixels)<br></br>
* We are basing this value off of the recommended 48dp Rhythm.<br></br>
* See: http://developer.android.com/design/style/metrics-grids.html#48dp-rhythm
*/
@JvmField
var touchRadius: Float
val touchRadius: Float = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, Resources.getSystem().displayMetrics),
Copy link
Member

Choose a reason for hiding this comment

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

agreed, but would suggest another PR to do the changes, so we keep it self contained

@Canato Canato linked an issue Jun 28, 2022 that may be closed by this pull request
@vanniktech vanniktech requested a review from Canato June 28, 2022 09:44
@Canato
Copy link
Member

Canato commented Jun 28, 2022

@vanniktech please fix the CI issues so I can test ^^.

Maybe the contributing guide can help with ktlint

@vanniktech
Copy link
Contributor Author

Mobile data is terrible where I am currently. I only have ktlint 0.46.0 & 0.46.1 locally and we can't seem to update this project #398, will run ktlint later

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 65 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 67 potential problems in the proposed changes. Check the Files changed tab for more details.

@vanniktech
Copy link
Contributor Author

@Canato updated the PR with ktlint fixes.

Copy link
Member

@Canato Canato left a comment

Choose a reason for hiding this comment

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

Nice work! need some rebase with the latest merged PRs

CONTRIBUTING.md Outdated Show resolved Hide resolved
@@ -18,7 +18,6 @@ internal class MainActivity : AppCompatActivity() {
binding.sampleCropImageView.setOnClickListener { SampleUsingImageView.newInstance().show() }
binding.sampleCustomActivity.setOnClickListener { SampleCustomActivity.start(this) }
binding.sampleCropImage.setOnClickListener { SampleCrop.newInstance().show() }
binding.sampleCropImageJava.setOnClickListener { SampleCropJava.newInstance().show() }
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see much benefit of providing it. We should not be the one teaching people how to use Kotlin from Java.

Copy link
Member

Choose a reason for hiding this comment

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

We should not be the one teaching people how to use Kotlin from Java\

Why should we not show how to use the library in Java?

There are many requests to use the library in Java code, we have documentation only for this and is by far the most amount of issues I get in the repo.

I need a way to manually test if is working, in the case someone spot a bug in the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this and is by far the most amount of issues I get in the repo.

Seems like we have different motivations. I'll eventually get around of it and update it. In the meantime, I'll build a version myself.

I need a way to manually test if is working, in the case someone spot a bug in the library.

And this can't be done using Kotlin only? What's a bug that is only targeting Java?

I'm just in favor of reducing maintenance cost here. We don't need similar things twice. Kotlin and Java.

Copy link
Contributor

Choose a reason for hiding this comment

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

Kotlin is the industry standard.

Javs usage is very simple and you get autocompletion. Also it's pretty well documented how interop is working in general.
https://kotlinlang.org/docs/java-interop.html

I believe it should not be a task of a library to document how kotlin-java interop works.

Copy link
Member

Choose a reason for hiding this comment

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

These are some of the cases.

Most of the time I'm maintaining the library by myself.
In other great times, good developers like you two (@PaulWoitaschek and @vanniktech) appear to provide valid help.
But so far no one took the step further of becoming responsible for the library too.

I believe it should not be a task of a library to document how kotlin-java interop works.

I strongly believe we can support the community with examples of library usage. And if we can use Kotlin and Java why not have both?

Sadly not all developers who use this library are good developers or even know how to use Kotlin.
There are some developers blocked on the versions before the v4, because they don't know how to use ActivityContracts or they don't have the skills to update Gradle and Java.

My goal with this library is to help the Android community, having it in Java helps a lot.
I already changed everything to Kotlin, fix issues and update to the latest Gradle, OS and Java.

I believe we can take time and help new developers on the path to becoming better Android developers instead of excluding them from using the library because they don't know Kotlin yet.

Copy link
Member

Choose a reason for hiding this comment

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

That said, if the community that uses this library wanna go in this direction, I will not oppose it. But we need someone to take ownership of the Java questions.

Comment on lines 95 to +98
customCropImage.launch(
options {
setImageSource(
includeGallery = includeGallery,
includeCamera = includeCamera,
CropImageContractOptions(
uri = null,
CropImageOptions(
Copy link
Member

Choose a reason for hiding this comment

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

We need to update the README, documentation, wiki etc.

setAllowRotation(true)
setNoOutputImage(false)
setFixAspectRatio(false)
// Odd Settings
Copy link
Member

Choose a reason for hiding this comment

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

Where is the new odd settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, people can look at the type itself to figure out all options

Copy link
Member

Choose a reason for hiding this comment

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

Can you please return the odd settings? I use this for testing when people make changes to the library.

Or if you really want to remove we can add CI tests that check is this values are been setup.

Comment on lines -64 to -70
<Button
style="@style/Sample.Button"
android:id="@+id/sampleCropImageJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/sample_calling_cropimage_java"/>
Copy link
Member

Choose a reason for hiding this comment

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

Why this was removed?

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 67 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 67 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 67 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 67 potential problems in the proposed changes. Check the Files changed tab for more details.

@vanniktech
Copy link
Contributor Author

Let's keep this mess organised! This issue has been automatically marked as stale because it has not had recent activity. =( It will be closed if no further activity occurs. Thank you for your contributions.

@vanniktech vanniktech closed this Jul 25, 2022
@vanniktech vanniktech deleted the better-CropImageOptions branch July 25, 2022 12:05
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.

Consistent names
3 participants