Skip to content
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
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ plugins {
}

android {
compileSdk 35
compileSdk 36
namespace = "otus.gpb.homework.viewandresources"
defaultConfig {
applicationId "otus.gpb.homework.viewandresources"
minSdk 23
targetSdk 35
targetSdk 36
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding = true
}

buildTypes {
release {
minifyEnabled false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,43 @@ package otus.gpb.homework.viewandresources

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class CartActivity : AppCompatActivity() {

private val cartItems = mutableListOf<CartItem>()

private val cartAdapter by lazy { CartAdapter() }

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

// Генерируем тестовые данные
generateTestData()

val rv = findViewById<RecyclerView>(R.id.recyclerView)
rv.adapter = cartAdapter

cartAdapter.setList(cartItems)
}

private fun generateTestData() {
cartItems.clear()
for (i in 1..100) {
cartItems.add(
CartItem(
image = R.drawable.cart_item,
title = getString(R.string.cart_item_headline, i),
category = getString(R.string.cart_item_category),
description = getString(R.string.cart_item_description),
price = i * 10
)
)
}

val cartCounter = findViewById<TextView>(R.id.cartCounter)
cartCounter.text = getString(R.string.cart_items, 100)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package otus.gpb.homework.viewandresources

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

class CartAdapter() : RecyclerView.Adapter<CartViewHolder>() {

private var list = emptyList<CartItem>()

fun setList(list: List<CartItem>) {
this.list = list.toList()
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.cart_item, parent, false)

return CartViewHolder(view)
}

override fun getItemCount() = list.size

override fun onBindViewHolder(viewHolder: CartViewHolder, position: Int) {
val item = list[position]
viewHolder.bind(item)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package otus.gpb.homework.viewandresources

data class CartItem(
val image: Int,
val title: String,
val category: String,
val description: String,
val price: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package otus.gpb.homework.viewandresources

import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
class CartViewHolder(view: View) : RecyclerView.ViewHolder(view) {

private val title: TextView by lazy { view.findViewById(R.id.name) }

Choose a reason for hiding this comment

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

В ViewHolder это неэффективно, так как findViewById вызывается при каждом создании холдера. Лучше инициализировать напрямую в конструкторе без lazy

private val category: TextView by lazy { view.findViewById(R.id.category) }
private val description: TextView by lazy { view.findViewById(R.id.description) }
private val price: TextView by lazy { view.findViewById(R.id.price) }
private val photo: ImageView by lazy { view.findViewById(R.id.image) }
fun bind(item: CartItem) {
title.text = item.title
price.text = buildString {
append("$")
append(item.price.toString())
}
category.text = item.category
description.text = item.description
photo.setImageResource(item.image)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ package otus.gpb.homework.viewandresources

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.appcompat.app.AlertDialog
import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText

class MainActivity : AppCompatActivity() {

private val login_Dialog by lazy { createMaterialDialog() }

Choose a reason for hiding this comment

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

Принято использовать camelCase для имен переменных. Давайте использовать loginDialog для соответствия конвенциям языка


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -19,9 +27,28 @@ class MainActivity : AppCompatActivity() {
}

findViewById<Button>(R.id.signin_button).setOnClickListener {
MaterialAlertDialogBuilder(this)
.setView(R.layout.dialog_signin)
.show()
login_Dialog.show()
}
}

private fun createMaterialDialog(): AlertDialog {
val builder = MaterialAlertDialogBuilder(this)
val view = layoutInflater.inflate(R.layout.dialog_signin, null)
builder.setView(view)
val dialog = builder.create()

view.findViewById<Button>(R.id.button_reset).setOnClickListener {
view.findViewById<TextInputEditText>(R.id.password_field).setText("")
}
view.findViewById<MaterialButton>(R.id.button_login).setOnClickListener{
Toast.makeText(this, "Login!!!", Toast.LENGTH_SHORT).show()
login_Dialog.dismiss()
}
view.findViewById<MaterialButton>(R.id.button_cancel).setOnClickListener{
Toast.makeText(this, "Cancel!!!", Toast.LENGTH_SHORT).show()
login_Dialog.dismiss()
}

return dialog
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/account_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/account_circle.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/account_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/account_outline.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24" >
<path
android:fillColor="?attr/icons_color"
android:pathData="M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,6A2,2 0 0,0 10,8A2,2 0 0,0 12,10A2,2 0 0,0 14,8A2,2 0 0,0 12,6M12,13C14.67,13 20,14.33 20,17V20H4V17C4,14.33 9.33,13 12,13M12,14.9C9.03,14.9 5.9,16.36 5.9,17V18.1H18.1V17C18.1,16.36 14.97,14.9 12,14.9Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/arrow_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/arrow_left.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/bookmark_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/bookmark_outline.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M17,18L12,15.82L7,18V5H17M17,3H7A2,2 0 0,0 5,5V21L12,18L19,21V5C19,3.89 18.1,3 17,3Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/calendar_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/calendar_outline.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M12 12H17V17H12V12M19 3H18V1H16V3H8V1H6V3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3M19 5V7H5V5H19M5 19V9H19V19H5Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/cart_arrow_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/cart_arrow_right.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M9,20A2,2 0 0,1 7,22A2,2 0 0,1 5,20A2,2 0 0,1 7,18A2,2 0 0,1 9,20M17,18A2,2 0 0,0 15,20A2,2 0 0,0 17,22A2,2 0 0,0 19,20A2,2 0 0,0 17,18M7.2,14.63C7.19,14.67 7.19,14.71 7.2,14.75A0.25,0.25 0 0,0 7.45,15H19V17H7A2,2 0 0,1 5,15C5,14.65 5.07,14.31 5.24,14L6.6,11.59L3,4H1V2H4.27L5.21,4H20A1,1 0 0,1 21,5C21,5.17 20.95,5.34 20.88,5.5L17.3,12C16.94,12.62 16.27,13 15.55,13H8.1L7.2,14.63M9,9.5H13V11.5L16,8.5L13,5.5V7.5H9V9.5Z" />
</vector>
29 changes: 29 additions & 0 deletions app/src/main/res/drawable/cart_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp"
android:height="80dp"
android:viewportWidth="24"
android:viewportHeight="24">

<!-- Фон: скруглённый квадрат -->
<path
android:fillColor="#D7D9DC"
android:pathData="M4,2h16a2,2 0 0 1 2,2v16a2,2 0 0 1 -2,2H4a2,2 0 0 1 -2,-2V4a2,2 0 0 1 2,-2z" />

<!-- Равносторонний треугольник (центрирован, чуть выше центра) -->
<path
android:fillColor="#6E7175"
android:pathData="M12,3.5 L8.5,10 L15.5,10 Z" />

<!-- Квадрат (слева, немного ниже центра) -->
<path
android:fillColor="#6E7175"
android:pathData="M4.5,13 H10.5 V19 H4.5 Z" />

<!-- Круг (справа, на той же высоте что и квадрат) -->
<path
android:fillColor="#6E7175"
android:pathData="M13.5,16
a3,3 0 1 0 6,0
a3,3 0 1 0 -6,0" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/cellphone_check.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/cellphone_check.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M14.54 23H7C5.9 23 5 22.11 5 21V3C5 1.89 5.89 1 7 1H17C18.1 1 19 1.89 19 3V13C18.3 13 17.63 13.13 17 13.35V5H7V19H13C13 20.54 13.58 21.94 14.54 23M17.75 22.16L15 19.16L16.16 18L17.75 19.59L21.34 16L22.5 17.41L17.75 22.16" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/close_circle_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/close_circle_outline.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22C17.53,22 22,17.53 22,12C22,6.47 17.53,2 12,2M14.59,8L12,10.59L9.41,8L8,9.41L10.59,12L8,14.59L9.41,16L12,13.41L14.59,16L16,14.59L13.41,12L16,9.41L14.59,8Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/dots_vertical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/dots_vertical.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/microphone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/microphone.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M12,2A3,3 0 0,1 15,5V11A3,3 0 0,1 12,14A3,3 0 0,1 9,11V5A3,3 0 0,1 12,2M19,11C19,14.53 16.39,17.44 13,17.93V21H11V17.93C7.61,17.44 5,14.53 5,11H7A5,5 0 0,0 12,16A5,5 0 0,0 17,11H19Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/paperclip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/paperclip.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M16.5,6V17.5A4,4 0 0,1 12.5,21.5A4,4 0 0,1 8.5,17.5V5A2.5,2.5 0 0,1 11,2.5A2.5,2.5 0 0,1 13.5,5V15.5A1,1 0 0,1 12.5,16.5A1,1 0 0,1 11.5,15.5V6H10V15.5A2.5,2.5 0 0,0 12.5,18A2.5,2.5 0 0,0 15,15.5V5A4,4 0 0,0 11,1A4,4 0 0,0 7,5V17.5A5.5,5.5 0 0,0 12.5,23A5.5,5.5 0 0,0 18,17.5V6H16.5Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/sunny.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/sunny.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/icons_color"
android:pathData="M11,4V2c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v2c0,0.55 -0.45,1 -1,1S11,4.55 11,4zM18.36,7.05l1.41,-1.42c0.39,-0.39 0.39,-1.02 0,-1.41c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.41,1.42c-0.39,0.39 -0.39,1.02 0,1.41C17.34,7.44 17.97,7.44 18.36,7.05zM22,11h-2c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h2c0.55,0 1,-0.45 1,-1S22.55,11 22,11zM12,19c-0.55,0 -1,0.45 -1,1v2c0,0.55 0.45,1 1,1s1,-0.45 1,-1v-2C13,19.45 12.55,19 12,19zM5.64,7.05L4.22,5.64c-0.39,-0.39 -0.39,-1.03 0,-1.41s1.03,-0.39 1.41,0l1.41,1.41c0.39,0.39 0.39,1.03 0,1.41S6.02,7.44 5.64,7.05zM16.95,16.95c-0.39,0.39 -0.39,1.03 0,1.41l1.41,1.41c0.39,0.39 1.03,0.39 1.41,0c0.39,-0.39 0.39,-1.03 0,-1.41l-1.41,-1.41C17.98,16.56 17.34,16.56 16.95,16.95zM2,13h2c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1H2c-0.55,0 -1,0.45 -1,1S1.45,13 2,13zM5.64,19.78l1.41,-1.41c0.39,-0.39 0.39,-1.03 0,-1.41s-1.03,-0.39 -1.41,0l-1.41,1.41c-0.39,0.39 -0.39,1.03 0,1.41C4.61,20.17 5.25,20.17 5.64,19.78zM12,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6s6,-2.69 6,-6S15.31,6 12,6z" />
</vector>

Loading