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: Changed channel content from chips to swipable tabs #6026

Closed

Conversation

amandeepsinghjamwal
Copy link
Contributor

@amandeepsinghjamwal amandeepsinghjamwal commented May 14, 2024

This PR adds enhancement mentioned in issue #6008

VID_20240514113238.online-video-cutter.com.1.mp4

@amandeepsinghjamwal amandeepsinghjamwal changed the title Changed channel content from chips to swipable tabs feat: Changed channel content from chips to swipable tabs May 14, 2024
Comment on lines 121 to 123
} catch (e: Exception) {
isLoading = false
}
Copy link
Member

Choose a reason for hiding this comment

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

isLoading = false should probably be outside of the catch block, and not become called in fetchTabNextPage, just for readability

Comment on lines 128 to 132
val tabData = try {
Json.decodeFromString<ChannelTab>(arguments?.getString(IntentData.tabData)?:"")
} catch (e: Exception) {
null
}
Copy link
Member

@Bnyro Bnyro May 14, 2024

Choose a reason for hiding this comment

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

Suggested change
val tabData = try {
Json.decodeFromString<ChannelTab>(arguments?.getString(IntentData.tabData)?:"")
} catch (e: Exception) {
null
}
val tabData = runCatching {
Json.decodeFromString<ChannelTab>(arguments?.getString(IntentData.tabData).orEmpty())
}.getOrNull()

Comment on lines 145 to 148
val visibleItemCount: Int = recyclerView.layoutManager!!.childCount
val totalItemCount: Int = recyclerView.layoutManager!!.getItemCount()
val firstVisibleItemPosition: Int =
(recyclerView.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val visibleItemCount: Int = recyclerView.layoutManager!!.childCount
val totalItemCount: Int = recyclerView.layoutManager!!.getItemCount()
val firstVisibleItemPosition: Int =
(recyclerView.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
val visibleItemCount = recyclerView.layoutManager!!.childCount
val totalItemCount = recyclerView.layoutManager!!.getItemCount()
val firstVisibleItemPosition =
(recyclerView.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I copy pasted this code hehe that's why I forgot to refactor it because your code for bottom reached listener was misbehaving

fun RecyclerView.addOnBottomReachedListener(onBottomReached: () -> Unit) {
    viewTreeObserver.addOnScrollChangedListener {
        if (!canScrollVertically(1)) onBottomReached()
    }
}

is misbehaving on second time you use it, instead of triggering when reached on bottom. It is triggered on each scroll. Atleast that was happening in my case. you might wanna check it out.

Comment on lines 159 to 175
if (!tabData?.data.isNullOrEmpty()) {
loadChannelTab(tabData ?: return)
} else {
val videoDataString = arguments?.getString(IntentData.videoList)
val videos = try {
Json.decodeFromString<List<StreamItem>>(videoDataString!!)
} catch (e: Exception) {
mutableListOf()
}
channelAdapter = VideosAdapter(
videos.toMutableList(),
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
)
binding.channelRecView.adapter = channelAdapter
binding.progressBar.visibility = View.GONE
binding.channelRecView.visibility = View.VISIBLE
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!tabData?.data.isNullOrEmpty()) {
loadChannelTab(tabData ?: return)
} else {
val videoDataString = arguments?.getString(IntentData.videoList)
val videos = try {
Json.decodeFromString<List<StreamItem>>(videoDataString!!)
} catch (e: Exception) {
mutableListOf()
}
channelAdapter = VideosAdapter(
videos.toMutableList(),
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
)
binding.channelRecView.adapter = channelAdapter
binding.progressBar.visibility = View.GONE
binding.channelRecView.visibility = View.VISIBLE
}
if (tabData?.data.isNullOrEmpty()) {
val videoDataString = arguments?.getString(IntentData.videoList)
val videos = runCatching {
Json.decodeFromString<List<StreamItem>>(videoDataString!!)
}.getOrElse { mutableListOf() }
channelAdapter = VideosAdapter(
videos.toMutableList(),
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
)
binding.channelRecView.adapter = channelAdapter
binding.progressBar.visibility = View.GONE
binding.channelRecView.visibility = View.VISIBLE
} else {
loadChannelTab(tabData!!)
}

Comment on lines 254 to 258
fragment.arguments = Bundle().apply {
putString(IntentData.tabData, Json.encodeToString(list[position]))
putString(IntentData.videoList, Json.encodeToString(videos))
putString(IntentData.channelId, channelId)
putString(IntentData.nextPage, nextPage)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fragment.arguments = Bundle().apply {
putString(IntentData.tabData, Json.encodeToString(list[position]))
putString(IntentData.videoList, Json.encodeToString(videos))
putString(IntentData.channelId, channelId)
putString(IntentData.nextPage, nextPage)
fragment.arguments = bundleOf(
IntentData.tabData to Json.encodeToString(list[position])
IntentData.videoList to Json.encodeToString(videos)
IntentData.channelId to channelId
IntentData.nextPage to nextPage

Comment on lines 554 to 555
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
Copy link
Member

Choose a reason for hiding this comment

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

😉

@Bnyro
Copy link
Member

Bnyro commented May 14, 2024

Thanks for your PR, looks great UI/UX-wise!

I noticed you did a lot of things like you were writing pure Java, so I'd guess you're coming from a Java background :)

Two general suggestions/things concerning this PR:

  • You can use View#isVisible and View#isGone instead of View#visibility = View.GONE / View.VISIBLE which is easier to read.
  • This PR removes internationalization (support for different languages) from the channel tabs, but I can also take care of this if you want me to.

Comment on lines 112 to 118
fetchChannelNextPage(nextPage ?: return@launch).let {
nextPage = it
}
} else {
fetchTabNextPage(nextPage ?: return@launch, tab).let {
nextPage = it
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fetchChannelNextPage(nextPage ?: return@launch).let {
nextPage = it
}
} else {
fetchTabNextPage(nextPage ?: return@launch, tab).let {
nextPage = it
}
nextPage = fetchChannelNextPage(nextPage ?: return@launch)
} else {
nextPage = fetchTabNextPage(nextPage ?: return@launch, tab)

Copy link
Contributor Author

@amandeepsinghjamwal amandeepsinghjamwal May 15, 2024

Choose a reason for hiding this comment

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

Thank you @Bnyro for all the corrections, I will keep these in mind next time. Got to learn a lot from your corrections. I'll correct it in next commit

@Bnyro Bnyro linked an issue May 15, 2024 that may be closed by this pull request
3 tasks
@Bnyro Bnyro closed this in #6053 May 18, 2024
@Bnyro
Copy link
Member

Bnyro commented May 18, 2024

Thank you for your work on this PR!

I've tried rebasing your code with some small code improvements which you seemed to have disabled unfortunately 😢, hence I merged the changes in #6053.

Again, thanks for your PR 👍

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.

Swipe to switch channel details
3 participants