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..ae547a3 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,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(R.id.cart_toolbar) + topAppBar.setNavigationOnClickListener { finish() } + + topAppBar.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.close -> { + finish() + true + } + + else -> false + } + } + + val rv = findViewById(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) + } } \ 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..be47220 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/viewandresources/CartItem.kt @@ -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 +) \ 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..6600c2a 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,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(R.id.contacts_toolbar).setNavigationOnClickListener { finish() } + + val bookingDateEditText = findViewById(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") + } + } } \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt b/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt index 22b779c..45c36f4 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt @@ -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?) { @@ -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