Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.lagradost.cloudstream3.ui.account

import android.os.Build
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import coil3.transform.RoundedCornersTransformation
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.databinding.AccountListItemAddBinding
import com.lagradost.cloudstream3.databinding.AccountListItemBinding
Expand All @@ -18,6 +15,8 @@ import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
import android.util.TypedValue
import android.view.View

class AccountAdapter(
private val accountSelectCallback: (DataStoreHelper.Account) -> Unit,
Expand All @@ -29,6 +28,12 @@ class AccountAdapter(
companion object {
const val VIEW_TYPE_SELECT_ACCOUNT = 0
const val VIEW_TYPE_EDIT_ACCOUNT = 2

fun View.setRippleForeground() {
val outValue = TypedValue()
context.theme.resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true)
foreground = context.getDrawable(outValue.resourceId)
}
}


Expand All @@ -47,45 +52,24 @@ class AccountAdapter(
when (val binding = holder.view) {
is AccountListItemBinding -> binding.apply {
val isTv = isLayout(TV or EMULATOR) || !root.isInTouchMode

val isLastUsedAccount = item.keyIndex == DataStoreHelper.selectedKeyIndex

accountName.text = item.name
accountImage.loadImage(item.image)
lockIcon.isVisible = item.lockPin != null
outline.isVisible = !isTv && isLastUsedAccount

if (isTv) {
// For emulator but this is fine on TV also
root.isFocusableInTouchMode = true
if (isLastUsedAccount) {
root.requestFocus()
}
if (isTv && isLastUsedAccount) root.requestFocus()
if (!isTv) cardView.setRippleForeground()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
root.foreground = ContextCompat.getDrawable(
root.context,
R.drawable.outline_drawable
)
}
} else {
if (!isTv) {
root.setOnLongClickListener {
showAccountEditDialog(
context = root.context,
account = item,
isNewAccount = false,
accountEditCallback = { account ->
accountEditCallback.invoke(
account
)
},
accountDeleteCallback = { account ->
accountDeleteCallback.invoke(
account
)
}
accountEditCallback = { account -> accountEditCallback.invoke(account) },
accountDeleteCallback = { account -> accountDeleteCallback.invoke(account) }
)

true
}
}
Expand All @@ -97,42 +81,22 @@ class AccountAdapter(

is AccountListItemEditBinding -> binding.apply {
val isTv = isLayout(TV or EMULATOR) || !root.isInTouchMode

val isLastUsedAccount = item.keyIndex == DataStoreHelper.selectedKeyIndex

accountName.text = item.name
accountImage.loadImage(item.image) {
RoundedCornersTransformation(10f)
}
accountImage.loadImage(item.image)
lockIcon.isVisible = item.lockPin != null
outline.isVisible = !isTv && isLastUsedAccount

if (isTv) {
// For emulator but this is fine on TV also
root.isFocusableInTouchMode = true
if (isLastUsedAccount) {
root.requestFocus()
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
root.foreground = ContextCompat.getDrawable(
root.context,
R.drawable.outline_drawable
)
}
}
if (isTv && isLastUsedAccount) root.requestFocus()
if (!isTv) cardView.setRippleForeground()

root.setOnClickListener {
showAccountEditDialog(
context = root.context,
account = item,
isNewAccount = false,
accountEditCallback = { account -> accountEditCallback.invoke(account) },
accountDeleteCallback = { account ->
accountDeleteCallback.invoke(
account
)
}
accountDeleteCallback = { account -> accountDeleteCallback.invoke(account) }
)
}
}
Expand All @@ -142,6 +106,9 @@ class AccountAdapter(
override fun onBindFooter(holder: ViewHolderState<Any>) {
val binding = holder.view as? AccountListItemAddBinding ?: return
binding.apply {
val isTv = isLayout(TV or EMULATOR) || !root.isInTouchMode
if (!isTv) cardView.setRippleForeground()

root.setOnClickListener {
val accounts = this@AccountAdapter.immutableCurrentList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideProgress
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.setRippleForeground
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout

object AccountHelper {
fun showAccountEditDialog(
Expand All @@ -56,6 +60,12 @@ object AccountHelper {

var currentEditAccount = account
val dialog = builder.show()
binding.accountImageHolder.requestFocus()

if (!isLayout(TV or EMULATOR)) {
binding.accountImageHolder.setRippleForeground()
binding.editProfilePhotoButtonHolder.setRippleForeground()
}

if (!isNewAccount) binding.title.setText(R.string.edit_account)

Expand Down Expand Up @@ -100,7 +110,7 @@ object AccountHelper {

// Handle the profile picture and its interactions
binding.accountImage.loadImage(account.image)
binding.accountImage.setOnClickListener {
binding.accountImageHolder.setOnClickListener {
// Roll the image forwards once
currentEditAccount = currentEditAccount.copy(customImage = null)
currentEditAccount =
Expand Down Expand Up @@ -166,7 +176,7 @@ object AccountHelper {

canSetPin = true

binding.editProfilePhotoButton.setOnClickListener {
binding.editProfilePhotoButtonHolder.setOnClickListener {
val bottomSheetDialog = BottomSheetDialog(context)
val sheetBinding = BottomInputDialogBinding.inflate(LayoutInflater.from(context))
bottomSheetDialog.setContentView(sheetBinding.root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ class AccountSelectActivity : FragmentActivity(), BiometricCallback {
// Scroll to current account (which is focused by default)
val layoutManager = recyclerView.layoutManager as GridLayoutManager
layoutManager.scrollToPositionWithOffset(selectedKeyIndex, 0)
if (isLayout(TV or EMULATOR)) {
recyclerView.post {
layoutManager.findViewByPosition(selectedKeyIndex)?.requestFocus()
}
}
}

observe(accountViewModel.isEditing) { isEditing ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AccountSelectLinearItemDecoration(private val size: Int) : RecyclerView.It
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val layoutParams = view.layoutParams as RecyclerView.LayoutParams
layoutParams.width = size
layoutParams.height = size
layoutParams.height = RecyclerView.LayoutParams.WRAP_CONTENT
view.layoutParams = layoutParams
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/color/account_edit_btn_tint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="?attr/black"/>
<item android:color="?attr/textColor"/>
</selector>
7 changes: 5 additions & 2 deletions app/src/main/res/drawable/outline_drawable_forced_round.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/outline_card"/> <!-- focused -->
<item android:state_focused="true" android:drawable="@drawable/oval_stroke_focus" />
<item android:state_hovered="true" android:drawable="@drawable/oval_stroke_focus" />
<item>
<shape android:shape="oval" />
</item>
</selector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/oval_stroke_focus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="3dp" android:color="?attr/white" />
</shape>
13 changes: 5 additions & 8 deletions app/src/main/res/drawable/rounded_outline.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white">

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/oval_stroke_focus" />
<item android:state_hovered="true" android:drawable="@drawable/oval_stroke_focus" />
<item>
<shape android:shape="oval">
<stroke
android:width="2dp"
android:color="?attr/white" />
<corners android:radius="10dp" />
<stroke android:width="2dp" android:color="?attr/account_unselected_stroke" />
</shape>
</item>
</ripple>
</selector>
85 changes: 58 additions & 27 deletions app/src/main/res/layout/account_edit_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,58 @@
android:layout_marginBottom="60dp"
android:orientation="vertical">

<androidx.cardview.widget.CardView
android:layout_width="@dimen/account_select_linear_item_size"
android:layout_height="@dimen/account_select_linear_item_size"
android:layout_gravity="center"
app:cardCornerRadius="@dimen/rounded_image_radius">

<ImageView
android:id="@+id/account_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">

<androidx.cardview.widget.CardView
android:id="@+id/account_image_holder"
android:layout_width="@dimen/account_select_linear_item_size"
android:layout_height="@dimen/account_select_linear_item_size"
android:layout_gravity="center"
android:contentDescription="@string/preview_background_img_des"
android:focusable="true"
android:foreground="@drawable/outline_drawable_forced_round"
android:scaleType="centerCrop"
android:src="@drawable/profile_bg_blue" />

<ImageView
android:id="@+id/edit_profile_photo_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultFocusHighlightEnabled="false"
android:nextFocusRight="@id/edit_profile_photo_button_holder"
android:nextFocusDown="@id/edit_profile_photo_button_holder"
app:cardCornerRadius="100dp"
app:cardElevation="0dp">

<requestFocus />

<ImageView
android:id="@+id/account_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:contentDescription="@string/preview_background_img_des"
android:scaleType="centerCrop"
android:src="@drawable/profile_bg_blue" />
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/edit_profile_photo_button_holder"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="bottom|end"
android:background="@color/skipOpTransparent"
android:padding="5dp"
android:src="@drawable/ic_baseline_edit_24" />
</androidx.cardview.widget.CardView>
android:defaultFocusHighlightEnabled="false"
android:foreground="@drawable/outline_drawable_forced_round"
android:nextFocusLeft="@id/account_image_holder"
android:nextFocusUp="@id/account_image_holder"
android:nextFocusDown="@id/account_name"
app:cardCornerRadius="16dp"
app:cardElevation="0dp"
app:cardBackgroundColor="@color/primaryGrayBackground">

<ImageView
android:id="@+id/edit_profile_photo_button"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="center"
android:src="@drawable/ic_baseline_edit_24"
app:tint="@color/white" />
</androidx.cardview.widget.CardView>
</FrameLayout>

<EditText
android:id="@+id/account_name"
Expand All @@ -71,9 +97,8 @@
android:autofillHints="username"
android:hint="@string/default_account"
android:inputType="text"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:nextFocusDown="@id/site_url_input"
android:nextFocusUp="@id/edit_profile_photo_button_holder"
android:nextFocusDown="@id/lockProfileCheckbox"
android:requiresFadingEdge="vertical"
android:textColorHint="?attr/grayTextColor"
tools:ignore="LabelFor" />
Expand All @@ -83,10 +108,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="?attr/textColor"
android:nextFocusUp="@id/account_name"
android:nextFocusDown="@id/apply_btt"
android:text="@string/lock_profile"
android:textColor="?attr/grayTextColor" />


</LinearLayout>

<RelativeLayout
Expand All @@ -104,6 +130,7 @@
android:layout_width="wrap_content"
android:layout_alignParentStart="true"
android:layout_gravity="center_vertical"
android:nextFocusUp="@id/lockProfileCheckbox"
android:nextFocusRight="@id/apply_btt"
android:text="@string/delete" />

Expand All @@ -113,6 +140,8 @@
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_toStartOf="@+id/cancel_btt"
android:nextFocusUp="@id/lockProfileCheckbox"
android:nextFocusDown="@id/cancel_btt"
android:nextFocusLeft="@id/delete_btt"
android:nextFocusRight="@id/cancel_btt"
android:text="@string/sort_apply" />
Expand All @@ -123,6 +152,8 @@
android:layout_width="wrap_content"
android:layout_alignParentEnd="true"
android:layout_gravity="center_vertical|end"
android:nextFocusUp="@id/apply_btt"
android:nextFocusDown="@id/apply_btt"
android:nextFocusLeft="@id/apply_btt"
android:text="@string/sort_cancel" />

Expand Down
Loading
Loading