-
Notifications
You must be signed in to change notification settings - Fork 526
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
Fix #1873: Fix OnboardingFragmentTest test cases on Robolectric #2482
Changes from 38 commits
df75643
af2fb52
a87d960
a23aea0
b498b4d
4d46313
be8405b
564d1bd
1e34fa2
7e2fbb6
eabd915
11a9b61
543d34c
da4f678
6b7b059
e028aa9
12540d3
db59608
708a488
75eac88
250530b
8929252
176dec4
8cc353f
6555129
811e772
5d92e0c
f8ce120
06a7a71
4a39e40
bf0b6b7
3f5fff8
9a3d39c
940137c
2151c45
709c7c8
6976d7d
54a4659
9840c22
950401c
2db7622
5a8a8cd
3b8e1fb
7f02b77
8903b00
4c33d03
f9cd0e5
5413965
4f2fff8
c1786e5
dd21e64
83f14db
b7a671f
ca84aea
3555545
98a4db2
26fb177
3023508
33a48da
1ee0cf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,65 +2,81 @@ package org.oppia.android.app.onboarding | |
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ScrollView | ||
import androidx.core.text.TextUtilsCompat | ||
import androidx.core.view.ViewCompat | ||
import androidx.viewpager.widget.PagerAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.oppia.android.databinding.OnboardingSlideBinding | ||
import org.oppia.android.databinding.OnboardingSlideFinalBinding | ||
import java.util.Locale | ||
|
||
/** Adapter to control the slide details in onboarding flow. */ | ||
private const val VIEW_TYPE_TITLE_TEXT = 1 | ||
private const val VIEW_TYPE_STORY_ITEM = 2 | ||
|
||
class OnboardingPagerAdapter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we going to use the Bindale Adapter and remove this Adapter in this PR only or we are keeping this as a separate issue? @rt4914 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems like a larger & unrelated change--I suggest splitting it off of this task. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, given that so much of the adapter has changed anyway, maybe it is worth trying to migrate to BindableAdapter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BenHenning So, should I replace it with a bindable Adapter in this PR only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I guess you are suggesting to track it via a new issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
val context: Context, | ||
val onboardingSlideFinalViewModel: OnboardingSlideFinalViewModel | ||
) : PagerAdapter() { | ||
// TODO (#2194 ): Remove this once the implementation is updated to ViewPager2 | ||
val isRTL = TextUtilsCompat | ||
.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL | ||
override fun instantiateItem(container: ViewGroup, position: Int): Any { | ||
if (position == TOTAL_NUMBER_OF_SLIDES - 1) { | ||
val binding = | ||
OnboardingSlideFinalBinding.inflate( | ||
) : | ||
RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return when (viewType) { | ||
VIEW_TYPE_TITLE_TEXT -> { | ||
val binding = OnboardingSlideBinding.inflate( | ||
LayoutInflater.from(context), | ||
container, | ||
parent, | ||
false | ||
) | ||
binding.viewModel = onboardingSlideFinalViewModel | ||
if (isRTL) { | ||
binding.finalLayout!!.rotationY = 180f | ||
OnboardingSlideViewHolder(binding) | ||
} | ||
|
||
container.addView(binding.root) | ||
return binding.root | ||
VIEW_TYPE_STORY_ITEM -> { | ||
val binding = | ||
OnboardingSlideFinalBinding.inflate( | ||
LayoutInflater.from(context), | ||
parent, | ||
false | ||
) | ||
OnboardingSlideFinalViewHolder(binding) | ||
} | ||
else -> throw IllegalArgumentException("Invalid view type: $viewType") | ||
} | ||
} | ||
|
||
val binding = OnboardingSlideBinding.inflate( | ||
LayoutInflater.from(context), | ||
container, | ||
false | ||
) | ||
if (isRTL) { | ||
binding.root.rotationY = 180f | ||
override fun getItemViewType(position: Int): Int { | ||
return if (position == TOTAL_NUMBER_OF_SLIDES - 1) { | ||
VIEW_TYPE_STORY_ITEM | ||
} else { | ||
VIEW_TYPE_TITLE_TEXT | ||
} | ||
val onboardingSlideViewModel = | ||
OnboardingSlideViewModel(context, ViewPagerSlide.getSlideForPosition(position)) | ||
binding.viewModel = onboardingSlideViewModel | ||
container.addView(binding.root) | ||
return binding.root | ||
} | ||
|
||
override fun getCount(): Int { | ||
override fun getItemCount(): Int { | ||
return TOTAL_NUMBER_OF_SLIDES | ||
} | ||
|
||
override fun isViewFromObject(view: View, `object`: Any): Boolean { | ||
return view == `object` | ||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
when (holder.itemViewType) { | ||
VIEW_TYPE_TITLE_TEXT -> { | ||
val onboardingSlideViewModel = | ||
OnboardingSlideViewModel(context, ViewPagerSlide.getSlideForPosition(position)) | ||
(holder as OnboardingSlideViewHolder).bind(onboardingSlideViewModel) | ||
} | ||
VIEW_TYPE_STORY_ITEM -> { | ||
(holder as OnboardingSlideFinalViewHolder).bind(onboardingSlideFinalViewModel) | ||
} | ||
} | ||
} | ||
|
||
inner class OnboardingSlideViewHolder( | ||
private val binding: OnboardingSlideBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(onboardingSlideViewModel: OnboardingSlideViewModel) { | ||
binding.viewModel = onboardingSlideViewModel | ||
} | ||
} | ||
|
||
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { | ||
container.removeView(`object` as ScrollView) | ||
inner class OnboardingSlideFinalViewHolder( | ||
private val binding: OnboardingSlideFinalBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(onboardingSlideFinalViewModel: OnboardingSlideFinalViewModel) { | ||
binding.viewModel = onboardingSlideFinalViewModel | ||
} | ||
} | ||
} |
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.
is it working correctly for RTL?
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.
I guess there's some problem with the back button -
Screenrecorder-2021-01-18-14-26-15-85.mp4
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.
@FareesHussain mentioning you here to help with RTL stuff.
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.
video looks fine
@prayutsu have a look at the todos in the
OnboardingFragmentPresenter
andOnboardingPagerAdapter
and revert themand then check if RTL works fine
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.
I checked it on the
develop
branch, and it looks ditto same as in this video.Is it correct?
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.
Yes