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

(Hopefully) some improvements to Kotlin code and some general cleanup #7

Merged
merged 15 commits into from
Apr 19, 2017

Conversation

Bombo
Copy link
Contributor

@Bombo Bombo commented Apr 18, 2017

I'm currently adapting Kotlin myself and in our current project we needed Fingerprint authentication, so I've stumbled upon your library and noticed some things, that weren't Kotlin enough for me. ;)

Everything is up for discussion, of course.

You should get all the information from my commit messages, but overall what I did is:

  • Mitigated the need for explicit init{} blocks
  • Removed the need for all !! operators
  • Removed hungarian notiation. I know where you're coming from here, and I too am using this in basically all my Android java classes, but after reading this great blog post from Jake Wharton I am in the middle of slowly reducing this. Either way, I think with Kotlin and properties, hungarian notiation should be avoided in Kotlin in General.
  • Moved from explicit getter/setter methods to property getters and setters. This overall just makes the library nicer to use from Kotlin. Overall everything should stay the same from a Java standpoint. I also added deprecated methods to be used from Kotlin with nice ReplaceWith parameters for easy Alt+Enter replacements.
  • Fixed spelling issue with FahSecureSettingsDialog.setPositive() methods, but kept setPostisive() methods around with added deprecation annotations. Same goes for FahErrorType.Auth.AUTH_TOO_MANY_TRIES.
  • Fixed small issue with Documentation headings.
  • Re-applied .gitignore file, so .idea folder is not source-controlled anymore. All of this is generated by Android Studio via build.gradle file anyway, and I tried a clean checkout and didn't have any issues.

Let me know what you think!

Bombo added 15 commits April 12, 2017 08:49
… are not needed. As far as I can see, this object is intended for internal use only, so it would only be used in Kotlin, and most of the fields can be declared as const values instead.
- Removed explicit android.support.annotation.NonNull annotation, as non-nullable Kotlin variables and parameters are annotated with org.jetbrains.annotations.NotNull, which should serve the same purpose.
- Moved constants into private companion object, so they would become actual static constants.
- Moved some stuff out of init{} block directly into property declarations. This removes the need for some fields being nullable, where they don't need to be and still behaves as if being set in the init{} block.
- Removed hungarian notation for private properties. Left it in for mTimeOutLeft and mTriesCountLeft for now, as they could potentially be intended to be part of the exposed API.
- Removed the need for the !! operator.
- Fixed spelling error with setPositive and deprecated setPostisive methods.
- Moved some stuff out of the Builder's init{} block directly into property declarations.
- Removed hungarian notation for private properties.
- Removed the need for the !! operator by making the context property not-nullable, lazily initializing the dialog, and not handling fallbacks for string properties directly in show() but directly where they are initialized.
- Removed hungarian notation.
- Removed the need for the !! operator by using the elvis operator.
- Made broadcastIntent property not-nullable by lazily initializing.
…ty for Java and Kotlin)

- Removed hungarian notation.
- Changed most private properties with extra getter functions into public ones with custom getters.
- Changed isSdkVersionOk from function to lazily initialized property.
- Changed FahManager reference to be immutable and initialize it immediately with either a correct reference or null. This removed the need for the !! operator or even ?. with proper null checks and implicit casts.
- Added JvmName annotations to properties, where the implicit getter name didn't match the removed getter function.
- Deprecated explicit getter functions, which should not be used anymore and set bogus JvmName annotations to avoid naming clashes with Java names.
… still using the old cleanTimeOut method, that method is now fully deprecated and implicit isTimeOutCleaned() method should be used instead.
…property this time, as that one wasn't needed.
…recated FahErrorType.Auth.AUTH_TO_MANY_RETRIES.
@@ -280,16 +263,20 @@ internal class FahManager(@NonNull c: Context, l: FahListener?, keyName: String,
}
}

val keyStore: KeyStore
Copy link
Owner

Choose a reason for hiding this comment

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

can you please explain, what is the goal to create local variable instead reinit the property one?

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 was done to avoid unnecessary null checks. As the keyStor property is mutable (var instead of val) it could possibly change from being not-null to null. Agreed, this shouldn't really happen, but the compiler things it might, so this is just to avoid warnings, essentially.

Copy link
Owner

Choose a reason for hiding this comment

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

thanks for explanation, it little bit more clear right now for me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! :)

I hope some day, I'll find a better way to do such things, but I'm kinda still learning Kotlin. ;)

Copy link
Owner

Choose a reason for hiding this comment

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

the same to me :)

@@ -303,11 +290,11 @@ internal class FahManager(@NonNull c: Context, l: FahListener?, keyName: String,
}

try {
mKeyStore!!.load(null)
keyStore.load(null)
Copy link
Owner

Choose a reason for hiding this comment

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

and here you are "loading" to null local variable instead property variable. or I am missing the idea of 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.

As the local variable and the property are referencing the same object, this would also affect the property.

mCancellationSignal = null
mIsListening = false
isActivityForeground = false
if (cancellationSignal != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

if (cancellationSignal != null) {
this one also can be changed for cancellationSignal?.le{

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're completely right! Will change that, when I get to my station!

Copy link
Owner

Choose a reason for hiding this comment

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

no needed, i am already pull your request to the separate branch and add this improvements ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect!

@pro100svitlo
Copy link
Owner

this is little bit different theme, but maybe you have some ideas about this issue?

@pro100svitlo pro100svitlo merged commit 23ba555 into pro100svitlo:master Apr 19, 2017
@pro100svitlo
Copy link
Owner

thanks for your job :)

@Bombo
Copy link
Contributor Author

Bombo commented Apr 19, 2017

No problem at all. This was fun! :)

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.

2 participants