pull/123/head
FongMi 4 years ago
parent 374c0cb056
commit 9e7137dd54
  1. 17
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  2. 16
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomLiveGridView.java

@ -195,7 +195,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Override
public void onItemClick(Group item) {
if (item.isSelected()) return;
mChannelAdapter.setItems(mGroup.getChannel(), null);
mBinding.channel.setSelectedPosition(mGroup.getPosition());
}
@ -214,7 +213,13 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
showInfo();
}
private void nextGroup() {
private void getUrl() {
mBinding.progress.getRoot().setVisibility(View.VISIBLE);
mViewModel.getUrl(mChannel);
}
@Override
public void nextGroup() {
int position = mBinding.group.getSelectedPosition() + 1;
if (position > mGroupAdapter.size() - 1) position = 0;
mGroup = (Group) mGroupAdapter.get(position);
@ -223,7 +228,8 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
mGroup.setPosition(0);
}
private void prevGroup() {
@Override
public void prevGroup() {
int position = mBinding.group.getSelectedPosition() - 1;
if (position < 0) position = mGroupAdapter.size() - 1;
mGroup = (Group) mGroupAdapter.get(position);
@ -232,11 +238,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
mGroup.setPosition(mGroup.getChannel().size() - 1);
}
private void getUrl() {
mBinding.progress.getRoot().setVisibility(View.VISIBLE);
mViewModel.getUrl(mChannel);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (isGone(mBinding.recycler) && mKeyDown.hasEvent(event)) return mKeyDown.onKeyDown(event);

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.leanback.widget.VerticalGridView;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.utils.Utils;
public class CustomLiveGridView extends VerticalGridView {
@ -32,17 +33,22 @@ public class CustomLiveGridView extends VerticalGridView {
}
private void moveTop() {
if (getSelectedPosition() == getAdapter().getItemCount() - 1) setSelectedPosition(0);
listener.setUITimer();
if (getSelectedPosition() != getAdapter().getItemCount() - 1) return;
if (getId() == R.id.channel) setSelectedPosition(0);
else listener.nextGroup();
}
private void moveBottom() {
if (getSelectedPosition() == 0) setSelectedPosition(getAdapter().getItemCount());
listener.setUITimer();
if (getSelectedPosition() != 0) return;
if (getId() == R.id.channel) setSelectedPosition(getAdapter().getItemCount());
else listener.prevGroup();
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
if (getVisibility() == View.GONE || event.getAction() != KeyEvent.ACTION_DOWN) return super.dispatchKeyEvent(event);
if (Utils.isUpKey(event)) moveBottom();
else if (Utils.isDownKey(event)) moveTop();
@ -52,5 +58,9 @@ public class CustomLiveGridView extends VerticalGridView {
public interface Callback {
void setUITimer();
void nextGroup();
void prevGroup();
}
}

Loading…
Cancel
Save