Skip to content

Commit

Permalink
Merge branch 'develop' into temp-integration-pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHenning committed Nov 20, 2019
2 parents 787f0a2 + fdccc6f commit 1c8442b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<InjectableFragment>(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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>(Topic.getDefaultInstance())

Expand All @@ -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
}
}
Binary file modified app/src/main/res/drawable/topic_fractions_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/selection_interaction_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</LinearLayout>
</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/topic_review_summary_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
<string name="play_pause_audio">Play/Pause Audio</string>
<string name="help">Help</string>
<string name="preferences">Preferences</string>
<string name="size_bytes">Bytes</string>
<string name="size_kb">KB</string>
<string name="size_mb">MB</string>
<string name="size_gb">GB</string>
<string name="size_tb">TB</string>
<string name="unknown_size">Unknown size</string>
<string name="size_bytes">%d Bytes</string>
<string name="size_kb">%d KB</string>
<string name="size_mb">%d MB</string>
<string name="size_gb">%d GB</string>
<plurals name="chapter_count">
<item quantity="one">
1 Chapter
Expand Down
2 changes: 1 addition & 1 deletion domain/src/main/assets/fractions_exploration1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,7 @@
"classifier_model_id": null,
"content": {
"content_id": "content",
"html": "<p>“Hi, Mr Crumb,” said Matthew. “I'd like to buy half of that chocolate cake, please.”</p><p>“Yes, fine,” said Crumb. He pulled out a knife and cut off a small corner of the cake for Matthew, like this:</p><oppia-noninteractive-image alt-with-value=\"&amp;quot;Square cake with 2/9ths cut off.&amp;quot;\" caption-with-value=\"&amp;quot;&amp;quot;\" filepath-with-value=\"&amp;quot;img_20180109_231743_oom5t5uurn_height_192_width_192.png&amp;quot;\"></oppia-noninteractive-image><p>Is Crumb giving Matthew the correct amount of cake?<br></p>"
"html": "<p>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.</p><p>“Hi, Mr. Crumb,” said Matthew. “I'd like to buy half of that chocolate cake, please.”</p><p>“Yes, fine,” said Crumb. He pulled out a knife and cut off a small corner of the cake for Matthew, like this:</p><oppia-noninteractive-image alt-with-value=\"&amp;quot;Square cake with 2/9ths cut off.&amp;quot;\" caption-with-value=\"&amp;quot;&amp;quot;\" filepath-with-value=\"&amp;quot;img_20180109_231743_oom5t5uurn_height_192_width_192.png&amp;quot;\"></oppia-noninteractive-image><p>Is Crumb giving Matthew the correct amount of cake?<br></p>"
},
"written_translations": {
"translations_mapping": {
Expand Down

0 comments on commit 1c8442b

Please sign in to comment.