-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/beyzaakkuzu/shoppinglist/Adapter/ShoppingItemAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.beyzaakkuzu.shoppinglist.Adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.beyzaakkuzu.shoppinglist.R | ||
import com.beyzaakkuzu.shoppinglist.data.db.entities.Shopping | ||
import com.beyzaakkuzu.shoppinglist.ui.shoppinglist.ShoppingViewModel | ||
import kotlinx.android.synthetic.main.shopping_item.view.* | ||
|
||
class ShoppingItemAdapter( | ||
var items: List<Shopping>, | ||
private val viewModel: ShoppingViewModel | ||
) : RecyclerView.Adapter<ShoppingItemAdapter.ShoppingViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShoppingViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.shopping_item, parent, false) | ||
return ShoppingViewHolder(view) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return items.size | ||
} | ||
|
||
override fun onBindViewHolder(holder: ShoppingViewHolder, position: Int) { | ||
val curShoppingItem= items[position] | ||
holder.itemView.nameTextView.text = curShoppingItem.name | ||
holder.itemView.amountTextView.text = "${curShoppingItem.amount}" | ||
|
||
holder.itemView.plus.setOnClickListener { | ||
curShoppingItem.amount++ | ||
viewModel.upsert(curShoppingItem) | ||
} | ||
holder.itemView.delete.setOnClickListener { | ||
viewModel.delete(curShoppingItem) | ||
} | ||
holder.itemView.minus.setOnClickListener { | ||
if(curShoppingItem.amount>0){ | ||
curShoppingItem.amount-- | ||
viewModel.upsert(curShoppingItem) | ||
} | ||
} | ||
|
||
} | ||
|
||
inner class ShoppingViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="#333333" | ||
android:alpha="0.6"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="#333333" | ||
android:alpha="0.6"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13L7,13v-2h10v2z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24" | ||
android:tint="#333333" | ||
android:alpha="0.6"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13h-4v4h-2v-4L7,13v-2h4L11,7h2v4h4v2z"/> | ||
</vector> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="16dp"> | ||
|
||
<TextView | ||
android:id="@+id/nameTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="TextView" | ||
android:textSize="20sp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/amountTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="TextView" | ||
android:textSize="20sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<ImageView | ||
android:id="@+id/delete" | ||
android:layout_width="35dp" | ||
android:layout_height="35dp" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
android:src="@drawable/ic_delete" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/nameTextView" /> | ||
|
||
<ImageView | ||
android:id="@+id/minus" | ||
android:layout_width="35dp" | ||
android:layout_height="35dp" | ||
android:layout_marginTop="16dp" | ||
android:src="@drawable/ic_minus" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/amountTextView" /> | ||
|
||
<ImageView | ||
android:id="@+id/plus" | ||
android:layout_width="35dp" | ||
android:layout_height="35dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginBottom="16dp" | ||
android:src="@drawable/ic_plus" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toStartOf="@+id/minus" | ||
app:layout_constraintTop_toBottomOf="@+id/amountTextView" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |