Skip to content

Instantly share code, notes, and snippets.

View manuelernesto's full-sized avatar
🟣

Manuel Ernesto manuelernesto

🟣
View GitHub Profile
class HomeFragment : StandardFragment() {
...
}
class SpeakersFragment : StandardFragment() {
...
}
open class StandardFragment:Fragment(),CoroutineScope {
private lateinit var job: Job
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
job = Job()
@Database(entities = [Palestrante::class], version = 1)
abstract class PalestranteDB: RoomDatabase() {
abstract fun dao(): PalestranteDAO
companion object {
@Volatile
private var TALK_INSTANCE: PalestranteDB? = null
fun getDatabase(context: Context): PalestranteDB {
@Dao
interface PalestranteDAO {
@Insert
suspend fun salvar(palestrante: Palestrante)
@Query("SELECT * FROM tb_palestrante")
suspend fun buscarTodos(): List<Palestrante>
@Update
suspend fun actualizar(palestrante: Palestrante)
@Entity(tableName = "tb_palestrante")
data class Palestrante(
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
@ColumnInfo(name = "nome_palestrante")
val palestrante: String,
val tecnologia: String,
val topico: String
):Serializable
apply plugin: 'kotlin-kapt'
implementation "androidx.room:room-ktx:$room_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
implementation "androidx.room:room-ktx:$room_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
class MainActivity : AppCompatActivity() {
private lateinit var mNavController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
...