-
-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement My media (small) home section #4011
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jellyfin.androidtv.ui.home | ||
|
||
import android.content.Context | ||
import androidx.leanback.widget.HeaderItem | ||
import androidx.leanback.widget.ListRow | ||
import androidx.leanback.widget.Row | ||
import org.jellyfin.androidtv.R | ||
import org.jellyfin.androidtv.data.querying.GetUserViewsRequest | ||
import org.jellyfin.androidtv.ui.itemhandling.ItemRowAdapter | ||
import org.jellyfin.androidtv.ui.presentation.CardPresenter | ||
import org.jellyfin.androidtv.ui.presentation.MutableObjectAdapter | ||
import org.jellyfin.androidtv.ui.presentation.UserViewCardPresenter | ||
|
||
class HomeFragmentViewsRow( | ||
val small: Boolean, | ||
) : HomeFragmentRow { | ||
private companion object { | ||
val smallCardPresenter = UserViewCardPresenter(true) | ||
val largeCardPresenter = UserViewCardPresenter(false) | ||
} | ||
|
||
override fun addToRowsAdapter(context: Context, cardPresenter: CardPresenter, rowsAdapter: MutableObjectAdapter<Row>) { | ||
val presenter = if (small) smallCardPresenter else largeCardPresenter | ||
val rowAdapter = ItemRowAdapter(context, GetUserViewsRequest, presenter, rowsAdapter) | ||
|
||
val header = HeaderItem(context.getString(R.string.lbl_my_media)) | ||
val row = ListRow(header, rowAdapter) | ||
rowAdapter.setRow(row) | ||
rowAdapter.Retrieve() | ||
rowsAdapter.add(row) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.jellyfin.androidtv.ui.presentation | ||
|
||
import android.util.TypedValue | ||
import android.view.ViewGroup | ||
import androidx.annotation.ColorInt | ||
import androidx.core.content.ContextCompat | ||
import androidx.leanback.widget.Presenter | ||
import org.jellyfin.androidtv.R | ||
import org.jellyfin.androidtv.ui.card.LegacyImageCardView | ||
import org.jellyfin.androidtv.ui.itemhandling.BaseRowItem | ||
import org.jellyfin.androidtv.util.ImageHelper | ||
import org.jellyfin.sdk.model.api.ImageType | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class UserViewCardPresenter( | ||
val small: Boolean, | ||
) : Presenter(), KoinComponent { | ||
private val imageHelper by inject<ImageHelper>() | ||
|
||
inner class ViewHolder( | ||
private val cardView: LegacyImageCardView, | ||
) : Presenter.ViewHolder(cardView) { | ||
fun setItem(rowItem: BaseRowItem?) { | ||
val baseItem = rowItem?.baseItem | ||
|
||
// Load image | ||
val imageTag = baseItem?.imageTags?.get(ImageType.PRIMARY) | ||
val imageBlurhash = imageTag?.let { baseItem.imageBlurHashes?.get(ImageType.PRIMARY)?.get(it) } | ||
val imageUrl = imageTag?.let { imageHelper.getImageUrl(baseItem.id, ImageType.PRIMARY, it) } | ||
cardView.mainImageView.load( | ||
url = imageUrl, | ||
blurHash = imageBlurhash, | ||
placeholder = ContextCompat.getDrawable(cardView.context, R.drawable.tile_land_folder), | ||
aspectRatio = ImageHelper.ASPECT_RATIO_16_9, | ||
blurHashResolution = 32, | ||
) | ||
|
||
// Set title | ||
cardView.setTitleText(rowItem?.getName(cardView.context)) | ||
|
||
// Set size | ||
if (small) { | ||
cardView.setMainImageDimensions(133, 75) | ||
Check warning Code scanning / detekt Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning
This expression contains a magic number. Consider defining it to a well named constant.
|
||
} else { | ||
cardView.setMainImageDimensions(224, 126) | ||
Check warning Code scanning / detekt Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning
This expression contains a magic number. Consider defining it to a well named constant.
Check warning Code scanning / detekt Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning
This expression contains a magic number. Consider defining it to a well named constant.
|
||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { | ||
val cardView = LegacyImageCardView(parent.context, true) | ||
cardView.isFocusable = true | ||
cardView.isFocusableInTouchMode = true | ||
|
||
val typedValue = TypedValue() | ||
val theme = parent.context.theme | ||
theme.resolveAttribute(R.attr.cardViewBackground, typedValue, true) | ||
@ColorInt val color = typedValue.data | ||
cardView.setBackgroundColor(color) | ||
|
||
return ViewHolder(cardView) | ||
} | ||
|
||
override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) { | ||
if (item !is BaseRowItem) return | ||
|
||
(viewHolder as? ViewHolder)?.setItem(item) | ||
} | ||
|
||
override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder?) { | ||
(viewHolder as? ViewHolder)?.setItem(null) | ||
} | ||
} |
Check warning
Code scanning / detekt
Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning