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
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

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

Expand All @@ -29,10 +29,13 @@ android {
kotlinOptions {
jvmTarget = '17'
}
viewBinding {
enabled = true
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,57 @@ package otus.gpb.homework.viewandresources

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView

class CartActivity : AppCompatActivity()/*, CartItemListener*/ {
private lateinit var textCartItemCount :TextView
private lateinit var textCartOrderTotalAmount :TextView
private lateinit var textCartSubtotalAmount :TextView
private lateinit var textCartShippingAmount :TextView
private lateinit var textCartTaxAmount :TextView
private lateinit var textCartOrderTotal :TextView
private lateinit var textCartSubtotal :TextView
private lateinit var textCartShipping :TextView
private lateinit var textCartTax :TextView

private lateinit var cartItemInc: View
private lateinit var textCartName :TextView


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

textCartOrderTotal = findViewById<TextView>(R.id.textCartOrderTotal)
textCartSubtotal = findViewById<TextView>(R.id.textCartSubtotal)
textCartShipping = findViewById<TextView>(R.id.textCartShipping)
textCartTax = findViewById<TextView>(R.id.textCartTax)
textCartItemCount = findViewById<TextView>(R.id.textCartItemCount)
textCartOrderTotalAmount = findViewById<TextView>(R.id.textCartOrderTotalAmount)

Choose a reason for hiding this comment

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

Переменные инициализируются, но значения устанавливаются напрямую в XML или через строковые ресурс, а не через эти переменные. Это лишний код, который усложняет понимание

textCartSubtotalAmount = findViewById<TextView>(R.id.textCartSubtotalAmount)
textCartShippingAmount = findViewById<TextView>(R.id.textCartShippingAmount)
textCartTaxAmount = findViewById<TextView>(R.id.textCartTaxAmount)

cartItemInc = findViewById<View>(R.id.сart_item_inc_1)

Choose a reason for hiding this comment

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

Один и тот же код повторяется 4 раза для установки текста элементов корзины. Это нарушает принцип DRY. Вынесите это в цикл или функцию, чтобы код был более читаемым

textCartName = cartItemInc.findViewById<TextView>(R.id.cart_item_caption)
textCartName.text = getString(R.string.cart_item_name_1)

cartItemInc = findViewById<View>(R.id.сart_item_inc_2)
textCartName = cartItemInc.findViewById<TextView>(R.id.cart_item_caption)
textCartName.text = getString(R.string.cart_item_name_2)

cartItemInc = findViewById<View>(R.id.сart_item_inc_3)
textCartName = cartItemInc.findViewById<TextView>(R.id.cart_item_caption)
textCartName.text = getString(R.string.cart_item_name_3)

cartItemInc = findViewById<View>(R.id.сart_item_inc_4)
textCartName = cartItemInc.findViewById<TextView>(R.id.cart_item_caption)
textCartName.text = getString(R.string.cart_item_name_4)

textCartOrderTotal.text = getString(R.string.order_total)
textCartSubtotal.text = getString(R.string.subtotal)
textCartShipping.text = getString(R.string.shipping)
textCartTax.text = getString(R.string.tax)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package otus.gpb.homework.viewandresources.components

import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.withStyledAttributes
import otus.gpb.homework.viewandresources.R
import otus.gpb.homework.viewandresources.databinding.CompoundViewContactsBinding


class CompoundViewContacts @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStileAttr: Int = 0
) : ConstraintLayout(context, attrs, defStileAttr) {

private val binding: CompoundViewContactsBinding

init {
binding = CompoundViewContactsBinding.inflate(LayoutInflater.from(context), this)
initCustomAttibutes(attrs, defStileAttr)
}

private fun initCustomAttibutes(attrs: AttributeSet?, defStyleAttr: Int) = with(binding) {
context.withStyledAttributes(attrs, R.styleable.CompoundViewContacts, defStyleAttr, 0) {
title.text = getString(R.styleable.CompoundViewContacts_contacts_title)
title.setTextColor(getColor(R.styleable.CompoundViewContacts_contacts_titleColor, 0))
text.text = getString(R.styleable.CompoundViewContacts_contacts_text)
text.setTextColor(getColor(R.styleable.CompoundViewContacts_contacts_textColor, 0))
binding.icon.setImageDrawable(getDrawable(R.styleable.CompoundViewContacts_contacts_icon))
binding.icon.setImageTintList(
ColorStateList.valueOf(
getColor(R.styleable.CompoundViewContacts_contacts_iconColor, 0)))
binding.divider.dividerColor = (getColor(R.styleable.CompoundViewContacts_contacts_dividerColor, 0))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

findViewById<Button>(R.id.contacts_button).setOnClickListener {
startActivity(Intent(this, ContactsActivity::class.java))
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_address.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="14dp"
android:height="18dp"
android:viewportWidth="14"
android:viewportHeight="18">
<path
android:pathData="M0,18V2C0,1.45 0.196,0.979 0.587,0.587C0.979,0.196 1.45,0 2,0H12C12.55,0 13.021,0.196 13.413,0.587C13.804,0.979 14,1.45 14,2V18L7,15L0,18ZM2,14.95L7,12.8L12,14.95V2H2V14.95Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_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="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M3.825,9L9.425,14.6L8,16L0,8L8,0L9.425,1.4L3.825,7H16V9H3.825Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_attach.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="11dp"
android:height="20dp"
android:viewportWidth="11"
android:viewportHeight="20">
<path
android:pathData="M5.5,20C3.967,20 2.667,19.467 1.6,18.4C0.533,17.333 0,16.033 0,14.5V4C0,2.9 0.392,1.958 1.175,1.175C1.958,0.392 2.9,0 4,0C5.1,0 6.042,0.392 6.825,1.175C7.608,1.958 8,2.9 8,4V13.5C8,14.2 7.758,14.792 7.275,15.275C6.792,15.758 6.2,16 5.5,16C4.8,16 4.208,15.758 3.725,15.275C3.242,14.792 3,14.2 3,13.5V4H4.5V13.5C4.5,13.783 4.596,14.021 4.787,14.212C4.979,14.404 5.217,14.5 5.5,14.5C5.783,14.5 6.021,14.404 6.213,14.212C6.404,14.021 6.5,13.783 6.5,13.5V4C6.5,3.3 6.258,2.708 5.775,2.225C5.292,1.742 4.7,1.5 4,1.5C3.3,1.5 2.708,1.742 2.225,2.225C1.742,2.708 1.5,3.3 1.5,4V14.5C1.5,15.6 1.892,16.542 2.675,17.325C3.458,18.108 4.4,18.5 5.5,18.5C6.6,18.5 7.542,18.108 8.325,17.325C9.108,16.542 9.5,15.6 9.5,14.5V4H11V14.5C11,16.033 10.467,17.333 9.4,18.4C8.333,19.467 7.033,20 5.5,20Z"
android:fillColor="@color/on_surface_variant"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_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="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M6.4,15L10,11.4L13.6,15L15,13.6L11.4,10L15,6.4L13.6,5L10,8.6L6.4,5L5,6.4L8.6,10L5,13.6L6.4,15ZM10,20C8.617,20 7.317,19.737 6.1,19.212C4.883,18.688 3.825,17.975 2.925,17.075C2.025,16.175 1.313,15.117 0.788,13.9C0.262,12.683 0,11.383 0,10C0,8.617 0.262,7.317 0.788,6.1C1.313,4.883 2.025,3.825 2.925,2.925C3.825,2.025 4.883,1.313 6.1,0.788C7.317,0.262 8.617,0 10,0C11.383,0 12.683,0.262 13.9,0.788C15.117,1.313 16.175,2.025 17.075,2.925C17.975,3.825 18.688,4.883 19.212,6.1C19.737,7.317 20,8.617 20,10C20,11.383 19.737,12.683 19.212,13.9C18.688,15.117 17.975,16.175 17.075,17.075C16.175,17.975 15.117,18.688 13.9,19.212C12.683,19.737 11.383,20 10,20ZM10,18C12.233,18 14.125,17.225 15.675,15.675C17.225,14.125 18,12.233 18,10C18,7.767 17.225,5.875 15.675,4.325C14.125,2.775 12.233,2 10,2C7.767,2 5.875,2.775 4.325,4.325C2.775,5.875 2,7.767 2,10C2,12.233 2.775,14.125 4.325,15.675C5.875,17.225 7.767,18 10,18Z"
android:fillColor="@color/on_surface_variant"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_date.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="18dp"
android:height="20dp"
android:viewportWidth="18"
android:viewportHeight="20">
<path
android:pathData="M6,14.5C5.3,14.5 4.708,14.258 4.225,13.775C3.742,13.292 3.5,12.7 3.5,12C3.5,11.3 3.742,10.708 4.225,10.225C4.708,9.742 5.3,9.5 6,9.5C6.7,9.5 7.292,9.742 7.775,10.225C8.258,10.708 8.5,11.3 8.5,12C8.5,12.7 8.258,13.292 7.775,13.775C7.292,14.258 6.7,14.5 6,14.5ZM2,20C1.45,20 0.979,19.804 0.587,19.413C0.196,19.021 0,18.55 0,18V4C0,3.45 0.196,2.979 0.587,2.588C0.979,2.196 1.45,2 2,2H3V0H5V2H13V0H15V2H16C16.55,2 17.021,2.196 17.413,2.588C17.804,2.979 18,3.45 18,4V18C18,18.55 17.804,19.021 17.413,19.413C17.021,19.804 16.55,20 16,20H2ZM2,18H16V8H2V18Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_login.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="22dp"
android:height="22dp"
android:viewportWidth="22"
android:viewportHeight="22">
<path
android:pathData="M11,14C11.833,14 12.542,13.708 13.125,13.125C13.708,12.542 14,11.833 14,11C14,10.167 13.708,9.458 13.125,8.875C12.542,8.292 11.833,8 11,8C10.167,8 9.458,8.292 8.875,8.875C8.292,9.458 8,10.167 8,11C8,11.833 8.292,12.542 8.875,13.125C9.458,13.708 10.167,14 11,14ZM11,16C9.617,16 8.438,15.512 7.463,14.538C6.488,13.563 6,12.383 6,11C6,9.617 6.488,8.438 7.463,7.463C8.438,6.488 9.617,6 11,6C12.383,6 13.563,6.488 14.538,7.463C15.512,8.438 16,9.617 16,11C16,12.383 15.512,13.563 14.538,14.538C13.563,15.512 12.383,16 11,16ZM4,12H0V10H4V12ZM22,12H18V10H22V12ZM10,4V0H12V4H10ZM10,22V18H12V22H10ZM5.4,6.75L2.875,4.325L4.3,2.85L6.7,5.35L5.4,6.75ZM17.7,19.15L15.275,16.625L16.6,15.25L19.125,17.675L17.7,19.15ZM15.25,5.4L17.675,2.875L19.15,4.3L16.65,6.7L15.25,5.4ZM2.85,17.7L5.375,15.275L6.75,16.6L4.325,19.125L2.85,17.7Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_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="15dp"
android:height="16dp"
android:viewportWidth="15"
android:viewportHeight="16">
<path
android:pathData="M10.125,7.25C10.438,7.25 10.703,7.141 10.922,6.922C11.141,6.703 11.25,6.438 11.25,6.125C11.25,5.813 11.141,5.547 10.922,5.328C10.703,5.109 10.438,5 10.125,5C9.813,5 9.547,5.109 9.328,5.328C9.109,5.547 9,5.813 9,6.125C9,6.438 9.109,6.703 9.328,6.922C9.547,7.141 9.813,7.25 10.125,7.25ZM4.875,7.25C5.188,7.25 5.453,7.141 5.672,6.922C5.891,6.703 6,6.438 6,6.125C6,5.813 5.891,5.547 5.672,5.328C5.453,5.109 5.188,5 4.875,5C4.563,5 4.297,5.109 4.078,5.328C3.859,5.547 3.75,5.813 3.75,6.125C3.75,6.438 3.859,6.703 4.078,6.922C4.297,7.141 4.563,7.25 4.875,7.25ZM7.5,12.125C8.35,12.125 9.122,11.884 9.816,11.403C10.509,10.922 11.012,10.288 11.325,9.5H3.675C3.987,10.288 4.491,10.922 5.184,11.403C5.878,11.884 6.65,12.125 7.5,12.125ZM7.5,15.5C6.463,15.5 5.488,15.303 4.575,14.909C3.662,14.516 2.869,13.981 2.194,13.306C1.519,12.631 0.984,11.837 0.591,10.925C0.197,10.012 0,9.038 0,8C0,6.963 0.197,5.988 0.591,5.075C0.984,4.162 1.519,3.369 2.194,2.694C2.869,2.019 3.662,1.484 4.575,1.091C5.488,0.697 6.463,0.5 7.5,0.5C8.538,0.5 9.512,0.697 10.425,1.091C11.337,1.484 12.131,2.019 12.806,2.694C13.481,3.369 14.016,4.162 14.409,5.075C14.803,5.988 15,6.963 15,8C15,9.038 14.803,10.012 14.409,10.925C14.016,11.837 13.481,12.631 12.806,13.306C12.131,13.981 11.337,14.516 10.425,14.909C9.512,15.303 8.538,15.5 7.5,15.5ZM7.5,14C9.175,14 10.594,13.419 11.756,12.256C12.919,11.094 13.5,9.675 13.5,8C13.5,6.325 12.919,4.906 11.756,3.744C10.594,2.581 9.175,2 7.5,2C5.825,2 4.406,2.581 3.244,3.744C2.081,4.906 1.5,6.325 1.5,8C1.5,9.675 2.081,11.094 3.244,12.256C4.406,13.419 5.825,14 7.5,14Z"
android:fillColor="#ffffff"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_name.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="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M8,8C6.9,8 5.958,7.608 5.175,6.825C4.392,6.042 4,5.1 4,4C4,2.9 4.392,1.958 5.175,1.175C5.958,0.392 6.9,0 8,0C9.1,0 10.042,0.392 10.825,1.175C11.608,1.958 12,2.9 12,4C12,5.1 11.608,6.042 10.825,6.825C10.042,7.608 9.1,8 8,8ZM0,16V13.2C0,12.633 0.146,12.113 0.438,11.637C0.729,11.163 1.117,10.8 1.6,10.55C2.633,10.033 3.683,9.646 4.75,9.387C5.817,9.129 6.9,9 8,9C9.1,9 10.183,9.129 11.25,9.387C12.317,9.646 13.367,10.033 14.4,10.55C14.883,10.8 15.271,11.163 15.563,11.637C15.854,12.113 16,12.633 16,13.2V16H0ZM2,14H14V13.2C14,13.017 13.954,12.85 13.863,12.7C13.771,12.55 13.65,12.433 13.5,12.35C12.6,11.9 11.692,11.563 10.775,11.337C9.858,11.113 8.933,11 8,11C7.067,11 6.142,11.113 5.225,11.337C4.308,11.563 3.4,11.9 2.5,12.35C2.35,12.433 2.229,12.55 2.138,12.7C2.046,12.85 2,13.017 2,13.2V14ZM8,6C8.55,6 9.021,5.804 9.413,5.412C9.804,5.021 10,4.55 10,4C10,3.45 9.804,2.979 9.413,2.588C9.021,2.196 8.55,2 8,2C7.45,2 6.979,2.196 6.588,2.588C6.196,2.979 6,3.45 6,4C6,4.55 6.196,5.021 6.588,5.412C6.979,5.804 7.45,6 8,6Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_notes.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="14dp"
android:height="19dp"
android:viewportWidth="14"
android:viewportHeight="19">
<path
android:pathData="M7,12C6.167,12 5.458,11.708 4.875,11.125C4.292,10.542 4,9.833 4,9V3C4,2.167 4.292,1.458 4.875,0.875C5.458,0.292 6.167,0 7,0C7.833,0 8.542,0.292 9.125,0.875C9.708,1.458 10,2.167 10,3V9C10,9.833 9.708,10.542 9.125,11.125C8.542,11.708 7.833,12 7,12ZM6,19V15.925C4.267,15.692 2.833,14.917 1.7,13.6C0.567,12.283 0,10.75 0,9H2C2,10.383 2.487,11.563 3.463,12.538C4.438,13.512 5.617,14 7,14C8.383,14 9.563,13.512 10.538,12.538C11.512,11.563 12,10.383 12,9H14C14,10.75 13.433,12.283 12.3,13.6C11.167,14.917 9.733,15.692 8,15.925V19H6Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_phone.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="18dp"
android:height="22dp"
android:viewportWidth="18"
android:viewportHeight="22">
<path
android:pathData="M2,22C1.45,22 0.979,21.804 0.587,21.413C0.196,21.021 0,20.55 0,20V2C0,1.45 0.196,0.979 0.587,0.587C0.979,0.196 1.45,0 2,0H12C12.55,0 13.021,0.196 13.413,0.587C13.804,0.979 14,1.45 14,2V6H12V5H2V17H12V16H14V20C14,20.55 13.804,21.021 13.413,21.413C13.021,21.804 12.55,22 12,22H2ZM2,19V20H12V19H2ZM10.95,15L6.7,10.75L8.1,9.35L10.95,12.2L16.6,6.55L18,7.95L10.95,15ZM2,3H12V2H2V3Z"
android:fillColor="#43474E"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_select.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="10dp"
android:height="5dp"
android:viewportWidth="10"
android:viewportHeight="5">
<path
android:pathData="M5,5L0,0H10L5,5Z"
android:fillColor="#43474E"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/shape_round_corners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="28dp" />
<solid android:color="@color/surface_container_high"/>
</shape>
Loading