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
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) |
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
@Dao | |
interface TodoTaskDao { | |
@Query("select * from todotasks order by id") | |
fun getallTasks(): LiveData<List<TodoTask>> | |
@Insert | |
fun insertTodoTask(todoTask: TodoTask) | |
@Update(onConflict = OnConflictStrategy.REPLACE) |
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
implementation "android.arch.lifecycle:extensions:1.1.0" | |
annotationProcessor "android.arch.lifecycle:compiler:1.1.0" |
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
@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" |
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
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 |
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
@Dao | |
interface TodoTaskDao { | |
@Query("select * from todotasks order by id") | |
fun getallTasks(): List<TodoTask> | |
@Insert | |
fun insertTodoTask(todoTask: TodoTask) | |
@Update(onConflict = OnConflictStrategy.REPLACE) |
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
@Entity(tableName = "todotasks") | |
class TodoTask(@field:PrimaryKey(autoGenerate = true) | |
var id: Int, var name: String?, @field:ColumnInfo(name = "due_date") | |
var dueDate: Date?) |
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
compile "android.arch.persistence.room:runtime:1.0.0" | |
annotationProcessor "android.arch.persistence.room:compiler:1.0.0" |
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
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 |
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
LoadersDemo |