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

Added detekt into the project #191

Merged
merged 1 commit into from
Oct 5, 2023
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 .github/workflows/app-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 11
#- name: Check Detekt
# run: chmod +x .github/scripts/gradlew_recursive.sh ; .github/scripts/gradlew_recursive.sh detekt
- name: Build project
run: chmod +x .github/scripts/gradlew_recursive.sh ; .github/scripts/gradlew_recursive.sh assembleDebug
- name: Zip artifacts
Expand Down
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ plugins {
alias libs.plugins.spotless
alias libs.plugins.navigation.safeargs
id "org.jetbrains.kotlin.plugin.serialization" version "1.7.0"

id "io.gitlab.arturbosch.detekt" version "1.22.0"
}
apply plugin: 'kotlin-android-extensions'

android {
compileSdk 34
Expand Down Expand Up @@ -136,6 +135,11 @@ task wrapper(type: Wrapper) {
gradleVersion = '7.2'
}

detekt {
config = files("${project.rootDir.absolutePath}/config/detekt/detekt.yml")
buildUponDefaultConfig = true
}

ktlint {
// android.set(true)
// reporters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.hieuwu.groceriesstore.presentation.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.hieuwu.groceriesstore.R
import com.hieuwu.groceriesstore.databinding.LayoutGridListItemBinding
import com.hieuwu.groceriesstore.domain.models.ProductModel
import kotlinx.android.synthetic.main.layout_grid_list_item.view.*

class GridListItemAdapter(val onClickListener: OnClickListener) :
class GridListItemAdapter(private val onClickListener: OnClickListener) :
ListAdapter<ProductModel, GridListItemAdapter.ProductGridViewHolder>(DiffCallback) {

class ProductGridViewHolder(private var binding: LayoutGridListItemBinding) :
class ProductGridViewHolder(private val binding: LayoutGridListItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(productModel: ProductModel) {
binding.product = productModel
Expand All @@ -26,15 +27,16 @@ class GridListItemAdapter(val onClickListener: OnClickListener) :
onClickListener.onClick(product)
}

holder.itemView.product_add_button.setOnClickListener {
holder.itemView.findViewById<View>(R.id.product_add_button).setOnClickListener {
onClickListener.addToCartListener(product)
}

holder.bind(product)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductGridViewHolder {
return ProductGridViewHolder(LayoutGridListItemBinding.inflate(LayoutInflater.from(parent.context)))
val binding = LayoutGridListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ProductGridViewHolder(binding)
}

companion object DiffCallback : DiffUtil.ItemCallback<ProductModel>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.hieuwu.groceriesstore.databinding.LayoutLineListItemBinding
import com.hieuwu.groceriesstore.domain.models.LineItemModel
import kotlinx.android.synthetic.main.layout_line_list_item.view.*

class LineListItemAdapter(val onClickListener: OnClickListener, val context: Context) :
ListAdapter<LineItemModel, LineListItemAdapter.LineItemViewHolder>(DiffCallback) {

class LineItemViewHolder(private var binding: LayoutLineListItemBinding) :
class LineItemViewHolder(val binding: LayoutLineListItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(lineItemModel: LineItemModel) {
binding.lineItem = lineItemModel
Expand All @@ -28,23 +27,24 @@ class LineListItemAdapter(val onClickListener: OnClickListener, val context: Con

override fun onBindViewHolder(holder: LineItemViewHolder, position: Int) {
val lineItem = getItem(position)
holder.itemView.plus_btn.setOnClickListener {
holder.binding.plusBtn.setOnClickListener {
onClickListener.onPlusClick(lineItem)
}

holder.itemView.minus_btn.setOnClickListener {
holder.binding.minusBtn.setOnClickListener {
onClickListener.onMinusClick(lineItem)
}

holder.itemView.delete_btn.setOnClickListener {
holder.binding.deleteBtn.setOnClickListener {
onClickListener.onRemoveItem(lineItem)
}

holder.bind(lineItem)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LineItemViewHolder {
return LineItemViewHolder(LayoutLineListItemBinding.inflate(LayoutInflater.from(parent.context)))
val binding = LayoutLineListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return LineItemViewHolder(binding)
}

companion object DiffCallback : DiffUtil.ItemCallback<LineItemModel>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.View.*
import android.view.ViewGroup
import android.widget.EditText
import androidx.appcompat.widget.AppCompatImageView
Expand All @@ -20,7 +21,6 @@ import com.hieuwu.groceriesstore.databinding.FragmentExploreBinding
import com.hieuwu.groceriesstore.presentation.adapters.CategoryItemAdapter
import com.hieuwu.groceriesstore.presentation.adapters.GridListItemAdapter
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.android.synthetic.main.fragment_main.*
import kotlinx.coroutines.launch
import timber.log.Timber

Expand All @@ -36,7 +36,7 @@ class ExploreFragment : Fragment() {
savedInstanceState: Bundle?
): View? {

binding = DataBindingUtil.inflate<FragmentExploreBinding>(
binding = DataBindingUtil.inflate(
inflater, R.layout.fragment_explore, container, false
)
binding.viewModel = viewModel
Expand Down Expand Up @@ -93,8 +93,8 @@ class ExploreFragment : Fragment() {
if (it.isEmpty()) {
Timber.d("Empty")
} else {
binding.productRecyclerview.visibility = View.VISIBLE
binding.animationLayout.visibility = View.GONE
binding.productRecyclerview.visibility = VISIBLE
binding.animationLayout.visibility = GONE
Timber.d("Has item")
}
}
Expand Down Expand Up @@ -130,14 +130,14 @@ class ExploreFragment : Fragment() {
Timber.d("Search focused")
// Hide category list
// Show search result list with empty list product
binding.categoryRecyclerview.visibility = View.GONE
binding.categoryRecyclerview.visibility = GONE
}

binding.searchView.setOnQueryTextFocusChangeListener { _, _ ->
Timber.d("Search focused")
// Hide category list
// Show search result list with empty list product
binding.categoryRecyclerview.visibility = View.GONE
binding.categoryRecyclerview.visibility = GONE
}

val closeSearchButton =
Expand All @@ -149,9 +149,9 @@ class ExploreFragment : Fragment() {
// Show category list
// Clear search result
// Hide search result
binding.productRecyclerview.visibility = View.GONE
binding.categoryRecyclerview.visibility = View.VISIBLE
binding.animationLayout.visibility = View.GONE
binding.productRecyclerview.visibility = GONE
binding.categoryRecyclerview.visibility = VISIBLE
binding.animationLayout.visibility = GONE
}
}
}
Loading
Loading