Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
PGSongJie committed Aug 24, 2020
1 parent 88c9293 commit 7900fcf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PokemonRepositoryImpl(
val mapper2InfoModel: Mapper<PokemonInfoEntity, PokemonInfoModel>
) : Repository {

override fun featchPokemonList(): Flow<PagingData<PokemonItemModel>> {
override fun fetchPokemonList(): Flow<PagingData<PokemonItemModel>> {
return Pager(
config = pageConfig,
remoteMediator = PokemonRemoteMediator(api, db)
Expand All @@ -60,7 +60,7 @@ class PokemonRepositoryImpl(
}
}

override suspend fun featchPokemonInfo(name: String): Flow<PokemonResult<PokemonInfoModel>> {
override suspend fun fetchPokemonInfo(name: String): Flow<PokemonResult<PokemonInfoModel>> {
return flow {
try {
val pokemonDao = db.pokemonInfoDao()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlinx.coroutines.flow.Flow
* </pre>
*/
interface Repository {
fun featchPokemonList(): Flow<PagingData<PokemonItemModel>>
fun fetchPokemonList(): Flow<PagingData<PokemonItemModel>>

suspend fun featchPokemonInfo(name: String): Flow<PokemonResult<PokemonInfoModel>>
suspend fun fetchPokemonInfo(name: String): Flow<PokemonResult<PokemonInfoModel>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import kotlinx.coroutines.launch
* </pre>
*/
class DetailViewModel @ViewModelInject constructor(
val polemonRepository: Repository
private val pokemonRepository: Repository
) : ViewModel() {
val mLoading = ObservableBoolean()

Expand All @@ -56,7 +56,7 @@ class DetailViewModel @ViewModelInject constructor(
*/
@OptIn(ExperimentalCoroutinesApi::class)
fun fectchPokemonInfo2(name: String) = liveData<PokemonInfoModel> {
polemonRepository.featchPokemonInfo(name)
pokemonRepository.fetchPokemonInfo(name)
.onStart {
// 在调用 flow 请求数据之前,做一些准备工作,例如显示正在加载数据的按钮
mLoading.set(true)
Expand Down Expand Up @@ -84,8 +84,8 @@ class DetailViewModel @ViewModelInject constructor(
* 方法三
*/
@OptIn(ExperimentalCoroutinesApi::class)
suspend fun fectchPokemonInfo3(name: String) =
polemonRepository.featchPokemonInfo(name)
suspend fun fetchPokemonInfo3(name: String) =
pokemonRepository.fetchPokemonInfo(name)
.onStart {
// 在调用 flow 请求数据之前,做一些准备工作,例如显示正在加载数据的按钮
mLoading.set(true)
Expand All @@ -103,8 +103,8 @@ class DetailViewModel @ViewModelInject constructor(
* 方法一
*/
@OptIn(ExperimentalCoroutinesApi::class)
fun fectchPokemonInfo1(name: String) = viewModelScope.launch {
polemonRepository.featchPokemonInfo(name)
fun fetchPokemonInfo1(name: String) = viewModelScope.launch {
pokemonRepository.fetchPokemonInfo(name)
.onStart {
// 在调用 flow 请求数据之前,做一些准备工作,例如显示正在加载数据的按钮
mLoading.set(true)
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/hi/dhl/pokemon/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ import kotlinx.coroutines.launch

@AndroidEntryPoint
class MainActivity : DataBindingAppCompatActivity() {
private val mBidning: ActivityMainBinding by binding(R.layout.activity_main)
private val mBinding: ActivityMainBinding by binding(R.layout.activity_main)
private val mViewModel: MainViewModel by viewModels()
private val mPomemonAdapter by lazy { PokemonAdapter() }
private val mPokemonAdapter by lazy { PokemonAdapter() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBidning.apply {
recyleView.adapter = mPomemonAdapter.withLoadStateFooter(FooterAdapter(mPomemonAdapter))
mBinding.apply {
recyleView.adapter = mPokemonAdapter.withLoadStateFooter(FooterAdapter(mPokemonAdapter))
mainViewModel = mViewModel
lifecycleOwner = this@MainActivity
}

mViewModel.postOfData().observe(this, Observer {
mPomemonAdapter.submitData(lifecycle, it)
mPokemonAdapter.submitData(lifecycle, it)
swiperRefresh.isEnabled = false
})

lifecycleScope.launchWhenCreated {
mPomemonAdapter.loadStateFlow.collectLatest { state ->
mPokemonAdapter.loadStateFlow.collectLatest { state ->
swiperRefresh.isRefreshing = state.refresh is LoadState.Loading
}
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/hi/dhl/pokemon/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ import com.hi.dhl.pokemon.model.PokemonItemModel
*/

class MainViewModel @ViewModelInject constructor(
val polemonRepository: Repository
private val pokemonRepository: Repository
) : ViewModel() {

fun postOfData(): LiveData<PagingData<PokemonItemModel>> =
polemonRepository.featchPokemonList().cachedIn(viewModelScope).asLiveData()

pokemonRepository.fetchPokemonList().cachedIn(viewModelScope).asLiveData()
}

0 comments on commit 7900fcf

Please sign in to comment.