Support epg api second

pull/590/head
FongMi 10 months ago
parent 465ed86d34
commit bb96543aaa
  1. 10
      app/src/main/java/com/fongmi/android/tv/bean/Epg.java
  2. 12
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  3. 9
      app/src/main/java/com/fongmi/android/tv/utils/Util.java

@ -26,10 +26,10 @@ public class Epg {
private int width;
public static Epg objectFrom(String str, String key, SimpleDateFormat format) throws Exception {
public static Epg objectFrom(String str, String key, List<SimpleDateFormat> formats) throws Exception {
if (!Json.isObj(str)) return EpgParser.getEpg(str, key);
Epg item = App.gson().fromJson(str, Epg.class);
item.setTime(format);
item.setTime(formats);
item.setKey(key);
return item;
}
@ -78,11 +78,11 @@ public class Epg {
return getDate().equals(date);
}
private void setTime(SimpleDateFormat format) {
private void setTime(List<SimpleDateFormat> formats) {
setList(new ArrayList<>(new LinkedHashSet<>(getList())));
for (EpgData item : getList()) {
item.setStartTime(Util.format(format, getDate().concat(item.getStart())));
item.setEndTime(Util.format(format, getDate().concat(item.getEnd())));
item.setStartTime(Util.format(getDate().concat(item.getStart()), formats));
item.setEndTime(Util.format(getDate().concat(item.getEnd()), formats));
if (item.getEndTime() < item.getStartTime()) item.checkDay();
item.setTitle(Trans.s2t(item.getTitle()));
}

@ -18,8 +18,10 @@ import com.fongmi.android.tv.player.Source;
import com.github.catvod.net.OkHttp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.Callable;
@ -34,8 +36,8 @@ public class LiveViewModel extends ViewModel {
private static final int URL = 2;
private static final int XML = 3;
private final List<SimpleDateFormat> formatTime;
private final SimpleDateFormat formatDate;
private final SimpleDateFormat formatTime;
public MutableLiveData<Channel> url;
public MutableLiveData<Boolean> xml;
@ -48,12 +50,14 @@ public class LiveViewModel extends ViewModel {
private ExecutorService executor4;
public LiveViewModel() {
this.formatTime = new SimpleDateFormat("yyyy-MM-ddHH:mm", Locale.getDefault());
this.formatDate = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
this.live = new MutableLiveData<>();
this.epg = new MutableLiveData<>();
this.url = new MutableLiveData<>();
this.xml = new MutableLiveData<>();
this.formatTime = new ArrayList<>();
this.formatDate = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
this.formatTime.add(new SimpleDateFormat("yyyy-MM-ddHH:mm", Locale.getDefault()));
this.formatTime.add(new SimpleDateFormat("yyyy-MM-ddHH:mm:ss", Locale.getDefault()));
}
public void getLive(Live item) {
@ -103,8 +107,8 @@ public class LiveViewModel extends ViewModel {
private void setTimeZone(Live live) {
try {
TimeZone timeZone = live.getTimeZone().isEmpty() ? TimeZone.getDefault() : TimeZone.getTimeZone(live.getTimeZone());
for (SimpleDateFormat format : formatTime) format.setTimeZone(timeZone);
formatDate.setTimeZone(timeZone);
formatTime.setTimeZone(timeZone);
} catch (Exception ignored) {
}
}

@ -139,12 +139,9 @@ public class Util {
return text;
}
public static long format(SimpleDateFormat format, String src) {
try {
return format.parse(src).getTime();
} catch (Exception e) {
return 0;
}
public static long format(String src, List<SimpleDateFormat> formats) {
for (SimpleDateFormat format : formats) try { return format.parse(src).getTime(); } catch (Exception ignored) {}
return 0;
}
public static boolean isLeanback() {

Loading…
Cancel
Save