-
Notifications
You must be signed in to change notification settings - Fork 528
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 #153/#154 : MultipleChoice/ItemSelection Interaction View #225
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e19af2b
Introduce first pass interface for ExplorationProgressController.
BenHenning 43766b0
Fill in the stubbed logic for ExplorationProgressController. Still no
BenHenning c8eaa66
Fix lateinit issue in ExplorationProgressController due to wrongly or…
BenHenning a0eb3ce
Fix a variaty of issues in the exp progress controller, properly hook…
BenHenning 1ea9d01
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning 41141b6
Created a separate ExplorationRetriever, hooked up
BenHenning ccbac0e
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning 5f326fc
Change the locking mechanism for ExplorationProgressController to work
BenHenning b5b7485
Finish tests for ExplorationProgressController and add test classific…
BenHenning a3c4667
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning 4a9aad1
ObservableViewModel
38c0275
Merge remote-tracking branch 'upstream/introduce-exploration-progress…
0705586
Load exploration and open ExplorationActivity
d38bbe1
Test case for load exploration
f337b70
fetch exploration
veena14cs 0fb1729
Connection with StateFragment
d04f66a
update
veena14cs ca0c356
update
veena14cs a3c7d55
Merge branch 'introduce-load-exploration-part-1' into exploration-pla…
veena14cs fe5ab82
working on fetching customization_args
veena14cs e45fb0a
Update StateFragmentPresenter.kt
veena14cs 86dc073
resolved conflicts
veena14cs c6bbfdb
Separated this in its own PR
veena14cs 0edaca1
Delete UrlImageParser.kt
veena14cs 9f02fba
Update StateFragmentPresenter.kt
veena14cs af8610b
Update build.gradle
veena14cs e5e351c
working on fetching custom_args
veena14cs ad00bdd
Merge branch 'develop' into exploration-player-content-interaction
veena14cs 0b379fc
Merge branch 'develop' into exploration-player-content-interaction
veena14cs 5bdedfc
fixing issues
veena14cs c481727
Update InteractionAdapter.kt
veena14cs ea1dc85
fixed issues
veena14cs 1b6a02d
Included in separate PR #226
veena14cs b798236
Included in separate Pr #205
veena14cs 08cd62c
fixed spacing
veena14cs 8797aae
Merge branch 'exploration-player-content-interaction' of https://gith…
veena14cs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
128 changes: 128 additions & 0 deletions
128
app/src/main/java/org/oppia/app/player/state/InteractionAdapter.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,128 @@ | ||
package org.oppia.app.player.state; | ||
|
||
import android.content.Context | ||
import android.text.Html | ||
import android.text.Spannable | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
import androidx.databinding.library.baseAdapters.BR | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.synthetic.main.item_selection_interaction_items.view.* | ||
import kotlinx.android.synthetic.main.multiple_choice_interaction_items.view.* | ||
import org.oppia.app.R | ||
import org.oppia.app.databinding.ItemSelectionInteractionItemsBinding | ||
import org.oppia.app.databinding.MultipleChoiceInteractionItemsBinding | ||
import org.oppia.util.data.HtmlParser | ||
|
||
const val VIEW_TYPE_MULTIPLE_CHOICE = 1 | ||
const val VIEW_TYPE_ITEM_SELECTION = 2 | ||
|
||
/** Adapter to bind the interactions to the [RecyclerView]. It handles MultipleChoiceInput and ItemSelectionInput interaction views. */ | ||
class InteractionAdapter( | ||
private val context: Context, | ||
private val entityType: String, | ||
private val entityId: String, | ||
val itemList: Array<String>?, | ||
val interactionInstanceId: String? | ||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
private var mSelectedItem = -1 | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return when (viewType) { | ||
VIEW_TYPE_MULTIPLE_CHOICE -> { | ||
val inflater = LayoutInflater.from(parent.getContext()) | ||
val binding = | ||
DataBindingUtil.inflate<MultipleChoiceInteractionItemsBinding>( | ||
inflater, | ||
R.layout.multiple_choice_interaction_items, | ||
parent, | ||
false | ||
) | ||
MultipleChoiceViewHolder(binding) | ||
} | ||
VIEW_TYPE_ITEM_SELECTION -> { | ||
val inflater = LayoutInflater.from(parent.getContext()) | ||
val binding = | ||
DataBindingUtil.inflate<ItemSelectionInteractionItemsBinding>( | ||
inflater, | ||
R.layout.item_selection_interaction_items, | ||
parent, | ||
false | ||
) | ||
ItemSelectionViewHolder(binding) | ||
} | ||
else -> throw IllegalArgumentException("Invalid view type") | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
when (holder.itemViewType) { | ||
VIEW_TYPE_MULTIPLE_CHOICE -> (holder as MultipleChoiceViewHolder).bind( | ||
itemList!!.get(position), | ||
position, | ||
mSelectedItem | ||
) | ||
VIEW_TYPE_ITEM_SELECTION -> (holder as ItemSelectionViewHolder).bind( | ||
itemList!!.get(position), | ||
position, | ||
mSelectedItem | ||
) | ||
} | ||
} | ||
|
||
// Determines the appropriate ViewType according to the interaction type. | ||
override fun getItemViewType(position: Int): Int { | ||
return if (interactionInstanceId.equals("ItemSelectionInput")) { | ||
VIEW_TYPE_ITEM_SELECTION | ||
} else { | ||
VIEW_TYPE_MULTIPLE_CHOICE | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return itemList!!.size | ||
} | ||
|
||
private inner class ItemSelectionViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) { | ||
internal fun bind(rawString: String?, position: Int, selectedPosition: Int) { | ||
binding.setVariable(BR.htmlContent, rawString) | ||
binding.executePendingBindings(); | ||
val html: Spannable = HtmlParser(context,entityType,entityId).parseHtml(rawString, binding.root.tv_item_selection_contents) | ||
binding.root.tv_item_selection_contents.text = html | ||
|
||
binding.root.rl_checkbox_container.setOnClickListener { | ||
if (binding.root.cb_item_selection.isChecked) | ||
binding.root.cb_item_selection.setChecked(false) | ||
else | ||
binding.root.cb_item_selection.setChecked(true) | ||
Toast.makeText(context, "" + binding.root.tv_item_selection_contents.text, Toast.LENGTH_LONG).show() | ||
notifyDataSetChanged() | ||
} | ||
} | ||
} | ||
|
||
private inner class MultipleChoiceViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) { | ||
internal fun bind(rawString: String?, position: Int, selectedPosition: Int) { | ||
binding.setVariable(BR.htmlContent, rawString) | ||
binding.executePendingBindings(); | ||
val html: Spannable = HtmlParser(context,entityType,entityId).parseHtml(rawString, binding.root.tv_multiple_choice_contents) | ||
binding.root.tv_multiple_choice_contents.text = html | ||
|
||
if (selectedPosition == position) | ||
binding.root.rb_multiple_choice.setChecked(true) | ||
else | ||
binding.root.rb_multiple_choice.setChecked(false) | ||
|
||
binding.root.rl_radio_container.setOnClickListener { | ||
Toast.makeText(context, "" + binding.root.tv_multiple_choice_contents.text, Toast.LENGTH_LONG).show() | ||
mSelectedItem = getAdapterPosition() | ||
notifyDataSetChanged() | ||
} | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
app/src/main/res/layout/item_selection_interaction_items.xml
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,28 @@ | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<data> | ||
<variable | ||
name="htmlContent" | ||
type="String"/> | ||
</data> | ||
<RelativeLayout | ||
android:id="@+id/rl_checkbox_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="4dp" | ||
android:orientation="vertical"> | ||
<androidx.appcompat.widget.AppCompatCheckBox | ||
android:id="@+id/cb_item_selection" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="4dp" | ||
app:buttonTint="@color/oppiaDarkBlue"/> | ||
<TextView | ||
android:id="@+id/tv_item_selection_contents" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_toRightOf="@+id/cb_item_selection" | ||
android:padding="4dp" | ||
android:text="@{htmlContent}" | ||
android:textColor="@color/oppiaDarkBlue"/> | ||
</RelativeLayout> | ||
</layout> |
28 changes: 28 additions & 0 deletions
28
app/src/main/res/layout/multiple_choice_interaction_items.xml
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,28 @@ | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<data> | ||
<variable | ||
name="htmlContent" | ||
type="String"/> | ||
</data> | ||
<RelativeLayout | ||
android:id="@+id/rl_radio_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="4dp" | ||
android:orientation="vertical"> | ||
<androidx.appcompat.widget.AppCompatRadioButton | ||
android:id="@+id/rb_multiple_choice" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="4dp" | ||
app:buttonTint="@color/oppiaDarkBlue"/> | ||
<TextView | ||
android:id="@+id/tv_multiple_choice_contents" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_toRightOf="@+id/rb_multiple_choice" | ||
android:padding="4dp" | ||
android:text="@{htmlContent}" | ||
android:textColor="@color/oppiaDarkBlue"/> | ||
</RelativeLayout> | ||
</layout> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@BenHenning Veena has added this library
'androidx.test.espresso:espresso-contrib:3.1.0'
, which helps in testing recyclerview items. Can I use this in my test-cases related to RecyclerView, #204There 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.
@BenHenning @veena14cs
We should not use this library because this library only provide click actions and there is no mechanism to check the content of an item.
Th solution for this is in my PR #204