存储pageToken
This commit is contained in:
parent
dbc6799b0a
commit
4de5c22139
|
|
@ -1,16 +1,23 @@
|
||||||
package com.gamedog.vididin
|
package com.gamedog.vididin
|
||||||
|
|
||||||
/**
|
object VidiConst {
|
||||||
* 描述:网络常量
|
/**
|
||||||
*
|
* 描述:网络常量
|
||||||
*/
|
*
|
||||||
const val URL_YOUTUBE_API = "https://www.googleapis.com"
|
*/
|
||||||
|
const val URL_YOUTUBE_API = "https://www.googleapis.com"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 描述:其他常量
|
* 描述:其他常量
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const val XXXX = "xxx"
|
const val YOUTUBE_API_KEY = "AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.gamedog.vididin.feature.home.api
|
package com.gamedog.vididin.feature.home.api
|
||||||
|
|
||||||
|
|
||||||
|
import com.gamedog.vididin.VidiConst
|
||||||
import com.gamedog.vididin.beans.ResYoutubeChannel
|
import com.gamedog.vididin.beans.ResYoutubeChannel
|
||||||
import com.gamedog.vididin.beans.ResYoutubePlayList
|
import com.gamedog.vididin.beans.ResYoutubePlayList
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
|
@ -17,7 +17,7 @@ interface YoutubeApi {
|
||||||
@GET("/youtube/v3/channels")
|
@GET("/youtube/v3/channels")
|
||||||
suspend fun getChannelList(
|
suspend fun getChannelList(
|
||||||
@Query("part") part: String="snippet",
|
@Query("part") part: String="snippet",
|
||||||
@Query("key") key: String="AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY",
|
@Query("key") key: String=VidiConst.YOUTUBE_API_KEY,
|
||||||
@Query("channelId") channelId: String="UCbTLwN10NoCU4WDzLf1JMOA",
|
@Query("channelId") channelId: String="UCbTLwN10NoCU4WDzLf1JMOA",
|
||||||
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
||||||
): ResYoutubeChannel
|
): ResYoutubeChannel
|
||||||
|
|
@ -29,7 +29,7 @@ interface YoutubeApi {
|
||||||
@GET("/youtube/v3/playlists")
|
@GET("/youtube/v3/playlists")
|
||||||
suspend fun getPlayList(
|
suspend fun getPlayList(
|
||||||
@Query("part") part: String="snippet",
|
@Query("part") part: String="snippet",
|
||||||
@Query("key") key: String="AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY",
|
@Query("key") key: String=VidiConst.YOUTUBE_API_KEY,
|
||||||
@Query("channelId") channelId: String="UCbTLwN10NoCU4WDzLf1JMOA",
|
@Query("channelId") channelId: String="UCbTLwN10NoCU4WDzLf1JMOA",
|
||||||
): ResYoutubePlayList
|
): ResYoutubePlayList
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ interface YoutubeApi {
|
||||||
@GET("/youtube/v3/playlistItems")
|
@GET("/youtube/v3/playlistItems")
|
||||||
suspend fun getVideoList1(
|
suspend fun getVideoList1(
|
||||||
@Query("part") part: String= URLEncoder.encode("id", "UTF-8"),
|
@Query("part") part: String= URLEncoder.encode("id", "UTF-8"),
|
||||||
@Query("key") key: String="AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY",
|
@Query("key") key: String=VidiConst.YOUTUBE_API_KEY,
|
||||||
@Query("playlistId") channelId: String="PLcVfz1-_0rj_KFKlQeW2ZJnWTSjgc-9Jp",
|
@Query("playlistId") channelId: String="PLcVfz1-_0rj_KFKlQeW2ZJnWTSjgc-9Jp",
|
||||||
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
||||||
//@Query("pageToken") pageToken: String=""
|
//@Query("pageToken") pageToken: String=""
|
||||||
|
|
@ -46,12 +46,12 @@ interface YoutubeApi {
|
||||||
@GET("/youtube/v3/videos")
|
@GET("/youtube/v3/videos")
|
||||||
suspend fun getVideoList(
|
suspend fun getVideoList(
|
||||||
@Query("part") part: String= URLEncoder.encode("id", "UTF-8"),
|
@Query("part") part: String= URLEncoder.encode("id", "UTF-8"),
|
||||||
@Query("key") key: String="AIzaSyBm9k2lS_j7Fdd43NEPkcfikJRotup5DMY",
|
@Query("key") key: String= VidiConst.YOUTUBE_API_KEY,
|
||||||
@Query("chart") chart: String="mostPopular",
|
@Query("chart") chart: String="mostPopular",
|
||||||
@Query("regionCode") regionCode: String="BR",
|
@Query("regionCode") regionCode: String="BR",
|
||||||
@Query("maxResults") maxResults: Int=10,
|
@Query("maxResults") maxResults: Int=3,
|
||||||
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
||||||
//@Query("pageToken") pageToken: String=""
|
@Query("pageToken") pageToken: String=""
|
||||||
): ResYoutubePlayList
|
): ResYoutubePlayList
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
package com.gamedog.vididin.di
|
package com.gamedog.vididin.di
|
||||||
|
|
||||||
|
|
||||||
import com.gamedog.vididin.URL_YOUTUBE_API
|
|
||||||
|
import com.gamedog.vididin.VidiConst.URL_YOUTUBE_API
|
||||||
import com.gamedog.vididin.core.network.di.GlobalInterceptor
|
import com.gamedog.vididin.core.network.di.GlobalInterceptor
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
|
|
@ -52,7 +53,6 @@ internal object NetworkModule {
|
||||||
.callFactory { okhttpCallFactory.get().newCall(it) }
|
.callFactory { okhttpCallFactory.get().newCall(it) }
|
||||||
.addConverterFactory(
|
.addConverterFactory(
|
||||||
GsonConverterFactory.create()
|
GsonConverterFactory.create()
|
||||||
//networkJson.asConverterFactory("application/json".toMediaType()),
|
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
|
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
|
||||||
import androidx.fragment.app.findFragment
|
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import com.ama.core.architecture.appBase.AppViewsFragment
|
import com.ama.core.architecture.appBase.AppViewsFragment
|
||||||
|
|
@ -61,6 +60,15 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
||||||
setHomeTabStyle(mViewPagerAdapter.getFragmentByIndex(position))
|
setHomeTabStyle(mViewPagerAdapter.getFragmentByIndex(position))
|
||||||
val curFragment: HomeItemFragment = mViewPagerAdapter.getFragmentByIndex(position) as HomeItemFragment
|
val curFragment: HomeItemFragment = mViewPagerAdapter.getFragmentByIndex(position) as HomeItemFragment
|
||||||
curFragment.loadVideo()
|
curFragment.loadVideo()
|
||||||
|
|
||||||
|
// load more
|
||||||
|
if (mViewPagerAdapter.itemCount > 0 && position == mViewPagerAdapter.itemCount - 2) {
|
||||||
|
// todo load more
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
super.onPageScrollStateChanged(state)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package com.gamedog.vididin.feature.home.repository
|
||||||
import com.gamedog.vididin.feature.home.api.YoutubeApi
|
import com.gamedog.vididin.feature.home.api.YoutubeApi
|
||||||
import com.gamedog.vididin.main.fragments.home.YoutubeDataSource
|
import com.gamedog.vididin.main.fragments.home.YoutubeDataSource
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.http.Query
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
|
@ -16,7 +17,6 @@ class DefaultYoutubeDatasource @Inject constructor(retrofit: Retrofit) : Youtube
|
||||||
override suspend fun getChannels(
|
override suspend fun getChannels(
|
||||||
) = shopApi.getChannelList()
|
) = shopApi.getChannelList()
|
||||||
|
|
||||||
override suspend fun getPlayList(
|
override suspend fun getVideoList(pageToken: String?) = shopApi.getVideoList()
|
||||||
) = shopApi.getVideoList()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -14,11 +14,13 @@ class DefaultYoutubeRepository @Inject constructor(
|
||||||
private val network: YoutubeDataSource,
|
private val network: YoutubeDataSource,
|
||||||
) : PageKeyedMemoryRefreshLoadMoreRepository<YoutubeVideo>(), YoutubeRepository {
|
) : PageKeyedMemoryRefreshLoadMoreRepository<YoutubeVideo>(), YoutubeRepository {
|
||||||
|
|
||||||
|
var mRespPlayList : ResYoutubePlayList? = null
|
||||||
|
|
||||||
override suspend fun getVideoList(
|
override suspend fun getVideoList(
|
||||||
page: Int,
|
page: Int,
|
||||||
size: Int
|
size: Int
|
||||||
): ResYoutubePlayList {
|
): ResYoutubePlayList {
|
||||||
return network.getPlayList()
|
return network.getVideoList(mRespPlayList?.nextPageToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getChannelList(
|
override suspend fun getChannelList(
|
||||||
|
|
@ -32,7 +34,8 @@ class DefaultYoutubeRepository @Inject constructor(
|
||||||
key: Int,
|
key: Int,
|
||||||
pageSize: Int
|
pageSize: Int
|
||||||
): List<YoutubeVideo>? {
|
): List<YoutubeVideo>? {
|
||||||
return getVideoList(key, pageSize).items
|
mRespPlayList = getVideoList(key, pageSize)
|
||||||
|
return mRespPlayList?.items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@ import com.gamedog.vididin.beans.ResYoutubePlayList
|
||||||
|
|
||||||
interface YoutubeDataSource {
|
interface YoutubeDataSource {
|
||||||
suspend fun getChannels(): ResYoutubeChannel
|
suspend fun getChannels(): ResYoutubeChannel
|
||||||
suspend fun getPlayList(): ResYoutubePlayList
|
suspend fun getVideoList(pageToken: String?): ResYoutubePlayList
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ class YoutubeViewModel @Inject constructor(
|
||||||
) : AppViewModel<YoutubeUiState>(), RefreshRepositoryOwner {
|
) : AppViewModel<YoutubeUiState>(), RefreshRepositoryOwner {
|
||||||
|
|
||||||
override val uiStateInitialValue: YoutubeUiState = YoutubeUiState()
|
override val uiStateInitialValue: YoutubeUiState = YoutubeUiState()
|
||||||
override val uiStateFlow: Flow<YoutubeUiState> = mRepository.result.map { listData ->
|
override val uiStateFlow: Flow<YoutubeUiState> = mRepository.dataListFlow.map { listData ->
|
||||||
YoutubeUiState(playLists = listData)
|
YoutubeUiState(playLists = listData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ abstract class BaseMemoryRefreshLoadMoreRepository<Key : Any?, Value : Any>(priv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val result: Flow<List<Value>?> = combine(getDataFlow, tempListFlow) { _, oldList ->
|
override val dataListFlow: Flow<List<Value>?> = combine(getDataFlow, tempListFlow) { _, oldList ->
|
||||||
// 每一次数据,都有提交,因为getDataFlow,不管成功与失败,始终有值在发出。
|
// 每一次数据,都有提交,因为getDataFlow,不管成功与失败,始终有值在发出。
|
||||||
oldList
|
oldList
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ package com.ama.core.architecture.page
|
||||||
|
|
||||||
interface OnRepositoryRefreshListener {
|
interface OnRepositoryRefreshListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* finish: the callback while 'refresh operation' over
|
||||||
|
*/
|
||||||
fun refresh(finish: (() -> Unit)? = null)
|
fun refresh(finish: (() -> Unit)? = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
|
|
||||||
@Suppress("KDocUnresolvedReference")
|
@Suppress("KDocUnresolvedReference")
|
||||||
// 刷新仓库
|
|
||||||
interface RefreshRepository<Value : Any> : OnRepositoryRefreshListener {
|
interface RefreshRepository<Value : Any> : OnRepositoryRefreshListener {
|
||||||
val loadState: MutableStateFlow<LoadState?>
|
val loadState: MutableStateFlow<LoadState?>
|
||||||
val result: Flow<List<Value>?>
|
val dataListFlow: Flow<List<Value>?>
|
||||||
//val resultBean: Flow<Value?>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue