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

Integrate ktlint and fix codestyle violations #115

Merged
merged 9 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
.cxx
*.xcuserstate
*.xcbkptlist
!/.idea/codeStyles/*
!/.idea/inspectionProfiles/*
138 changes: 138 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
exclude("META-INF/*.kotlin_module")
}
buildTypes {
getByName("release") {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
Expand All @@ -30,6 +30,11 @@ android {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

lintOptions {
isWarningsAsErrors = true
isAbortOnError = true
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package co.touchlab.kampkit.android

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.touchlab.kampkit.db.Breed
import co.touchlab.kampkit.models.BreedModel
import androidx.lifecycle.viewModelScope
import co.touchlab.kampkit.models.ItemDataSummary
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
Expand All @@ -19,7 +19,6 @@ class BreedViewModel : ViewModel() {
observeBreeds()
}


private fun observeBreeds() {
viewModelScope.launch {
breedModel.selectAllBreeds().collect {
Expand All @@ -35,9 +34,9 @@ class BreedViewModel : ViewModel() {
}
}
}
fun updateBreedFavorite(breed: Breed){
fun updateBreedFavorite(breed: Breed) {
viewModelScope.launch {
breedModel.updateBreedFavorite(breed)
}
}
}
}
28 changes: 16 additions & 12 deletions app/src/main/java/co/touchlab/kampkit/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import co.touchlab.kampkit.android.adapter.MainAdapter
import co.touchlab.kampkit.android.R
import co.touchlab.kermit.Kermit
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_main.*
Expand All @@ -19,25 +18,30 @@ class MainActivity : AppCompatActivity(), KoinComponent {
val TAG = MainActivity::class.java.simpleName
}
private lateinit var adapter: MainAdapter
private val log:Kermit by inject { parametersOf("MainActivity") }
private val log: Kermit by inject { parametersOf("MainActivity") }

private lateinit var viewModel: BreedViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)


viewModel = ViewModelProviders.of(this).get(BreedViewModel::class.java)

viewModel.breedLiveData.observe(this, Observer { itemData ->
log.v { "List submitted to adapter" }
adapter.submitList(itemData.allItems)
})
viewModel.errorLiveData.observe(this, Observer { errorMessage ->
log.e { "Error displayed: $errorMessage" }
Snackbar.make(breed_list, errorMessage, Snackbar.LENGTH_SHORT).show()
})
viewModel.breedLiveData.observe(
this,
Observer { itemData ->
log.v { "List submitted to adapter" }
adapter.submitList(itemData.allItems)
}
)
viewModel.errorLiveData.observe(
this,
Observer { errorMessage ->
log.e { "Error displayed: $errorMessage" }
Snackbar.make(breed_list, errorMessage, Snackbar.LENGTH_SHORT).show()
}
)
adapter = MainAdapter {
viewModel.updateBreedFavorite(it)
}
Expand All @@ -47,4 +51,4 @@ class MainActivity : AppCompatActivity(), KoinComponent {

viewModel.getBreedsFromNetwork()
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/co/touchlab/kampkit/android/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class MainApp : Application() {
modules(module { single<Context> { this@MainApp } })
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class MainAdapter(private val breedClickListener: (Breed) -> Unit) :
private val breedCallback = object : DiffUtil.ItemCallback<Breed>() {
override fun areContentsTheSame(oldItem: Breed, newItem: Breed): Boolean =
(oldItem.id == newItem.id) &&
(oldItem.favorite == newItem.favorite)
(oldItem.favorite == newItem.favorite)

override fun areItemsTheSame(oldItem: Breed, newItem: Breed): Boolean =
oldItem.id == newItem.id
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class MainViewHolder(itemView: View, breedClickListener: (Int) -> Unit) : Recycl
favoriteButton.setBackgroundResource(R.drawable.ic_favorite_24px)
}
}
}
}
17 changes: 8 additions & 9 deletions app/src/main/res/layout/item_breed.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="wrap_content">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/aboutTextBody"
android:layout_width="match_parent"
Expand All @@ -15,22 +15,21 @@
android:layout_width="wrap_content"
android:layout_height="32dp"
android:gravity="center_vertical"
android:text="@string/breed"
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI a nice way to keep lint happy without needing to make this a string resource is to use tools:text. This will show it in the layout preview only. The other advantage of that is we won't accidentally leave bad initial text in-place if something fails to initialize in code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about this, but idk if in the case of failing to initialize blank is better than a default like this. I could see either way

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. Not a huge deal since it's just sample code anyway. Don't need to dig to hard on Android best-practices when most people's focus will be on KMP and iOS.

android:textSize="22sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="TEST!23"
/>
app:layout_constraintTop_toTopOf="parent" />

<ImageButton
style="@style/Widget.AppCompat.Button.Borderless"
android:id="@+id/favorite_button"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/set_breed_as_a_favorite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">KaMP Kit</string>
<string name="set_breed_as_a_favorite">Set breed as a favorite</string>
<string name="breed">Breed</string>
</resources>
17 changes: 0 additions & 17 deletions app/src/test/java/com/touchlab/myapplication/ExampleUnitTest.kt

This file was deleted.

Loading