-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into topic-review-low…
…-fi-part-1
- Loading branch information
Showing
15 changed files
with
576 additions
and
24 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
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
58 changes: 55 additions & 3 deletions
58
app/src/main/java/org/oppia/app/topic/conceptcard/ConceptCardViewModel.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 |
---|---|---|
@@ -1,11 +1,63 @@ | ||
package org.oppia.app.topic.conceptcard | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.Transformations | ||
import androidx.lifecycle.ViewModel | ||
import org.oppia.app.fragment.FragmentScope | ||
import org.oppia.app.model.ConceptCard | ||
import org.oppia.app.model.SubtitledHtml | ||
import org.oppia.domain.topic.TopicController | ||
import org.oppia.util.data.AsyncResult | ||
import org.oppia.util.logging.Logger | ||
import javax.inject.Inject | ||
|
||
/** [ViewModel] for concept card, providing rich text and worked examples */ | ||
@FragmentScope | ||
class ConceptCardViewModel @Inject constructor() : ViewModel() { | ||
fun getDummyText() = "hello world" | ||
} | ||
class ConceptCardViewModel @Inject constructor( | ||
private val topicController: TopicController, | ||
private val logger: Logger | ||
) : ViewModel() { | ||
|
||
private lateinit var skillId: String | ||
|
||
/** Live Data for concept card explanation */ | ||
val conceptCardLiveData: LiveData<ConceptCard> by lazy { | ||
processConceptCardLiveData() | ||
} | ||
|
||
/** Live Data for concept card worked examples. */ | ||
val workedExamplesLiveData: LiveData<List<SubtitledHtml>> by lazy { | ||
processWorkedExamplesLiveData() | ||
} | ||
|
||
/** Sets the value of skillId. Must be called before setting ViewModel to binding. */ | ||
fun setSkillId(id: String) { | ||
skillId = id | ||
} | ||
|
||
private val conceptCardResultLiveData: LiveData<AsyncResult<ConceptCard>> by lazy { | ||
topicController.getConceptCard(skillId) | ||
} | ||
|
||
private fun processConceptCardLiveData(): LiveData<ConceptCard> { | ||
return Transformations.map(conceptCardResultLiveData, ::processConceptCardResult) | ||
} | ||
|
||
private fun processWorkedExamplesLiveData(): LiveData<List<SubtitledHtml>> { | ||
return Transformations.map(conceptCardResultLiveData, ::processConceptCardWorkExamples) | ||
} | ||
|
||
private fun processConceptCardResult(conceptCardResult: AsyncResult<ConceptCard>): ConceptCard { | ||
if (conceptCardResult.isFailure()) { | ||
logger.e("ConceptCardFragment", "Failed to retrieve Concept Card: " + conceptCardResult.getErrorOrNull()) | ||
} | ||
return conceptCardResult.getOrDefault(ConceptCard.getDefaultInstance()) | ||
} | ||
|
||
private fun processConceptCardWorkExamples(conceptCardResult: AsyncResult<ConceptCard>): List<SubtitledHtml> { | ||
if (conceptCardResult.isFailure()) { | ||
logger.e("ConceptCardFragment", "Failed to retrieve Concept Card: " + conceptCardResult.getErrorOrNull()) | ||
} | ||
return conceptCardResult.getOrDefault(ConceptCard.getDefaultInstance()).workedExampleList | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/oppia/app/topic/conceptcard/testing/ConceptCardFragmentTestActivity.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,17 @@ | ||
package org.oppia.app.topic.conceptcard.testing | ||
|
||
import android.os.Bundle | ||
import org.oppia.app.activity.InjectableAppCompatActivity | ||
import javax.inject.Inject | ||
|
||
/** Test Activity used for testing ConceptCardFragment */ | ||
class ConceptCardFragmentTestActivity : InjectableAppCompatActivity() { | ||
|
||
@Inject lateinit var conceptCardFragmentTestActivityController: ConceptCardFragmentTestActivityPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
activityComponent.inject(this) | ||
conceptCardFragmentTestActivityController.handleOnCreate() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../java/org/oppia/app/topic/conceptcard/testing/ConceptCardFragmentTestActivityPresenter.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,26 @@ | ||
package org.oppia.app.topic.conceptcard.testing | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import kotlinx.android.synthetic.main.concept_card_fragment_test_activity.* | ||
import org.oppia.app.R | ||
import org.oppia.app.topic.conceptcard.ConceptCardFragment | ||
import org.oppia.domain.topic.TEST_SKILL_ID_1 | ||
import org.oppia.domain.topic.TEST_SKILL_ID_2 | ||
import javax.inject.Inject | ||
|
||
private const val TAG_CONCEPT_CARD_DIALOG = "CONCEPT_CARD_DIALOG" | ||
|
||
/** The presenter for [ConceptCardFragmentTestActivity] */ | ||
class ConceptCardFragmentTestActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { | ||
fun handleOnCreate() { | ||
activity.setContentView(R.layout.concept_card_fragment_test_activity) | ||
activity.open_dialog_1.setOnClickListener { | ||
val frag = ConceptCardFragment.newInstance(TEST_SKILL_ID_1) | ||
frag.showNow(activity.supportFragmentManager, TAG_CONCEPT_CARD_DIALOG) | ||
} | ||
activity.open_dialog_2.setOnClickListener { | ||
val frag = ConceptCardFragment.newInstance(TEST_SKILL_ID_2) | ||
frag.showNow(activity.supportFragmentManager, TAG_CONCEPT_CARD_DIALOG) | ||
} | ||
} | ||
} |
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<data> | ||
<variable | ||
name="subtitledHtml" | ||
type="org.oppia.app.model.SubtitledHtml" /> | ||
</data> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
<TextView | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textColor="@android:color/black" | ||
android:text="@{subtitledHtml.getHtml()}"/> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</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
14 changes: 14 additions & 0 deletions
14
app/src/main/res/layout/concept_card_fragment_test_activity.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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<Button | ||
android:id="@+id/open_dialog_1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
<Button | ||
android:id="@+id/open_dialog_2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
</LinearLayout> |
Oops, something went wrong.