Skip to content

Commit fa85b50

Browse files
committed
add details
1 parent 2cdd791 commit fa85b50

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

10-mars-photos/app/src/main/java/com/example/android/marsphotos/detail/DetailViewModel.kt

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import android.app.Application
44
import androidx.lifecycle.AndroidViewModel
55
import androidx.lifecycle.LiveData
66
import androidx.lifecycle.MutableLiveData
7+
import androidx.lifecycle.Transformations
8+
import com.example.android.marsphotos.R
79
import com.example.android.marsphotos.network.MarsPhoto
810

911
class DetailViewModel(marsProperty: MarsPhoto, app: Application) : AndroidViewModel(app) {
@@ -14,4 +16,22 @@ class DetailViewModel(marsProperty: MarsPhoto, app: Application) : AndroidViewMo
1416
init {
1517
_selectedProperty.value = marsProperty
1618
}
19+
20+
val displayPropertyPrice = Transformations.map(selectedProperty) {
21+
app.applicationContext.getString(
22+
when (it.isRental) {
23+
true -> R.string.display_price_monthly_rental
24+
false -> R.string.display_price
25+
}, it.price
26+
)
27+
}
28+
29+
val displayPropertyType = Transformations.map(selectedProperty) {
30+
app.applicationContext.getString(R.string.display_type,
31+
app.applicationContext.getString(
32+
when (it.isRental) {
33+
true -> R.string.type_rent
34+
false -> R.string.type_sale
35+
}))
36+
}
1737
}

10-mars-photos/app/src/main/res/layout/fragment_detail.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
android:layout_marginTop="16dp"
3939
android:textColor="#de000000"
4040
android:textSize="39sp"
41-
android:text="nothing"
41+
android:text="@{viewModel.displayPropertyType}"
4242
app:layout_constraintStart_toStartOf="parent"
4343
app:layout_constraintTop_toBottomOf="@+id/main_photo_image"
4444
tools:text="To Rent" />
@@ -50,7 +50,7 @@
5050
android:layout_marginTop="8dp"
5151
android:textColor="#de000000"
5252
android:textSize="20sp"
53-
android:text="nothing"
53+
android:text="@{viewModel.displayPropertyPrice}"
5454
app:layout_constraintStart_toStartOf="parent"
5555
app:layout_constraintTop_toBottomOf="@+id/property_type_text"
5656
tools:text="$100,000" />

0 commit comments

Comments
 (0)