diff options
author | lado <herrlado@gmail.com> | 2014-01-29 01:23:35 +0100 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2014-01-29 01:23:35 +0100 |
commit | 5ea5b1fe64a5974ebc34a02232d8f75b5fda1e35 (patch) | |
tree | a21d905d017b3202e1886f95a6737eced85ed847 | |
parent | a8b224cc17e9c10a5ab40405ff32a99d03003852 (diff) | |
download | vdr-manager-5ea5b1fe64a5974ebc34a02232d8f75b5fda1e35.tar.gz vdr-manager-5ea5b1fe64a5974ebc34a02232d8f75b5fda1e35.tar.bz2 |
recording structure + vps
5 files changed, 232 insertions, 141 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventAdapter.java index f670951..dde92d0 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventAdapter.java @@ -22,8 +22,8 @@ import de.bjusystems.vdrmanager.data.Recording; import de.bjusystems.vdrmanager.data.TimerMatch; import de.bjusystems.vdrmanager.data.Timerable; -abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> implements - Filterable +abstract class BaseEventAdapter<T extends EventListItem> extends + ArrayAdapter<T> implements Filterable // , SectionIndexer { @@ -83,16 +83,16 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> TextView header; } - private boolean canReuseConvertView(View convertView, int itemViewType){ - if(convertView == null){ + private boolean canReuseConvertView(View convertView, int itemViewType) { + if (convertView == null) { return false; } Object o = convertView.getTag(); - if(itemViewType == TYPE_ITEM){ + if (itemViewType == TYPE_ITEM) { return o instanceof EventListItemHolder; } - if(itemViewType == TYPE_HEADER){ + if (itemViewType == TYPE_HEADER) { return o instanceof EventListItemHeaderHolder; } @@ -100,7 +100,6 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> } - @Override public View getView(final int position, View convertView, final ViewGroup parent) { @@ -135,13 +134,15 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> return convertView; } - protected EventListItemHolder getEventViewHolder(EventListItem item, View view) { + protected EventListItemHolder getEventViewHolder(EventListItem item, + View view) { EventListItemHolder itemHolder = new EventListItemHolder(); itemHolder = new EventListItemHolder(); itemHolder.state = (ImageView) view.findViewById(R.id.timer_item_state); + itemHolder.other = (ImageView) view.findViewById(R.id.timer_item_other); itemHolder.time = (TextView) view.findViewById(R.id.timer_item_time); itemHolder.channel = (TextView) view .findViewById(R.id.timer_item_channel); @@ -168,7 +169,20 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> itemHolder.state.setImageResource(R.drawable.timer_recording); } else { itemHolder.state.setImageResource(R.drawable.timer_none); + itemHolder.other.setVisibility(View.GONE); + if (r.isNeww() == true) { + itemHolder.state.setImageResource(R.drawable.newrecording); + if (r.isCut()) { + itemHolder.other.setVisibility(View.VISIBLE); + itemHolder.other.setImageResource(R.drawable.schere); + } else { + itemHolder.other.setVisibility(View.GONE); + } + } else if (r.isCut()) { + itemHolder.state.setImageResource(R.drawable.schere); + } } + } else if (item.getEvent() instanceof Timerable) { TimerMatch match = ((Timerable) item.getEvent()).getTimerMatch(); switch (((Timerable) item.getEvent()).getTimerState()) { @@ -177,21 +191,21 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> match, R.drawable.timer_active, R.drawable.timer_active_begin, R.drawable.timer_active_end, - R.drawable.timer_active_conflict)); + R.drawable.timer_active_conflict)); break; case Inactive: itemHolder.state.setImageResource(Utils.getTimerStateDrawable( match, R.drawable.timer_inactive, R.drawable.timer_inactive_begin, R.drawable.timer_inactive_end, - R.drawable.timer_inactive)); + R.drawable.timer_inactive)); break; case Recording: itemHolder.state.setImageResource(Utils.getTimerStateDrawable( match, R.drawable.timer_recording, R.drawable.timer_recording_begin, R.drawable.timer_recording_end, - R.drawable.timer_recording_conflict)); + R.drawable.timer_recording_conflict)); break; case None: itemHolder.state.setImageResource(R.drawable.timer_none); @@ -245,7 +259,6 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> } } - protected EventListItemHeaderHolder getHeaderViewHolder(EventListItem item, View view) { EventListItemHeaderHolder itemHolder = new EventListItemHeaderHolder(); @@ -280,8 +293,8 @@ abstract class BaseEventAdapter<T extends EventListItem> extends ArrayAdapter<T> public void setHideChannelName(boolean hideChannelName) { this.hideChannelName = hideChannelName; } - - protected boolean isHeader(EventListItem item){ + + protected boolean isHeader(EventListItem item) { return item.isHeader(); } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventListItemHolder.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventListItemHolder.java index 7b9c93b..eaf70bb 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventListItemHolder.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventListItemHolder.java @@ -7,6 +7,7 @@ import android.widget.TextView; class EventListItemHolder { public ImageView state; + public ImageView other; public TextView title; public TextView date; public TextView time; diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingDir.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingDir.java new file mode 100644 index 0000000..ce7b995 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingDir.java @@ -0,0 +1,71 @@ +package de.bjusystems.vdrmanager.gui; + +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; + +import de.bjusystems.vdrmanager.data.Recording; + +public class RecordingDir { + + public RecordingDir() { + + } + + public String name; + + public RecordingDir parent; + + public TreeMap<String, RecordingDir> dirs = new TreeMap<String, RecordingDir>(); + + public List<Recording> recordings = new ArrayList<Recording>(); + + public String getName() { + return name; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("[").append(name).append(" => {"); + String sep = ""; + for (RecordingDir e : dirs.values()) { + sb.append(sep).append(e.toString()); + sep = ", "; + } + + sb.append("}\n-").append("\n"); + + sb.append("{").append(""); + + sep = ""; + for (Recording r : recordings) { + sb.append(sep).append(r.toString()); + } + sb.append("}]"); + return sb.toString(); + } + + public void clear() { + for (RecordingDir dir : dirs.values()) { + dir.clear(); + } + recordings.clear(); + } + + public int size() { + int sum = 0; + for (RecordingDir d : dirs.values()) { + sum += d.size(); + } + sum += recordings.size(); + return sum; + } + + public String getPath(){ + if(parent == null){ + return "/"; + } + return parent.getPath() + name + "/"; + } +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java index e3a3b4e..b8c248d 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java @@ -2,15 +2,10 @@ package de.bjusystems.vdrmanager.gui; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.Stack; -import java.util.TreeMap; -import java.util.TreeSet; import android.os.Bundle; import android.util.Log; @@ -41,7 +36,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpStartListener; /** * This class is used for showing what's current running on all channels - * + * * @author bju */ public class RecordingListActivity extends BaseEventListActivity<Recording> @@ -57,11 +52,13 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> // protected static ArrayList<Recording> CACHE = new ArrayList<Recording>(); - private static Map<String, List<Recording>> CACHE = new TreeMap<String, List<Recording>>(); + // private static Map<String, List<Recording>> CACHE = new TreeMap<String, + // List<Recording>>(); - public static final Map<String, Set<String>> FOLDERS = new TreeMap<String, Set<String>>(); + // public static final Map<String, Set<String>> FOLDERS = new + // TreeMap<String, Set<String>>(); - private String currentFolder = Recording.ROOT_FOLDER; + private RecordingDir currentFolder; // Recording.ROOT_FOLDER; private final int ASC_DESC = ASC; @@ -85,12 +82,14 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> private int percent = -1; + private RecordingDir ROOT = new RecordingDir(); + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); adapter = new RecordingAdapter(this); - + currentFolder = ROOT; // attach adapter to ListView listView = (ListView) findViewById(R.id.recording_list); folderInfo = (TextView) findViewById(R.id.folder_info); @@ -166,27 +165,28 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> final RecordingListItem item = (RecordingListItem) adapter .getItem(position); if (item.isFolder()) { - if (currentFolder.equals(Recording.ROOT_FOLDER)) { - currentFolder = item.folder; - } else { - currentFolder = currentFolder + Recording.FOLDERDELIMCHAR - + item.folder; - } - stack.push(currentFolder); + currentFolder = item.folder; + // if (currentFolder.equals(Recording.ROOT_FOLDER)) { + // currentFolder = item.folder; + // } else { + // currentFolder = currentFolder + Recording.FOLDERDELIMCHAR + // + item.folder; + // } + // stack.push(currentFolder); fillAdapter(); } else { super.onItemClick(parent, view, position, id); } } - private void updateCurrentFolderInfo( int size) { - folderInfo.setText("/" + currentFolder.replaceAll("~", "/")); + private void updateCurrentFolderInfo(int size) { + folderInfo.setText(currentFolder.getPath()); currentCount.setText(String.valueOf(size)); } /* * (non-Javadoc) - * + * * @see * de.bjusystems.vdrmanager.gui.BaseActivity#onCreateOptionsMenu(android * .view.Menu) @@ -335,65 +335,36 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> } } - private List<Recording> CACHEget(String currentFolder) { - List<Recording> list = CACHE.get(currentFolder); - if (list != null) { - return list; - } - return EMPTY; + private List<Recording> CACHEget(RecordingDir currentFolder) { + return currentFolder.recordings; } - private int getCountInFolder(String base, String folder) { - - if (base.equals(Recording.ROOT_FOLDER) == false) { - folder = base + Recording.FOLDERDELIMCHAR + folder; - } - int count = CACHEget(folder).size(); - - Set<String> set = FOLDERS.get(folder); - - if (set == null) { - return count; - } - - for (String f : set) { - count += getCountInFolder(folder, f); - } - - return count; - } @Override protected void fillAdapter() { adapter.clear(); - List<Recording> list = CACHEget(currentFolder); - sort(); final Calendar cal = Calendar.getInstance(); int day = -1; - final Set<String> folders = FOLDERS.get(currentFolder); - int currenFolderSum = 0; - if (folders != null) { - for (final String f : folders) { - final RecordingListItem recordingListItem = new RecordingListItem( - f); - recordingListItem.folder = f; - // final String sf = currentFolder.length() > 0 ? currentFolder - // + Recording.FOLDERDELIMCHAR + f : f; - // final List<Recording> list2 = CACHE.get(sf); - // if (list2 != null) { - recordingListItem.count = getCountInFolder(currentFolder, f); - currenFolderSum += recordingListItem.count; - // } - adapter.add(recordingListItem); - } + final Collection<RecordingDir> folders = currentFolder.dirs.values(); + for (final RecordingDir d : folders) { + final RecordingListItem recordingListItem = new RecordingListItem( + d.name); + recordingListItem.folder = d; + // final String sf = currentFolder.length() > 0 ? currentFolder + // + Recording.FOLDERDELIMCHAR + f : f; + // final List<Recording> list2 = CACHE.get(sf); + // if (list2 != null) { + // recordingListItem.getCcount = getCountInFolder(currentFolder, f); + // } + adapter.add(recordingListItem); } - updateCurrentFolderInfo(list.size() + currenFolderSum); + updateCurrentFolderInfo(currentFolder.size()); for (final Event rec : CACHEget(currentFolder)) { cal.setTime(rec.getStart()); @@ -410,66 +381,103 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> @Override public void onBackPressed() { - if (stack.isEmpty()) { + if (currentFolder.parent == null) { super.onBackPressed(); - } else { - stack.pop(); - if (stack.isEmpty()) { - currentFolder = ""; - } else { - currentFolder = stack.peek(); - } - fillAdapter(); + return; } - + currentFolder = currentFolder.parent; + fillAdapter(); } +// private List<Recording> readDummy() { +// +// List<Recording> list = new ArrayList<Recording>(); +// try { +// LineNumberReader r = new LineNumberReader(new FileReader(new File( +// "/sdcard/vdrmanager.txt"))); +// +// String line; +// +// while ((line = r.readLine()) != null) { +// Recording rec = null; +// try { +// rec = new Recording(line); +// } catch (Exception ex) { +// ex.printStackTrace(); +// } +// list.add(rec); +// } +// +// } catch (Exception ex) { +// ex.printStackTrace(); +// } +// +// return list; +// +// } + @Override protected boolean finishedSuccessImpl(final List<Recording> results) { + + // results.clear(); + // results.addAll(readDummy()); + clearCache(); + for (final Recording r : results) { final String folder = r.getFolder(); - if (folder.length() > 0) { - final String[] split = folder.split(Recording.FOLDERDELIMCHAR); - String key = null; - String value = null; - if (split.length == 1) { - key = Recording.ROOT_FOLDER; - value = split[0]; - } else { - value = split[split.length - 1]; - // StringBuilder sb = new StringBuilder(); - // String sep = ""; - // for(int i = 0; i < split.length - 1; ++i){ - // sb.append(sep).append(split[i]); - // sep = Recording.FOLDERDELIMCHAR; - // } - key = folder.subSequence(0, - folder.length() - (value.length() + 1)).toString(); - - } - - Set<String> list = FOLDERS.get(key); - if (list == null) { - list = new TreeSet<String>(new Comparator<String>() { - @Override - public int compare(final String lhs, final String rhs) { - return lhs.compareToIgnoreCase(rhs); - } - }); - FOLDERS.put(key, list); - } - list.add(value); + if (folder.length() == 0) { + ROOT.recordings.add(r); + } else { + final String[] split = folder.split(Recording.FOLDERDELIMCHAR); - if (key.equals(Recording.ROOT_FOLDER) == false) { - Set<String> set = FOLDERS.get(Recording.ROOT_FOLDER); - if (set == null) { - set = new HashSet<String>(); - FOLDERS.put(key, set); + RecordingDir parent = ROOT; + RecordingDir dir = null; // "a~b~c"; + for (int i = 0; i < split.length; ++i) { + String dn = split[i]; + + dir = parent.dirs.get(dn); + if(dir == null) { + dir = new RecordingDir(); + dir.parent = parent; + dir.name = dn; + parent.dirs.put(dn, dir); } - set.add(key); + parent = dir; } + dir.recordings.add(r); + + // StringBuilder sb = new StringBuilder(); + // String sep = ""; + // for(int i = 0; i < split.length - 1; ++i){ + // sb.append(sep).append(split[i]); + // sep = Recording.FOLDERDELIMCHAR; + // } + // key = folder.subSequence(0, + // folder.length() - (value.length() + 1)).toString(); + + // Set<String> list = FOLDERS.get(key); + // if (list == null) { + // list = new TreeSet<String>(new Comparator<String>() { + // @Override + // public int compare(final String lhs, final String rhs) { + // return lhs.compareToIgnoreCase(rhs); + // } + // }); + // FOLDERS.put(key, list); + // } + // + // list.add(value); + // + // if (key.equals(Recording.ROOT_FOLDER) == false) { + // Set<String> set = FOLDERS.get(Recording.ROOT_FOLDER); + // if (set == null) { + // set = new HashSet<String>(); + // FOLDERS.put(key, set); + // } + // set.add(key); + // } // a b // a @@ -477,12 +485,12 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> // a~b > k } - List<Recording> list = CACHE.get(folder); - if (list == null) { - list = new ArrayList<Recording>(); - CACHE.put(folder, list); - } - list.add(r); + // List<Recording> list = CACHE.get(folder); + // if (list == null) { + // list = new ArrayList<Recording>(); + // CACHE.put(folder, list); + // } + // list.add(r); } pushResultCountToTitle(); @@ -504,19 +512,15 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> @Override public void clearCache() { - CACHE.clear(); - FOLDERS.clear(); + ROOT.clear(); + // CACHE.clear(); + // FOLDERS.clear(); } @Override protected List<Recording> getCACHE() { - final List<Recording> list = CACHE.get(currentFolder); - - if (list != null) { - return list; - } - return EMPTY; + return currentFolder.recordings; } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java index 94368dc..c91b4b7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java @@ -213,10 +213,12 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, Date start = new Date(timer.getStart().getTime() - prefs.getTimerPreMargin() * 60000); + timer.setStart(start); Date end = new Date(timer.getStop().getTime() + prefs.getTimerPostMargin() * 60000); - + timer.setStop(end); + updateDates(start, end); break; case MODIFY: |