Skip to content

Commit

Permalink
Order select account first, block click and add check icon for curren…
Browse files Browse the repository at this point in the history
…t account
  • Loading branch information
tevincent committed Oct 9, 2024
1 parent d9ef56b commit e200200
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.infomaniak.drive.databinding.ViewSwitchSettingsBinding
import com.infomaniak.drive.ui.login.LoginActivity
import com.infomaniak.drive.ui.menu.UserAdapter
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.lib.core.models.user.User

class SwitchUserActivity : AppCompatActivity() {

Expand All @@ -41,7 +40,9 @@ class SwitchUserActivity : AppCompatActivity() {
}

AccountUtils.getAllUsers().observe(this@SwitchUserActivity) { users ->
usersRecyclerView.adapter = UserAdapter(users as ArrayList<User>) { user ->
val currentUserId = AccountUtils.currentUserId
val orderedUsers = users.sortedBy { it.id != currentUserId }
usersRecyclerView.adapter = UserAdapter(orderedUsers) { user ->
trackAccountEvent("switch")
AccountUtils.currentUser = user
AccountUtils.currentDriveId = -1
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/infomaniak/drive/ui/menu/UserAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import com.infomaniak.drive.utils.setUserView
import com.infomaniak.lib.core.models.user.User

class UserAdapter(
private val users: ArrayList<User>,
private val isCardview: Boolean = true,
private val users: List<User>,
private val isCardView: Boolean = true,
private val onItemClicked: (user: User) -> Unit,
) : Adapter<UserViewHolder>() {

override fun getItemViewType(position: Int): Int {
return if (isCardview) VIEW_TYPE_CARDVIEW
return if (isCardView) VIEW_TYPE_CARDVIEW
else VIEW_TYPE_NORMAL
}

Expand All @@ -59,7 +59,7 @@ class UserAdapter(
this as ItemUserBinding
}

itemUserBinding.setUserView(user, isCardview, onItemClicked)
itemUserBinding.setUserView(user, isCardView, onItemClicked)
}

override fun getItemCount() = users.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SelectDriveDialog : FullScreenBottomSheetDialog() {
}
binding.userCardview.root.isVisible = true

popupLayoutBinding.usersRecyclerView.adapter = UserAdapter(users as ArrayList<User>, isCardview = false) { user ->
popupLayoutBinding.usersRecyclerView.adapter = UserAdapter(users as ArrayList<User>, isCardView = false) { user ->
selectedUserId.value = user.id
driveListAdapter.setDrives(getDriveList())

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/infomaniak/drive/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,15 @@ fun Activity.setColorNavigationBar(appBar: Boolean = false) = with(window) {
fun String.isValidUrl(): Boolean = Patterns.WEB_URL.matcher(this).matches()

fun ItemUserBinding.setUserView(user: User, showChevron: Boolean = true, onItemClicked: (user: User) -> Unit) {
val isCurrentUser = AccountUtils.currentUserId == user.id
userName.text = user.displayName
userEmail.text = user.email
userAvatar.loadAvatar(user)
chevron.isVisible = showChevron
root.setOnClickListener { onItemClicked(user) }
chevron.isVisible = showChevron && !isCurrentUser
check.isVisible = isCurrentUser
if (!isCurrentUser) {
root.setOnClickListener { onItemClicked(user) }
}
}

fun ImageView.animateRotation(isDeployed: Boolean = false) {
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/layout/item_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,23 @@
android:id="@+id/chevron"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="18dp"
android:src="@drawable/ic_chevron_right"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/check"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginEnd="18dp"
tools:ignore="ContentDescription" />

<ImageView
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="18dp"
android:src="@drawable/ic_check"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit e200200

Please sign in to comment.