-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…dableAdapter" (#4951) This reverts commit `7fd290d68f0440d926f2d443dbd7bfb28ab20547`, fixing part of #2116. While testing #2116, we found that the UI for default profile view does not display correctly, and traced the change to #4874 in [this discusson](#2116 (comment)). #4874 introduces a change to `MarginBindingAdapters` which utilizes `MarginLayoutParamsCompat` to compute the margins of a layout before drawing it. I suspect that this works for the `Promoted Story` and `Topic Summary` because we compute the start and end margins of each item relative to grid columns laid out on the HomeActivity, but no such implementation exists for the Profile Chooser view. We need to do some further investigation into this, hence the decision to revert. We will need to test all the associated screens to make sure they still look as expected: ![Screenshot 2023-04-19 at 18 01 28](https://user-images.githubusercontent.com/59600948/233117952-8c981fa2-2d0c-45cc-80ff-651862c1fd96.png) ## Essential Checklist <!-- Please tick the relevant boxes by putting an "x" in them. --> - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## For UI-specific PRs only This was mainly a re-implimentation per #632, and the UI did not change. Please refer to #4874 for screenshots. The Affected screen displays okay with this revert: ![Screenshot_1681916915](https://user-images.githubusercontent.com/59600948/233125096-2242fb7e-eb9f-4b78-8db0-c22abb6b5cc3.png) Other screens: | | | |---|---| |![Screenshot_1681917117](https://user-images.githubusercontent.com/59600948/233126283-45a860c7-26ac-47f6-8b38-e54b1ee7cb1f.png)|![Screenshot_1681917190](https://user-images.githubusercontent.com/59600948/233126350-08033853-4434-462d-9bf3-98040ff2356d.png)|
- Loading branch information
1 parent
1ba98dd
commit 80d2cd0
Showing
7 changed files
with
323 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
app/src/main/java/org/oppia/android/app/home/recentlyplayed/PromotedStoryListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.oppia.android.app.home.recentlyplayed | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.oppia.android.databinding.RecentlyPlayedStoryCardBinding | ||
import org.oppia.android.databinding.SectionTitleBinding | ||
|
||
private const val VIEW_TYPE_SECTION_TITLE_TEXT = 1 | ||
private const val VIEW_TYPE_SECTION_STORY_ITEM = 2 | ||
|
||
/** | ||
* Adapter to inflate different items/views inside [RecyclerView] for Ongoing Story List. | ||
* | ||
* @property itemList the items that may be displayed in [RecentlyPlayedFragment]'s recycler view | ||
*/ | ||
class PromotedStoryListAdapter( | ||
private val itemList: MutableList<RecentlyPlayedItemViewModel> | ||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
private var titleIndex: Int = 0 | ||
private var storyGridPosition: Int = 0 | ||
private var spanCount = 0 | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return when (viewType) { | ||
// TODO(#632): Generalize this binding to make adding future items easier. | ||
VIEW_TYPE_SECTION_TITLE_TEXT -> { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = | ||
SectionTitleBinding.inflate( | ||
inflater, | ||
parent, | ||
/* attachToParent= */ false | ||
) | ||
SectionTitleViewHolder(binding) | ||
} | ||
VIEW_TYPE_SECTION_STORY_ITEM -> { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = | ||
RecentlyPlayedStoryCardBinding.inflate( | ||
inflater, | ||
parent, | ||
/* attachToParent= */ false | ||
) | ||
PromotedStoryViewHolder(binding) | ||
} | ||
else -> throw IllegalArgumentException("Invalid view type: $viewType") | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) = | ||
when (holder.itemViewType) { | ||
VIEW_TYPE_SECTION_TITLE_TEXT -> { | ||
titleIndex = position | ||
(holder as SectionTitleViewHolder).bind(itemList[position] as SectionTitleViewModel) | ||
} | ||
VIEW_TYPE_SECTION_STORY_ITEM -> { | ||
storyGridPosition = position - titleIndex | ||
(holder as PromotedStoryViewHolder).bind(itemList[position] as PromotedStoryViewModel) | ||
} | ||
else -> throw IllegalArgumentException("Invalid item view type: ${holder.itemViewType}") | ||
} | ||
|
||
override fun getItemViewType(position: Int): Int { | ||
return when (itemList[position]) { | ||
is SectionTitleViewModel -> { | ||
VIEW_TYPE_SECTION_TITLE_TEXT | ||
} | ||
is PromotedStoryViewModel -> { | ||
VIEW_TYPE_SECTION_STORY_ITEM | ||
} | ||
else -> throw IllegalArgumentException( | ||
"Invalid type of data $position with item ${itemList[position]}" | ||
) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return itemList.size | ||
} | ||
|
||
/** | ||
* Specifies the number of columns of recently played stories shown in the recently played stories | ||
* list. | ||
* | ||
* @param spanCount specifies the number of spaces this item should occupy, based on screen size | ||
*/ | ||
fun setSpanCount(spanCount: Int) { | ||
this.spanCount = spanCount | ||
} | ||
|
||
private class SectionTitleViewHolder( | ||
val binding: SectionTitleBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
/** Binds the view model that sets section titles. */ | ||
fun bind(sectionTitleViewModel: SectionTitleViewModel) { | ||
binding.viewModel = sectionTitleViewModel | ||
} | ||
} | ||
|
||
private class PromotedStoryViewHolder( | ||
val binding: RecentlyPlayedStoryCardBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
/** Binds the view model that sets recently played items. */ | ||
fun bind(promotedStoryViewModel: PromotedStoryViewModel) { | ||
binding.viewModel = promotedStoryViewModel | ||
} | ||
} | ||
} |
Oops, something went wrong.