Skip to content

Сделал ДЗ № 10 #50

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.core:core-ktx:1.16.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
implementation 'androidx.recyclerview:recyclerview:1.4.0'
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,105 @@
package otus.gpb.homework.viewandresources

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class CartActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cart)

class CartItem(
var image: Int,
var name: String,
var category: String,
var extra: String,
var price: Double = 0.0
)

fun formatPrice(price: Double): String {
return "%.2f".format(price)
}
class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val itemName: TextView = itemView.findViewById(R.id.cart_item_name)
val itemCategory: TextView = itemView.findViewById(R.id.cart_item_category)
val itemExtra: TextView = itemView.findViewById(R.id.cart_item_extra)
val itemPrice: TextView = itemView.findViewById(R.id.cart_item_price)
val itemImage: ImageView = itemView.findViewById(R.id.cart_item_image)
}

class MyAdapter(private val data: List<CartItem>) :
RecyclerView.Adapter<MyViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.cart_item, parent, false)
return MyViewHolder(view)
}

override fun getItemCount(): Int {
return data.size
}

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.itemName.width = holder.itemName.measuredWidth
holder.itemName.isSelected = true
with(data[position]) {
holder.itemName.text = name
holder.itemPrice.text = formatPrice(price)
holder.itemCategory.text = category
holder.itemExtra.text = extra

holder.itemImage.setImageResource(image)
}

}

override fun onViewAttachedToWindow(holder: MyViewHolder) {
holder.itemName.isSelected = true
}

override fun onViewDetachedFromWindow(holder: MyViewHolder) {
holder.itemName.isSelected = false
}

}



val recyclerView = findViewById<RecyclerView>(R.id.item_list)

val data: List<CartItem> = listOf(
CartItem(R.drawable.eggs, "Куриные яйца", "Продукты", "Сорт С2", 12.0),
CartItem(R.drawable.banana, "Бананы", "Продукты", "Ямайка", 2.0),
CartItem(R.drawable.salt, "Соль пищевая", "Продукты", "Без ГМО", 1.0),
CartItem(R.drawable.butter, "Сливочное масло", "Продукты", "72.5% жирности", 2.55),
CartItem(R.drawable.bread, "Хлеб ржаной", "Продукты", "Собвестнного производства", 1.99),
CartItem(R.drawable.sausage, "Сосиски молочные", "Продукты", "Без молока и мяса", 4.0)
)

recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = MyAdapter(data)

findViewById<TextView>(R.id.cart_items_count).text = resources.getQuantityString(R.plurals.cart_items_count, data.count(), data.count())

var subtotal = 0.0
data.forEach { item ->
subtotal += item.price
}
findViewById<TextView>(R.id.cart_subtotal_value).text = formatPrice(subtotal)
val shipping = 25.0
findViewById<TextView>(R.id.cart_shipping_value).text = formatPrice(shipping)
val tax = 0.2
val taxAmount = subtotal * tax
findViewById<TextView>(R.id.cart_tax_value).text = formatPrice(taxAmount)
val orderTotal = subtotal + taxAmount + shipping
findViewById<TextView>(R.id.cart_order_total_value).text = formatPrice(orderTotal)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package otus.gpb.homework.viewandresources

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.Toast

class ContactsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MainActivity : AppCompatActivity() {
}

findViewById<Button>(R.id.signin_button).setOnClickListener {
MaterialAlertDialogBuilder(this)
MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialog_Material3_Login)
.setView(R.layout.dialog_signin)
.show()
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/arrow_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="m313,520 l224,224 -57,56 -320,-320 320,-320 57,56 -224,224h487v80L313,520Z"
android:fillColor="?attr/colorOnSurface"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/attach_file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M720,630q0,104 -73,177T470,880q-104,0 -177,-73t-73,-177v-370q0,-75 52.5,-127.5T400,80q75,0 127.5,52.5T580,260v350q0,46 -32,78t-78,32q-46,0 -78,-32t-32,-78v-370h80v370q0,13 8.5,21.5T470,640q13,0 21.5,-8.5T500,610v-350q-1,-42 -29.5,-71T400,160q-42,0 -71,29t-29,71v370q-1,71 49,120.5T470,800q70,0 119,-49.5T640,630v-390h80v390Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
Binary file added app/src/main/res/drawable/banana.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/bookmark.xml
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="960"
android:name="bookmark"
android:viewportHeight="960">

<path
android:pathData="M200,840v-640q0,-33 23.5,-56.5T280,120h400q33,0 56.5,23.5T760,200v640L480,720 200,840ZM280,718 L480,632 680,718v-518L280,200v518ZM280,200h400,-400Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
Binary file added app/src/main/res/drawable/bread.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/butter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/calendar_today.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:name="calendar_today"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M360,660q-42,0 -71,-29t-29,-71q0,-42 29,-71t71,-29q42,0 71,29t29,71q0,42 -29,71t-71,29ZM200,880q-33,0 -56.5,-23.5T120,800v-560q0,-33 23.5,-56.5T200,160h40v-80h80v80h320v-80h80v80h40q33,0 56.5,23.5T840,240v560q0,33 -23.5,56.5T760,880L200,880ZM200,800h560v-400L200,400v400ZM200,320h560v-80L200,240v80ZM200,320v-80,80Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/cancel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="m336,680 l144,-144 144,144 56,-56 -144,-144 144,-144 -56,-56 -144,144 -144,-144 -56,56 144,144 -144,144 56,56ZM480,880q-83,0 -156,-31.5T197,763q-54,-54 -85.5,-127T80,480q0,-83 31.5,-156T197,197q54,-54 127,-85.5T480,80q83,0 156,31.5T763,197q54,54 85.5,127T880,480q0,83 -31.5,156T763,763q-54,54 -127,85.5T480,880ZM480,800q134,0 227,-93t93,-227q0,-134 -93,-227t-227,-93q-134,0 -227,93t-93,227q0,134 93,227t227,93ZM480,480Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
Binary file added app/src/main/res/drawable/eggs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/light_mode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M480,600q50,0 85,-35t35,-85q0,-50 -35,-85t-85,-35q-50,0 -85,35t-35,85q0,50 35,85t85,35ZM480,680q-83,0 -141.5,-58.5T280,480q0,-83 58.5,-141.5T480,280q83,0 141.5,58.5T680,480q0,83 -58.5,141.5T480,680ZM200,520L40,520v-80h160v80ZM920,520L760,520v-80h160v80ZM440,200v-160h80v160h-80ZM440,920v-160h80v160h-80ZM256,310l-101,-97 57,-59 96,100 -52,56ZM748,806 L651,705 704,650 805,747 748,806ZM650,256 L747,155 806,212 706,308 650,256ZM154,748l101,-97 55,53 -97,101 -59,-57ZM480,480Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/microphone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:name="microphone"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M480,560q-50,0 -85,-35t-35,-85v-240q0,-50 35,-85t85,-35q50,0 85,35t35,85v240q0,50 -35,85t-85,35ZM480,320ZM440,840v-123q-104,-14 -172,-93t-68,-184h80q0,83 58.5,141.5T480,640q83,0 141.5,-58.5T680,440h80q0,105 -68,184t-172,93v123h-80ZM480,480q17,0 28.5,-11.5T520,440v-240q0,-17 -11.5,-28.5T480,160q-17,0 -28.5,11.5T440,200v240q0,17 11.5,28.5T480,480Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/mood.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M620,440q25,0 42.5,-17.5T680,380q0,-25 -17.5,-42.5T620,320q-25,0 -42.5,17.5T560,380q0,25 17.5,42.5T620,440ZM340,440q25,0 42.5,-17.5T400,380q0,-25 -17.5,-42.5T340,320q-25,0 -42.5,17.5T280,380q0,25 17.5,42.5T340,440ZM480,700q68,0 123.5,-38.5T684,560L276,560q25,63 80.5,101.5T480,700ZM480,880q-83,0 -156,-31.5T197,763q-54,-54 -85.5,-127T80,480q0,-83 31.5,-156T197,197q54,-54 127,-85.5T480,80q83,0 156,31.5T763,197q54,54 85.5,127T880,480q0,83 -31.5,156T763,763q-54,54 -127,85.5T480,880ZM480,480ZM480,800q134,0 227,-93t93,-227q0,-134 -93,-227t-227,-93q-134,0 -227,93t-93,227q0,134 93,227t227,93Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/more_vert.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M480,800q-33,0 -56.5,-23.5T400,720q0,-33 23.5,-56.5T480,640q33,0 56.5,23.5T560,720q0,33 -23.5,56.5T480,800ZM480,560q-33,0 -56.5,-23.5T400,480q0,-33 23.5,-56.5T480,400q33,0 56.5,23.5T560,480q0,33 -23.5,56.5T480,560ZM480,320q-33,0 -56.5,-23.5T400,240q0,-33 23.5,-56.5T480,160q33,0 56.5,23.5T560,240q0,33 -23.5,56.5T480,320Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/person.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:name="person"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M480,480q-66,0 -113,-47t-47,-113q0,-66 47,-113t113,-47q66,0 113,47t47,113q0,66 -47,113t-113,47ZM160,800v-112q0,-34 17.5,-62.5T224,582q62,-31 126,-46.5T480,520q66,0 130,15.5T736,582q29,15 46.5,43.5T800,688v112L160,800ZM240,720h480v-32q0,-11 -5.5,-20T700,654q-54,-27 -109,-40.5T480,600q-56,0 -111,13.5T260,654q-9,5 -14.5,14t-5.5,20v32ZM480,400q33,0 56.5,-23.5T560,320q0,-33 -23.5,-56.5T480,240q-33,0 -56.5,23.5T400,320q0,33 23.5,56.5T480,400ZM480,320ZM480,720Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
Binary file added app/src/main/res/drawable/salt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/sausage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/smartphone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:name="smartphone"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M280,920q-33,0 -56.5,-23.5T200,840v-720q0,-33 23.5,-56.5T280,40h400q33,0 56.5,23.5T760,120v720q0,33 -23.5,56.5T680,920L280,920ZM280,800v40h400v-40L280,800ZM280,720h400v-480L280,240v480ZM280,160h400v-40L280,120v40ZM280,160v-40,40ZM280,800v40,-40Z"
android:fillColor="?attr/colorOnSurfaceVariant"/>
</vector>
Loading