Skip to content

Commit

Permalink
Fix touch support in home/auth screens (#1230)
Browse files Browse the repository at this point in the history
* Fix touch support for "switch user" button

* Fix touch support for server button

(cherry picked from commit a6f17e8)
  • Loading branch information
nielsvanvelzen committed Nov 4, 2021
1 parent 3a49573 commit ec467db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ServerButtonView @JvmOverloads constructor(

init {
isFocusable = true
isClickable = true
descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.jellyfin.androidtv.ui.home

import android.content.Intent
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomViewTarget
import com.bumptech.glide.request.transition.Transition
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.TvApp
import org.jellyfin.androidtv.auth.SessionRepository
import org.jellyfin.androidtv.databinding.FragmentToolbarHomeBinding
Expand Down Expand Up @@ -40,7 +41,7 @@ class HomeToolbarFragment : Fragment() {
activity?.startActivity(settingsIntent)
}

binding.switchUsersContainer.setOnClickListener {
binding.switchUsers.setOnClickListener {
switchUser()
}

Expand All @@ -55,25 +56,23 @@ class HomeToolbarFragment : Fragment() {
private fun setUserImage(image: String?) {
Glide.with(requireContext())
.load(image)
.placeholder(R.drawable.ic_switch_users)
.centerInside()
.circleCrop()
.into(object : CustomViewTarget<ImageButton, Drawable>(binding.switchUsersImage) {
.into(object : CustomViewTarget<ImageButton, Drawable>(binding.switchUsers) {
override fun onLoadFailed(errorDrawable: Drawable?) {
binding.switchUsersImage.isVisible = false
binding.switchUsersIcon.isVisible = true
binding.switchUsersImage.setImageDrawable(null)
binding.switchUsers.imageTintMode = PorterDuff.Mode.SRC_IN
binding.switchUsers.setImageDrawable(errorDrawable)
}

override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
binding.switchUsersImage.isVisible = true
binding.switchUsersIcon.isVisible = false
binding.switchUsersImage.setImageDrawable(resource)
binding.switchUsers.imageTintMode = null
binding.switchUsers.setImageDrawable(resource)
}

override fun onResourceCleared(placeholder: Drawable?) {
binding.switchUsersImage.isVisible = false
binding.switchUsersIcon.isVisible = true
binding.switchUsersImage.setImageDrawable(null)
binding.switchUsers.imageTintMode = PorterDuff.Mode.SRC_IN
binding.switchUsers.setImageDrawable(placeholder)
}
})
}
Expand Down
35 changes: 7 additions & 28 deletions app/src/main/res/layout/fragment_toolbar_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,12 @@
android:layout_width="8dp"
android:layout_height="0dp" />

<!-- Only one of the next 2 buttons should be shown at a time -->
<FrameLayout
android:id="@+id/switch_users_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusable="true">

<ImageButton
android:id="@+id/switch_users_icon"
style="@style/Button.Icon"
android:layout_width="41dp"
android:layout_height="41dp"
android:contentDescription="@string/lbl_switch_user"
android:duplicateParentState="true"
android:src="@drawable/ic_switch_users" />

<ImageButton
android:id="@+id/switch_users_image"
style="@style/Button.Icon"
android:layout_width="41dp"
android:layout_height="41dp"
android:contentDescription="@string/lbl_switch_user"
android:duplicateParentState="true"
android:tint="@null"
android:visibility="gone" />
</FrameLayout>
<ImageButton
android:id="@+id/switch_users"
style="@style/Button.Icon"
android:layout_width="41dp"
android:layout_height="41dp"
android:contentDescription="@string/lbl_switch_user"
android:src="@drawable/ic_switch_users" />
</LinearLayout>
</org.jellyfin.androidtv.ui.shared.ToolbarView>
1 change: 1 addition & 0 deletions app/src/main/res/layout/view_button_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/Button.Default"
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
Expand Down

0 comments on commit ec467db

Please sign in to comment.