Coder Social home page Coder Social logo

codelab-android-using-kotlin's Introduction

MyAddressBook

This is the repository that contains both the starter and finished app for the Taking Advantage of Kotlin codelab. The starter app is written in Java, which is then converted to Kotlin and extended.

Introduction

MyAddressBook is an address book android application, that lists contacts containing a first name, last name, and email address. The contacts can be generated quickly from an included JSON file, or created manually in the app. It contains validation for the input fields, stores the data in SharedPreferences, and supports swipe to delete in the RecyclerView.

Pre-requisites

A basic knowledge of developing Android apps in Java, specifically:

  • Displaying data in a RecyclerView.
  • Using SharedPreferences to persist data.
  • How to create JavaBean objects.
  • Creating layouts using ConstraintLayout.
  • Displaying an AlertDialog.
  • Validating user input in an EditText.

Getting Started

  1. Download the code.
  2. Pick either the starter or finished directory and open the respective folder in Android Studio 3.0.
  3. Run the app.

License

Copyright 2018 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

codelab-android-using-kotlin's People

Contributors

mco-gh avatar ngamolsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codelab-android-using-kotlin's Issues

Missing explanation on using Kotlin Android Extensions

In the chapter "4. Kotlin View Binding, Lambdas & Standard Library Extensions", subsection "Kotlin Android Extensions view binding" it tells the learner to "remove the statements with findViewById() calls".

However, the R.id preceding the view id must be also removed. Example:

        val fab = findViewById<FloatingActionButton>(R.id.fab)

will be

        val fab = R.id.fab

which is not correct.

It would be great to explain this in a different way, so the learner is not confusing the view id with a reference to the actual view.

Let me know what you think and maybe I can submit a pull request ๐Ÿ˜„

FAB does not respond in MyAddressBook-final

FAB can't handle click on it. In case when there are some generated values in Recycler View then click on FAB causes that click on Recycler View's item is performed.

I have already found the solution - in activity_contacts.xml the FloatingActionButton should be declared after <include layout="@layout/content_contacts" />

Animation transition in codelab is counter-intuitive

While I was reading this cool lab I encountered a bug in sliding animation.

If you try to go from page1 to page2, the animation is good.
But if you go from page2 to page1 the animation is not right (The exactly opposite animation should have been used).

Issue Found While Inline this variable into the return statement

In one of the guides of codelabs Called Taking Advantage of Kotlin

We can see the implementation like below :

  private fun loadContacts(): ArrayList<Contact> {
        val contactSet = mPrefs.getStringSet(CONTACT_KEY, HashSet())
        val contacts: ArrayList<Contact> = contactSet.mapTo(ArrayList<Contact>()) { Gson().fromJson(it, Contact::class.java) }

        return contacts
    }

Now we can inline the contacts variable to the return statement directly, as the contacts variable is not useful anymore.

There are two ways to do it

  1. Manually by re-writing it alongside with return.
  2. Using (Alt + Enter) and then choosing an inline variable from options.

But By Using (Alt + Enter Method)

It gives an error of type arguments. And The Code is :

 private fun loadContacts(): ArrayList<Contact> {
        val contactSet = mPrefs.getStringSet(CONTACT_KEY, HashSet())

        return contactSet.mapTo<String?, Contact?, ArrayList<Contact>>(ArrayList()) { Gson().fromJson(it, Contact::class.java) }
    }

So it expect the mutableCollection of Contact besides ArrayList in the above return statement by using this method.

Not nullable value required to call an 'iterator()' method on for-loop range

Having converted ContactsActivity to Kotlin, using the automatic conversion as per the codelab step Convert ContactsActivity to Kotlin, the error:

Not nullable value required to call an 'iterator()' method on for-loop range

occurs.

Replacing for (contactString in contactSet) { with for (contactString in contactSet!!) { is one fix for this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.