package com.parnswir.unmp.playlist;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Filter extends PlaylistElement {

	private static final long serialVersionUID = -4786047903938579938L;
	
	private SQLiteDatabase db = null;
	private Cursor cursor = null;
	private String sql;
	private Playlist playlist;
	
	public Filter(SQLiteDatabase database, String query) {
		db = database;
		sql = query;
		initPlaylist();
		fillPlaylist();
	}
	
	private void initPlaylist() {
		playlist = new Playlist();
		playlist.setRepeating(isRepeating());
		playlist.setShuffled(isShuffled());
	}
	
	private void fillPlaylist() {
		cursor = db.rawQuery(sql, null);
		boolean successful = cursor.moveToFirst();
		if (successful)
			while (! cursor.isAfterLast()) {
				playlist.children.add(new MediaFile(cursor.getString(0)));
				cursor.moveToNext();
			}
		freeCursor();
		playlist.start();
	}
	
	private void freeCursor() {
		if (cursor != null) {
			cursor.close();
		}
	}

	@Override
	public String getCurrentFile() {
		return playlist.getCurrentFile();
	}
	
	@Override
	public String getNextFile() {
		return playlist.getNextFile();
	}

}

@@ -230,96 +230,8 @@
 8L;%0A
-%09%0A%09private SQLiteDatabase db = null;%0A%09private Cursor cursor = null;%0A%09private String sql;
 %0A%09pr
@@ -317,40 +317,8 @@
 ) %7B%0A
-%09%09db = database;%0A%09%09sql = query;%0A
 %09%09in
@@ -342,24 +342,39 @@
 illPlaylist(
+database, query
 );%0A%09%7D%0A%09%0A%09pri
@@ -539,22 +539,58 @@
 laylist(
-) %7B%0A%09%09
+SQLiteDatabase db, String sql) %7B%0A%09%09Cursor 
 cursor =
@@ -810,78 +810,8 @@
 %09%09%7D%0A
-%09%09freeCursor();%0A%09%09playlist.start();%0A%09%7D%0A%09%0A%09private void freeCursor() %7B%0A
 %09%09if
@@ -853,19 +853,40 @@
 ();%0A%09%09%7D%0A
+%09%09playlist.start();%0A
 %09%7D%0A
+%09
 %0A%09@Overr

Make Filter class serializable