diff --git a/app/build.gradle b/app/build.gradle index 4332a31..89d87f8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,10 +29,13 @@ android { kotlinOptions { jvmTarget = '1.8' } + buildFeatures { + viewBinding = true + } } dependencies { - implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.core:core-ktx:1.8.0' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 608e135..c2a3db9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,12 +15,12 @@ tools:targetApi="31"> + android:exported="false" + android:label="Cart" /> + android:exported="false" + android:label="Contacts" /> diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/CartActivity.kt b/app/src/main/java/otus/gpb/homework/viewandresources/CartActivity.kt index b6cbf73..1e73d43 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/CartActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/CartActivity.kt @@ -7,5 +7,6 @@ class CartActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_cart) + supportActionBar?.hide() } } \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/CartItem.kt b/app/src/main/java/otus/gpb/homework/viewandresources/CartItem.kt new file mode 100644 index 0000000..f93a161 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/viewandresources/CartItem.kt @@ -0,0 +1,84 @@ +package otus.gpb.homework.viewandresources + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.withStyledAttributes +import otus.gpb.homework.viewandresources.databinding.CartItemBinding + +enum class CartItemType { ITEM, TOTAL, SUBTOTAL } + +class CartItem @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + private val binding: CartItemBinding + + var itemType: CartItemType = CartItemType.ITEM + + var name: String = "" + set(value) { + field = value + binding.name.text = value + } + var caption: String = "" + set(value) { + field = value + binding.caption.text = value + } + + var price: Float = 0F + set(value) { + field = value + val s = "${if (itemType == CartItemType.ITEM) "\$US, " else ""}${"%.2f".format(value)}" + binding.price.text = s + } + + var imageRes: Int = 0 + set(value) { + field = value + binding.image.setImageResource(value) + } + + init { + binding = CartItemBinding.inflate(LayoutInflater.from(context), this) + initView(attrs, defStyleAttr) + } + + private fun initView(attrs: AttributeSet?, defStyleAttr: Int) { + val attrsRetrieve = intArrayOf( + android.R.attr.layout_width, + android.R.attr.layout_height + ).apply { sort() } + + context.withStyledAttributes(attrs, attrsRetrieve, defStyleAttr) { + layoutParams = LayoutParams( + getInt(attrsRetrieve.indexOf(android.R.attr.layout_width), LayoutParams.WRAP_CONTENT), + getInt(attrsRetrieve.indexOf(android.R.attr.layout_height), LayoutParams.WRAP_CONTENT), + ) + } + + context.withStyledAttributes(attrs, R.styleable.CartItem, defStyleAttr) { + itemType = CartItemType.values()[getInt(R.styleable.CartItem_cart_item_type, 0)] + name = getString(R.styleable.CartItem_cart_item_name) ?: "" + price = getFloat(R.styleable.CartItem_cart_item_price, 0F) + + if (itemType == CartItemType.ITEM) { + caption = getString(R.styleable.CartItem_cart_item_caption) ?: "" + imageRes = getResourceId(R.styleable.CartItem_cart_item_image, 0) + } else { + binding.image.visibility = GONE + binding.caption.visibility = GONE + binding.close.visibility = GONE + } + + if (itemType == CartItemType.TOTAL) { + binding.name.setTextAppearance(R.style.MyLabel_HeadAccent) + binding.price.setTextAppearance(R.style.MyLabel_HeadAccent) + } + + } + } +} \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/ContactsActivity.kt b/app/src/main/java/otus/gpb/homework/viewandresources/ContactsActivity.kt index 25f1ffb..49d515e 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/ContactsActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/ContactsActivity.kt @@ -1,11 +1,12 @@ package otus.gpb.homework.viewandresources -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity class ContactsActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_contacts) + supportActionBar?.hide() } } \ No newline at end of file diff --git a/app/src/main/res/color/stroke_colors.xml b/app/src/main/res/color/stroke_colors.xml new file mode 100644 index 0000000..911e8f4 --- /dev/null +++ b/app/src/main/res/color/stroke_colors.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/color/stroke_colors_dlg.xml b/app/src/main/res/color/stroke_colors_dlg.xml new file mode 100644 index 0000000..6b6abd1 --- /dev/null +++ b/app/src/main/res/color/stroke_colors_dlg.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/account.xml b/app/src/main/res/drawable/account.xml new file mode 100644 index 0000000..fdd209f --- /dev/null +++ b/app/src/main/res/drawable/account.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/calendar.xml b/app/src/main/res/drawable/calendar.xml new file mode 100644 index 0000000..5c93a21 --- /dev/null +++ b/app/src/main/res/drawable/calendar.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/close.xml b/app/src/main/res/drawable/close.xml new file mode 100644 index 0000000..6091296 --- /dev/null +++ b/app/src/main/res/drawable/close.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/credit_card_chip_outline.xml b/app/src/main/res/drawable/credit_card_chip_outline.xml new file mode 100644 index 0000000..3ec2857 --- /dev/null +++ b/app/src/main/res/drawable/credit_card_chip_outline.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/dots_vertical.xml b/app/src/main/res/drawable/dots_vertical.xml new file mode 100644 index 0000000..5a3d1fd --- /dev/null +++ b/app/src/main/res/drawable/dots_vertical.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/item1.png b/app/src/main/res/drawable/item1.png new file mode 100644 index 0000000..b795849 Binary files /dev/null and b/app/src/main/res/drawable/item1.png differ diff --git a/app/src/main/res/drawable/item2.png b/app/src/main/res/drawable/item2.png new file mode 100644 index 0000000..e1f0cd0 Binary files /dev/null and b/app/src/main/res/drawable/item2.png differ diff --git a/app/src/main/res/drawable/item3.png b/app/src/main/res/drawable/item3.png new file mode 100644 index 0000000..4f1ddd3 Binary files /dev/null and b/app/src/main/res/drawable/item3.png differ diff --git a/app/src/main/res/drawable/item4.png b/app/src/main/res/drawable/item4.png new file mode 100644 index 0000000..063a0e5 Binary files /dev/null and b/app/src/main/res/drawable/item4.png differ diff --git a/app/src/main/res/drawable/magnify.xml b/app/src/main/res/drawable/magnify.xml new file mode 100644 index 0000000..3b5ca83 --- /dev/null +++ b/app/src/main/res/drawable/magnify.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/map_marker.xml b/app/src/main/res/drawable/map_marker.xml new file mode 100644 index 0000000..3af16ba --- /dev/null +++ b/app/src/main/res/drawable/map_marker.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/menu_down.xml b/app/src/main/res/drawable/menu_down.xml new file mode 100644 index 0000000..22bfc56 --- /dev/null +++ b/app/src/main/res/drawable/menu_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/pencil.xml b/app/src/main/res/drawable/pencil.xml new file mode 100644 index 0000000..404c172 --- /dev/null +++ b/app/src/main/res/drawable/pencil.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/phone.xml b/app/src/main/res/drawable/phone.xml new file mode 100644 index 0000000..dc3a02e --- /dev/null +++ b/app/src/main/res/drawable/phone.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/tag_heart.xml b/app/src/main/res/drawable/tag_heart.xml new file mode 100644 index 0000000..9931fc5 --- /dev/null +++ b/app/src/main/res/drawable/tag_heart.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/font/roboto.ttf b/app/src/main/res/font/roboto.ttf new file mode 100644 index 0000000..3313686 Binary files /dev/null and b/app/src/main/res/font/roboto.ttf differ diff --git a/app/src/main/res/layout/activity_cart.xml b/app/src/main/res/layout/activity_cart.xml index 57dc4d4..15f1155 100644 --- a/app/src/main/res/layout/activity_cart.xml +++ b/app/src/main/res/layout/activity_cart.xml @@ -1,9 +1,155 @@ - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + +