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
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
package otus.gpb.homework.viewandresources

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.MaterialToolbar

class CartActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Log.i("Salnikov", "Start activity")
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cart)

val topAppBar = findViewById<MaterialToolbar>(R.id.cart_toolbar)
topAppBar.setNavigationOnClickListener { finish() }

topAppBar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.close -> {
finish()
true
}

else -> false
}
}

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

val itemsList = listOf(
CartItem(image = R.drawable.cart_item_sample, title = "Title 1", category = "category", description = "description 1", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 2", category = "category", description = "description 2", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 3", category = "category", description = "description 3", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 4", category = "category", description = "description 4", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 1", category = "category", description = "description 1", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 2", category = "category", description = "description 2", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 3", category = "category", description = "description 3", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 4", category = "category", description = "description 4", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 1", category = "category", description = "description 1", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 2", category = "category", description = "description 2", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 3", category = "category", description = "description 3", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 4", category = "category", description = "description 4", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 1", category = "category", description = "description 1", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 2", category = "category", description = "description 2", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 3", category = "category", description = "description 3", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 4", category = "category", description = "description 4", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 1", category = "category", description = "description 1", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 2", category = "category", description = "description 2", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 3", category = "category", description = "description 3", price = 32),
CartItem(image = R.drawable.cart_item_sample, title = "Title 4", category = "category", description = "description 4", price = 32),
)

rv.adapter = ViewCartItem(itemsList)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package otus.gpb.homework.viewandresources

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

import androidx.appcompat.app.AppCompatActivity
import android.icu.text.SimpleDateFormat
import android.icu.util.TimeZone
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.textfield.TextInputEditText
import java.util.Date
import java.util.Locale

class ContactsActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.N)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_contacts)

findViewById<MaterialToolbar>(R.id.contacts_toolbar).setNavigationOnClickListener { finish() }

val bookingDateEditText = findViewById<TextInputEditText>(R.id.booking_date_edit_text)


val datePickerBuilder = MaterialDatePicker.Builder.datePicker()
datePickerBuilder.setTitleText("Select Date")
if (bookingDateEditText.text.toString().isNotEmpty()) {
try {
val dateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
dateFormat.timeZone = TimeZone.getTimeZone("UTC")
val parsedDate = dateFormat.parse(bookingDateEditText.text.toString())
parsedDate?.let {
datePickerBuilder.setSelection(it.time)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
val datePicker = datePickerBuilder.build()
datePicker.addOnPositiveButtonClickListener { selection ->
val dateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
dateFormat.timeZone = TimeZone.getTimeZone("UTC")
val formattedDate = dateFormat.format(Date(selection))
bookingDateEditText.setText(formattedDate)
}
datePicker.addOnNegativeButtonClickListener {
bookingDateEditText.clearFocus()
}
datePicker.addOnDismissListener {
bookingDateEditText.clearFocus()
}

bookingDateEditText.setOnClickListener {
datePicker.show(supportFragmentManager, "date_picker_tag")
}

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

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -18,10 +19,23 @@ class MainActivity : AppCompatActivity() {
startActivity(Intent(this, CartActivity::class.java))
}


val builder = MaterialAlertDialogBuilder(this)
val view = layoutInflater.inflate(R.layout.dialog_signin, null)
builder.setView(view)
val dialog = builder.create()

view.findViewById<Button>(R.id.password_reset).setOnClickListener {
view.findViewById<TextInputEditText>(R.id.password_field).setText("")
}

view.findViewById<Button>(R.id.cancel_btn).setOnClickListener {
dialog.dismiss()
}

findViewById<Button>(R.id.signin_button).setOnClickListener {
MaterialAlertDialogBuilder(this)
.setView(R.layout.dialog_signin)
.show()
dialog.show()
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package otus.gpb.homework.viewandresources

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.imageview.ShapeableImageView

class ViewCartItem(private val itemsList: List<CartItem>) : RecyclerView.Adapter<ViewCartItem.ViewCartItemHolder>() {

class ViewCartItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val image: ShapeableImageView = itemView.findViewById(R.id.cart_item_image)
val title: TextView = itemView.findViewById(R.id.cart_item_title)
val category: TextView = itemView.findViewById(R.id.cart_item_category)
val description: TextView = itemView.findViewById(R.id.cart_item_description)
val price: TextView = itemView.findViewById(R.id.cart_item_price)
}

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

override fun onBindViewHolder(
holder: ViewCartItemHolder,
position: Int
) {
val currentItem = itemsList[position]
holder.image.setImageResource(currentItem.image)
holder.title.text = currentItem.title
holder.category.text = currentItem.category
holder.description.text = currentItem.description

val price = holder.itemView.context.getString(R.string.price, currentItem.price)

holder.price.text = price
}

override fun getItemCount(): Int = itemsList.size
}
1 change: 1 addition & 0 deletions app/src/main/res/drawable/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="?attr/my_icons_color" 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 app/src/main/res/drawable/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="?attr/my_icons_color" 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 app/src/main/res/drawable/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="?attr/my_icons_color" android:pathData="M17,18L12,15.82L7,18V5H17M17,3H7A2,2 0 0,0 5,5V21L12,18L19,21V5C19,3.89 18.1,3 17,3Z" /></vector>
3 changes: 3 additions & 0 deletions app/src/main/res/drawable/calendar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="?attr/my_icons_color" android:pathData="M17,12h-5v5h5v-5zM16,1v2L8,3L8,1L6,1v2L5,3c-1.11,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2h-1L18,1h-2zM19,19L5,19L5,8h14v11z"/>
</vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/cart_item_sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- drawable/shape.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
>
<path
android:fillColor="#dadce0"
android:pathData="M0,0 L24,0 L24,24 L0,24 Z"/>
<path
android:fillColor="#9aa0a6"
android:pathData="M11,13.5V21.5H3V13.5H11M12,2L17.5,11H6.5L12,2M17.5,13C20,13 22,15 22,17.5C22,20 20,22 17.5,22C15,22 13,20 13,17.5C13,15 15,13 17.5,13Z" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/drawable/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="?attr/my_icons_color" 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 app/src/main/res/drawable/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="?attr/my_icons_color" 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 app/src/main/res/drawable/dots_vertical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/dots_vertical.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="?attr/my_icons_color" android:pathData="M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z" /></vector>
1 change: 1 addition & 0 deletions app/src/main/res/drawable/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="?attr/my_icons_color" 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 app/src/main/res/drawable/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="?attr/my_icons_color" 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 app/src/main/res/drawable/white_balance_sunny.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/white_balance_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="?attr/my_icons_color" android:pathData="M3.55 19.09L4.96 20.5L6.76 18.71L5.34 17.29M12 6C8.69 6 6 8.69 6 12S8.69 18 12 18 18 15.31 18 12C18 8.68 15.31 6 12 6M20 13H23V11H20M17.24 18.71L19.04 20.5L20.45 19.09L18.66 17.29M20.45 5L19.04 3.6L17.24 5.39L18.66 6.81M13 1H11V4H13M6.76 5.39L4.96 3.6L3.55 5L5.34 6.81L6.76 5.39M1 13H4V11H1M13 20H11V23H13" /></vector>
Loading