-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feature/impl db #105
base: develop
Are you sure you want to change the base?
Feature/impl db #105
Conversation
@@ -22,55 +24,55 @@ class AboutActivity : AppCompatActivity() { | |||
override fun onCreate(savedInstanceState: Bundle?) { | |||
super.onCreate(savedInstanceState) | |||
setContentView(R.layout.activity_about) | |||
val toolbar = findViewById(R.id.toolbar) as Toolbar | |||
val toolbar = findViewById<Toolbar>(R.id.toolbar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally a lot cleaner to use generic inference rather than explicitly defining the generic and relying on type inference such as
val toolbar: Toolbar = findViewById(R.id.toolbar)
In at least one use case you ended up specifying it both ways.
@@ -22,55 +24,55 @@ class AboutActivity : AppCompatActivity() { | |||
override fun onCreate(savedInstanceState: Bundle?) { | |||
super.onCreate(savedInstanceState) | |||
setContentView(R.layout.activity_about) | |||
val toolbar = findViewById(R.id.toolbar) as Toolbar | |||
val toolbar = findViewById<Toolbar>(R.id.toolbar) | |||
setSupportActionBar(toolbar) | |||
supportActionBar?.setDisplayHomeAsUpEnabled(true) | |||
bind() | |||
} | |||
|
|||
fun bind() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using getters instead of a large bind method.
private val logo: ImageView
get() = findViewById(R.id.cfo_logo)
.autoConnect() | ||
} | ||
|
||
private fun toAnimalList(response: PetfinderPetRecordResponse): List<Animal> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more functional approach would be this.
private fun toAnimalList(response: PetfinderPetRecordResponse): List<Animal>
= response.petfinder
.pets
.petList
.map { animal ->
Animal.AnimalBuilder()
...
.createAnimal()
}
return outputAnimals | ||
} | ||
|
||
private fun photosToStringUrls(photos: PetfinderAnimal.Media.Photos?): List<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the previously mentioned functional approach
return urlList | ||
} | ||
|
||
private fun getBreed(breed: PetfinderAnimal.Breeds.Breed?): String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be consolidated to a single line
return bread?.let{ breed.content } ?: ""
This is the logical equivalent of
if (breed != null) {
return breed.content;
}
return "";
|
||
class AnimalMapper @Inject constructor(){ | ||
|
||
fun map(from: Animal): AnimalEntity { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly suggest avoiding the function name of map in kotlin as it will be confusing to a reader. A more specific name would remove any confusion. mapToAnimalEntity
import javax.inject.Inject | ||
|
||
|
||
class AnimalMapper @Inject constructor(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a utility class which means it should not be a class in kotlin. Instead of placeholder classes purely to provide extension functionality just write extension functions and get rid of the container class.
fun Animal.mapToAnimalEntity(): AnimalEntity
...
Room Database implemented. We are using two tables, Animals and Images. Through the
AnimalAndImageDao
, you have all the properties to map it toAnimal
.Changes:
Converted PetfinderProvider to Kotlin
Updated support library to 27.1
Updated SDK to 26 while making roomdb compatible with project.