Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,45 @@ package otus.gpb.homework.viewandresources

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

class CartActivity : AppCompatActivity() {

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

val rv = findViewById<RecyclerView>(R.id.recyclerView)
rv.addItemDecoration(
DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
)
rv.layoutManager = LinearLayoutManager(this)

val itemsList = listOf(
CartItem("SportsCar", "Avto", "car", R.drawable.ic_car_sports, "$500000.00"),
CartItem("MotoBike", "Avto", "motorcycle", R.drawable.ic_motorbike, "$5000.00"),
CartItem("Snowmobile", "Avto", "snowmobile", R.drawable.ic_snowmobile, "$10000.00"),
CartItem("Bicycle", "Avto", "bicycle",R.drawable.ic_bicycle, "$300.00"),
CartItem("Skateboard", "Avto", "skateboard",R.drawable.ic_skateboard, "$100.00"),
)

var amount = 0.0
for(i in itemsList){
amount +=i.price.drop(1).toFloat()
}

findViewById<TextView>(R.id.text).text = "${itemsList.count()}" + getString(R.string.count_items)
findViewById<TextView>(R.id.textTaxAmount).text = String.format("$%d.%02d", (amount.toInt() / 100) , amount.toInt() % 100)
findViewById<TextView>(R.id.textSubtotalAmount).text = "$%.02f".format(amount)

findViewById<TextView>(R.id.textOrderTotalAmount).text = "$%.02f".format(
findViewById<TextView>(R.id.textTaxAmount).text.drop(1).toString().toFloat() +
findViewById<TextView>(R.id.textSubtotalAmount).text.drop(1).toString().toFloat() +
findViewById<TextView>(R.id.textShippingAmount).text.drop(1).toString().toFloat())

rv.adapter = RecyclerViewItem(itemsList)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package otus.gpb.homework.viewandresources

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

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class RecyclerViewItem(private val itemsList: List<CartItem>) : RecyclerView.Adapter<RecyclerViewItem.RecyclerItemHolder>() {

class RecyclerItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val imageView: ImageView = itemView.findViewById(R.id.imageView)
val textViewTitle: TextView = itemView.findViewById(R.id.name)
val textView: TextView = itemView.findViewById(R.id.category)
val textDescription: TextView = itemView.findViewById(R.id.description)
val priceView: TextView = itemView.findViewById(R.id.price)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerItemHolder {
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.items_cart, parent, false)
return RecyclerItemHolder(itemView)
}

override fun onBindViewHolder(holder: RecyclerItemHolder, position: Int) {
val currentItem = itemsList[position]
holder.imageView.setImageResource(currentItem.image)
holder.textViewTitle.text = currentItem.name
holder.textView.text = currentItem.category
holder.textDescription.text = currentItem.description
holder.priceView.text = currentItem.price
}

override fun getItemCount() = itemsList.size
}
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_account_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" 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>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_arrow_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" android:pathData="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_bicycle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/bicycle.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="M19 10C18.44 10 17.91 10.11 17.41 10.28L14.46 4.5H11V6H13.54L14.42 7.72L12 13.13L10.23 8.95C10.5 8.85 10.74 8.58 10.74 8.25C10.74 7.84 10.41 7.5 10 7.5H8C7.58 7.5 7.24 7.84 7.24 8.25S7.58 9 8 9H8.61L10.86 14.25H9.92C9.56 11.85 7.5 10 5 10C2.24 10 0 12.24 0 15S2.24 20 5 20C7.5 20 9.56 18.15 9.92 15.75H12.5L15.29 9.43L16.08 10.96C14.82 11.87 14 13.34 14 15C14 17.76 16.24 20 19 20S24 17.76 24 15 21.76 10 19 10M5 18.5C3.07 18.5 1.5 16.93 1.5 15S3.07 11.5 5 11.5C6.67 11.5 8.07 12.68 8.41 14.25H4V15.75H8.41C8.07 17.32 6.67 18.5 5 18.5M19 18.5C17.07 18.5 15.5 16.93 15.5 15C15.5 13.92 16 12.97 16.77 12.33L18.57 15.85L19.89 15.13L18.1 11.63C18.39 11.56 18.69 11.5 19 11.5C20.93 11.5 22.5 13.07 22.5 15S20.93 18.5 19 18.5Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_bookmark_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" android:pathData="M17,18L12,15.82L7,18V5H17M17,3H7A2,2 0 0,0 5,5V21L12,18L19,21V5C19,3.89 18.1,3 17,3Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_calendar_today_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/calendar_today_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="#000000" android:pathData="M19 3H18V1H16V3H8V1H6V3H5C3.9 3 3 3.89 3 5V19C3 20.11 3.9 21 5 21H19C20.11 21 21 20.11 21 19V5C21 3.89 20.11 3 19 3M19 19H5V9H19V19M19 7H5V5H19M7 11H12V16H7" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_car_sports.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/car_sports.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="M12,8.5H7L4,11H3C1.89,11 1,11.89 1,13V16H3.17C3.6,17.2 4.73,18 6,18C7.27,18 8.4,17.2 8.82,16H15.17C15.6,17.2 16.73,18 18,18C19.27,18 20.4,17.2 20.82,16H23V15C23,13.89 21.97,13.53 21,13L12,8.5M5.25,12L7.5,10H11.5L15.5,12H5.25M6,13.5A1.5,1.5 0 0,1 7.5,15A1.5,1.5 0 0,1 6,16.5A1.5,1.5 0 0,1 4.5,15A1.5,1.5 0 0,1 6,13.5M18,13.5A1.5,1.5 0 0,1 19.5,15A1.5,1.5 0 0,1 18,16.5A1.5,1.5 0 0,1 16.5,15A1.5,1.5 0 0,1 18,13.5Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_cellphone_check.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" 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>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_chevron_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/chevron_down.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="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_close_circle_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" 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>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_emoticon_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/emoticon_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="#000000" android:pathData="M12,17.5C14.33,17.5 16.3,16.04 17.11,14H6.89C7.69,16.04 9.67,17.5 12,17.5M8.5,11A1.5,1.5 0 0,0 10,9.5A1.5,1.5 0 0,0 8.5,8A1.5,1.5 0 0,0 7,9.5A1.5,1.5 0 0,0 8.5,11M15.5,11A1.5,1.5 0 0,0 17,9.5A1.5,1.5 0 0,0 15.5,8A1.5,1.5 0 0,0 14,9.5A1.5,1.5 0 0,0 15.5,11M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2C6.47,2 2,6.5 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_microphone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" 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>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_motorbike.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/motorbike.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="M17.42,10L13.41,6H9V8H12.59L14.59,10H6.5C4,10 2,12 2,14.5C2,17 4,19 6.5,19C8.72,19 10.56,17.38 10.92,15.27L13.04,14C13,14.17 13,14.33 13,14.5C13,17 15,19 17.5,19C20,19 22,17 22,14.5C22,12 20,10 17.5,10M8.84,15.26C8.5,16.27 7.58,17 6.47,17C5.09,17 3.97,15.88 3.97,14.5C3.97,13.12 5.09,12 6.47,12C7.59,12 8.5,12.74 8.84,13.75H6V15.25L8.84,15.26M17.47,17C16.09,17 14.97,15.88 14.97,14.5C14.97,13.12 16.09,12 17.47,12A2.5,2.5 0 0,1 19.97,14.5A2.5,2.5 0 0,1 17.47,17Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_paperclip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- 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="#000000" 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>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_skateboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/skateboard.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 14.5C9 15.33 8.33 16 7.5 16S6 15.33 6 14.5 6.67 13 7.5 13 9 13.67 9 14.5M16.5 13C15.67 13 15 13.67 15 14.5S15.67 16 16.5 16C17.33 16 18 15.33 18 14.5S17.33 13 16.5 13M21.59 9.19C21.14 8.87 20.5 8.97 20.19 9.41L20.06 9.59C19.88 9.85 19.57 10 19.26 10L4.74 10C4.43 10 4.13 9.85 3.94 9.59L3.81 9.41C3.5 8.97 2.86 8.87 2.41 9.19C1.96 9.5 1.87 10.15 2.19 10.59L2.32 10.77C2.88 11.54 3.79 12 4.74 12H19.26C20.21 12 21.12 11.54 21.68 10.77L21.81 10.59C22.13 10.15 22.04 9.5 21.59 9.19Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_snowmobile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/snowmobile.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="M20.34 17.93L18.4 16C19.5 15.91 22.66 15.53 22.97 13.36C23 13.12 22.92 12.89 22.78 12.7C22.12 11.82 19.88 9.07 15 5H12V7H14L16 9L12 11L3 10L1 13L5.58 14.38L2.58 16.09C2.22 16.26 1 16.89 1 18.05C1 18.4 1 18.89 1.33 19.32C1.83 20 2.71 20 3 20H9C10.26 20 12.53 19.13 12.93 16H15.59L17.59 18H15V20H20C21.65 20 23 18.65 23 17H21C21 17.43 20.73 17.79 20.34 17.93M9 18H3.25C3.33 17.95 3.41 17.91 3.5 17.87L8.22 15.17L10.92 16C10.58 17.84 9.28 18 9 18Z" /></vector>
1 change: 1 addition & 0 deletions 1 app/src/main/res/drawable/ic_weather_sunny.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/weather_sunny.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="M12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,2L14.39,5.42C13.65,5.15 12.84,5 12,5C11.16,5 10.35,5.15 9.61,5.42L12,2M3.34,7L7.5,6.65C6.9,7.16 6.36,7.78 5.94,8.5C5.5,9.24 5.25,10 5.11,10.79L3.34,7M3.36,17L5.12,13.23C5.26,14 5.53,14.78 5.95,15.5C6.37,16.24 6.91,16.86 7.5,17.37L3.36,17M20.65,7L18.88,10.79C18.74,10 18.47,9.23 18.05,8.5C17.63,7.78 17.1,7.15 16.5,6.64L20.65,7M20.64,17L16.5,17.36C17.09,16.85 17.62,16.22 18.04,15.5C18.46,14.77 18.73,14 18.87,13.21L20.64,17M12,22L9.59,18.56C10.33,18.83 11.14,19 12,19C12.82,19 13.63,18.83 14.37,18.56L12,22Z" /></vector>
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.