Merge pull request #502 from okcaptain/dev

Dev
pull/503/head^2
okcaptain 2 years ago committed by GitHub
commit 2b20a7df99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/build.gradle
  2. 6
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  3. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  4. 2
      app/src/main/java/com/fongmi/android/tv/Constant.java
  5. 17
      app/src/main/java/com/fongmi/android/tv/api/EpgParser.java
  6. 17
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  7. 6
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java

@ -14,7 +14,7 @@ android {
//noinspection ExpiredTargetSdkVersion
targetSdk 28
versionCode 237
versionName "0611"
versionName "0613"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]

@ -236,8 +236,10 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, GroupP
private void setViewModel() {
mViewModel = new ViewModelProvider(this).get(LiveViewModel.class);
mViewModel.url.observe(this, result -> mPlayers.start(result, getTimeout()));
mViewModel.xml.observe(this, this::setEpg);
mViewModel.epg.observe(this, this::setEpg);
mViewModel.live.observe(this, live -> {
mViewModel.getXml(live);
hideProgress();
setGroup(live);
setWidth(live);
@ -661,6 +663,10 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, GroupP
setMetadata();
}
private void setEpg(boolean success) {
if (mChannel != null && success) mViewModel.getEpg(mChannel);
}
private void setEpg(Epg epg) {
if (mChannel != null && mChannel.getTvgName().equals(epg.getKey())) setEpg();
}

@ -1135,7 +1135,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
if (btn == null || !isVisible(btn) || !btn.isEnabled()) continue;
for(int j=i+1; j<count; j++) {
View next = mBinding.control.actionLayout.getChildAt(j);
if (next == null || !isVisible(next) || !btn.isEnabled()) continue;
if (next == null || !isVisible(next) || !next.isEnabled()) continue;
btn.setNextFocusRightId(next.getId());
next.setNextFocusLeftId(btn.getId());
break;

@ -13,6 +13,8 @@ public class Constant {
public static final int TIMEOUT_LIVE = 30 * 1000;
//節目爬蟲時間
public static final int TIMEOUT_EPG = 5 * 1000;
//節目爬蟲時間
public static final int TIMEOUT_XML = 15 * 1000;
//播放超時時間
public static final int TIMEOUT_PLAY = 15 * 1000;
//解析預設時間

@ -27,16 +27,13 @@ import java.util.Set;
public class EpgParser {
public static void start(Live live) {
try {
if (!live.getEpg().endsWith(".xml") && !live.getEpg().endsWith(".gz")) return;
File file = Path.epg(Uri.parse(live.getEpg()).getLastPathSegment());
if (shouldDownload(file)) Download.create(live.getEpg(), file).start();
if (file.getName().endsWith(".gz")) readGzip(live, file);
else readXml(live, file);
} catch (Exception e) {
e.printStackTrace();
}
public static boolean start(Live live) throws Exception {
if (!live.getEpg().endsWith(".xml") && !live.getEpg().endsWith(".gz")) return false;
File file = Path.epg(Uri.parse(live.getEpg()).getLastPathSegment());
if (shouldDownload(file)) Download.create(live.getEpg(), file).start();
if (file.getName().endsWith(".gz")) readGzip(live, file);
else readXml(live, file);
return true;
}
private static boolean shouldDownload(File file) {

@ -30,17 +30,20 @@ public class LiveViewModel extends ViewModel {
private static final int LIVE = 0;
private static final int EPG = 1;
private static final int URL = 2;
private static final int XML = 3;
private final SimpleDateFormat formatDate;
private final SimpleDateFormat formatTime;
public MutableLiveData<Channel> url;
public MutableLiveData<Boolean> xml;
public MutableLiveData<Live> live;
public MutableLiveData<Epg> epg;
private ExecutorService executor1;
private ExecutorService executor2;
private ExecutorService executor3;
private ExecutorService executor4;
public LiveViewModel() {
this.formatTime = new SimpleDateFormat("yyyy-MM-ddHH:mm", Locale.getDefault());
@ -48,18 +51,22 @@ public class LiveViewModel extends ViewModel {
this.live = new MutableLiveData<>();
this.epg = new MutableLiveData<>();
this.url = new MutableLiveData<>();
this.xml = new MutableLiveData<>();
}
public void getLive(Live item) {
execute(LIVE, () -> {
VodConfig.get().setRecent(item.getJar());
LiveParser.start(item);
EpgParser.start(item);
verify(item);
return item;
});
}
public void getXml(Live item) {
execute(XML, () -> EpgParser.start(item));
}
public void getEpg(Channel item) {
String date = formatDate.format(new Date());
String url = item.getEpg().replace("{date}", date);
@ -109,6 +116,11 @@ public class LiveViewModel extends ViewModel {
executor3 = Executors.newFixedThreadPool(2);
executor3.execute(runnable(type, callable, executor3));
break;
case XML:
if (executor4 != null) executor4.shutdownNow();
executor4 = Executors.newFixedThreadPool(2);
executor4.execute(runnable(type, callable, executor4));
break;
}
}
@ -118,6 +130,7 @@ public class LiveViewModel extends ViewModel {
if (Thread.interrupted()) return;
if (type == EPG) epg.postValue((Epg) executor.submit(callable).get(Constant.TIMEOUT_EPG, TimeUnit.MILLISECONDS));
if (type == LIVE) live.postValue((Live) executor.submit(callable).get(Constant.TIMEOUT_LIVE, TimeUnit.MILLISECONDS));
if (type == XML) xml.postValue((Boolean) executor.submit(callable).get(Constant.TIMEOUT_XML, TimeUnit.MILLISECONDS));
if (type == URL) url.postValue((Channel) executor.submit(callable).get(Constant.TIMEOUT_PARSE_LIVE, TimeUnit.MILLISECONDS));
} catch (Throwable e) {
if (e instanceof InterruptedException || Thread.interrupted()) return;
@ -125,6 +138,7 @@ public class LiveViewModel extends ViewModel {
else if (type == URL) url.postValue(new Channel());
if (type == LIVE) live.postValue(new Live());
if (type == EPG) epg.postValue(new Epg());
if (type == XML) xml.postValue(false);
e.printStackTrace();
}
};
@ -135,5 +149,6 @@ public class LiveViewModel extends ViewModel {
if (executor1 != null) executor1.shutdownNow();
if (executor2 != null) executor2.shutdownNow();
if (executor3 != null) executor3.shutdownNow();
if (executor4 != null) executor4.shutdownNow();
}
}

@ -264,8 +264,10 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, Custom
private void setViewModel() {
mViewModel = new ViewModelProvider(this).get(LiveViewModel.class);
mViewModel.url.observeForever(mObserveUrl);
mViewModel.xml.observe(this, this::setEpg);
mViewModel.epg.observeForever(mObserveEpg);
mViewModel.live.observe(this, live -> {
mViewModel.getXml(live);
hideProgress();
setGroup(live);
setWidth(live);
@ -708,6 +710,10 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, Custom
setMetadata();
}
private void setEpg(boolean success) {
if (mChannel != null && success) mViewModel.getEpg(mChannel);
}
private void setEpg(Epg epg) {
if (mChannel != null && mChannel.getTvgName().equals(epg.getKey())) setEpg();
}

Loading…
Cancel
Save