-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Running Content List UI #495
Conversation
if (loadState is LoadState.Error) { | ||
if (loadState.error.localizedMessage?.contains("404") == true){ | ||
binding.emptyTitle.text = "Content Not Found" | ||
binding.emptyDescription.text = "Content Not Found, Please try after some time" | ||
} | ||
} | ||
binding.progressBar.isVisible = loadState is LoadState.Loading | ||
binding.retryButton.isVisible = loadState is LoadState.Error | ||
binding.errorMessageContainer.isVisible = loadState is LoadState.Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be extracted
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
parseArguments() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
savedInstanceState: Bundle? | ||
): View? { | ||
parseArguments() | ||
initializeViewModel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
private fun bindViews() { | ||
binding.apply { | ||
this@RunningContentListFragment.recyclerView = binding.recyclerView | ||
this@RunningContentListFragment.emptyContainer = binding.errorContainer | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
private fun bindListView() { | ||
binding.apply { | ||
lifecycleScope.launchWhenCreated { | ||
adapter.loadStateFlow.collect { | ||
val notLoading = it.refresh is LoadState.NotLoading | ||
val loading = it.refresh is LoadState.Loading | ||
val error = it.refresh is LoadState.Error | ||
val isItemCountZero = adapter.itemCount == 0 | ||
|
||
shimmerViewContainer.isVisible = loading | ||
recyclerView.isVisible = (notLoading || error) && adapter.itemCount != 0 | ||
showEmptyOrErrorMessage( | ||
notLoading && isItemCountZero, | ||
error && isItemCountZero | ||
) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intention is not clear
try { | ||
page = when (loadType) { | ||
LoadType.REFRESH -> DEFAULT_PAGE_INDEX | ||
LoadType.PREPEND -> return MediatorResult.Success(endOfPaginationReached = true) | ||
LoadType.APPEND -> { | ||
val remoteKeys = getRemoteKeyForLastItem(state) | ||
val nextKey = remoteKeys?.nextKey | ||
?: return MediatorResult.Success(endOfPaginationReached = remoteKeys != null) | ||
nextKey | ||
} | ||
} | ||
|
||
val apiResponse = fetchRunningContents(page) | ||
val result = apiResponse.results | ||
endOfPaginationReached = (apiResponse.next == null) | ||
|
||
storeDataInDB(loadType,result) | ||
|
||
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) | ||
} catch (e: IOException) { | ||
return MediatorResult.Error(e) | ||
} catch (e: HttpException) { | ||
return MediatorResult.Error(e) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract
if (content != null) { | ||
val domainContent = content.asDomainContent() | ||
holder.bind(domainContent) { onItemClick(domainContent, holder.itemView.context) } | ||
holder.setDateAndVisiblity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name itself is confusing. If I am going to set a date then obviously it should be visible.
pageNumber = when (loadType) { | ||
LoadType.REFRESH -> DEFAULT_PAGE_INDEX | ||
LoadType.PREPEND -> return MediatorResult.Success(endOfPaginationReached = true) | ||
LoadType.APPEND -> { | ||
getNextPageNumber(state) | ||
?: return MediatorResult.Success(endOfPaginationReached = true) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be extracted to separate method. Let it return -1 for prepend or no next page
|
||
storeDataInDB(loadType,apiResponse.results) | ||
|
||
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) | |
return MediatorResult.Success(endOfPaginationReached = (apiResponse.next == null)) |
private fun getCurrentMonthMills(): Long { | ||
val calendar = Calendar.getInstance() | ||
val daysInCurrentMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) | ||
return TimeUnit.DAYS.toMillis(daysInCurrentMonth.toLong()) | ||
} | ||
|
||
private fun getCurrentYearMills(): Long { | ||
val calendar = Calendar.getInstance() | ||
val daysInCurrentYear = calendar.getActualMaximum(Calendar.DAY_OF_YEAR) | ||
return TimeUnit.DAYS.toMillis(daysInCurrentYear.toLong()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow step down ruie
} | ||
} | ||
|
||
private fun updateListView() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change name
@@ -33,4 +52,50 @@ object DateUtils { | |||
|
|||
return seconds | |||
} | |||
|
|||
fun getHumanizedTimeDifferenceOrEmpty(startTimeOrEndTime: String?, context: Context): String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun getHumanizedTimeDifferenceOrEmpty(startTimeOrEndTime: String?, context: Context): String { | |
fun getRelativeTimeString(startTimeOrEndTime: String?, context: Context): String { |
super.onViewCreated(view, savedInstanceState) | ||
initializeListView() | ||
initializeListeners() | ||
observeAdapterLoadingStateAndUpdateUI() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
observeAdapterLoadingStateAndUpdateUI() | |
showLoadingOrContentsList() |
course/src/main/java/in/testpress/course/adapter/BaseContentListAdapter.kt
Show resolved
Hide resolved
setDate(content) | ||
setDateVisiblity(content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let these derived view holder override bind and display these. By default date should not be visible and if needed then viewholder will derive and display it.
Don't use set
in method name in derived class
Changes done