diff --git a/app/src/main/java/org/oppia/app/player/state/SelectionInteractionView.kt b/app/src/main/java/org/oppia/app/player/state/SelectionInteractionView.kt index dae7e63b1a2..57d367bd2cd 100644 --- a/app/src/main/java/org/oppia/app/player/state/SelectionInteractionView.kt +++ b/app/src/main/java/org/oppia/app/player/state/SelectionInteractionView.kt @@ -39,22 +39,18 @@ class SelectionInteractionView @JvmOverloads constructor( lateinit var entityType: String private lateinit var explorationId: String - init { - adapter = createAdapter() - } - override fun onAttachedToWindow() { super.onAttachedToWindow() FragmentManager.findFragment(this).createViewComponent(this).inject(this) } - fun setItemInputType(selectionItemInputType: SelectionItemInputType) { + fun setAllOptionsItemInputType(selectionItemInputType: SelectionItemInputType) { // TODO(#299): Find a cleaner way to initialize the item input type. Using data-binding results in a race condition // with setting the adapter data, so this needs to be done in an order-agnostic way. There should be a way to do // this more efficiently and cleanly than always relying on notifying of potential changes in the adapter when the // type is set (plus the type ought to be permanent). this.selectionItemInputType = selectionItemInputType - adapter!!.notifyDataSetChanged() + adapter = createAdapter() } // TODO(#264): Clean up HTML parser such that it can be handled completely through a binding adapter, allowing @@ -106,10 +102,10 @@ class SelectionInteractionView @JvmOverloads constructor( } /** Sets the [SelectionItemInputType] for a specific [SelectionInteractionView] via data-binding. */ -@BindingAdapter("itemInputType") -fun setItemInputType( +@BindingAdapter("allOptionsItemInputType") +fun setAllOptionsItemInputType( selectionInteractionView: SelectionInteractionView, selectionItemInputType: SelectionItemInputType -) = selectionInteractionView.setItemInputType(selectionItemInputType) +) = selectionInteractionView.setAllOptionsItemInputType(selectionItemInputType) /** Sets the exploration ID for a specific [SelectionInteractionView] via data-binding. */ @BindingAdapter("explorationId") diff --git a/app/src/main/java/org/oppia/app/topic/overview/TopicOverviewViewModel.kt b/app/src/main/java/org/oppia/app/topic/overview/TopicOverviewViewModel.kt index 513796f20ef..0a98433f743 100644 --- a/app/src/main/java/org/oppia/app/topic/overview/TopicOverviewViewModel.kt +++ b/app/src/main/java/org/oppia/app/topic/overview/TopicOverviewViewModel.kt @@ -15,7 +15,7 @@ import javax.inject.Inject class TopicOverviewViewModel @Inject constructor( private val context: Context ) : ObservableViewModel() { - private val decimalFormat: DecimalFormat = DecimalFormat("#.###") + private val decimalFormat: DecimalFormat = DecimalFormat("##") val topic = ObservableField(Topic.getDefaultInstance()) @@ -25,20 +25,21 @@ class TopicOverviewViewModel @Inject constructor( /** Returns the space this topic requires on disk, formatted for display. */ fun getTopicSizeWithUnit(): String { - val size: Double = topic.get()?.diskSizeBytes!!.toDouble() - if (size == 0.0) { - return "0 " + context.getString(R.string.size_bytes) - } - val sizeInKB = size / 1024.0 - val sizeInMB = size / 1024.0 / 1024.0 - val sizeInGB = size / 1024.0 / 1024.0 / 1024.0 - val sizeInTB = size / 1024.0 / 1024.0 / 1024.0 / 1024.0 - return when { - sizeInTB >= 1 -> decimalFormat.format(sizeInTB) + " " + context.getString(R.string.size_tb) - sizeInGB >= 1 -> decimalFormat.format(sizeInGB) + " " + context.getString(R.string.size_gb) - sizeInMB >= 1 -> decimalFormat.format(sizeInMB) + " " + context.getString(R.string.size_mb) - sizeInKB >= 1 -> decimalFormat.format(sizeInKB) + " " + context.getString(R.string.size_kb) - else -> decimalFormat.format(size) + " " + context.getString(R.string.size_bytes) - } + return topic.get()?.let { topic -> + val sizeInBytes: Int = topic.diskSizeBytes.toInt() + val sizeInKb = sizeInBytes / 1024 + val sizeInMb = sizeInKb / 1024 + val sizeInGb = sizeInMb / 1024 + return@let when { + sizeInGb >= 1 -> context.getString(R.string.size_gb, roundUpToHundreds(sizeInGb)) + sizeInMb >= 1 -> context.getString(R.string.size_mb, roundUpToHundreds(sizeInMb)) + sizeInKb >= 1 -> context.getString(R.string.size_kb, roundUpToHundreds(sizeInKb)) + else -> context.getString(R.string.size_bytes, roundUpToHundreds(sizeInBytes)) + } + } ?: context.getString(R.string.unknown_size) + } + + private fun roundUpToHundreds(intValue: Int): Int { + return ((intValue + 9) / 10) * 10 } } diff --git a/app/src/main/res/drawable/topic_fractions_04.png b/app/src/main/res/drawable/topic_fractions_04.png index b31d2b02e34..10488688411 100644 Binary files a/app/src/main/res/drawable/topic_fractions_04.png and b/app/src/main/res/drawable/topic_fractions_04.png differ diff --git a/app/src/main/res/layout/selection_interaction_item.xml b/app/src/main/res/layout/selection_interaction_item.xml index c391195ac29..fee386dbc41 100644 --- a/app/src/main/res/layout/selection_interaction_item.xml +++ b/app/src/main/res/layout/selection_interaction_item.xml @@ -35,9 +35,9 @@ android:layout_marginEnd="20dp" android:layout_marginBottom="@dimen/divider_margin_bottom" android:divider="@android:color/transparent" + app:allOptionsItemInputType="@{viewModel.getSelectionItemInputType()}" app:data="@{viewModel.choiceItems}" app:explorationId="@{viewModel.explorationId}" - app:itemInputType="@{viewModel.getSelectionItemInputType()}" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> diff --git a/app/src/main/res/layout/topic_review_summary_view.xml b/app/src/main/res/layout/topic_review_summary_view.xml index f7e358c916a..fd653184137 100755 --- a/app/src/main/res/layout/topic_review_summary_view.xml +++ b/app/src/main/res/layout/topic_review_summary_view.xml @@ -29,7 +29,7 @@ android:layout_width="0dp" android:layout_height="104dp" android:importantForAccessibility="no" - android:scaleType="fitXY" + android:scaleType="centerInside" android:src="@{skill.skillThumbnail.thumbnailGraphic}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e507e13c08..67d405d5aba 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,11 +64,11 @@ Play/Pause Audio Help Preferences - Bytes - KB - MB - GB - TB + Unknown size + %d Bytes + %d KB + %d MB + %d GB 1 Chapter diff --git a/domain/src/main/assets/fractions_exploration1.json b/domain/src/main/assets/fractions_exploration1.json index cbdea63a09f..2c781f174eb 100644 --- a/domain/src/main/assets/fractions_exploration1.json +++ b/domain/src/main/assets/fractions_exploration1.json @@ -2739,7 +2739,7 @@ "classifier_model_id": null, "content": { "content_id": "content", - "html": "

“Hi, Mr Crumb,” said Matthew. “I'd like to buy half of that chocolate cake, please.”

“Yes, fine,” said Crumb. He pulled out a knife and cut off a small corner of the cake for Matthew, like this:

Is Crumb giving Matthew the correct amount of cake?

" + "html": "

Matthew was happy to go back to the bakery, because he wanted to get more cake for his friends. However, when he got there, he met a lazy-looking Assistant Baker behind the counter, named Crumb.

“Hi, Mr. Crumb,” said Matthew. “I'd like to buy half of that chocolate cake, please.”

“Yes, fine,” said Crumb. He pulled out a knife and cut off a small corner of the cake for Matthew, like this:

Is Crumb giving Matthew the correct amount of cake?

" }, "written_translations": { "translations_mapping": {