Skip to content

Commit

Permalink
add my appraoach
Browse files Browse the repository at this point in the history
  • Loading branch information
subhajitxyz committed Jan 8, 2025
1 parent 970e083 commit d055e32
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class StateFragmentPresenter @Inject constructor(

showOrHideAudioByState(ephemeralState.state)

val dataPair = recyclerViewAssembler.compute(
var dataPair = recyclerViewAssembler.compute(
ephemeralState,
explorationId,
shouldSplit
Expand All @@ -349,19 +349,47 @@ class StateFragmentPresenter @Inject constructor(
Log.d("testhint",stateViewModel.rightItemList.toString())
Log.d("testhint",dataPair.second.toString())

//subha
if (!areListsTheSame(stateViewModel.itemList, dataPair.first)) {
stateViewModel.itemList.clear()
stateViewModel.itemList += dataPair.first
}
if (!areListsTheSame(stateViewModel.rightItemList, dataPair.second)) {
stateViewModel.rightItemList.clear()
stateViewModel.rightItemList += dataPair.second
val oldData = stateViewModel.itemList
var newData = dataPair.first


//subha hint try

if(containsTextInputInteraction(oldData) && containsTextInputInteraction(newData)) {
val isAnswerAvailableOldData = foundIsAnswerAvailable(oldData)
if (isAnswerAvailableOldData) {
//do not add newdata for only text input interaction
//so remove textInteraction viewmodel from dataPair and add old textInteraction viewmodel

newData = newData.filter {
it.viewType != StateItemViewModel.ViewType.TEXT_INPUT_INTERACTION
}.toMutableList()

// Add TEXT_INPUT_INTERACTION view models from oldData to newData
val oldTextInputInteractions = oldData.filter {
it.viewType == StateItemViewModel.ViewType.TEXT_INPUT_INTERACTION
}

Log.d("testhint","newdata ${newData}")
newData.addAll(oldTextInputInteractions)
Log.d("testhint","newdata ${newData}")
}
}
// stateViewModel.itemList.clear()
// stateViewModel.itemList += dataPair.first
// stateViewModel.rightItemList.clear()
// stateViewModel.rightItemList += dataPair.second


//subha
// if (!areListsTheSame(stateViewModel.itemList, dataPair.first)) {
// stateViewModel.itemList.clear()
// stateViewModel.itemList += dataPair.first
// }
// if (!areListsTheSame(stateViewModel.rightItemList, dataPair.second)) {
// stateViewModel.rightItemList.clear()
// stateViewModel.rightItemList += dataPair.second
//}
stateViewModel.itemList.clear()
stateViewModel.itemList += newData
stateViewModel.rightItemList.clear()
stateViewModel.rightItemList += dataPair.second

if (isInNewState) {
(binding.stateRecyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
Expand All @@ -370,16 +398,41 @@ class StateFragmentPresenter @Inject constructor(
)
}
}
//subha hint
private fun areListsTheSame(l: List<StateItemViewModel>, r: List<StateItemViewModel>): Boolean {
if (l.size != r.size) {
return false
// //subha hint
// private fun areListsTheSame(l: List<StateItemViewModel>, r: List<StateItemViewModel>): Boolean {
// if (l.size != r.size) {
// return false
// }
//
// return l.zip(r).all { (x, y) ->
// if(x.viewType == StateItemViewModel.ViewType.TEXT_INPUT_INTERACTION &&
// y.viewType == StateItemViewModel.ViewType.TEXT_INPUT_INTERACTION ) {
// if(x.userInputAvaliable()) {
// ///do not
// }
// }
// Log.d("testhint","x " + l.toString())
// Log.d("testhint","y "+y.toString())
// Log.d("testhint", "Comparing: ${x} with ${y}, result: ${x.areContentsTheSame(y)}")
// x.areContentsTheSame(y) }
// }
private fun containsTextInputInteraction(data: List<StateItemViewModel>): Boolean {
data.forEach {
if(it.viewType == StateItemViewModel.ViewType.TEXT_INPUT_INTERACTION) {
return true
}
}
return l.zip(r).all { (x, y) ->
Log.d("testhint","x " + l.toString())
Log.d("testhint","y "+y.toString())
Log.d("testhint", "Comparing: ${x} with ${y}, result: ${x.areContentsTheSame(y)}")
x.areContentsTheSame(y) }
return false
}
private fun foundIsAnswerAvailable(data: List<StateItemViewModel>): Boolean {
data.forEach {
if(it.viewType == StateItemViewModel.ViewType.TEXT_INPUT_INTERACTION) {
it.userInputAvailable()
}

}
return false

}

/** Subscribes to the result of requesting to show a hint or solution. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ abstract class StateItemViewModel(val viewType: ViewType) : ObservableViewModel(
override fun toString(): String {
return "StateItemViewModel(viewType=$viewType)"
}
override fun userInputAvailable(): Boolean {
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class TextInputViewModel private constructor(
"isAnswerAvailable=${isAnswerAvailable.get()}, " +
"errorMessage='${errorMessage.get()}')"
}
//subha
override fun userInputAvailable(): Boolean {
return isAnswerAvailable.get() == true
}

override fun checkPendingAnswerError(category: AnswerErrorCategory): String? {
answerErrorCetegory = category
Expand Down

0 comments on commit d055e32

Please sign in to comment.