package com.xixun.xixunplayer; import android.content.Context; import android.view.View; import android.widget.AbsoluteLayout; import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; import gnph.util.Dates; import gnph.util.JSList; import gnph.util.JSMap; public class Page extends AbsoluteLayout { public static class EleBase { View view; long endMilli = Long.MAX_VALUE; long startMilli = Long.MAX_VALUE; int startTime; int endTime; String id; String type; boolean isShort; } public static class Layer { ArrayList eles = new ArrayList<>(); long endMilli = Long.MAX_VALUE; int dur; boolean repeat; } public static class Sche { long startDate = -1, endDate = -1; int startTime = -1, endTime = -1; JSList weeks; } ArrayList layers = new ArrayList<>(); ArrayList sches; long endMilli = Long.MAX_VALUE; int dur, repeatTimes; boolean hasVideo = false; public Page(Context context) { super(context); } public void setMillis(long milli) { endMilli = milli + dur; for(var layer : layers) { if(layer.repeat) layer.endMilli = milli + layer.dur; for(var ele : layer.eles) if(ele.isShort) { if(ele.startTime > 0) { ele.startMilli = milli + ele.startTime; ele.view.setVisibility(GONE); } else ele.view.setVisibility(VISIBLE); ele.endMilli = milli + ele.endTime; } } if(getLeft() != 0) setLeft(0); setVisibility(VISIBLE); } public void remove(View view) { view.setVisibility(GONE); removeView(view); for(int ll=0; ll 1) layer.eles.remove(ee); else layers.remove(ll); return; } } } public boolean isSchedule(long milli) { if(sches==null) return true; var local = milli + Dates.zoneOff; var time = local % 86400000L; var week = -1; for(var sche : sches) { if(notInRange(sche.startDate, local, sche.endDate)) continue; if(notInRange(sche.startTime, time, sche.endTime)) continue; if(sche.weeks==null) return true; if(week==-1) week = LocalDate.ofEpochDay(local / 86400000L).getDayOfWeek().getValue(); if(sche.weeks.contains(week)) return true; } return false; } public boolean notInRange(long start, long val, long end) { if(end==-1) return false; return start <= end ? !(val >= start && val < end) : val >= end && val < start; } public void parse(JSList schedules) { if(schedules!=null) for(var schedule : schedules) { var sche = new Sche(); var startTime = schedule.str("startTime"); if(startTime!=null) sche.startTime = LocalTime.parse(startTime).toSecondOfDay()*1000; var endTime = schedule.str("endTime"); if(endTime!=null) sche.endTime = LocalTime.parse(endTime).toSecondOfDay()*1000; if(sche.startTime==sche.endTime) sche.startTime = sche.endTime = -1; var startDate = schedule.str("startDate"); if(startDate!=null) sche.startDate = LocalDate.parse(startDate).toEpochDay() * 86400000L; var endDate = schedule.str("endDate"); if(endDate!=null) sche.endDate = (LocalDate.parse(endDate).toEpochDay() + 1) * 86400000L; if(sche.startDate==sche.endDate) sche.startDate = sche.endDate = -1; JSList weekFilter = schedule.jslist("weekFilter"); if(weekFilter!=null && ! weekFilter.isEmpty() && weekFilter.size() < 7) sche.weeks = weekFilter; if(sches==null) sches = new ArrayList<>(); sches.add(sche); } } }