[leanback] fix live crash

pull/137/head
FongMi 3 years ago
parent 8b55067ddc
commit 5e54e6b6c0
  1. 25
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  2. 6
      app/src/main/java/com/fongmi/android/tv/bean/Group.java
  3. 2
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java

@ -235,7 +235,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
if (position[0] >= mGroupAdapter.size()) return;
mGroup = (Group) mGroupAdapter.get(position[0]);
mBinding.group.setSelectedPosition(position[0]);
if (mGroup.getChannel().isEmpty()) return;
mGroup.setPosition(position[1]);
onItemClick(mGroup);
onItemClick(mGroup.current());
@ -499,6 +498,14 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
showProgress();
}
private void release() {
mChannelAdapter.clear();
mGroupAdapter.clear();
mHides.clear();
mChannel = null;
mGroup = null;
}
@Override
public void onTrackClick(Track item) {
}
@ -507,8 +514,8 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
public void setLive(Live item) {
LiveConfig.get().setHome(item);
mPlayers.stop();
mHides.clear();
hideControl();
release();
getLive();
}
@ -584,19 +591,21 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
}
private void prevChannel() {
if (mGroup == null) return;
int position = mGroup.getPosition() - 1;
boolean limit = position < 0;
if (Prefers.isAcross() & limit) prevGroup(true);
else mGroup.setPosition(limit ? mChannelAdapter.size() - 1 : position);
setChannel(mGroup.current());
if (!mGroup.isEmpty()) setChannel(mGroup.current());
}
private void nextChannel() {
if (mGroup == null) return;
int position = mGroup.getPosition() + 1;
boolean limit = position > mChannelAdapter.size() - 1;
if (Prefers.isAcross() && limit) nextGroup(true);
else mGroup.setPosition(limit ? 0 : position);
setChannel(mGroup.current());
if (!mGroup.isEmpty()) setChannel(mGroup.current());
}
private void prevLine() {
@ -640,6 +649,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
public boolean nextGroup(boolean skip) {
int position = mBinding.group.getSelectedPosition() + 1;
if (position > mGroupAdapter.size() - 1) position = 0;
if (mGroup == mGroupAdapter.get(position)) return false;
mGroup = (Group) mGroupAdapter.get(position);
mBinding.group.setSelectedPosition(position);
if (skip && mGroup.skip()) return nextGroup(true);
@ -652,6 +662,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
public boolean prevGroup(boolean skip) {
int position = mBinding.group.getSelectedPosition() - 1;
if (position < 0) position = mGroupAdapter.size() - 1;
if (mGroup == mGroupAdapter.get(position)) return false;
mGroup = (Group) mGroupAdapter.get(position);
mBinding.group.setSelectedPosition(position);
if (skip && mGroup.skip()) return prevGroup(true);
@ -662,9 +673,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Override
public boolean dispatch(boolean check) {
boolean condition1 = mGroup != null && mChannel != null;
boolean condition2 = isGone(mBinding.recycler) && isGone(mBinding.control.getRoot());
return check ? condition1 && condition2 : condition1;
return !check || isGone(mBinding.recycler) && isGone(mBinding.control.getRoot());
}
@Override
@ -701,6 +710,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Override
public void onKeyLeft(int time) {
if (mChannel == null) return;
if (mChannel.isOnly() && mPlayers.isVod()) App.post(() -> seekTo(time), 250);
else if (!mChannel.isOnly()) prevLine();
mKeyDown.resetTime();
@ -708,6 +718,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
@Override
public void onKeyRight(int time) {
if (mChannel == null) return;
if (mChannel.isOnly() && mPlayers.isVod()) App.post(() -> seekTo(time), 250);
else if (!mChannel.isOnly()) nextLine(true);
mKeyDown.resetTime();

@ -117,8 +117,12 @@ public class Group {
return getName().equals(ResUtil.getString(R.string.keep));
}
public boolean isEmpty() {
return getChannel().isEmpty();
}
public boolean skip() {
return isKeep() || getChannel().isEmpty();
return isKeep();
}
public void loadLogo(ImageView view) {

@ -44,7 +44,7 @@ public class LiveViewModel extends ViewModel {
private void verify(Live item) {
Iterator<Group> iterator = item.getGroups().iterator();
while (iterator.hasNext()) if (iterator.next().getChannel().isEmpty()) iterator.remove();
while (iterator.hasNext()) if (iterator.next().isEmpty()) iterator.remove();
}
public void getUrl(Channel item) {

Loading…
Cancel
Save