Skip to content

Commit

Permalink
Fix #1957: Optimise code in profile_chooser_profile_view.xml (#2100)
Browse files Browse the repository at this point in the history
* Last Update

* Fix #1957: Optimise codes in profile_chooser_profile_view
  • Loading branch information
peculiaruc authored Nov 12, 2020
1 parent 40568f0 commit 6dbde25
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 162 deletions.
20 changes: 8 additions & 12 deletions app/src/main/res/layout-land/profile_chooser_profile_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
name="viewModel"
type="org.oppia.android.app.model.ProfileChooserUiModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand All @@ -28,15 +27,15 @@
android:id="@+id/profile_chooser_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="@dimen/space_16dp"
android:layout_marginEnd="@dimen/space_16dp"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layoutMarginBottom="@{hasProfileEverBeenAddedValue ? @dimen/space_16dp : @dimen/space_28dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_16dp : @dimen/space_24dp}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layoutMarginBottom="@{hasProfileEverBeenAddedValue ? @dimen/space_16dp : @dimen/space_28dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_16dp : @dimen/space_24dp}">
app:layout_constraintTop_toTopOf="parent">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_avatar_img"
Expand All @@ -49,16 +48,13 @@

<TextView
android:id="@+id/profile_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Caption"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:maxLines="2"
android:singleLine="false"
android:text="@{viewModel.profile.name}"
android:textColor="@color/white"
android:textSize="14sp" />
android:textColor="@color/white" />

<TextView
android:id="@+id/profile_last_visited"
Expand Down
103 changes: 53 additions & 50 deletions app/src/main/res/layout-sw600dp-land/profile_chooser_profile_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,92 @@
type="org.oppia.android.app.model.ProfileChooserUiModel" />
</data>

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.TOP|Gravity.CENTER : Gravity.START}"
android:orientation="vertical"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_298dp}"
android:layout_margin="@dimen/space_16dp"
android:padding="@dimen/space_4dp"
app:layoutMarginBottom="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_0dp}"
app:layoutMarginEnd="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_298dp}"
app:layoutMarginBottom="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_0dp}">
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_298dp}">

<LinearLayout
android:id="@+id/profile_chooser_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER}"
android:orientation="@{hasProfileEverBeenAddedValue ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}"
app:layoutMarginEnd="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_24dp}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_24dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_24dp}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
profile:ignore="RtlSymmetry">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_avatar_img"
android:layout_width="108dp"
android:layout_height="108dp"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_48dp : @dimen/space_0dp}"
app:civ_border_color="@color/avatarBorder"
app:civ_border_width="1dp"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_48dp : @dimen/space_0dp}"
profile:src="@{viewModel.profile.avatar}" />

<LinearLayout
<TextView
android:id="@+id/profile_name_text"
style="@style/Heading2"
android:ellipsize="end"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:maxLines="2"
android:orientation="vertical"
android:singleLine="false"
android:text="@{viewModel.profile.name}"
android:textColor="@color/white"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/profile_view_already_added_description_parent_margin_top : @dimen/space_0dp}" />

<TextView
android:id="@+id/profile_last_visited"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-light"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:orientation="vertical"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/profile_view_already_added_description_parent_margin_top : @dimen/space_0dp}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}">

<TextView
android:id="@+id/profile_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:maxLines="2"
android:singleLine="false"
android:text="@{viewModel.profile.name}"
android:textColor="@color/white"
android:textSize="20sp" />
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.lastLoggedInTimestampMs > 0 ? View.VISIBLE : View.GONE}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/profile_view_already_added_description_parent_margin_top : @dimen/space_4dp}"
profile:lastVisited="@{viewModel.profile.lastLoggedInTimestampMs}" />

<TextView
android:id="@+id/profile_last_visited"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginTop="4dp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.lastLoggedInTimestampMs > 0 ? View.VISIBLE : View.GONE}"
profile:lastVisited="@{viewModel.profile.lastLoggedInTimestampMs}" />

<TextView
android:id="@+id/profile_is_admin_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/profile_chooser_admin"
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginTop="4dp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.isAdmin &amp;&amp; hasProfileEverBeenAddedValue ? View.VISIBLE : View.GONE}" />
</LinearLayout>
<TextView
android:id="@+id/profile_is_admin_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-light"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:orientation="vertical"
android:text="@string/profile_chooser_admin"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.isAdmin &amp;&amp; hasProfileEverBeenAddedValue ? View.VISIBLE : View.GONE}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/profile_view_already_added_description_parent_margin_top : @dimen/space_0dp}" />
</LinearLayout>

<View
android:id="@+id/add_profile_divider_view"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="40dp"
android:layout_marginTop="@dimen/space_40dp"
android:background="@color/oppiaProfileChooserDivider"
android:visibility="@{hasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}" />
</LinearLayout>
android:visibility="@{hasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_chooser_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
104 changes: 53 additions & 51 deletions app/src/main/res/layout-sw600dp-port/profile_chooser_profile_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,91 @@
type="org.oppia.android.app.model.ProfileChooserUiModel" />
</data>

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.TOP|Gravity.CENTER : Gravity.START}"
android:orientation="vertical"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_170dp}"
android:layout_margin="@dimen/space_16dp"
android:padding="@dimen/space_4dp"
app:layoutMarginBottom="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_0dp}"
app:layoutMarginEnd="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_170dp}"
app:layoutMarginBottom="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_0dp}">
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_170dp}">

<LinearLayout
android:id="@+id/profile_chooser_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER}"
android:orientation="@{hasProfileEverBeenAddedValue ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}"
app:layoutMarginEnd="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_24dp}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_24dp}"
app:layoutMarginEnd="@{hasProfileEverBeenAddedValue ? @dimen/space_16dp : @dimen/profile_view_not_added_margin}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_16dp : @dimen/profile_view_not_added_margin}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_24dp}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
profile:ignore="RtlSymmetry">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_avatar_img"
android:layout_width="108dp"
android:layout_height="108dp"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_48dp : @dimen/space_0dp}"
app:civ_border_color="@color/avatarBorder"
app:civ_border_width="1dp"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/space_48dp : @dimen/space_0dp}"
profile:src="@{viewModel.profile.avatar}" />

<LinearLayout
<TextView
android:id="@+id/profile_name_text"
style="@style/Heading2"
android:ellipsize="end"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:maxLines="2"
android:orientation="vertical"
android:singleLine="false"
android:text="@{viewModel.profile.name}"
android:textColor="@color/white"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/profile_view_already_added_description_parent_margin_top : @dimen/space_0dp}" />

<TextView
android:id="@+id/profile_last_visited"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-light"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:orientation="vertical"
app:layoutMarginTop="@{hasProfileEverBeenAddedValue ? @dimen/profile_view_already_added_description_parent_margin_top : @dimen/space_0dp}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}">

<TextView
android:id="@+id/profile_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:maxLines="2"
android:singleLine="false"
android:text="@{viewModel.profile.name}"
android:textColor="@color/white"
android:textSize="20sp" />
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.lastLoggedInTimestampMs > 0 ? View.VISIBLE : View.GONE}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_28dp}"
profile:lastVisited="@{viewModel.profile.lastLoggedInTimestampMs}" />

<TextView
android:id="@+id/profile_last_visited"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginTop="4dp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.lastLoggedInTimestampMs > 0 ? View.VISIBLE : View.GONE}"
profile:lastVisited="@{viewModel.profile.lastLoggedInTimestampMs}" />

<TextView
android:id="@+id/profile_is_admin_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/profile_chooser_admin"
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginTop="4dp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.isAdmin &amp;&amp; hasProfileEverBeenAddedValue ? View.VISIBLE : View.GONE}" />
</LinearLayout>
<TextView
android:id="@+id/profile_is_admin_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-light"
android:gravity="@{hasProfileEverBeenAddedValue ? Gravity.CENTER_HORIZONTAL : Gravity.CENTER_VERTICAL}"
android:orientation="vertical"
android:text="@string/profile_chooser_admin"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.isAdmin &amp;&amp; hasProfileEverBeenAddedValue ? View.VISIBLE : View.GONE}"
app:layoutMarginStart="@{hasProfileEverBeenAddedValue ? @dimen/space_0dp : @dimen/space_32dp}" />
</LinearLayout>

<View
android:id="@+id/add_profile_divider_view"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="72dp"
android:layout_marginTop="92dp"
android:background="@color/oppiaProfileChooserDivider"
android:visibility="@{hasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}" />
</LinearLayout>
android:visibility="@{hasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_chooser_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading

0 comments on commit 6dbde25

Please sign in to comment.