Skip to content
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

Merged
merged 27 commits into from
Mar 30, 2023
Merged

Conversation

PruthiviRaj27
Copy link
Contributor

@PruthiviRaj27 PruthiviRaj27 commented Mar 28, 2023

Changes done

  • Added Running content list view UI
  • Added pagination for fetching and storing data

Comment on lines 36 to 44
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
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment on lines 74 to 80
private fun bindViews() {
binding.apply {
this@RunningContentListFragment.recyclerView = binding.recyclerView
this@RunningContentListFragment.emptyContainer = binding.errorContainer
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment on lines 112 to 130
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
)
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intention is not clear

Comment on lines 38 to 62
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)
}
}
Copy link
Contributor

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(
Copy link
Contributor

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.

Comment on lines 39 to 46
pageNumber = when (loadType) {
LoadType.REFRESH -> DEFAULT_PAGE_INDEX
LoadType.PREPEND -> return MediatorResult.Success(endOfPaginationReached = true)
LoadType.APPEND -> {
getNextPageNumber(state)
?: return MediatorResult.Success(endOfPaginationReached = true)
}
}
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
return MediatorResult.Success(endOfPaginationReached = (apiResponse.next == null))

Comment on lines +18 to +28
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())
}
Copy link
Contributor

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() {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun getHumanizedTimeDifferenceOrEmpty(startTimeOrEndTime: String?, context: Context): String {
fun getRelativeTimeString(startTimeOrEndTime: String?, context: Context): String {

super.onViewCreated(view, savedInstanceState)
initializeListView()
initializeListeners()
observeAdapterLoadingStateAndUpdateUI()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
observeAdapterLoadingStateAndUpdateUI()
showLoadingOrContentsList()

Comment on lines 55 to 56
setDate(content)
setDateVisiblity(content)
Copy link
Contributor

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

@bharathwaaj bharathwaaj merged commit f4654cc into master Mar 30, 2023
@delete-merged-branch delete-merged-branch bot deleted the feature_running_content branch March 30, 2023 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants