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 sample app to Kotlin #10

Closed
andyb129 opened this issue Feb 20, 2018 · 4 comments
Closed

Convert sample app to Kotlin #10

andyb129 opened this issue Feb 20, 2018 · 4 comments

Comments

@andyb129
Copy link
Owner

andyb129 commented Feb 20, 2018

Convert the sample app classes to Kotlin (I'll then merge these to the 'kotlin-version' branch so create feature branch from that).

  • MainActivity
  • PourBeerTask
@andyb129 andyb129 changed the title Convert sample app to kotlin Convert sample app to Kotlin Feb 20, 2018
@mezpahlan
Copy link
Contributor

Taking this one one.

@mezpahlan
Copy link
Contributor

Good evening Mr. B.

I am having some difficulty converting the sample app in particular the MainActivity. On the face of it the initial conversion is straight forward however as I mentioned in Slack the AsyncTask is proving a bit thorny. Here's what I have:

  • I can't restart the AsyncTask. Maybe I'm being dense but it seems that once the task completes that's it. It's been ages since I've used one so happy hear otherwise.
  • In the Java MainActivity the AsyncTask gets effectively reset such that it can be restarted by nulling the reference and reassigning which works pretty well in Java.
  • In Kotlin, however I cannot null a val reference. So I make it a var so that I can set it to null and reinitialise it when I switch tabs. However I cannot do that either as I need to change the type from a PourBeerTask to a PourBeerTask? - a nullable type.
  • I end up writing Kotlin code but it is still littered with null checks.

In doing this I fear that I'm not writing idiomatic Kotlin code and carrying over bad practices from Java? Thoughts?

@mezpahlan
Copy link
Contributor

I've added a PR (#13) to show how it looks in code. So far I've only converted the MainActivity.

My thinking now is that there is probably a better way to do the loop that the AsyncTask is doing. But perhaps that is out of scope of this issue? What do you think?

@andyb129
Copy link
Owner Author

Great, thanks for the conversion. I've merged it in and we can do a few tweaks as we learn more about this Kotlin magic! 👍

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

No branches or pull requests

2 participants