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 A(private val b: B) { | |
b.doSomething() | |
} | |
class B { | |
fun doSomething | |
} |
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 A { | |
val b = B() | |
b.doSomething() | |
} | |
class B { | |
fun doSomething | |
} |
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 ApplicationClass : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
val constraint = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.CONNECTED) | |
.build() | |
val workManager = WorkManager.getInstance(applicationContext) |
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 = [User::class], | |
version = 1, | |
exportSchema = false | |
) | |
abstract class DatabaseClass : RoomDatabase() { | |
abstract fun userDao(): UserDao | |
companion object { | |
private var instance: DatabaseClass? = 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
@Dao | |
interface UserDao { | |
@Query("SELECT * FROM user") | |
fun getUsers(): LiveData<List<User>> | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun saveUsers(user: User) | |
@Query("DELETE FROM user") | |
fun deleteAll() |
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
import androidx.room.Entity | |
import androidx.room.PrimaryKey | |
@Entity(tableName = "user") | |
data class User( | |
@PrimaryKey | |
val id: String, | |
val firstName: String, | |
val lastName: 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
//ActivityViewModel.kt | |
private val _textToShow = MutableLiveData<String>() | |
val textToShow : LiveData<String>() | |
get() = textToShow | |
fun buttonClicked(){ | |
_textToShow.value = "Hello" | |
} |
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 CourseAdapter(private val viewModel: CourseViewModel) : | |
ListAdapter<Course, ViewHolder>(CourseDiffCallback()) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val inflater = LayoutInflater.from(parent.context) | |
return ViewHolder(inflater.inflate(R.layout.course_item, parent, false)) | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.bind(viewModel, getItem(position)) | |
} |
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 val userId = MutableLiveData<String>() | |
val userDetails = userId.switchMap { | |
userRepo.getUser(it) | |
} | |
val userFullName = userDetails.map { | |
getFullName(it.firstName, it.lastName) | |
} |