Skip to content

Commit

Permalink
Set visibility of icon manually to prevent flickering (#2559)
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 authored Jul 25, 2024
1 parent 69b610f commit 002c4f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.android.ground.ui.surveyselector

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.ground.databinding.SurveyCardItemBinding
Expand All @@ -42,10 +43,17 @@ class SurveyListAdapter(

/** Binds [SurveyListItem] data to [ViewHolder]. */
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item: SurveyListItem = surveys[position]
holder.binding.item = item
holder.binding.viewModel = viewModel
holder.binding.fragment = fragment
val surveyListItem = surveys[position]
with(holder.binding) {
val me = this@SurveyListAdapter
item = surveyListItem
viewModel = me.viewModel
fragment = me.fragment

val offlineVisibility = if (surveyListItem.availableOffline) View.VISIBLE else View.GONE
offlineIcon.visibility = offlineVisibility
overflowMenu.visibility = offlineVisibility
}
}

/** Returns the size of the list. */
Expand Down
20 changes: 9 additions & 11 deletions ground/src/main/res/layout/survey_card_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

<com.google.android.material.card.MaterialCardView
android:id="@+id/survey_card"
style="@style/Widget.App.CardView.SurfaceContainerLowest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
style="@style/Widget.App.CardView.SurfaceContainerLowest"
android:clickable="true"
android:focusable="true"
android:onClick="@{() -> viewModel.activateSurvey(item.id)}"
Expand All @@ -56,8 +56,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@{item.title}"
app:layout_constraintEnd_toStartOf="@id/survey_card_item_widgets"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -70,25 +70,25 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:text="@{item.description}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="@id/title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="Report areas of suspected or observed deforestation." />

<LinearLayout
android:id="@+id/survey_card_item_widgets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/offlineIcon"
android:layout_width="24dp"
Expand All @@ -100,18 +100,16 @@
app:layout_constraintBottom_toBottomOf="@id/overflowMenu"
app:layout_constraintEnd_toStartOf="@+id/overflowMenu"
app:layout_constraintTop_toTopOf="@id/overflowMenu"
app:srcCompat="@drawable/ic_offline_pin"
app:visible="@{item.availableOffline}" />
app:srcCompat="@drawable/ic_offline_pin" />

<!-- Overflow menu "..." affordance. -->
<Button
android:id="@+id/overflowMenu"
style="@style/Widget.App.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationX="4dp"
android:onClick="@{(view) -> fragment.showPopupMenu(view, item.id)}"
app:visible="@{item.availableOffline}"
android:translationX="4dp"
app:icon="@drawable/ic_more_vert" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down

0 comments on commit 002c4f6

Please sign in to comment.