Skip to content

homework view resources #44

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 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ android {
kotlinOptions {
jvmTarget = '17'
}

buildFeatures {
viewBinding true
}
}

dependencies {
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.view.Menu
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.RecyclerView
import otus.gpb.homework.viewandresources.cart.CartAdapter
import otus.gpb.homework.viewandresources.cart.CartData

class CartActivity : AppCompatActivity() {

private val cartAdapter: CartAdapter by lazy { CartAdapter() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cart)
var toolbar = findViewById<Toolbar>(R.id.topAppBar)
setSupportActionBar(toolbar)

val recyclerView = findViewById<RecyclerView>(R.id.cartRW)
recyclerView.adapter = cartAdapter
cartAdapter.createCarts(createCarts())
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main_menu_card, menu)
return true
}

private fun createCarts(): List<CartData> {

val carts = (1..15).map {
CartData(
headerTitle = "List item $it",
image = R.drawable.cart_image,
category = "category",
supporting = "Supporting line text lorem ipsum dolor sit amet, consectetur.",
price = "$35",
)
}.toList()
return carts
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ package otus.gpb.homework.viewandresources

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import androidx.appcompat.widget.Toolbar

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

var toolbar = findViewById<Toolbar>(R.id.topAppBar)
toolbar.setTitle(R.string.personName)
setSupportActionBar(findViewById<Toolbar>(R.id.topAppBar))
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main_menu, menu)
return true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder


class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package otus.gpb.homework.viewandresources.cart

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import otus.gpb.homework.viewandresources.R

class CartAdapter : RecyclerView.Adapter<CartViewHolder>() {
private var carts = listOf<CartData>()

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 onBindViewHolder(
holder: CartViewHolder,
position: Int
) {
val item = carts.getOrNull(position)
item?.let {
holder.bind(it)
}
}

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

fun createCarts(newCarts: List<CartData>) {
carts = newCarts
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package otus.gpb.homework.viewandresources.cart

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

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import otus.gpb.homework.viewandresources.R

class CartViewHolder(
private val viewCartItem: View,
) : RecyclerView.ViewHolder(viewCartItem) {

private val image: ImageView by lazy { viewCartItem.findViewById(R.id.imageView) }
private val headerTitle: TextView by lazy { viewCartItem.findViewById(R.id.header_title) }
private val category: TextView by lazy { viewCartItem.findViewById(R.id.category) }
private val supporting: TextView by lazy { viewCartItem.findViewById(R.id.supporting) }
private val price: TextView by lazy { viewCartItem.findViewById(R.id.price) }

fun bind(items: CartData) {
image.setImageResource(items.image)
headerTitle.text = items.headerTitle
category.text = items.category
supporting.text = items.supporting
price.text = items.price
}
}
Binary file added app/src/main/res/drawable-nodpi/cart_image.png
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/address.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="14dp"
android:height="18dp"
android:viewportWidth="14"
android:tint="?attr/colorOnBackground"
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>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/baseline_arrow_back_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="?attr/colorOnBackground"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />

</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/baseline_attach_file_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:tint="?attr/colorOnBackground"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M16.5,6v11.5c0,2.21 -1.79,4 -4,4s-4,-1.79 -4,-4V5c0,-1.38 1.12,-2.5 2.5,-2.5s2.5,1.12 2.5,2.5v10.5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6H10v9.5c0,1.38 1.12,2.5 2.5,2.5s2.5,-1.12 2.5,-2.5V5c0,-2.21 -1.79,-4 -4,-4S7,2.79 7,5v12.5c0,3.04 2.46,5.5 5.5,5.5s5.5,-2.46 5.5,-5.5V6h-1.5z" />

</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/baseline_mic_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorOnBackground"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z" />

</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/baseline_perm_identity_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorOnBackground"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4z" />

</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/calendar.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="18dp"
android:height="20dp"
android:tint="?attr/colorOnBackground"
android:viewportWidth="18"
android:viewportHeight="20">
<path
android:fillColor="#43474E"
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" />
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/drop.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="10dp"
android:height="5dp"
android:tint="?attr/colorOnBackground"
android:viewportWidth="10"
android:viewportHeight="5">
<path
android:pathData="M5,5L0,0H10L5,5Z"
android:fillColor="#43474E"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/mood.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="15dp"
android:height="16dp"
android:tint="?attr/colorPrimary"
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>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/phone.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="18dp"
android:height="22dp"
android:tint="?attr/colorOnBackground"
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>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/round_close.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="20dp"
android:height="20dp"
android:tint="?attr/colorOnBackground"
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="#C4C6CF"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/sun.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="22dp"
android:height="22dp"
android:tint="?attr/colorOnBackground"
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>
52 changes: 52 additions & 0 deletions app/src/main/res/layout/activity_cart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,56 @@
android:layout_height="match_parent"
tools:context=".CartActivity">

<include layout="@layout/main_toolbar" />

<LinearLayout
android:id="@+id/cartLayout"
android:layout_width="match_parent"
android:layout_height="0.dp"
android:layout_margin="16.dp"
android:orientation="vertical"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/topAppBar">

<TextView
android:id="@+id/cartCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:paddingBottom="10dp"
android:text="@string/items_in_your_cart" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cartRW"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager">

</androidx.recyclerview.widget.RecyclerView>

<include layout="@layout/cart_price_block" />

<com.google.android.material.button.MaterialButton
android:id="@+id/priceOrderButton"
android:contentDescription="@string/mood"
app:icon="@drawable/mood"
app:iconGravity="textStart"
app:iconSize="16dp"
app:iconPadding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="sans-serif-medium"
android:textSize="14sp"
android:text="@string/price_order" />

</LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
37 changes: 37 additions & 0 deletions app/src/main/res/layout/activity_contacts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,41 @@
android:layout_height="match_parent"
tools:context=".ContactsActivity">

<include layout="@layout/main_toolbar" />

<LinearLayout
android:id="@+id/personLayout"
android:layout_width="match_parent"
android:layout_height="0.dp"
android:layout_margin="10.dp"
android:orientation="vertical"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/topAppBar">

<include layout="@layout/person_name_text_field" />

<include layout="@layout/person_phone_block" />

<include layout="@layout/person_address_text_field" />

<include layout="@layout/person_city_block" />

<include layout="@layout/person_birthday_text_field" />

<include layout="@layout/person_notes_text_field" />

</LinearLayout>

<com.google.android.material.button.MaterialButton
android:layout_width="392.dp"
android:layout_height="40.dp"
android:text="@string/buttonSave"
app:layout_constraintBottom_toBottomOf="@+id/personLayout"
app:layout_constraintEnd_toEndOf="@+id/personLayout"
app:layout_constraintStart_toStartOf="@+id/personLayout" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading