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 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 { |
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
@Inject lateinit var viewModelFactory: AppViewModelFactory | |
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(MainActivityViewModel::class.java) } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
AndroidInjection.inject(this) | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
} |
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 = "SearchHistory") | |
data class History( | |
@PrimaryKey val search: String, | |
val history: Long | |
) |
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 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) |
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 = [(History::class), (Follower::class), (GithubUser::class)], version = 2) | |
abstract class AppDatabase: RoomDatabase() { | |
abstract fun historyDao(): HistoryDao | |
abstract fun githubUserDao(): GithubUserDao | |
abstract fun followersDao(): FollowersDao | |
} |
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
override | |
fun loadFromDb(): LiveData<List<Follower>> { | |
return followersDao.getFollowers(user, page, isFollowers) | |
} |
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
@Singleton | |
class GithubUserRepository @Inject | |
constructor(val githubUserDao: GithubUserDao, val service: GithubService) { | |
@InjectPreference lateinit var profile: Preference_UserProfile | |
init { | |
Timber.d("Injection GithubUserRepository") | |
PreferenceComponent_PrefAppComponent.getInstance().inject(this) | |
} |
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
@PreferenceEntity(name = "UserProfile") | |
open class Profile { | |
@KeyName(name = "name") @JvmField val userName = "skydoves" | |
@KeyName(name = "menuPosition") @JvmField val selectedPosition = 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
@PreferenceComponent(entities = [(Profile::class)]) | |
interface PrefAppComponent { | |
fun inject(target: SearchActivityViewModel) | |
fun inject(target: DetailActivityViewModel) | |
fun inject(target: GithubUserRepository) | |
} |
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
@InjectPreference lateinit var profile: Preference_UserProfile | |
init { | |
Timber.d("Injection GithubUserRepository") | |
PreferenceComponent_PrefAppComponent.getInstance().inject(this) | |
} |