|
|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|