'How to improve the following Kotlin app project code?

I am really new to android app development using Kotlin. I got a coding challenge to develop an app to search for tv shows using the TV MAZE API. I learned some Kotlin basics and developed the app. I got the following feedback for my coding. Can anybody help me to understand the following points and how to improve my current code with respect to following points?

  1. No architecture at all (Nearly everything is in the Activity)
  2. using var not val for variables
  3. a lot of useless comments (e.g. sets the text to the textview or return the number of the items in the list)
  4. using findViewById() method (better: enable DataBinding or ViewBinding)
  5. No usage of the Strings.xml (only hardcoded strings)
  6. Manual json parsing (better use Gson/kotlinX.Serialization/Moshi)
  7. Creation Adapter/Layout manager every time a call happens/user search something
  8. Code format could be improved (remove useless empty lines)

Here is the code link



Solution 1:[1]

It is impossible to answer the questions in StackOverflow. But for your reference, I can provide some resources and documentation which you can follow to improve your code -

  1. MVVM in Android by G&G
  2. Modern Android App Architecture by Google
  3. Sample App with MVVM architecture
  4. How to consume API with Retrofit and GSON.

Solution 2:[2]

1- Let's make it clear for you, it's about separation of concern!
Imagine you have a project, You are working on it, and this project gets larger and larger, if you want to debug your application or maintain it later, it's very difficult. when you use an app architecture, separate each layer of your application, for example, you have a View layer that you working on your UI and no business logic of your app exist in this layer, so the code is concise and clear to read and maintain and debugging, you can write test better and some other benefits.
2- When you need a variable that you want to change later, you must use a var keyword, otherwise there is no need to declare a variable as a var.
3- comments use for clearing some codes for other developers or yourself to understand these codes better, Avoiding unusable comments in your project.
4- findViewById() method, is most costly, however if you use viewBinding android use this method behind the scene. benefit to use viewBinding is all of your views is initialized and there is no concern about NPE(Null Pointer Exception).
5- When you want to release your app for users all around the world for some language you have to find hardcoded strings and convert it to that country language, do you agree that this is a complicated procedure? :)
6- Always use Parsers or ORM in your project, because if you parse json by hand it may produce some exception in your app by using wrong json key.
7- Inflating layout in android is most costly, you must update your data and just update your adapter.
8- always be update, and improve your code. :)
read Android Developer Site it can help you, see some course in youtube and books are best friends for us, don't forget to read more books. :), happy coding.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Naimul Kabir
Solution 2 OneDev