Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3b44b9b
Terminei as duas aulas: 12 e 13
alanliongar Jul 4, 2024
2955bdd
Terminei as duas aulas: 12 e 13
alanliongar Jul 5, 2024
4dcbfbd
Terminei as duas aulas: 12 e 13
alanliongar Jul 5, 2024
cc6fb81
Terminei a aula: 15
alanliongar Jul 5, 2024
aa03392
Terminei a aula: 15
alanliongar Jul 5, 2024
5b4af7c
Terminei a aula: 15
alanliongar Jul 9, 2024
0b9a037
Terminei a aula: 15
alanliongar Jul 9, 2024
80da605
Terminei a aula: 15
alanliongar Jul 9, 2024
18b8b3a
Terminei as duas aulas: 12 e 13
alanliongar Jul 4, 2024
87708af
Terminei as duas aulas: 12 e 13
alanliongar Jul 5, 2024
09cda52
Terminei as duas aulas: 12 e 13
alanliongar Jul 5, 2024
0b17484
Terminei a aula: 15
alanliongar Jul 5, 2024
09c48b5
Terminei a aula: 15
alanliongar Jul 5, 2024
b2113bb
Terminei a aula: 15
alanliongar Jul 9, 2024
1e545e9
Terminei a aula: 15
alanliongar Jul 9, 2024
77a6f7f
Terminei a aula: 15
alanliongar Jul 9, 2024
98266c4
Merge remote-tracking branch 'origin/aula-16' into aula-16
alanliongar Jul 9, 2024
084cfd9
Terminei a aula: 16 com uma observação:
alanliongar Jul 9, 2024
568733b
Terminei a aula: 17 - deletando apenas a categoria.
alanliongar Jul 10, 2024
86e76e3
Terminei a aula: 18 - deletando apenas a categoria - detalhamento: cr…
alanliongar Jul 10, 2024
8a69648
Terminei a aula: 19 - nela aprendemos a relacionar as tabelas criando…
alanliongar Jul 10, 2024
7554db8
Terminei a aula: 19 - nela aprendemos a relacionar as tabelas criando…
alanliongar Jul 10, 2024
2a166db
Terminei a aula: 20 - nela eu tive uma grande dor de cabeça, coloquei…
alanliongar Jul 10, 2024
4a70057
Terminei a aula: 20 - nela eu tive uma grande dor de cabeça, coloquei…
alanliongar Jul 10, 2024
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.

8 changes: 6 additions & 2 deletions app/src/main/java/com/devspace/taskbeats/CategoryDao.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.devspace.taskbeats

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
Expand All @@ -11,11 +12,14 @@ interface CategoryDao {
@Query("Select * From categoryentity")
fun getAll(): List<CategoryEntity>

@Insert(onConflict = OnConflictStrategy.REPLACE)
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insetAll(categoryEntity: List<CategoryEntity>) //removemos o vararg e usamos a lista
//mesmo com a documentação dizendo pra usar vararg e nao usar lista.

@Insert(onConflict = OnConflictStrategy.REPLACE)
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun inset(categoryEntity: CategoryEntity)

@Delete
fun delete(categoryEntity: CategoryEntity)

}
15 changes: 13 additions & 2 deletions app/src/main/java/com/devspace/taskbeats/CategoryListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ class CategoryListAdapter :
ListAdapter<CategoryUiData, CategoryListAdapter.CategoryViewHolder>(CategoryListAdapter) {

private var onClick: (CategoryUiData) -> Unit = {} //optei por inicializar SEMPRE, por padrão, como uma função VAZIA, pra nao dar crash caso eu nao inicialize
private lateinit var onLongClick: (CategoryUiData) -> Unit

fun setOnClickListener(onClick: (CategoryUiData) -> Unit) {
this.onClick = onClick
}

fun setOnLongClickListener(onLongClick: (CategoryUiData) -> Unit){
this.onLongClick = onLongClick
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.item_category, parent, false)
Expand All @@ -25,19 +30,25 @@ class CategoryListAdapter :

override fun onBindViewHolder(holder: CategoryViewHolder, position: Int) {
val category = getItem(position)
holder.bind(category, onClick)
holder.bind(category, onClick, onLongClick)
}

class CategoryViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
private val tvCategory = view.findViewById<TextView>(R.id.tv_category)

fun bind(category: CategoryUiData, onClick: (CategoryUiData) -> Unit) {
fun bind(category: CategoryUiData, onClick: (CategoryUiData) -> Unit, onLongClick: (CategoryUiData) -> Unit) {
tvCategory.text = category.name
tvCategory.isSelected = category.isSelected

view.setOnClickListener {
onClick.invoke(category)
}

view.setOnLongClickListener {
onLongClick.invoke(category)
true
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.devspace.taskbeats

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.Spinner
import android.widget.TextView
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputEditText

class CreateOrUpdateTaskBottomSheet(
private val categoryList: List<CategoryUiData>,
private val task: TaskUiData? = null,
private val onCreateClicked: (TaskUiData) -> Unit,
private val onUpdateClicked: (TaskUiData) -> Unit,
private val onDeleteClicked: (TaskUiData) -> Unit
) : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.create_or_update_task_bottom_sheet, container, false)
val btnCreateOrUpdate = view.findViewById<Button>(R.id.btn_task_create_or_update)
val btnDelete = view.findViewById<Button>(R.id.btn_task_delete)
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 }
ArrayAdapter(
requireActivity().baseContext,
android.R.layout.simple_spinner_item,
categoryStr.toList()
).also { adapter ->
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item)
catSpin.adapter = adapter
}
catSpin.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
taskCategory = categoryStr.get(position)
}

override fun onNothingSelected(parent: AdapterView<*>?) {

}
}



btnCreateOrUpdate.setOnClickListener {
val name = tieTaskName.text.toString().trim()
if (taskCategory != null && name.isNotEmpty()) {
if (task == null) {
onCreateClicked.invoke(
TaskUiData(
id = 0,
name = name,
category = requireNotNull(taskCategory)
)
)
dismiss()
} else {
onUpdateClicked.invoke(
TaskUiData(
id = task.id,
name = name,
category = requireNotNull(taskCategory)
)
)
dismiss()
}


} else {
Snackbar.make(btnCreateOrUpdate, "Please select a category", Snackbar.LENGTH_LONG)
.show()
}
}
if (task == null) {
btnDelete.isVisible = false
tvTitle.setText(R.string.create_task_title)
btnCreateOrUpdate.setText(R.string.create)
} else {
tvTitle.setText(R.string.update_task_title)
btnCreateOrUpdate.setText(R.string.update)
tieTaskName.setText(task.name)
btnDelete.isVisible = true
btnDelete.setOnClickListener {
if (task != null) {
onDeleteClicked.invoke(task)
dismiss()
} else {
Log.d("CreateOrUpdateTaskBottomSheet", "Task not found")
}
}
val currentCategory = categoryList.first { it.name == task.category }
catSpin.setSelection(categoryList.indexOf(currentCategory))
}
return view
}
}
68 changes: 0 additions & 68 deletions app/src/main/java/com/devspace/taskbeats/CreateTaskBottomSheet.kt

This file was deleted.

43 changes: 43 additions & 0 deletions app/src/main/java/com/devspace/taskbeats/InfoBottomSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.devspace.taskbeats

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

class InfoBottomSheet(
private val title: String,
private val description: String,
private val btnText: String,
private val onClicked: () -> Unit
) : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.info_bottom_sheet, container, false)
val btnDelete = view.findViewById<Button>(R.id.btn_yes)
val btnNotDelete = view.findViewById<Button>(R.id.btn_no)
val tvTitle = view.findViewById<TextView>(R.id.tv_info_title)
val tvDesc = view.findViewById<TextView>(R.id.tv_info_description)

tvTitle.text = title
tvDesc.text = description
btnDelete.text = btnText

btnDelete.setOnClickListener {
onClicked.invoke()
dismiss()
}

btnNotDelete.setOnClickListener {
dismiss()
}

return view
}
}
Loading