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..e620130 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,120 @@ package otus.gpb.homework.viewandresources -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageButton +import android.widget.ImageView +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +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) + + // Set click listener for the back button + findViewById(R.id.btn_back).setOnClickListener({ + // Handle back button click + onBackPressedDispatcher.onBackPressed() // Example action + }) + + // Set click listener for the close button + findViewById(R.id.btn_close).setOnClickListener({ + // Handle back button click + finish() // Example action + }) + + findViewById(R.id.place_order_button).setOnClickListener({ + // Handle back button click + finish() // Example action + }) + + val recyclerView: RecyclerView = findViewById(R.id.rv_items) // Replace with your RecyclerView ID + + val divider = DividerItemDecoration(this, DividerItemDecoration.VERTICAL) + divider.setDrawable(ContextCompat.getDrawable(this, R.drawable.recycler_view_devider)!!) + recyclerView.addItemDecoration(divider) + + // Sample data + val items = listOf( + CartItem( + iconResId = R.drawable.ic_cart_item, // Replace with your drawable resource + title = "Item 1", + price = "$43.88", + category = "Category 1", + note = "This is a note for Item 1" + ), + CartItem( + iconResId = R.drawable.ic_cart_item, + title = "Item 2", + price = "$43.88", + category = "Category 2", + note = "This is a note for Item 2" + ), + CartItem( + iconResId = R.drawable.ic_cart_item, + title = "Item 3", + price = "$43.87", + category = "Category 3", + note = "This is a note for Item 3" + ), + CartItem( + iconResId = R.drawable.ic_cart_item, + title = "Item 4", + price = "$43.87", + category = "Category 4", + note = "This is a note for Item 4" + ) + + ) + + // Set up RecyclerView + recyclerView.layoutManager = LinearLayoutManager(this) + recyclerView.adapter = CartAdapter(items) } + + data class CartItem( + val iconResId: Int, // Resource ID for the image + val title: String, // Title of the item + val price: String, // Price of the item + val category: String, // Category of the item + val note: String // Additional note + ) + + class CartAdapter(private val items: List) : + RecyclerView.Adapter() { + + // ViewHolder to hold references to views in the item layout + class CartViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val icon: ImageView = itemView.findViewById(R.id.icon) + val title: TextView = itemView.findViewById(R.id.cart_item_title) + val price: TextView = itemView.findViewById(R.id.cart_item_price_val) + val category: TextView = itemView.findViewById(R.id.cart_item_category) + val note: TextView = itemView.findViewById(R.id.cart_item_note) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.activity_cart_list_item, parent, false) // Replace with your item layout + return CartViewHolder(view) + } + + override fun onBindViewHolder(holder: CartViewHolder, position: Int) { + val item = items[position] + holder.icon.setImageResource(item.iconResId) + holder.title.text = item.title + holder.price.text = item.price + holder.category.text = item.category + holder.note.text = item.note + } + + override fun getItemCount(): Int = items.size + } + } \ 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..18fa10a 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,57 @@ package otus.gpb.homework.viewandresources -import androidx.appcompat.app.AppCompatActivity +import android.net.Uri import android.os.Bundle +import android.widget.ImageButton +import android.widget.Toast +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AppCompatActivity class ContactsActivity : AppCompatActivity() { + // Define the ActivityResultLauncher + private lateinit var filePickerLauncher: ActivityResultLauncher + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_contacts) + + // Set click listener for the back button + findViewById(R.id.btn_back).setOnClickListener({ + // Handle back button click + onBackPressedDispatcher.onBackPressed() // Example action + }) + + // Set click listener for the attach file icon + findViewById(R.id.btn_attach).setOnClickListener({ + // Handle attach file click + openFilePicker() // Example action + }) + + // Set click listener for the save button + findViewById(R.id.save_button).setOnClickListener({ + finish() // Example action + }) + + // Initialize the ActivityResultLauncher + filePickerLauncher = + registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> + if (uri != null) { + handleFileSelection(uri) + } else { + Toast.makeText(this, "No file selected", Toast.LENGTH_SHORT).show() + } + } + } + + + private fun openFilePicker() { + filePickerLauncher.launch("*/*") + } + + // Handle the selected file URI + private fun handleFileSelection(uri: Uri) { + Toast.makeText(this, "File selected: $uri", Toast.LENGTH_SHORT).show() + // Implement your logic to use the selected file } } \ 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..388b592 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt @@ -3,25 +3,99 @@ package otus.gpb.homework.viewandresources import android.content.Intent import android.os.Bundle import android.widget.Button +import android.widget.ImageButton +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.NotificationManagerCompat +import com.google.android.material.button.MaterialButton import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.textfield.TextInputEditText class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) findViewById