Skip to content

Commit

Permalink
Tweak cast list
Browse files Browse the repository at this point in the history
Simplify cast view by using ConstraintLayout
Fix GridLayout cell dimensions, by specifying weight and gravity on each cell, compute slightly smaller image sizes and let the ImageView adjust when the image is set
  • Loading branch information
SyncedSynapse committed Aug 15, 2022
1 parent 7bb1b47 commit 0665552
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 130 deletions.
Expand Up @@ -55,7 +55,7 @@ public class AllCastActivity extends BaseActivity {
// Extras to be passed to this activity: title and the cast list
public static final String EXTRA_TITLE = "EXTRA_TITLE";
public static final String EXTRA_CAST_LIST = "EXTRA_CAST_LIST";
public static final float CAST_NAME_ALPHA = 0.9f;
public static final float CAST_NAME_ALPHA = 0.8f;

// Passed arguments
private String movie_tvshow_title;
Expand Down Expand Up @@ -152,7 +152,8 @@ private void setupActionBar(String title) {

public static class CastArrayAdapter extends ArrayAdapter<VideoType.Cast> {
private final HostManager hostManager;
private int artWidth = -1, artHeight = -1;
private int artWidth = -1, artHeight = -1,
backgroundInfoColor = -1;

public CastArrayAdapter(Context context, ArrayList<VideoType.Cast> castArrayList) {
super(context, 0, castArrayList);
Expand All @@ -163,7 +164,7 @@ public CastArrayAdapter(Context context, ArrayList<VideoType.Cast> castArrayList
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext())
.inflate(R.layout.grid_item_cast, parent, false);
.inflate(R.layout.item_cast, parent, false);

if (artWidth == -1) {
Resources resources = getContext().getResources();
Expand All @@ -184,7 +185,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
viewHolder.roleView = convertView.findViewById(R.id.role);
viewHolder.nameView = convertView.findViewById(R.id.name);
viewHolder.pictureView = convertView.findViewById(R.id.picture);
viewHolder.castNameGroupView = convertView.findViewById(R.id.cast_name_group);

if (backgroundInfoColor == -1)
backgroundInfoColor = UIUtils.getTranslucidViewColor(viewHolder.nameView, AllCastActivity.CAST_NAME_ALPHA);

convertView.setTag(viewHolder);

Expand All @@ -200,7 +203,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
UIUtils.loadImageWithCharacterAvatar(getContext(), hostManager,
cast.thumbnail, cast.name,
viewHolder.pictureView, artWidth, artHeight);
viewHolder.castNameGroupView.setAlpha(CAST_NAME_ALPHA);
viewHolder.roleView.setBackgroundColor(backgroundInfoColor);
viewHolder.nameView.setBackgroundColor(backgroundInfoColor);
viewHolder.castName = cast.name;

return convertView;
Expand All @@ -215,7 +219,6 @@ private static class ViewHolder {
TextView roleView;
TextView nameView;
ImageView pictureView;
View castNameGroupView;

String castName;
}
Expand Down
55 changes: 36 additions & 19 deletions app/src/main/java/org/xbmc/kore/utils/UIUtils.java
Expand Up @@ -38,6 +38,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.GridLayout;
import android.widget.ImageView;
Expand All @@ -54,7 +55,7 @@

import org.xbmc.kore.R;
import org.xbmc.kore.Settings;
import org.xbmc.kore.databinding.GridItemCastBinding;
import org.xbmc.kore.databinding.ItemCastBinding;
import org.xbmc.kore.host.HostInfo;
import org.xbmc.kore.host.HostManager;
import org.xbmc.kore.jsonrpc.type.GlobalType;
Expand All @@ -78,7 +79,7 @@
public class UIUtils {

public static final float IMAGE_RESIZE_FACTOR = 1.0f;
public static final int DEFAULT_SURFACE_ALFA = 0xff;
public static final float DEFAULT_SURFACE_ALFA = 1.0f;

public static final int initialButtonRepeatInterval = 400; // ms
public static final int buttonRepeatInterval = 80; // ms
Expand Down Expand Up @@ -273,40 +274,45 @@ public static void setupCastInfo(final Activity activity,
int numRows = resources.getInteger(R.integer.cast_grid_view_rows);
int maxCastPictures = numColumns * numRows;

int parentWidth = castListView.getMeasuredWidth();
if (parentWidth <= 0) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
parentWidth = displayMetrics.widthPixels - 2 * resources.getDimensionPixelSize(R.dimen.info_panel_horiz_margin);
}
int imageWidth = parentWidth / numColumns - 2 * resources.getDimensionPixelSize(R.dimen.image_grid_margin); int imageHeight = (int)(imageWidth * 1.5);
// Calculate image size. Note: we're assuming that the Grid fills the entire screen, otherwise this won't work
// Furthermore, we need to make sure that the image size is less than the one available on the grid, including
// any margins that are set, so we scale the size by a factor. This is fixed when placed on the View
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
int imageWidth = (int)(displayMetrics.widthPixels / numColumns * 0.8);
int imageHeight = (int)(imageWidth * 1.5);

int backgroundInfoColor = -1;
for (int i = 0; i < Math.min(castList.size(), maxCastPictures); i++) {
VideoType.Cast actor = castList.get(i);

GridItemCastBinding binding = GridItemCastBinding.inflate(LayoutInflater.from(activity), castListView, false);
ItemCastBinding binding = ItemCastBinding.inflate(LayoutInflater.from(activity), castListView, false);
View castView = binding.getRoot();

castView.getLayoutParams().width = imageWidth;
castView.getLayoutParams().height = imageHeight;
castView.setTag(actor.name);

UIUtils.loadImageWithCharacterAvatar(activity, hostManager,
actor.thumbnail, actor.name,
binding.picture, imageWidth, imageHeight);
loadImageWithCharacterAvatar(activity, hostManager,
actor.thumbnail, actor.name,
binding.picture, imageWidth, imageHeight);
if (backgroundInfoColor == -1)
backgroundInfoColor = getTranslucidViewColor(binding.name, AllCastActivity.CAST_NAME_ALPHA);

if ((i == maxCastPictures - 1) && (castList.size() > i + 1)) {
binding.castNameGroup.setVisibility(View.GONE);
binding.allCastGroup.setVisibility(View.VISIBLE);
binding.allCastGroup.setAlpha(0.8f * AllCastActivity.CAST_NAME_ALPHA);
binding.name.setVisibility(View.GONE);
binding.role.setVisibility(View.GONE);
binding.remainingCastCount.setVisibility(View.VISIBLE);
binding.remainingCastCount.setBackgroundColor(changeColorAlpha(backgroundInfoColor, 0.8f * AllCastActivity.CAST_NAME_ALPHA));
binding.remainingCastCount.setText(String.format(activity.getString(R.string.remaining_cast_count), castList.size() - maxCastPictures + 1));

castView.setOnClickListener(v -> {
activity.startActivity(allCastActivityLaunchIntent);
activity.overridePendingTransition(R.anim.activity_enter, R.anim.activity_exit);
});
} else {
binding.castNameGroup.setAlpha(AllCastActivity.CAST_NAME_ALPHA);
binding.name.setBackgroundColor(backgroundInfoColor);
binding.role.setBackgroundColor(backgroundInfoColor);
binding.name.setText(actor.name);
binding.role.setText(actor.role);
castView.setOnClickListener(castListClickListener);
Expand Down Expand Up @@ -354,8 +360,8 @@ public static void tintElevatedView(View v) {
* @param v Ciew
* @return Translucid view color
*/
public static int getTranslucidViewColor(View v) {
return changeColorAlpha(getViewBackgroundColor(v), UIUtils.DEFAULT_SURFACE_ALFA);
public static int getTranslucidViewColor(View v, float alpha) {
return changeColorAlpha(getViewBackgroundColor(v), (int)(alpha * 0xFF));
}

/**
Expand All @@ -371,6 +377,17 @@ public static int getViewBackgroundColor(View v) {
return Color.TRANSPARENT;
}

/**
* Changes the alpha component of a color
* @param color Color to change
* @param alpha New alpha to set
* @return color with new alpha
*/
public static int changeColorAlpha(int color, float alpha)
{
return changeColorAlpha(color, (int)(alpha * 0xff));
}

/**
* Changes the alpha component of a color
* @param color Color to change
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/res/layout/activity_all_cast.xml
Expand Up @@ -35,16 +35,11 @@
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/small_padding"
android:layout_margin="@dimen/small_padding"
android:stretchMode="columnWidth"
android:numColumns="@integer/cast_grid_view_columns"
android:horizontalSpacing="@dimen/small_padding"
android:verticalSpacing="@dimen/small_padding"
android:fastScrollEnabled="false"
android:choiceMode="none"
android:listSelector="?attr/selectableItemBackground"
android:drawSelectorOnTop="true"
/>
android:verticalSpacing="@dimen/small_padding" />
</LinearLayout>

<androidx.fragment.app.FragmentContainerView android:id="@+id/navigation_drawer"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout/fragment_cast.xml
Expand Up @@ -32,7 +32,11 @@
<GridLayout
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="@dimen/tiny_padding"
android:layout_marginEnd="@dimen/tiny_padding"
android:useDefaultMargins="true"
android:columnCount="@integer/cast_grid_view_columns">
</GridLayout>
</LinearLayout>
11 changes: 5 additions & 6 deletions app/src/main/res/layout/fragment_now_playing.xml
Expand Up @@ -42,14 +42,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clipChildren="false">
android:clipChildren="false"
android:layout_marginLeft="@dimen/info_panel_horiz_margin"
android:layout_marginRight="@dimen/info_panel_horiz_margin">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/info_title_margin_top"
android:layout_marginLeft="@dimen/info_panel_horiz_margin"
android:layout_marginRight="@dimen/info_panel_horiz_margin"
style="@style/Widget.Kore.InfoPanel">

<TextView
Expand Down Expand Up @@ -169,11 +169,10 @@
<GridLayout
android:id="@+id/cast_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_padding"
android:layout_marginLeft="@dimen/info_panel_horiz_margin"
android:layout_marginRight="@dimen/info_panel_horiz_margin"
android:columnCount="@integer/cast_grid_view_columns"
android:useDefaultMargins="true"
android:orientation="horizontal" />

</LinearLayout>
Expand Down
89 changes: 0 additions & 89 deletions app/src/main/res/layout/grid_item_cast.xml

This file was deleted.

66 changes: 66 additions & 0 deletions app/src/main/res/layout/item_cast.xml
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2015 Synced Synapse. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:foreground="?android:selectableItemBackground">

<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/poster"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/name"
style="@style/Widget.Kore.TextView.MediaCast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
app:layout_constraintBottom_toTopOf="@id/role"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/role"
style="@style/Widget.Kore.TextView.MediaCast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:textColor="?attr/colorOnSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/remaining_cast_count"
style="@style/Widget.Kore.TextView.MediaInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:gravity="center"
android:visibility="gone"
android:paddingTop="48dp"
app:drawableTopCompat="@drawable/ic_open_in_new_white_24dp"
app:drawableTint="?attr/colorOnSurface" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 0665552

Please sign in to comment.