Skip to content

Instantly share code, notes, and snippets.

View vprabhu's full-sized avatar

Vignesh Prabhu vprabhu

View GitHub Profile
var mTodoTaskList : LiveData<List<TodoTask>> = mDatabase.todoTaskDao().getallTasks()
mTodoTaskList.observe(
this ,
Observer<List<TodoTask>>() {
Log.d("List" , it?.size.toString())
if (it != null) {
mTodoTaskAdapters = TodoTaskAdapters(this , it)
mTaskRecyclerView.layoutManager = LinearLayoutManager(
this.applicationContext ,
LinearLayout.VERTICAL , false)
@Dao
interface TodoTaskDao {
@Query("select * from todotasks order by id")
fun getallTasks(): LiveData<List<TodoTask>>
@Insert
fun insertTodoTask(todoTask: TodoTask)
@Update(onConflict = OnConflictStrategy.REPLACE)
implementation "android.arch.lifecycle:extensions:1.1.0"
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
@Database(entities = arrayOf(TodoTask::class), version = 1, exportSchema = false)
@TypeConverters(DataConverter::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun todoTaskDao(): TodoTaskDao
companion object {
private val LOCK = Any()
private val DATABASE_NAME = "todotaskList"
object DateConverter {
@TypeConverter
fun toDate(timestamp: Long?): Date? {
return if (timestamp == null) null else Date(timestamp)
}
@TypeConverter
fun toTimestamp(date: Date?): Long? {
return date?.time
@Dao
interface TodoTaskDao {
@Query("select * from todotasks order by id")
fun getallTasks(): List<TodoTask>
@Insert
fun insertTodoTask(todoTask: TodoTask)
@Update(onConflict = OnConflictStrategy.REPLACE)
@Entity(tableName = "todotasks")
class TodoTask(@field:PrimaryKey(autoGenerate = true)
var id: Int, var name: String?, @field:ColumnInfo(name = "due_date")
var dueDate: Date?)
compile "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
@vprabhu
vprabhu / kotlin_toplevelfunction.csv
Last active March 21, 2018 10:26
TopLevelFunction in Kotlin
Java Kotlin
Keywords used : public & static no keywords
Class Instance is required to call a method No class instance is required to call a function
LoadersDemo