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
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ import android.widget.Spinner
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputEditText
import org.w3c.dom.Text

class CreateTaskBottomSheet(
class CreateOrUpdateTaskBottomSheet(
private val categoryList: List<CategoryUiData>,
private val task: TaskUiData? = null,
private val onCreateClicked: (TaskUiData) -> Unit
) : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.create_task, container, false)
val view = inflater.inflate(R.layout.create_or_update_task_bottom_sheet, container, false)
val btnCreate = view.findViewById<Button>(R.id.btn_task_create)
val tieTaskName = view.findViewById<TextView>(R.id.tie_task_name)
val tvTitle = view.findViewById<TextView>(R.id.tv_title)
val tieTaskName = view.findViewById<TextInputEditText>(R.id.tie_task_name)
val catSpin = view.findViewById<Spinner>(R.id.category_list)
var taskCategory: String? = null
val categoryStr: List<String> = categoryList.map { it.name }
Expand Down Expand Up @@ -63,6 +67,22 @@ class CreateTaskBottomSheet(
Snackbar.make(btnCreate, "Please select a category", Snackbar.LENGTH_LONG).show()
}
}
if (task == null) {
tvTitle.setText(R.string.create_task_title)
btnCreate.setText(R.string.create)
} else {
tvTitle.setText(R.string.update_task_title)
btnCreate.setText(R.string.update)
tieTaskName.setText(task.name)

val currentCategory = categoryList.first{it.name == task.category}
catSpin.setSelection(categoryList.indexOf(currentCategory))



}

//
return view
}
}
18 changes: 11 additions & 7 deletions app/src/main/java/com/devspace/taskbeats/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.devspace.taskbeats
//Onde parei? Terminei aula 11 e parei nos 13:30 da aula 12 - que é click na lista de tarefas. ele vai debugar o código agora.
//Onde parei? Terminei aula 13 e devo iniciar a aula 14
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -12,7 +12,7 @@ import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
private var categoriess = listOf<CategoryUiData>()
private var taskss = listOf<TaskUiData>()
private val taskAdapter by lazy{
private val taskAdapter by lazy {
TaskListAdapter()
}
private val categoryAdapter = CategoryListAdapter()
Expand Down Expand Up @@ -46,6 +46,10 @@ class MainActivity : AppCompatActivity() {
showCreateUpdateTaskBottomSheet()
}

taskAdapter.setOnClickListener { task ->
showCreateUpdateTaskBottomSheet(task)
}

categoryAdapter.setOnClickListener { selected ->
if (selected.name == "+") {
val createCategoryBottomSheet = CreateCategoryBottomSheet { categoryName ->
Expand Down Expand Up @@ -85,9 +89,7 @@ class MainActivity : AppCompatActivity() {
getCategoriesFromDataBase()
}
rvTask.adapter = taskAdapter
taskAdapter.setOnClickListener {
showCreateUpdateTaskBottomSheet()
}


//categoryAdapter.submitList(categories)
GlobalScope.launch(Dispatchers.IO) {
Expand Down Expand Up @@ -173,8 +175,10 @@ class MainActivity : AppCompatActivity() {
}
}

private fun showCreateUpdateTaskBottomSheet() {
val createTaskBottomSheet = CreateTaskBottomSheet(categoriess)
private fun showCreateUpdateTaskBottomSheet(taskUiData: TaskUiData? = null) {
val createTaskBottomSheet = CreateOrUpdateTaskBottomSheet(
task = taskUiData,
categoryList = categoriess)
{ taskToBeCreated ->
val taskEntityToBeInsert = TaskEntity(
id = taskToBeCreated.id, //cuidado com essa porra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Create Task"
android:text="@string/create_task_title"
android:textSize="24sp"
android:textStyle="bold" />

Expand Down Expand Up @@ -46,7 +46,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Create" />
android:text="@string/create" />


</LinearLayout>
1 change: 0 additions & 1 deletion app/src/main/res/layout/item_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<resources>
<string name="app_name">TaskBeats</string>
<string name="app_name">TaskBeat</string>
<string name="home_title">Task Beat</string>
<string name="create_task_title">Create task</string>
<string name="create">Create</string>
<string name="update_task_title">Update task</string>
<string name="update">Update</string>
</resources>