Skip to content

Conversation

@albertoazinar
Copy link
Contributor

The tab names are appearing.
But the images are not loading on the screen.

@google-cla
Copy link

google-cla bot commented Oct 23, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Member

@thatfiredev thatfiredev left a comment

Choose a reason for hiding this comment

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

I haven't yet reviewed the Java and Kotlin files. I'll do it once the XML is fixed:

mViewPager = binding.viewPager;
mViewPager = (ViewPager2)findViewById(R.id.viewPager);
mViewPager.setAdapter(mImagePagerAdapter);
mViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);

Choose a reason for hiding this comment

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

Do we need to set the orientation to Horizontal?
I think the default orientation is Horizontal only.

Comment on lines 83 to 87
//binding.viewPager.adapter = imagePagerAdapter
val viewPager: ViewPager2 = findViewById(R.id.viewPager)
viewPager.adapter = imagePagerAdapter

// Workaround for AppCompat issue not showing ViewPager titles
val params = binding.pagerTabStrip.layoutParams as ViewPager.LayoutParams
params.isDecor = true

// When the visible image changes, send a screen view hit.
binding.viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageSelected(position: Int) {
recordImageView()
recordScreenView()
}
})
val tabLayout: TabLayout = findViewById(R.id.tab_layout)
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep viewbinding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we implement OnPageChangeCallback instead of addOnPageChangeListener
Because I'm getting an warning on addOnPageChangeListener what makes me think it is not recognized anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, yes, let's use OnPageChangeCallback. I believe the method is registerOnPageChangeCallback()

*/
private fun getCurrentImageId(): String {
val position = binding.viewPager.currentItem
val position = 0//binding.viewPager.currentItem
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 position = 0//binding.viewPager.currentItem
val position = binding.viewPager.currentItem

@SuppressLint("WrongConstant")
inner class ImagePagerAdapter(
fm: FragmentManager,
fm: FragmentActivity,
Copy link
Member

Choose a reason for hiding this comment

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

Let's use the same constructor we used on Java.

* A [FragmentStateAdapter] that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
@SuppressLint("WrongConstant")
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
@SuppressLint("WrongConstant")

Comment on lines 244 to 246
override fun getItemCount(): Int {
return infos.size
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: this can actually become a single line:

Suggested change
override fun getItemCount(): Int {
return infos.size
}
override fun getItemCount(): Int = infos.size

Copy link
Member

@thatfiredev thatfiredev left a comment

Choose a reason for hiding this comment

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

@AlbertoYabeda Thanks for patiently working on each and every review comment here.
We're 99% done 😬 Just a few more comments

/local.properties
.DS_Store
build/
google-services.json
Copy link
Member

Choose a reason for hiding this comment

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

This line shouldn't be removed. 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ops! 😅

*/
private String getCurrentImageId() {
int position = mViewPager.getCurrentItem();
int position = mViewPager.getCurrentItem();;
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
int position = mViewPager.getCurrentItem();;
int position = mViewPager.getCurrentItem();

Comment on lines 88 to 89
val viewPager: ViewPager2 = findViewById(R.id.viewPager)
viewPager.adapter = imagePagerAdapter
Copy link
Member

Choose a reason for hiding this comment

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

Let's stick to ViewBinding:

Suggested change
val viewPager: ViewPager2 = findViewById(R.id.viewPager)
viewPager.adapter = imagePagerAdapter


binding.viewPager.registerOnPageChangeCallback(pageChangedCallback)

val tabLayout: TabLayout = findViewById(R.id.tab_layout)
Copy link
Member

Choose a reason for hiding this comment

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

Let's stick to ViewBinding:

Suggested change
val tabLayout: TabLayout = findViewById(R.id.tab_layout)
val tabLayout: TabLayout = binding.tabLayout

Comment on lines 245 to 246
lc: Lifecycle
) : FragmentStateAdapter(fm, lc) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe we should make the variable name consistent with the java sample:

Suggested change
lc: Lifecycle
) : FragmentStateAdapter(fm, lc) {
lifecycle: Lifecycle
) : FragmentStateAdapter(fm, lifecycle) {

@albertoazinar
Copy link
Contributor Author

Thanks for your patience reviewing my PR. 😄

Comment on lines 88 to 89
val viewPager: ViewPager2 = binding.viewPager
viewPager.adapter = imagePagerAdapter
Copy link
Member

Choose a reason for hiding this comment

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

This code is simply repeating the line above it.

Suggested change
val viewPager: ViewPager2 = binding.viewPager
viewPager.adapter = imagePagerAdapter

binding.viewPager.registerOnPageChangeCallback(pageChangedCallback)

val tabLayout: TabLayout = binding.tabLayout
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
Copy link
Member

Choose a reason for hiding this comment

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

If the code repetition comment gets applied:

Suggested change
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
TabLayoutMediator(tabLayout, binding.viewPager) { tab, position ->

Comment on lines 25 to 26
app:layout_constraintBottom_toTopOf="@+id/viewPager"
app:layout_constraintEnd_toEndOf="@id/viewPager"
Copy link
Member

Choose a reason for hiding this comment

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

Let's not attach this to the viewPager. (note that this is my personal preference, I don't think there's specific guidance on that.)

Suggested change
app:layout_constraintBottom_toTopOf="@+id/viewPager"
app:layout_constraintEnd_toEndOf="@id/viewPager"
app:layout_constraintEnd_toEndOf="parent"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll set the end to EndOf "parent"

but I think the Bottom of the tabLayout should be at the top of ViewPager.

Correct me if I'm wrong.

Comment on lines 32 to 35
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
Copy link
Member

Choose a reason for hiding this comment

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

This layout seems to be missing horizontal constraints. Can we have some constraints at the Start and End? That will allow us to set the width to "0dp".

Suggested change
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh Yes. that would be awesome.

Copy link
Member

@thatfiredev thatfiredev left a comment

Choose a reason for hiding this comment

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

Thank you so much @AlbertoYabeda !

@thatfiredev thatfiredev merged commit 93d08e9 into firebase:master Nov 29, 2022
@albertoazinar
Copy link
Contributor Author

Welcome
and thanks for your support @thatfiredev 👌

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