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
@Query("SELECT * FROM users") | |
fun getUsers(): Flowable<List<User>> |
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
@Query("SELECT * FROM users") | |
fun getUsers(): LiveData<List<User>> |
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 UserDao { | |
@Insert | |
fun insertAll(users: List<User>) | |
@Update | |
fun update(user: User) | |
@Delete |
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 = "users") | |
data class User( | |
@PrimaryKey(autoGenerate = true) | |
var id: Int = 0, | |
var name: String = "", | |
@Ignore | |
var secretId: String = "" | |
) |
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 = "users") | |
data class User( | |
@PrimaryKey(autoGenerate = true) | |
var id: Int = 0, | |
@ColumnInfo(name = "full_name") | |
var name: String = "" | |
) |
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 = "users", primaryKeys = arrayOf("id", "name")) | |
data class User( | |
var id: Int = 0, | |
var name: String = "" | |
) |
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 = "users") | |
data class User( | |
@PrimaryKey(autoGenerate = true) | |
var id: Int = 0, | |
var name: String = "" | |
) |
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 FileLiveData(private val context: Context) : LiveData<List<String>>() { | |
private val fileObserver: FileObserver | |
init { | |
val path = File(context.filesDir, "users.txt").path | |
fileObserver = object : FileObserver(path) { | |
override fun onEvent(event: Int, path: String?) { | |
// The file has changed, so let’s reload the data | |
loadData() | |
} |
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 UserViewModel() : ViewModel() { | |
/** | |
* The user | |
*/ | |
private var user: LiveData<User> | |
/** | |
* Full name of the user | |
*/ |
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 DetailUserActivity : LifecycleActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_detail) | |
// Get the ViewModel instance | |
val userViewModel = ViewModelProviders.of(this).get(UserViewModel::class.java) | |
userViewModel.setUserId(getSelectedUserId()) | |
userViewModel.getUser().observe(this, Observer { |