Optimize home content load

pull/605/head
FongMi 5 months ago
parent 24c50e35ea
commit 6ec0e4df14
  1. 7
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/HomeActivity.java
  2. 2
      app/src/leanback/res/layout/adapter_progress.xml
  3. 6
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  4. 6
      app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java

@ -243,10 +243,11 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
setTitle();
mResult = Result.empty();
int index = getRecommendIndex();
if (mAdapter.size() > index) mAdapter.removeItems(index, mAdapter.size() - index);
if (getSite().getKey().isEmpty()) return;
boolean gone = mAdapter.indexOf("progress") == -1;
boolean hasItem = gone && mAdapter.size() > index;
if (hasItem) mAdapter.removeItems(index, mAdapter.size() - index);
if (gone) mAdapter.add("progress");
mViewModel.homeContent();
mAdapter.add("progress");
}
private void addVideo(Result result) {

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
android:padding="64dp">
<include
layout="@layout/view_progress"

@ -27,6 +27,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@ -144,15 +145,12 @@ public class LiveViewModel extends ViewModel {
executor.execute(() -> {
try {
T result = newFuture.get(type.timeout, TimeUnit.MILLISECONDS);
if (newFuture.isCancelled()) return;
if (type == TaskType.EPG) epg.postValue((Epg) result);
else if (type == TaskType.LIVE) live.postValue((Live) result);
else if (type == TaskType.XML) xml.postValue((Boolean) result);
else if (type == TaskType.URL) url.postValue((Channel) result);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Throwable e) {
if (newFuture.isCancelled()) return;
if (e instanceof CancellationException) return;
if (e.getCause() instanceof ExtractException) url.postValue(Channel.error(e.getCause().getMessage()));
else if (type == TaskType.URL) url.postValue(new Channel());
else if (type == TaskType.LIVE) live.postValue(new Live());

@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@ -261,12 +262,9 @@ public class SiteViewModel extends ViewModel {
executor.execute(() -> {
try {
Result taskResult = future.get(Constant.TIMEOUT_VOD, TimeUnit.MILLISECONDS);
if (future.isCancelled()) return;
result.postValue(taskResult);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Throwable e) {
if (future.isCancelled()) return;
if (e instanceof CancellationException) return;
if (e.getCause() instanceof ExtractException) result.postValue(Result.error(e.getCause().getMessage()));
else result.postValue(Result.empty());
e.printStackTrace();

Loading…
Cancel
Save