This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun apagarPalestrante() { | |
AlertDialog.Builder(requireContext()).apply { | |
setTitle("Deseja realmente apagar?") | |
setNegativeButton("Não") { _, _ -> | |
} | |
setPositiveButton("Sim") { _, _ -> | |
launch { | |
context.let { | |
PalestranteDB.getDatabase(it).dao().apagar(mPalestrante!!) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<Button | |
android:id="@+id/room_btn_apagar" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="32dp" | |
android:text="@string/txt_apagar" | |
android:visibility="invisible" | |
app:layout_constraintEnd_toEndOf="@+id/room_btn_salvar" | |
app:layout_constraintStart_toStartOf="@+id/room_btn_salvar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
private var mPalestrante: Palestrante? = null | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
launch { | |
context?.let { | |
if (mPalestrante != null) { | |
palestrante.id = mPalestrante!!.id | |
PalestranteDB.getDatabase(it).dao().actualizar(palestrante) | |
Toast.makeText(it, "Palestrante actualizado!", Toast.LENGTH_SHORT).show() | |
} else { | |
PalestranteDB.getDatabase(it).dao().salvar(palestrante) | |
Toast.makeText(it, "Cadastro com sucesso!", Toast.LENGTH_SHORT).show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
holder.view.setOnClickListener { | |
val action = HomeFragmentDirections.toSpeakersFragment() | |
action.palestrante = palestrantes[position] | |
Navigation.findNavController(it).navigate(action) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
rv_room.setHasFixedSize(true) | |
rv_room.layoutManager = LinearLayoutManager(context) | |
launch { | |
context?.let { | |
val palestrantes = PalestranteDB.getDatabase(it).dao().buscarTodos() | |
rv_room.adapter = PalestranteAdapter(palestrantes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PalestranteAdapter(private val palestrantes: List<Palestrante>) : | |
RecyclerView.Adapter<PalestranteAdapter.PalestranteViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = PalestranteViewHolder( | |
LayoutInflater.from(parent.context).inflate(R.layout.palestrante_item, parent, false) | |
) | |
override fun onBindViewHolder(holder: PalestranteViewHolder, position: Int) { | |
holder.view.room_item_txt_nome.text = palestrantes[position].palestrante | |
holder.view.room_item_txt_tecnologia.text = palestrantes[position].tecnologia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<TextView | |
android:id="@+id/room_item_txt_nome" | |
android:layout_width="0dp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
room_btn_salvar.setOnClickListener { | |
val palestrante = Palestrante( | |
palestrante = room_et_nome.text.toString(), | |
tecnologia = room_et_tecnologia.text.toString(), | |
topico = room_et_topico.text.toString() | |
) |