feat(createEvent): Add ui for category adding
This commit is contained in:
parent
82de68633d
commit
24b6791a76
|
@ -9,20 +9,26 @@ import android.os.Bundle
|
|||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageButton
|
||||
import android.widget.Toast
|
||||
import android.widget.ViewSwitcher
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.dhaval2404.colorpicker.ColorPickerDialog
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.google.gson.Gson
|
||||
import com.p_vacho.neat_calendar.R
|
||||
import com.p_vacho.neat_calendar.adapters.CategoryChipAdapter
|
||||
import com.p_vacho.neat_calendar.api.RetrofitClient
|
||||
import com.p_vacho.neat_calendar.api.models.CategoryResponse
|
||||
import com.p_vacho.neat_calendar.api.models.EventRequest
|
||||
import com.p_vacho.neat_calendar.api.models.EventResponse
|
||||
import com.p_vacho.neat_calendar.api.models.ValidationError
|
||||
|
@ -45,7 +51,12 @@ class CreateEventActivity : AppCompatActivity() {
|
|||
private lateinit var txtEndTime: TextInputEditText
|
||||
private lateinit var btnCreateEvent: MaterialButton
|
||||
private lateinit var btnColorPicker: MaterialButton
|
||||
private lateinit var addCategoryButton: ImageButton
|
||||
private lateinit var categoryRecyclerView: RecyclerView
|
||||
private lateinit var categoryViewSwitcher: ViewSwitcher
|
||||
|
||||
private lateinit var eventCategories: MutableList<CategoryResponse>
|
||||
private lateinit var allCategories: List<CategoryResponse>
|
||||
private lateinit var defaultDate: LocalDate
|
||||
|
||||
private var instantEvent: Boolean = true
|
||||
|
@ -66,8 +77,13 @@ class CreateEventActivity : AppCompatActivity() {
|
|||
val dateString = intent.getStringExtra("date")!!
|
||||
defaultDate = LocalDate.parse(dateString)
|
||||
|
||||
// TODO: Fetch the available categories from the API
|
||||
allCategories = emptyList()
|
||||
eventCategories = mutableListOf()
|
||||
|
||||
initializeViews()
|
||||
setupListeners()
|
||||
updateCategoryView()
|
||||
}
|
||||
|
||||
private fun initializeViews() {
|
||||
|
@ -80,6 +96,13 @@ class CreateEventActivity : AppCompatActivity() {
|
|||
txtEndTime = findViewById(R.id.txtEndTime)
|
||||
btnCreateEvent = findViewById(R.id.btnCreateEvent)
|
||||
btnColorPicker = findViewById(R.id.btnColorPicker)
|
||||
addCategoryButton = findViewById(R.id.btnAddCategory)
|
||||
categoryViewSwitcher = findViewById(R.id.categoryViewSwitcher)
|
||||
categoryRecyclerView = findViewById(R.id.categoryChipRecyclerView)
|
||||
|
||||
categoryRecyclerView.layoutManager =
|
||||
LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
|
||||
categoryRecyclerView.adapter = CategoryChipAdapter(eventCategories, true, ::onCategoryRemoved)
|
||||
|
||||
selectedColor = ContextCompat.getColor(this, R.color.event_indicator_color)
|
||||
}
|
||||
|
@ -122,10 +145,33 @@ class CreateEventActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
addCategoryButton.setOnClickListener { addCategory() }
|
||||
btnColorPicker.setOnClickListener { openColorPickerDialog() }
|
||||
btnCreateEvent.setOnClickListener { createEvent() }
|
||||
}
|
||||
|
||||
private fun addCategory() {
|
||||
// This should probably open some modal with a dropdown
|
||||
// showing all the available categories (without the already picked ones)
|
||||
|
||||
var newCategory = TODO("Implement category adding")
|
||||
if (newCategory == null) return
|
||||
|
||||
eventCategories.add(newCategory)
|
||||
categoryRecyclerView.adapter!!.notifyItemInserted(eventCategories.size - 1)
|
||||
updateCategoryView()
|
||||
}
|
||||
|
||||
/**
|
||||
* This is triggered by the CategoryChipAdapter, when the remove button on
|
||||
* the category chip was clicked.
|
||||
*/
|
||||
private fun onCategoryRemoved(category: CategoryResponse, position: Int) {
|
||||
TODO("Implement category removing")
|
||||
|
||||
updateCategoryView()
|
||||
}
|
||||
|
||||
private fun createEvent() {
|
||||
val title = etEventTitle.text.toString()
|
||||
val description = etEventDescription.text.toString()
|
||||
|
@ -222,4 +268,12 @@ class CreateEventActivity : AppCompatActivity() {
|
|||
private fun formatDateTime(dateTime: LocalDateTime?): String {
|
||||
return dateTime?.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")) ?: "Select Time"
|
||||
}
|
||||
|
||||
private fun updateCategoryView() {
|
||||
if (eventCategories.isEmpty()) {
|
||||
categoryViewSwitcher.displayedChild = 1 // Show placeholder text
|
||||
} else {
|
||||
categoryViewSwitcher.displayedChild = 0 // Show RecyclerView
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import com.p_vacho.neat_calendar.api.models.CategoryResponse
|
|||
class CategoryChipAdapter(
|
||||
private val categories: List<CategoryResponse>,
|
||||
private val isRemovable: Boolean = false,
|
||||
private val onRemoveCategory: ((CategoryResponse) -> Unit)? = null
|
||||
private val onRemoveCategory: ((CategoryResponse, Int) -> Unit)? = null
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
inner class CategoryViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView)
|
||||
|
@ -50,7 +50,7 @@ class CategoryChipAdapter(
|
|||
holder.textView.backgroundTintList = ColorStateList.valueOf(category.color.toArgb())
|
||||
|
||||
holder.removeButton.setOnClickListener {
|
||||
onRemoveCategory?.invoke(category)
|
||||
onRemoveCategory?.invoke(category, position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.p_vacho.neat_calendar.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
|
@ -128,6 +128,55 @@
|
|||
app:cornerRadius="8dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
|
||||
|
||||
<!-- Categories Section -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ViewSwitcher
|
||||
android:id="@+id/categoryViewSwitcher"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:animateFirstView="true">
|
||||
|
||||
<!-- RecyclerView for categories -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/categoryChipRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/item_removable_category_chip"
|
||||
tools:itemCount="3"
|
||||
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:orientation="horizontal" />
|
||||
|
||||
<!-- Placeholder Text, when there aren't any categories -->
|
||||
<TextView
|
||||
android:id="@+id/txtPlaceholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="@string/add_category"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:textColor="?attr/colorOnSurface" />
|
||||
</ViewSwitcher>
|
||||
|
||||
<!-- Add Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnAddCategory"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_add"
|
||||
app:tint="?attr/colorPrimary"
|
||||
android:contentDescription="@string/add_category" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Create Button -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnCreateEvent"
|
||||
|
|
|
@ -42,4 +42,5 @@
|
|||
<string name="create_event">Create Event</string>
|
||||
<string name="select_color">Select Color</string>
|
||||
<string name="remove_category">Remove the category</string>
|
||||
<string name="add_category">Add category</string>
|
||||
</resources>
|
Loading…
Reference in a new issue