diff --git a/app/build.gradle b/app/build.gradle index debcfaf..a4ea930 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,6 @@ android { targetSdk 35 versionCode 1 versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -29,11 +28,15 @@ android { kotlinOptions { jvmTarget = '17' } + buildFeatures{ + viewBinding = true + } } 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' } \ No newline at end of file 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..ca0891a 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/CartActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/CartActivity.kt @@ -1,11 +1,69 @@ package otus.gpb.homework.viewandresources -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import com.google.android.material.divider.MaterialDividerItemDecoration +import otus.gpb.homework.viewandresources.databinding.ActivityCartBinding class CartActivity : AppCompatActivity() { + + private val listItem = mutableListOf() + private val binding by lazy { + ActivityCartBinding.inflate(layoutInflater) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_cart) + setContentView(binding.root) + + binding.backBtn.setOnClickListener { + finish() + } + + createListCartItem() + val adapter = ItemCartAdapter() + adapter.items = listItem + binding.counterLabel.text = String.format( + this.resources.getString(R.string.counterLabel), + adapter.items.size + ) + val dividerItemDecoration = MaterialDividerItemDecoration(binding.recyclerViewCartList.context, MaterialDividerItemDecoration.VERTICAL) + dividerItemDecoration.setDividerColor(ContextCompat.getColor(applicationContext, R.color.outline_variant)) + dividerItemDecoration.dividerThickness = 2 + dividerItemDecoration.isLastItemDecorated = true + + binding.recyclerViewCartList.addItemDecoration(dividerItemDecoration) + binding.recyclerViewCartList.adapter = adapter + + val pricePair = calculateOrderPrice(listItem) + binding.taxPrice.text = String.format(this.resources.getString(R.string.price), TAX_PRICE) + binding.shippingPrice.text = String.format(this.resources.getString(R.string.price), SHIPPING_PRICE) + binding.subtotalPrice.text = String.format(this.resources.getString(R.string.price), pricePair.second) + binding.totalPrice.text = String.format(this.resources.getString(R.string.price), pricePair.first) + } + + private fun createListCartItem() { + for(i in 1..5){ + val cartItem = ItemCart(i, 35, CATEGORY, DESCRIPTION, IMAGE) + listItem.add(cartItem) + } + } + + private fun calculateOrderPrice(listItem: MutableList):Pair{ + var totalPrice = TAX_PRICE + SHIPPING_PRICE + var subtotalPrice = 0.0 + listItem.forEach { subtotalPrice += it.price } + totalPrice +=subtotalPrice + return Pair(totalPrice,subtotalPrice) + } + + companion object{ + private const val DESCRIPTION = "Supporting line text lorem ipsum dolor sit amet, consectetur." + private const val CATEGORY = "Category" + private const val IMAGE = "drawable/food_steak" + + private const val TAX_PRICE = 10.5 + private const val SHIPPING_PRICE = 25.0 } } \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/CartItemViewHolder.kt b/app/src/main/java/otus/gpb/homework/viewandresources/CartItemViewHolder.kt new file mode 100644 index 0000000..b292650 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/viewandresources/CartItemViewHolder.kt @@ -0,0 +1,31 @@ +package otus.gpb.homework.viewandresources + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView + +class CartItemViewHolder(view: View): RecyclerView.ViewHolder(view){ + + private val categoryText:TextView by lazy { view.findViewById(R.id.categoryText) } + private val supportingText:TextView by lazy { view.findViewById(R.id.supportingText) } + private val priceText:TextView by lazy { view.findViewById(R.id.priceText) } + private val nameItemText:TextView by lazy { view.findViewById(R.id.nameItemText) } + private val itemImage:ImageView by lazy { view.findViewById(R.id.itemImage) } + + private val maxLength = 32 + + fun bind(itemCart: ItemCart){ + nameItemText.text = String.format(itemView.context.resources.getString(R.string.nameItemText), itemCart.id) + categoryText.text = String.format(itemView.context.resources.getString(R.string.categoryText), itemCart.category) + supportingText.text = + if (itemCart.supportingText.length > maxLength) { + itemCart.supportingText.substring(0, maxLength) + "..." + }else{ + itemCart.supportingText + } + priceText.text = String.format(itemView.context.resources.getString(R.string.priceText), itemCart.price) + } + + +} \ 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..cd2d1f0 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/ContactsActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/ContactsActivity.kt @@ -2,10 +2,19 @@ package otus.gpb.homework.viewandresources import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import otus.gpb.homework.viewandresources.databinding.ActivityContactsBinding class ContactsActivity : AppCompatActivity() { + + private val binding by lazy { + ActivityContactsBinding.inflate(layoutInflater) + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_contacts) + setContentView(binding.root) + + binding.backBtn.setOnClickListener { + finish() + } } } \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/ItemCart.kt b/app/src/main/java/otus/gpb/homework/viewandresources/ItemCart.kt new file mode 100644 index 0000000..8800cb0 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/viewandresources/ItemCart.kt @@ -0,0 +1,9 @@ +package otus.gpb.homework.viewandresources + +data class ItemCart( + val id: Int, + val price: Int, + val category: String, + val supportingText: String, + val logo: String +) \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/ItemCartAdapter.kt b/app/src/main/java/otus/gpb/homework/viewandresources/ItemCartAdapter.kt new file mode 100644 index 0000000..0fdba7f --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/viewandresources/ItemCartAdapter.kt @@ -0,0 +1,25 @@ +package otus.gpb.homework.viewandresources + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView + +class ItemCartAdapter: RecyclerView.Adapter() { + + var items = listOf() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartItemViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.item_layout_cart, parent, false) + return CartItemViewHolder(view) + } + + override fun onBindViewHolder(holder: CartItemViewHolder, position: Int) { + val cartItem: ItemCart = items[position] + holder.bind(cartItem) + } + + override fun getItemCount(): Int { + return items.size + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/address_save.xml b/app/src/main/res/drawable/address_save.xml new file mode 100644 index 0000000..702cd6b --- /dev/null +++ b/app/src/main/res/drawable/address_save.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/attach.xml b/app/src/main/res/drawable/attach.xml new file mode 100644 index 0000000..a1a7f58 --- /dev/null +++ b/app/src/main/res/drawable/attach.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/back_button.xml b/app/src/main/res/drawable/back_button.xml new file mode 100644 index 0000000..61802da --- /dev/null +++ b/app/src/main/res/drawable/back_button.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/cancel_button.xml b/app/src/main/res/drawable/cancel_button.xml new file mode 100644 index 0000000..c4d2575 --- /dev/null +++ b/app/src/main/res/drawable/cancel_button.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/close_circle_outline.xml b/app/src/main/res/drawable/close_circle_outline.xml new file mode 100644 index 0000000..1a51e0a --- /dev/null +++ b/app/src/main/res/drawable/close_circle_outline.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/date.xml b/app/src/main/res/drawable/date.xml new file mode 100644 index 0000000..313674d --- /dev/null +++ b/app/src/main/res/drawable/date.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/down.xml b/app/src/main/res/drawable/down.xml new file mode 100644 index 0000000..01e56f2 --- /dev/null +++ b/app/src/main/res/drawable/down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/item_img.png b/app/src/main/res/drawable/item_img.png new file mode 100644 index 0000000..4203cbd Binary files /dev/null and b/app/src/main/res/drawable/item_img.png differ diff --git a/app/src/main/res/drawable/microphone.xml b/app/src/main/res/drawable/microphone.xml new file mode 100644 index 0000000..07059a0 --- /dev/null +++ b/app/src/main/res/drawable/microphone.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/person.xml b/app/src/main/res/drawable/person.xml new file mode 100644 index 0000000..bcdb5f4 --- /dev/null +++ b/app/src/main/res/drawable/person.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..e3ec167 --- /dev/null +++ b/app/src/main/res/drawable/phone.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/points.xml b/app/src/main/res/drawable/points.xml new file mode 100644 index 0000000..f5369d1 --- /dev/null +++ b/app/src/main/res/drawable/points.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/show_password_icon.xml b/app/src/main/res/drawable/show_password_icon.xml new file mode 100644 index 0000000..0e92704 --- /dev/null +++ b/app/src/main/res/drawable/show_password_icon.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/smile.xml b/app/src/main/res/drawable/smile.xml new file mode 100644 index 0000000..4b93dfd --- /dev/null +++ b/app/src/main/res/drawable/smile.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_cart.xml b/app/src/main/res/layout/activity_cart.xml index 57dc4d4..fa67c2b 100644 --- a/app/src/main/res/layout/activity_cart.xml +++ b/app/src/main/res/layout/activity_cart.xml @@ -4,6 +4,163 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/background" tools:context=".CartActivity"> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_contacts.xml b/app/src/main/res/layout/activity_contacts.xml index 6ef087b..41ae1b1 100644 --- a/app/src/main/res/layout/activity_contacts.xml +++ b/app/src/main/res/layout/activity_contacts.xml @@ -5,5 +5,236 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ContactsActivity"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_signin.xml b/app/src/main/res/layout/dialog_signin.xml index 77d9ef6..51b51ee 100644 --- a/app/src/main/res/layout/dialog_signin.xml +++ b/app/src/main/res/layout/dialog_signin.xml @@ -1,6 +1,108 @@ + android:layout_height="match_parent" + android:background="@color/surface_container_high" + android:padding="16dp" + xmlns:app="http://schemas.android.com/apk/res-auto"> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_layout_cart.xml b/app/src/main/res/layout/item_layout_cart.xml new file mode 100644 index 0000000..f7c3158 --- /dev/null +++ b/app/src/main/res/layout/item_layout_cart.xml @@ -0,0 +1,60 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml new file mode 100644 index 0000000..0922528 --- /dev/null +++ b/app/src/main/res/values-night/colors.xml @@ -0,0 +1,16 @@ + + + #C4C6CF + #E1E2E9 + #8E9199 + #A7C8FF + #33353A + #111318 + #BDC7DC + #111318 + #282A2F + + #DBBCE1 + #43474E + #04305F + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127..3e50977 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,18 @@ #FF018786 #FF000000 #FFFFFFFF + + #43474E + #191C20 + #74777F + #3E5F90 + #E1E2E9 + #F9F9FF + #555F71 + #F9F9FF + #E7E8EE + + #6E5676 + #C4C6CF + #FFFFFF \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a7036ac..c67d519 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,15 @@ View & Resources + Login + Password + Reset my password + Cancel + + Cart + Cart №%1$d + Category: %1$s + Supporting line text lorem ipsum dolor sit amet, consectetur. + %1$d$ + %1$d Items in your cart + $%1$.2f \ No newline at end of file