diff options
5 files changed, 213 insertions, 88 deletions
diff --git a/vdrmanager/res/layout/timer_detail.xml b/vdrmanager/res/layout/timer_detail.xml index d86d9ef..b74d54e 100644 --- a/vdrmanager/res/layout/timer_detail.xml +++ b/vdrmanager/res/layout/timer_detail.xml @@ -110,7 +110,7 @@ </LinearLayout> </LinearLayout> - <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> + <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/timer_block"> <TextView android:width="80dp" android:text="@string/timer_detail_use_vps" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/timer_detail_vps" android:layout_height="wrap_content" android:layout_width="wrap_content"/> </LinearLayout> diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java index bfc41b1..7fc873b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java @@ -2,6 +2,7 @@ package de.bjusystems.vdrmanager.data; import java.util.Date; +import android.text.TextUtils; import de.bjusystems.vdrmanager.StringUtils; import de.bjusystems.vdrmanager.app.C; import de.bjusystems.vdrmanager.gui.Utils; @@ -9,7 +10,7 @@ import static de.bjusystems.vdrmanager.gui.Utils.mapSpecialChars; /** * Class for EPG events - * + * * @author bju */ public class Epg extends Event implements Timerable { @@ -51,6 +52,11 @@ public class Epg extends Event implements Timerable { } } + if (words.length > 10) { + if (TextUtils.isEmpty(words[10]) == false) { + vps = Long.valueOf(words[10]) * 1000; + } + } } public Timer getTimer() { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java index a1aace4..0c841b9 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java @@ -7,9 +7,9 @@ import android.text.TextUtils; /** * Basisc class for all Events - * + * * @author bju,lado - * + * */ public abstract class Event { @@ -22,9 +22,11 @@ public abstract class Event { protected String description; protected Date start; protected Date stop; + protected String rawAudio; protected int[] content = {}; - + + protected long vps = 0; public int[] getContent() { return content; @@ -40,13 +42,12 @@ public abstract class Event { return audio; } - - public long getDuration(){ + public long getDuration() { long millis = getStop().getTime() - getStart().getTime(); return millis; } - public Event(){ + public Event() { } @@ -88,6 +89,8 @@ public abstract class Event { start = event.getStart(); stop = event.getStop(); rawAudio = event.rawAudio; + content = event.content; + vps = event.vps; } public Long getChannelNumber() { @@ -106,7 +109,6 @@ public abstract class Event { return channelId; } - public String getShortText() { if (TextUtils.isEmpty(shortText) == false) { return shortText; @@ -132,14 +134,23 @@ public abstract class Event { return stop; } - public String getStreamId(){ - if(channelId != null){ + public String getStreamId() { + if (channelId != null) { return channelId; } return String.valueOf(channelNumber); } - public boolean isConflict() { - return false; - } + public boolean isConflict() { + return false; + } + + public boolean hasVPS() { + return vps > 0; + } + + public long getVPS() { + return vps; + } + } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java index bf2f048..e0f8b49 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java @@ -11,17 +11,16 @@ import de.bjusystems.vdrmanager.gui.Utils; /** * Class for timer data - * + * * @author bju */ public class Timer extends Event implements Timerable { - -// tfActive = 0x0001, -// tfInstant = 0x0002, -// tfVps = 0x0004, -// tfRecording = 0x0008, -// tfAll = 0xFFFF, + // tfActive = 0x0001, + // tfInstant = 0x0002, + // tfVps = 0x0004, + // tfRecording = 0x0008, + // tfAll = 0xFFFF, private static final int ACTIVE = 1; private static final int INSTANT = 2; private static final int VPS = 4; @@ -32,31 +31,28 @@ public class Timer extends Event implements Timerable { private int priority; private int lifetime; private String weekdays = "-------"; - private boolean conflict; + private boolean conflict; + public void setPriority(int priority) { this.priority = priority; } - public void setLifetime(int lifetime) { this.lifetime = lifetime; } - public String getWeekdays() { return weekdays; } - public void setWeekdays(String weekdays) { this.weekdays = weekdays; } - /** * Constructs a timer from SvdrpHelper result line - * + * * @param timerData * result line */ @@ -87,31 +83,39 @@ public class Timer extends Event implements Timerable { this.description = values.length > 9 ? values[9] : "";// aux // 10 and 11 are optional if there where event with this timer - this.shortText = values.length > 10 ? Utils - .mapSpecialChars(values[10]) : ""; + this.shortText = values.length > 10 ? Utils.mapSpecialChars(values[10]) + : ""; if (values.length > 11) { this.description = values[11]; // if real description, set it } - if(values.length > 12 ){ + if (values.length > 12) { this.channelId = values[12]; } - if(values.length > 13) { + if (values.length > 13) { this.weekdays = values[13]; } - if (values.length > 14) { - this.conflict = values[14].equals("1"); - } - + if (values.length > 14) { + this.conflict = values[14].equals("1"); + } description = Utils.mapSpecialChars(description); - } + if (values.length > 15) { + if (TextUtils.isEmpty(values[15]) == false) { + vps = Long.valueOf(values[15]) * 1000; + } else if (isVps()) { + vps = start.getTime(); + } + + } - public Timer copy(){ + } + + public Timer copy() { Timer t = new Timer(this); t.flags = flags; t.number = number; @@ -121,36 +125,34 @@ public class Timer extends Event implements Timerable { t.stop = new Date(stop.getTime()); t.title = title; t.weekdays = weekdays; - t.conflict = conflict; + t.conflict = conflict; + t.vps = vps; return t; } public Timer(final Event event) { - final Preferences prefs = Preferences.getPreferences(); this.number = 0; this.flags = ACTIVE; this.channelNumber = event.getChannelNumber(); this.channelName = event.getChannelName(); this.channelId = event.getChannelId(); - this.priority = prefs.getTimerDefaultPriority(); - this.lifetime = prefs.getTimerDefaultLifetime(); - this.start = new Date(event.getStart().getTime() - - prefs.getTimerPreMargin() * 60000); - this.stop = new Date(event.getStop().getTime() - + prefs.getTimerPostMargin() * 60000); + this.start = event.getStart(); + + this.stop = event.getStop(); this.title = event.getTitle(); - if(Utils.isSerie(event.getContent())){ - if(TextUtils.isEmpty(event.getShortText()) == false){ - this.title+="~"+event.getShortText(); + if (Utils.isSerie(event.getContent())) { + if (TextUtils.isEmpty(event.getShortText()) == false) { + this.title += "~" + event.getShortText(); } } this.description = event.getDescription(); + this.vps = event.getVPS(); } - public boolean isRecurring(){ + public boolean isRecurring() { return weekdays.equals("-------") == false; } @@ -158,17 +160,20 @@ public class Timer extends Event implements Timerable { final StringBuilder line = new StringBuilder(); - //line.append(number).append(":"); + // line.append(number).append(":"); line.append(flags).append(":"); line.append(channelNumber).append(":"); final Calendar cal = Calendar.getInstance(); cal.setTime(start); - cal.setTimeZone(TimeZone.getTimeZone(Preferences.get().getCurrentVdr().getServerTimeZone())); + cal.setTimeZone(TimeZone.getTimeZone(Preferences.get().getCurrentVdr() + .getServerTimeZone())); - line.append((weekdays.equals("-------") == false ? weekdays + "@" : "") + String.format("%04d-%02d-%02d:", cal.get(Calendar.YEAR), - cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))); + line.append((weekdays.equals("-------") == false ? weekdays + "@" : "") + + String.format("%04d-%02d-%02d:", cal.get(Calendar.YEAR), + cal.get(Calendar.MONTH) + 1, + cal.get(Calendar.DAY_OF_MONTH))); line.append(String.format("%02d%02d:", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE))); @@ -220,9 +225,9 @@ public class Timer extends Event implements Timerable { return (flags & RECORDING) == RECORDING; } - public boolean isConflict() { - return conflict; - } + public boolean isConflict() { + return conflict; + } public void setStart(final Date start) { this.start = start; @@ -232,8 +237,8 @@ public class Timer extends Event implements Timerable { this.stop = stop; } - public void setVps(boolean useVps){ - if(useVps){ + public void setVps(boolean useVps) { + if (useVps) { flags = flags | VPS; } else { flags = flags & ~VPS; @@ -256,16 +261,12 @@ public class Timer extends Event implements Timerable { return new Timer(this); } - @Override public TimerMatch getTimerMatch() { - if (isConflict()) - return TimerMatch.Conflict; + if (isConflict()) + return TimerMatch.Conflict; - return TimerMatch.Full; + return TimerMatch.Full; } - - - } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java index d31ac43..94368dc 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java @@ -19,6 +19,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.DatePicker; import android.widget.EditText; import android.widget.TextView; @@ -29,9 +30,11 @@ import de.bjusystems.vdrmanager.app.Intents; import de.bjusystems.vdrmanager.app.VdrManagerApp; import de.bjusystems.vdrmanager.data.EpgCache; import de.bjusystems.vdrmanager.data.EventFormatter; +import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.data.Timer; import de.bjusystems.vdrmanager.tasks.CreateTimerTask; import de.bjusystems.vdrmanager.tasks.ModifyTimerTask; +import de.bjusystems.vdrmanager.utils.date.DateFormatter; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; @@ -44,6 +47,12 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, public static final int REQUEST_CODE_TIMER_ADD = 36; + private CharSequence prevStart; + + private CharSequence prevEnd; + + private CharSequence prevDate; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -77,8 +86,9 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, tView.modifyButton.setOnClickListener(this); tView.repeat.setOnClickListener(this); setContentView(view); - timer = getApp().getCurrentTimer(); - original = timer.copy(); + timer = getApp().getCurrentTimer().copy(); + original = getApp().getCurrentTimer().copy(); + int op = getIntent().getExtras().getInt(Intents.TIMER_OP); switch (op) { case Intents.ADD_TIMER: @@ -94,6 +104,64 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, finish(); } + if (timer.isVps() == false && timer.hasVPS() == false) { + findViewById(R.id.timer_block).setVisibility(View.GONE); + } else { + tView.vps + .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + if (isChecked == true) { + vpsChecked(false); + } else { + vpsUnchecked(); + } + } + }); + } + } + + private void vpsChecked(boolean initial) { + + if (initial == false) { + prevStart = tView.startField.getText(); + prevEnd = tView.endField.getText(); + prevDate = tView.dateField.getText(); + } + + DateFormatter formatter = new DateFormatter(new Date(original.getVPS())); + String date = formatter.getDateString(); + tView.startField.setEnabled(false); + tView.startField.setText(formatter.getTimeString()); + timer.setStart(new Date(timer.getVPS())); + + DateFormatter stopF = new DateFormatter(original.getStop()); + + tView.endField.setEnabled(false); + tView.endField.setText(stopF.getTimeString()); + timer.setStop(original.getStop()); + + tView.dateField.setEnabled(false); + tView.dateField.setText(date); + + } + + private void vpsUnchecked() { + if (prevStart != null) { + tView.startField.setText(prevStart); + } + tView.startField.setEnabled(true); + + if (prevEnd != null) { + tView.endField.setText(prevEnd); + } + tView.endField.setEnabled(true); + + if (prevDate != null) { + tView.dateField.setText(prevDate); + } + tView.dateField.setEnabled(true); } public class EditTimerViewHolder { @@ -121,39 +189,67 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, Timer original; + private void updateDates(Date start, Date stop) { + DateFormatter startF = new DateFormatter(start); + DateFormatter endF = new DateFormatter(stop); + tView.startField.setText(startF.getTimeString()); + tView.endField.setText(endF.getTimeString()); + tView.dateField.setText(startF.getDateString()); + } + private void updateDisplay(TimerOperation op) { updateDisplay(); + switch (op) { case CREATE: tView.modifyButton.setVisibility(View.GONE); tView.saveButton.setVisibility(View.VISIBLE); tView.saveButton.setText(R.string.timer_details_create_title); + Preferences prefs = Preferences.get(); + tView.priority.setText(String.valueOf(prefs + .getTimerDefaultPriority())); + tView.lifecycle.setText(String.valueOf(prefs + .getTimerDefaultLifetime())); + + Date start = new Date(timer.getStart().getTime() + - prefs.getTimerPreMargin() * 60000); + + Date end = new Date(timer.getStop().getTime() + + prefs.getTimerPostMargin() * 60000); + + updateDates(start, end); break; case MODIFY: tView.saveButton.setVisibility(View.GONE); tView.modifyButton.setVisibility(View.VISIBLE); tView.saveButton.setText(R.string.timer_details_save_title); + tView.priority.setText(String.valueOf(timer.getPriority())); + tView.lifecycle.setText(String.valueOf(timer.getLifetime())); + if (timer.isVps()) { + vpsChecked(true); + } else { + updateDates(timer.getStart(), timer.getStop()); + } + break; + default: + throw new RuntimeException("Unknown Operation: " + op); } + } private void updateDisplay() { - EventFormatter f = new EventFormatter(timer, true); tView.channel.setText(timer.getChannelNumber() + " " + timer.getChannelName()); // tView.title.setText(timer.isVps() ? // getString(R.string.timer_detail_title_vps, f.getTitle()) : // f.getTitle()); + EventFormatter f = new EventFormatter(timer, true); tView.title.setText(f.getTitle()); - tView.dateField.setText(f.getDate()); - tView.startField.setText(f.getTime()); - tView.endField.setText(f.getStop()); - tView.vps.setChecked(timer.isVps()); - tView.priority.setText(String.valueOf(timer.getPriority())); - tView.lifecycle.setText(String.valueOf(timer.getLifetime())); tView.repeat.setText(getSelectedItems().toString(this, true)); EpgCache.CACHE.remove(timer.getChannelId()); EpgCache.NEXT_REFRESH.remove(timer.getChannelId()); + tView.vps.setChecked(timer.isVps()); } @@ -221,7 +317,7 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, timer.setVps(tView.vps.isChecked()); timer.setPriority(getIntOr0(tView.priority)); timer.setLifetime(getIntOr0(tView.lifecycle)); - + createTimer(timer); // say(R.string.done); break; @@ -235,10 +331,12 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, weekdays[Calendar.THURSDAY], weekdays[Calendar.FRIDAY], weekdays[Calendar.SATURDAY], weekdays[Calendar.SUNDAY], }; - final DaysOfWeek mNewDaysOfWeek = new DaysOfWeek(getSelectedItems().mDays); + final DaysOfWeek mNewDaysOfWeek = new DaysOfWeek( + getSelectedItems().mDays); final AlertDialog b = new AlertDialog.Builder(this) - .setMultiChoiceItems(values, getSelectedItems().getBooleanArray(), + .setMultiChoiceItems(values, + getSelectedItems().getBooleanArray(), new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { @@ -251,15 +349,25 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, public void onClick(DialogInterface dialog, int which) { StringBuilder sb = new StringBuilder(7); - sb.append(mNewDaysOfWeek.isSet(0) ? 'M' : '-'); - sb.append(mNewDaysOfWeek.isSet(1) ? 'T' : '-'); - sb.append(mNewDaysOfWeek.isSet(2) ? 'W' : '-'); - sb.append(mNewDaysOfWeek.isSet(3) ? 'T' : '-'); - sb.append(mNewDaysOfWeek.isSet(4) ? 'F' : '-'); - sb.append(mNewDaysOfWeek.isSet(5) ? 'S' : '-'); - sb.append(mNewDaysOfWeek.isSet(6) ? 'S' : '-'); + sb.append(mNewDaysOfWeek.isSet(0) ? 'M' + : '-'); + sb.append(mNewDaysOfWeek.isSet(1) ? 'T' + : '-'); + sb.append(mNewDaysOfWeek.isSet(2) ? 'W' + : '-'); + sb.append(mNewDaysOfWeek.isSet(3) ? 'T' + : '-'); + sb.append(mNewDaysOfWeek.isSet(4) ? 'F' + : '-'); + sb.append(mNewDaysOfWeek.isSet(5) ? 'S' + : '-'); + sb.append(mNewDaysOfWeek.isSet(6) ? 'S' + : '-'); timer.setWeekdays(sb.toString()); - tView.repeat.setText(mNewDaysOfWeek.toString(TimerDetailsActivity.this, true)); + tView.repeat.setText(mNewDaysOfWeek + .toString( + TimerDetailsActivity.this, + true)); } }).create(); @@ -276,7 +384,6 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, return dow; } - dow.set(0, str.charAt(0) == 'M'); dow.set(1, str.charAt(1) == 'T'); dow.set(2, str.charAt(2) == 'W'); @@ -308,14 +415,14 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, timer.setStop(calculateTime(timer.getStop(), hourOfDay, minute, timer.getStart())); } - updateDisplay(); + updateDates(timer.getStart(), timer.getStop()); } public void onDateSet(final DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) { timer.setStart(calculateDate(timer.getStart(), year, monthOfYear, dayOfMonth)); - updateDisplay(); + updateDates(timer.getStart(), timer.getStop()); } private Date calculateDate(final Date oldDate, final int year, |