Skip to content

Commit

Permalink
fix #57
Browse files Browse the repository at this point in the history
  • Loading branch information
WirelessAlien committed Dec 3, 2024
1 parent 6c3dc84 commit c447c47
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FavoriteFragment : BaseFragment() {
private var pastVisibleItems = 0
private var visibleItemCount = 0
private var totalItemCount = 0
private var totalPages = 0

@Volatile
private var isLoadingData = false
Expand Down Expand Up @@ -94,6 +95,7 @@ class FavoriteFragment : BaseFragment() {
showIdSet.clear()
mShowAdapter.notifyDataSetChanged()
currentPage = 1
totalPages = 0
mListType = if ("movie" == mListType) "tv" else "movie"
loadFavoriteList(mListType, 1)
val fab = requireActivity().findViewById<FloatingActionButton>(R.id.fab)
Expand Down Expand Up @@ -142,7 +144,7 @@ class FavoriteFragment : BaseFragment() {
visibleThreshold
}
if (!loading && visibleItemCount + pastVisibleItems + threshold >= totalItemCount) {
if (mShowArrayList.isNotEmpty()) {
if (mShowArrayList.isNotEmpty() && hasMoreItemsToLoad()) {
currentPage++
loadFavoriteList(mListType, currentPage)
}
Expand Down Expand Up @@ -202,6 +204,7 @@ class FavoriteFragment : BaseFragment() {

try {
val reader = JSONObject(response)
totalPages = reader.getInt("total_pages")
val arrayData = reader.getJSONArray("results")
val newItems = mutableListOf<JSONObject>()
for (i in 0 until arrayData.length()) {
Expand All @@ -227,6 +230,10 @@ class FavoriteFragment : BaseFragment() {
loading = false
}

private fun hasMoreItemsToLoad(): Boolean {
return currentPage < totalPages
}

companion object {
private const val DEFAULT_MEDIA_TYPE = "key_default_media_type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class RatedListFragment : BaseFragment() {
private var pastVisibleItems = 0
private var visibleItemCount = 0
private var totalItemCount = 0
private var totalPages = 0

@Volatile
private var isLoadingData = false
Expand Down Expand Up @@ -94,6 +95,7 @@ class RatedListFragment : BaseFragment() {
showIdSet.clear()
mShowAdapter.notifyDataSetChanged()
currentPage = 1
totalPages = 0
mListType = if ("movie" == mListType) "tv" else "movie"
loadRatedList(mListType, 1)
val fab = requireActivity().findViewById<FloatingActionButton>(R.id.fab)
Expand Down Expand Up @@ -142,7 +144,7 @@ class RatedListFragment : BaseFragment() {
visibleThreshold
}
if (!loading && visibleItemCount + pastVisibleItems + threshold >= totalItemCount) {
if (mShowArrayList.isNotEmpty()) {
if (mShowArrayList.isNotEmpty() && hasMoreItemsToLoad()) {
currentPage++
loadRatedList(mListType, currentPage)
}
Expand Down Expand Up @@ -202,6 +204,7 @@ class RatedListFragment : BaseFragment() {

try {
val reader = JSONObject(response)
totalPages = reader.getInt("total_pages")
val arrayData = reader.getJSONArray("results")
val newItems = mutableListOf<JSONObject>()
for (i in 0 until arrayData.length()) {
Expand All @@ -227,6 +230,10 @@ class RatedListFragment : BaseFragment() {
loading = false
}

private fun hasMoreItemsToLoad(): Boolean {
return currentPage < totalPages
}

companion object {
private const val DEFAULT_MEDIA_TYPE = "key_default_media_type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class WatchlistFragment : BaseFragment() {
private var pastVisibleItems = 0
private var visibleItemCount = 0
private var totalItemCount = 0
private var totalPages = 0

@Volatile
private var isLoadingData = false
Expand Down Expand Up @@ -94,6 +95,7 @@ class WatchlistFragment : BaseFragment() {
showIdSet.clear()
mShowAdapter.notifyDataSetChanged()
currentPage = 1
totalPages = 0
mListType = if ("movie" == mListType) "tv" else "movie"
loadWatchList(mListType, 1)
val fab = requireActivity().findViewById<FloatingActionButton>(R.id.fab)
Expand Down Expand Up @@ -142,7 +144,7 @@ class WatchlistFragment : BaseFragment() {
visibleThreshold
}
if (!loading && visibleItemCount + pastVisibleItems + threshold >= totalItemCount) {
if (mShowArrayList.isNotEmpty()) {
if (mShowArrayList.isNotEmpty() && hasMoreItemsToLoad()) {
currentPage++
loadWatchList(mListType, currentPage)
}
Expand Down Expand Up @@ -202,6 +204,7 @@ class WatchlistFragment : BaseFragment() {

try {
val reader = JSONObject(response)
totalPages = reader.getInt("total_pages")
val arrayData = reader.getJSONArray("results")
val newItems = mutableListOf<JSONObject>()
for (i in 0 until arrayData.length()) {
Expand All @@ -227,6 +230,10 @@ class WatchlistFragment : BaseFragment() {
loading = false
}

private fun hasMoreItemsToLoad(): Boolean {
return currentPage < totalPages
}

companion object {
private const val DEFAULT_MEDIA_TYPE = "key_default_media_type"
}
Expand Down

0 comments on commit c447c47

Please sign in to comment.