pull/2/head
FongMi 4 years ago
parent ca3a8ae3de
commit 79e114899c
  1. 2
      app/src/main/java/com/fongmi/bear/ui/activity/HomeActivity.java
  2. 5
      app/src/main/java/com/fongmi/bear/ui/activity/VodActivity.java
  3. 8
      app/src/main/java/com/fongmi/bear/ui/custom/CustomHorizontalGridView.java
  4. 75
      app/src/main/java/com/fongmi/bear/ui/custom/CustomVerticalGridView.java
  5. 28
      app/src/main/java/com/fongmi/bear/ui/custom/CustomViewPager.java
  6. 8
      app/src/main/java/com/fongmi/bear/ui/fragment/VodFragment.java
  7. 27
      app/src/main/res/layout/activity_detail.xml
  8. 1
      app/src/main/res/layout/activity_vod.xml
  9. 2
      app/src/main/res/layout/adapter_item.xml
  10. 4
      app/src/main/res/layout/fragment_vod.xml

@ -107,7 +107,7 @@ public class HomeActivity extends BaseActivity implements VodPresenter.OnClickLi
switch (item.getResId()) {
case R.string.home_vod:
Result result = mSiteViewModel.getResult().getValue();
if (result != null) VodActivity.start(this, result);
VodActivity.start(this, result);
break;
case R.string.home_setting:
SettingActivity.start(this);

@ -11,8 +11,6 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.leanback.widget.ArrayObjectAdapter;
import androidx.leanback.widget.FocusHighlight;
import androidx.leanback.widget.FocusHighlightHelper;
import androidx.leanback.widget.ItemBridgeAdapter;
import androidx.leanback.widget.OnChildViewHolderSelectedListener;
import androidx.recyclerview.widget.RecyclerView;
@ -37,6 +35,7 @@ public class VodActivity extends BaseActivity {
}
public static void start(Activity activity, Result result) {
if (result == null || result.getTypes().isEmpty()) return;
Intent intent = new Intent(activity, VodActivity.class);
intent.putExtra("result", result.toString());
activity.startActivity(intent);
@ -68,6 +67,7 @@ public class VodActivity extends BaseActivity {
public void onChildViewHolderSelected(@NonNull RecyclerView parent, @Nullable RecyclerView.ViewHolder child, int position, int subposition) {
mBinding.pager.setCurrentItem(position);
if (mOldView != null) mOldView.setActivated(false);
if (child == null) return;
mOldView = child.itemView;
mOldView.setActivated(true);
}
@ -81,7 +81,6 @@ public class VodActivity extends BaseActivity {
adapter.addAll(0, mResult.getTypes());
ItemBridgeAdapter bridgeAdapter = new ItemBridgeAdapter(adapter);
mBinding.recycler.setAdapter(bridgeAdapter);
FocusHighlightHelper.setupBrowseItemFocusHighlight(bridgeAdapter, FocusHighlight.ZOOM_FACTOR_MEDIUM, false);
}
private void setPager() {

@ -41,8 +41,8 @@ public class CustomHorizontalGridView extends HorizontalGridView {
@Override
public View focusSearch(View focused, int direction) {
if (focused != null) {
final FocusFinder finder = FocusFinder.getInstance();
final View found = finder.findNextFocus(this, focused, direction);
FocusFinder finder = FocusFinder.getInstance();
View found = finder.findNextFocus(this, focused, direction);
if (direction == View.FOCUS_LEFT || direction == View.FOCUS_RIGHT) {
if ((found == null || found.getId() != R.id.name) && getScrollState() == SCROLL_STATE_IDLE) {
focused.clearAnimation();
@ -103,14 +103,14 @@ public class CustomHorizontalGridView extends HorizontalGridView {
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
if (nextFocused == null || nextFocused == currentFocused) {
if (direction == FOCUS_LEFT || direction == FOCUS_RIGHT) {
shakeX(currentFocused);
shake(currentFocused);
handled = true;
}
}
return handled;
}
private void shakeX(View currentFocused) {
private void shake(View currentFocused) {
if (currentFocused != null && getScrollState() == SCROLL_STATE_IDLE) {
currentFocused.clearAnimation();
currentFocused.startAnimation(shake);

@ -0,0 +1,75 @@
package com.fongmi.bear.ui.custom;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.leanback.widget.OnChildViewHolderSelectedListener;
import androidx.leanback.widget.VerticalGridView;
import androidx.recyclerview.widget.RecyclerView;
public class CustomVerticalGridView extends VerticalGridView {
private View mTabView;
private boolean pressUp;
private boolean pressDown;
public CustomVerticalGridView(@NonNull Context context) {
super(context);
}
public CustomVerticalGridView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public CustomVerticalGridView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void initAttributes(@NonNull Context context, @Nullable AttributeSet attrs) {
super.initAttributes(context, attrs);
setOnChildViewHolderSelectedListener(new OnChildViewHolderSelectedListener() {
@Override
public void onChildViewHolderSelected(@NonNull RecyclerView parent, @Nullable ViewHolder child, int position, int subposition) {
if (pressUp && position == 0) {
mTabView.setVisibility(View.VISIBLE);
} else if (pressDown && position == 1) {
mTabView.setVisibility(View.GONE);
}
}
});
}
public void setTabView(View tabView) {
this.mTabView = tabView;
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() != KeyEvent.ACTION_DOWN) return super.dispatchKeyEvent(event);
pressUp = false;
pressDown = false;
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_UP:
pressUp = true;
return super.dispatchKeyEvent(event);
case KeyEvent.KEYCODE_DPAD_DOWN:
pressDown = true;
return super.dispatchKeyEvent(event);
case KeyEvent.KEYCODE_BACK:
moveToTop();
return true;
default:
return super.dispatchKeyEvent(event);
}
}
public void moveToTop() {
mTabView.setVisibility(View.VISIBLE);
scrollToPosition(0);
}
}

@ -37,12 +37,12 @@ public class CustomViewPager extends ViewPager {
this.shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);
setPageTransformer(false, (page, position) -> {
page.setTranslationX(page.getWidth() * -position);
if (position <= -1.0F || position >= 1.0F) {
page.setAlpha(0.0F);
} else if (position == 0.0F) {
page.setAlpha(1.0F);
if (position <= -1 || position >= 1) {
page.setAlpha(0);
} else if (position == 0) {
page.setAlpha(1);
} else {
page.setAlpha(1.0F - Math.abs(position));
page.setAlpha(1 - Math.abs(position));
}
});
}
@ -87,16 +87,16 @@ public class CustomViewPager extends ViewPager {
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
if (nextFocused != null && nextFocused != currentFocused) {
if (direction == View.FOCUS_LEFT) {
final int nextLeft = getChildRectInPagerCoordinates(rect, nextFocused).left;
final int currLeft = getChildRectInPagerCoordinates(rect, currentFocused).left;
int nextLeft = getChildRectInPagerCoordinates(rect, nextFocused).left;
int currLeft = getChildRectInPagerCoordinates(rect, currentFocused).left;
if (currentFocused != null && nextLeft >= currLeft) {
handled = pageLeft();
} else {
handled = nextFocused.requestFocus();
}
} else if (direction == View.FOCUS_RIGHT) {
final int nextLeft = getChildRectInPagerCoordinates(rect, nextFocused).left;
final int currLeft = getChildRectInPagerCoordinates(rect, currentFocused).left;
int nextLeft = getChildRectInPagerCoordinates(rect, nextFocused).left;
int currLeft = getChildRectInPagerCoordinates(rect, currentFocused).left;
if (currentFocused != null && nextLeft <= currLeft) {
handled = pageRight();
} else {
@ -105,14 +105,14 @@ public class CustomViewPager extends ViewPager {
}
} else if (direction == FOCUS_LEFT) {
if (getCurrentItem() == 0) {
shakeX(currentFocused);
shake(currentFocused);
handled = true;
} else {
handled = pageLeft();
}
} else if (direction == FOCUS_RIGHT) {
if (getAdapter() != null && getCurrentItem() == getAdapter().getCount() - 1) {
shakeX(currentFocused);
shake(currentFocused);
handled = true;
} else {
handled = pageRight();
@ -138,7 +138,7 @@ public class CustomViewPager extends ViewPager {
outRect.bottom = child.getBottom();
ViewParent parent = child.getParent();
while (parent instanceof ViewGroup && parent != this) {
final ViewGroup group = (ViewGroup) parent;
ViewGroup group = (ViewGroup) parent;
outRect.left += group.getLeft();
outRect.right += group.getRight();
outRect.top += group.getTop();
@ -157,14 +157,14 @@ public class CustomViewPager extends ViewPager {
}
boolean pageRight() {
if (getAdapter() != null && getCurrentItem() < (getAdapter().getCount() - 1)) {
if (getAdapter() != null && getCurrentItem() < getAdapter().getCount() - 1) {
setCurrentItem(getCurrentItem() + 1, true);
return true;
}
return false;
}
private void shakeX(View currentFocused) {
private void shake(View currentFocused) {
if (currentFocused != null) {
currentFocused.clearAnimation();
currentFocused.startAnimation(shake);

@ -13,6 +13,7 @@ import androidx.leanback.widget.ItemBridgeAdapter;
import androidx.leanback.widget.ListRow;
import androidx.lifecycle.ViewModelProvider;
import com.fongmi.bear.R;
import com.fongmi.bear.bean.Filter;
import com.fongmi.bear.bean.Vod;
import com.fongmi.bear.databinding.FragmentVodBinding;
@ -80,6 +81,7 @@ public class VodFragment extends Fragment implements Scroller.Callback, VodPrese
selector.addPresenter(ListRow.class, new CustomRowPresenter(16), VodPresenter.class);
selector.addPresenter(ListRow.class, new CustomRowPresenter(8), FilterPresenter.class);
mBinding.recycler.addOnScrollListener(mScroller = new Scroller(this));
mBinding.recycler.setTabView(getActivity().findViewById(R.id.recycler));
mBinding.recycler.setVerticalSpacing(ResUtil.dp2px(16));
mBinding.recycler.setAdapter(new ItemBridgeAdapter(mAdapter = new ArrayObjectAdapter(selector)));
}
@ -138,4 +140,10 @@ public class VodFragment extends Fragment implements Scroller.Callback, VodPrese
public void onLoadMore(String page) {
getVideo(page);
}
@Override
public void onResume() {
super.onResume();
mBinding.recycler.moveToTop();
}
}

@ -6,10 +6,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.StyledPlayerView
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video"
android:layout_width="400dp"
android:layout_height="225dp"
android:layout_width="360dp"
android:layout_height="200dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
@ -31,7 +31,7 @@
tools:text="慶餘年第二季" />
<LinearLayout
android:id="@+id/row1"
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
@ -45,7 +45,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="12dp"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
@ -56,29 +56,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="12dp"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="年份:2022" />
</LinearLayout>
<LinearLayout
android:id="@+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row1"
android:layout_alignStart="@+id/name"
android:layout_marginEnd="24dp"
android:layout_toEndOf="@+id/video"
android:orientation="horizontal">
<TextView
android:id="@+id/area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="12dp"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16sp"
@ -100,7 +89,7 @@
android:id="@+id/director"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/row2"
android:layout_below="@+id/row"
android:layout_alignStart="@+id/name"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"

@ -14,7 +14,6 @@
android:paddingStart="24dp"
android:paddingTop="24dp"
android:paddingEnd="24dp"
android:paddingBottom="8dp"
app:focusOutEnd="true"
app:focusOutFront="true" />

@ -9,5 +9,5 @@
android:focusableInTouchMode="true"
android:gravity="center"
android:textColor="@color/white"
android:textSize="18sp"
android:textSize="16sp"
tools:text="泥巴" />

@ -4,14 +4,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.leanback.widget.VerticalGridView
<com.fongmi.bear.ui.custom.CustomVerticalGridView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingStart="24dp"
android:paddingTop="8dp"
android:paddingTop="16dp"
android:paddingEnd="24dp"
android:paddingBottom="24dp"
app:focusOutEnd="true"

Loading…
Cancel
Save