Skip to content

Instantly share code, notes, and snippets.

Coffee coffee

Jaewoong Eum skydoves

Coffee coffee
Block or report user

Report or block skydoves

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
skydoves / GithubUserRepository.kt
Last active Mar 16, 2018
View GithubUserRepository.kt
class GithubUserRepository @Inject
constructor(val githubUserDao: GithubUserDao, val service: GithubService) {
@InjectPreference lateinit var profile: Preference_UserProfile
init {
Timber.d("Injection GithubUserRepository")
View loadFromDb.kt
fun loadFromDb(): LiveData<List<Follower>> {
return followersDao.getFollowers(user, page, isFollowers)
View AppDatabase.kt
@Database(entities = [(History::class), (Follower::class), (GithubUser::class)], version = 2)
abstract class AppDatabase: RoomDatabase() {
abstract fun historyDao(): HistoryDao
abstract fun githubUserDao(): GithubUserDao
abstract fun followersDao(): FollowersDao
View HistoryDao.kt
interface HistoryDao {
@Query("SELECT* FROM SearchHistory ORDER BY history DESC LIMIT 20")
fun selectRecentHistoryList(): LiveData<List<History>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertHistory(history: History)
@Query("DELETE FROM SearchHistory WHERE search = :search")
fun deleteHistory(search: String)
View History.kt
@Entity(tableName = "SearchHistory")
data class History(
@PrimaryKey val search: String,
val history: Long
skydoves / InjectionExampleMainActivity.kt
Last active Mar 15, 2018
View InjectionExampleMainActivity.kt
@Inject lateinit var viewModelFactory: AppViewModelFactory
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get( }
override fun onCreate(savedInstanceState: Bundle?) {
View SearchActivityViewModel.kt
class SearchActivityViewModel @Inject
constructor(private val githubUserRepository: GithubUserRepository, private val historyRepository: HistoryRepository): ViewModel() {
val login: MutableLiveData<String> = MutableLiveData()
var githubUserLiveData: LiveData<Resource<GithubUser>> = MutableLiveData()
val historiesLiveData: MutableLiveData<List<History>> = MutableLiveData()
val toast: MutableLiveData<String> = MutableLiveData()
init {
public class AppViewModelFactory implements ViewModelProvider.Factory {
private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators;
public AppViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
this.creators = creators;
View PreferenceRoom_kotlin2.kt
lateinit var component: PreferenceComponent_UserProfileComponent
override fun onCreate(savedInstanceState: Bundle?) {
PreferenceComponent_UserProfileComponent.getInstance().inject(this) // inject dependency injection to MainActivity.
View PreferenceRoom_kotlin1.kt
@PreferenceComponent(entities = arrayOf(Profile::class, Device::class))
interface UserProfileComponent {
* declare dependency injection targets.
fun inject(target: MainActivity)
fun inject(target: LoginActivity)
You can’t perform that action at this time.