1. Spencer Herzberg
  2. mythtv-for-android-mavenize

Commits

Daniel Frey  committed 6966792

implementing content provider

  • Participants
  • Parent commits 4c9a109
  • Branches master

Comments (0)

Files changed (17)

File AndroidManifest.xml

View file
 		<activity 
 		    android:name=".client.ui.setup.capture.CaptureCardsActivity" />
 		
+		<!-- MythTV Android Services -->
 		<service android:name=".service.dvr.DvrService" />
 		
+		<!-- MythTV Android Providers -->
+		<provider
+            android:name=".provider.dvr.ProgramProvider"
+            android:authorities="org.mythtv.dvr.programs" />
+        		
 	</application>
 
 </manifest>

File src/org/mythtv/client/db/DatabaseHelper.java

-/**
- *  This file is part of MythTV for Android
- * 
- *  MythTV for Android is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  MythTV for Android is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with MythTV for Android.  If not, see <http://www.gnu.org/licenses/>.
- *   
- * @author Daniel Frey <dmfrey at gmail dot com>
- * @author John Baab <rhpot1991@ubuntu.com>
- * 
- * This software can be found at <https://github.com/dmfrey/mythtv-for-android/>
- *
- */
-
-package org.mythtv.client.db;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
-
-/**
- * @author Daniel Frey
- * @author John Baab
- *
- */
-public class DatabaseHelper extends SQLiteOpenHelper {
-
-	private static final String TAG = DatabaseHelper.class.getSimpleName();
-	
-	private static final String DATABASE_NAME = "mythtvdb";
-	private static final int DATABASE_VERSION = 5;
-
-	public static final String TABLE_LOCATION_PROFILE = "LOCATION_PROFILE";
-	public static final String TABLE_LOCATION_PROFILE_ID = "_ID";
-	public static final String TABLE_LOCATION_PROFILE_TYPE = "TYPE";
-	public static final String TABLE_LOCATION_PROFILE_NAME = "NAME";
-	public static final String TABLE_LOCATION_PROFILE_URL = "URL";
-	public static final String TABLE_LOCATION_PROFILE_SELECTED = "SELECTED";
-	public static final String SELECT_LOCATION_PROFILE =
-			"select " +
-				"lp._id, lp.type, lp.name, lp.url, lp.selected " +
-			"from " +
-				"location_profile lp";
-	
-	public static final String TABLE_PLAYBACK_PROFILE = "PLAYBACK_PROFILE";
-	public static final String TABLE_PLAYBACK_PROFILE_ID = "_ID";
-	public static final String TABLE_PLAYBACK_PROFILE_TYPE = "TYPE";
-	public static final String TABLE_PLAYBACK_PROFILE_NAME = "NAME";
-	public static final String TABLE_PLAYBACK_PROFILE_WIDTH = "WIDTH";
-	public static final String TABLE_PLAYBACK_PROFILE_HEIGHT = "HEIGHT";
-	public static final String TABLE_PLAYBACK_PROFILE_BITRATE = "BITRATE";
-	public static final String TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE = "AUDIO_BITRATE";
-	public static final String TABLE_PLAYBACK_PROFILE_SAMPLE_RATE = "SAMPLE_RATE";
-	public static final String TABLE_PLAYBACK_PROFILE_SELECTED = "SELECTED";
-	public static final String SELECT_PLAYBACK_PROFILE =
-			"select " +
-				"pp._id, pp.type, pp.name, pp.width, pp.height, pp.bitrate, pp.audio_bitrate, pp.sample_rate, lp.selected " +
-			"from " +
-				"playback_profile pp";
-
-	
-	public DatabaseHelper( Context context ) {
-		super( context, DATABASE_NAME, null, DATABASE_VERSION );
-	}
-	
-	/* (non-Javadoc)
-	 * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
-	 */
-	@Override
-	public void onCreate( SQLiteDatabase db ) {
-		Log.v( TAG, "onCreate : enter" );
-		
-		db.execSQL( "CREATE TABLE location_profile( _id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, name TEXT, url TEXT, selected INTEGER default 0 );" );
-
-		createPlaybackProfiles( db );
-		
-		Log.v( TAG, "onCreate : exit" );
-	}
-
-	/* (non-Javadoc)
-	 * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)
-	 */
-	@Override
-	public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ) {
-		Log.v( TAG, "onUpgrade : enter" );
-
-	    db.execSQL( "DROP TABLE IF EXISTS playback_profile" );
-
-	    createPlaybackProfiles( db );
-	    
-		Log.v( TAG, "onUpgrade : exit" );
-	}
-
-	// internal helpers
-	
-	private void createPlaybackProfiles( SQLiteDatabase db ) {
-		Log.v( TAG, "createPlaybackProfiles : enter" );
-		
-		db.execSQL( "CREATE TABLE playback_profile( _id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, name TEXT, url TEXT, width INTEGER, height INTEGER, bitrate INTEGER default 800000, audio_bitrate INTEGER default 64000, sample_rate INTEGER default 44100, selected INTEGER default 0 );" );
-
-		ContentValues values = new ContentValues();
-
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "HOME" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "720p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 1280 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 720 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 2000000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 192000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "AWAY" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "720p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 1280 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 720 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 2000000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 192000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-		
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "HOME" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "630p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 1120 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 630 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 1500000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 192000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "AWAY" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "630p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 1120 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 630 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 1500000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 192000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-		
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "HOME" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "540p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 960 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 540 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 1000000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 128000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 1 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "AWAY" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "540p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 960 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 540 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 1000000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 128000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "HOME" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "480p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 854 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 480 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 800000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 128000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "AWAY" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "480p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 854 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 480 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 800000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 128000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "HOME" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "360p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 640 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 360 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 500000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 96000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "AWAY" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "360p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 640 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 360 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 500000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 96000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 1 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-		
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "HOME" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "270p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 480 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 270 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 300000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 96000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-
-		values = new ContentValues();
-		values.put( TABLE_PLAYBACK_PROFILE_TYPE, "AWAY" );
-		values.put( TABLE_PLAYBACK_PROFILE_NAME, "270p" );
-		values.put( TABLE_PLAYBACK_PROFILE_WIDTH, 480 );
-		values.put( TABLE_PLAYBACK_PROFILE_HEIGHT, 270 );
-		values.put( TABLE_PLAYBACK_PROFILE_BITRATE, 300000 );
-		values.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, 96000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, 48000 );
-		values.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-		db.insert( TABLE_PLAYBACK_PROFILE, null, values );
-		
-		Log.v( TAG, "createPlaybackProfiles : exit" );
-	}
-	
-}

File src/org/mythtv/client/db/MythtvDatabaseManager.java

-/**
- *  This file is part of MythTV for Android
- * 
- *  MythTV for Android is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  MythTV for Android is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with MythTV for Android.  If not, see <http://www.gnu.org/licenses/>.
- *   
- * @author Daniel Frey <dmfrey at gmail dot com>
- * 
- * This software can be found at <https://github.com/dmfrey/mythtv-for-android/>
- *
- */
-
-package org.mythtv.client.db;
-
-import static org.mythtv.client.db.DatabaseHelper.TABLE_LOCATION_PROFILE;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_LOCATION_PROFILE_ID;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_LOCATION_PROFILE_NAME;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_LOCATION_PROFILE_SELECTED;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_LOCATION_PROFILE_TYPE;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_LOCATION_PROFILE_URL;
-
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_ID;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_NAME;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_SELECTED;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_TYPE;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_WIDTH;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_HEIGHT;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_BITRATE;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE;
-import static org.mythtv.client.db.DatabaseHelper.TABLE_PLAYBACK_PROFILE_SAMPLE_RATE;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.mythtv.R;
-import org.mythtv.client.ui.preferences.LocationProfile;
-import org.mythtv.client.ui.preferences.LocationProfile.LocationType;
-import org.mythtv.client.ui.preferences.PlaybackProfile;
-
-import android.app.AlertDialog;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.database.Cursor;
-import android.database.SQLException;
-import android.database.sqlite.SQLiteDatabase;
-import android.util.Log;
-
-/**
- * @author Daniel Frey
- * 
- */
-public class MythtvDatabaseManager {
-
-	private static final String TAG = MythtvDatabaseManager.class.getSimpleName();
-
-	private final Context context;
-
-	private DatabaseHelper helper;
-	private SQLiteDatabase db;
-
-	/**
-	 * @param context
-	 */
-	public MythtvDatabaseManager( final Context context ) {
-		Log.v( TAG, "initialize : enter" );
-
-		this.context = context;
-		this.helper = new DatabaseHelper( context );
-
-		Log.v( TAG, "initialize : exit" );
-	}
-
-	/**
-	 * 
-	 */
-	private void open() {
-		Log.v( TAG, "open : enter" );
-
-		if( null != db ) {
-			close();
-		}
-
-		db = helper.getWritableDatabase();
-
-		Log.v( TAG, "open : exit" );
-	}
-
-	/**
-	 * 
-	 */
-	private void close() {
-		Log.v( TAG, "close : enter" );
-
-		helper.close();
-		db = null;
-
-		Log.v( TAG, "open : exit" );
-
-	}
-
-	/**
-	 * @return
-	 */
-	public List<LocationProfile> fetchHomeLocationProfiles() {
-		Log.v( TAG, "fetchHomeLocationProfiles : enter" );
-		Log.v( TAG, "fetchHomeLocationProfiles : exit" );
-		return fetchLocationProfilesByType( LocationType.HOME );
-	}
-
-	/**
-	 * @return
-	 */
-	public List<LocationProfile> fetchAwayLocationProfiles() {
-		Log.v( TAG, "fetchAwayLocationProfiles : enter" );
-		Log.v( TAG, "fetchAwayLocationProfiles : exit" );
-		return fetchLocationProfilesByType( LocationType.AWAY );
-	}
-
-	public LocationProfile fetchLocationProfile( long id ) {
-		Log.v( TAG, "fetchLocationProfile : enter" );
-		
-		open();
-		
-		LocationProfile profile = null;
-		
-		try {
-			Cursor cursor = db.query( 
-						TABLE_LOCATION_PROFILE, 
-						new String[] { TABLE_LOCATION_PROFILE_ID, TABLE_LOCATION_PROFILE_TYPE, TABLE_LOCATION_PROFILE_NAME, TABLE_LOCATION_PROFILE_URL, TABLE_LOCATION_PROFILE_SELECTED }, 
-						TABLE_LOCATION_PROFILE_ID + "=" + id, 
-						null, null, null, null 
-					  );
-			
-			if( cursor.getCount() == 1 && cursor.moveToFirst() ) {
-				Log.v( TAG, "fetchLocationProfile : location profile found" );
-
-				profile = convertCursorToLocationProfile( cursor );
-			}
-			
-			cursor.close();
-			
-		} catch( SQLException e ) {
-			Log.e( TAG, "fetchLocationProfile : error", e );
-			
-			AlertDialog.Builder builder = new AlertDialog.Builder( context );
-			builder.setTitle( "DataBase Error" );
-			builder.setMessage( "An error occurred locating profile" );
-			builder.setNeutralButton( R.string.close, new OnClickListener() {
-
-				public void onClick( DialogInterface dialog, int which ) { }
-			
-			});
-		} finally {
-			close();
-		}
-		
-		Log.v( TAG, "fetchLocationProfile : exit" );
-		return profile;
-	}
-
-	/**
-	 * @param profile
-	 * @return
-	 */
-	public long createHomeLocationProfile( LocationProfile profile ) {
-		Log.v( TAG, "createHomeLocationProfile : enter" );
-
-		profile.setType( LocationType.HOME );
-
-		long id = createLocationProfile( profile );
-		
-		if( fetchHomeLocationProfiles().size() == 1 ) {
-			Log.v( TAG, "createHomeLocationProfile : making default" );
-
-			setSelectedHomeLocationProfile( id );
-		}
-		
-		Log.v( TAG, "createHomeLocationProfile : exit" );
-		return id;
-	}
-
-	/**
-	 * @param profile
-	 * @return
-	 */
-	public long createAwayLocationProfile( LocationProfile profile ) {
-		Log.v( TAG, "createAwayLocationProfile : enter" );
-
-		profile.setType( LocationType.AWAY );
-
-		long id = createLocationProfile( profile );
-
-		if( fetchAwayLocationProfiles().size() == 1 ) {
-			Log.v( TAG, "createAwayLocationProfile : making default" );
-
-			setSelectedAwayLocationProfile( id );
-		}
-				
-		Log.v( TAG, "createAwayLocationProfile : enter" );
-		return id;
-	}
-
-	/**
-	 * @param profile
-	 * @return
-	 */
-	public boolean updateLocationProfile( LocationProfile profile ) {
-		Log.v( TAG, "updateLocationProfile : enter" );
-
-		open();
-
-		ContentValues args = new ContentValues();
-		args.put( TABLE_LOCATION_PROFILE_TYPE, profile.getType().name() );
-		args.put( TABLE_LOCATION_PROFILE_NAME, profile.getName() );
-		args.put( TABLE_LOCATION_PROFILE_URL, profile.getUrl() );
-		args.put( TABLE_LOCATION_PROFILE_SELECTED, profile.isSelected() ? 1 : 0 );
-
-		int rows = db.update( TABLE_LOCATION_PROFILE, args, TABLE_LOCATION_PROFILE_ID + "=" + profile.getId(), null );
-	
-		close();
-
-		Log.v( TAG, "updateLocationProfile : exit" );
-		return rows > 0;
-	}
-
-	/**
-	 * @param id
-	 * @return
-	 */
-	public boolean deleteLocationProfile( long id ) {
-		Log.v( TAG, "deleteLocationProfile : enter" );
-		
-		open();
-		
-		boolean result = db.delete( TABLE_LOCATION_PROFILE, TABLE_LOCATION_PROFILE_ID + "=" + id, null ) > 0;
-		
-		close();
-		
-		Log.v( TAG, "deleteLocationProfile : exit" );
-		return result;
-	}
-
-	/**
-	 * @param id
-	 * @return
-	 */
-	public boolean setSelectedHomeLocationProfile( long id ) {
-		Log.v( TAG, "setSelectedHomeLocationProfile : enter" );
-		Log.v( TAG, "setSelectedHomeLocationProfile : exit" );
-		return setSelectedLocationProfile( id, LocationType.HOME );
-	}
-
-	/**
-	 * @param id
-	 * @return
-	 */
-	public boolean setSelectedAwayLocationProfile( long id ) {
-		Log.v( TAG, "setSelectedAwayLocationProfile : enter" );
-		Log.v( TAG, "setSelectedAwayLocationProfile : exit" );
-		return setSelectedLocationProfile( id, LocationType.AWAY );
-	}
-
-	/**
-	 * @return
-	 */
-	public LocationProfile fetchSelectedHomeLocationProfile() {
-		Log.v( TAG, "fetchSelectedHomeLocationProfile : enter" );
-		Log.v( TAG, "fetchSelectedHomeLocationProfile : exit" );
-		return fetchSelectedLocationProfileByType( LocationType.HOME );
-	}
-
-	/**
-	 * @return
-	 */
-	public LocationProfile fetchSelectedAwayLocationProfile() {
-		Log.v( TAG, "fetchSelectedAwayLocationProfile : enter" );
-		Log.v( TAG, "fetchSelectedAwayLocationProfile : exit" );
-		return fetchSelectedLocationProfileByType( LocationType.AWAY );
-	}
-
-	/**
-	 * @return
-	 */
-	public List<PlaybackProfile> fetchHomePlaybackProfiles() {
-		Log.v( TAG, "fetchHomePlaybackProfiles : enter" );
-		Log.v( TAG, "fetchHomePlaybackProfiles : exit" );
-		return fetchPlaybackProfilesByType( LocationType.HOME );
-	}
-
-	/**
-	 * @return
-	 */
-	public List<PlaybackProfile> fetchAwayPlaybackProfiles() {
-		Log.v( TAG, "fetchAwayPlaybackProfiles : enter" );
-		Log.v( TAG, "fetchAwayPlaybackProfiles : exit" );
-		return fetchPlaybackProfilesByType( LocationType.AWAY );
-	}
-
-	public PlaybackProfile fetchPlaybackProfile( long id ) {
-		Log.v( TAG, "fetchPlaybackProfile : enter" );
-		
-		open();
-		
-		PlaybackProfile profile = null;
-		
-		try {
-			Cursor cursor = db.query( 
-						TABLE_PLAYBACK_PROFILE, 
-						new String[] { TABLE_PLAYBACK_PROFILE_ID, TABLE_PLAYBACK_PROFILE_TYPE, TABLE_PLAYBACK_PROFILE_NAME, TABLE_PLAYBACK_PROFILE_WIDTH, TABLE_PLAYBACK_PROFILE_HEIGHT, TABLE_PLAYBACK_PROFILE_BITRATE, TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, TABLE_PLAYBACK_PROFILE_SELECTED }, 
-						TABLE_PLAYBACK_PROFILE_ID + "=" + id, 
-						null, null, null, null 
-					  );
-			
-			if( cursor.getCount() == 1 && cursor.moveToFirst() ) {
-				Log.v( TAG, "fetchPlaybackProfile : playback profile found" );
-
-				profile = convertCursorToPlaybackProfile( cursor );
-			}
-			
-			cursor.close();
-			
-		} catch( SQLException e ) {
-			Log.e( TAG, "fetchPlaybackProfile : error", e );
-			
-			AlertDialog.Builder builder = new AlertDialog.Builder( context );
-			builder.setTitle( "DataBase Error" );
-			builder.setMessage( "An error occurred locating profile" );
-			builder.setNeutralButton( R.string.close, new OnClickListener() {
-
-				public void onClick( DialogInterface dialog, int which ) { }
-			
-			});
-		}
-		
-		close();
-		
-		Log.v( TAG, "fetchPlaybackProfile : exit" );
-		return profile;
-	}
-
-	/**
-	 * @param profile
-	 * @return
-	 */
-	public boolean updatePlaybackProfile( PlaybackProfile profile ) {
-		Log.v( TAG, "updatePlaybackProfile : enter" );
-
-		open();
-
-		ContentValues args = new ContentValues();
-		args.put( TABLE_PLAYBACK_PROFILE_TYPE, profile.getType().name() );
-		args.put( TABLE_PLAYBACK_PROFILE_NAME, profile.getName() );
-		args.put( TABLE_PLAYBACK_PROFILE_WIDTH, profile.getWidth() );
-		args.put( TABLE_PLAYBACK_PROFILE_HEIGHT, profile.getHeight() );
-		args.put( TABLE_PLAYBACK_PROFILE_BITRATE, profile.getVideoBitrate() );
-		args.put( TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, profile.getAudioBitrate() );
-		args.put( TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, profile.getAudioSampleRate() );
-		args.put( TABLE_PLAYBACK_PROFILE_SELECTED, profile.isSelected() ? 1 : 0 );
-
-		int rows = db.update( TABLE_PLAYBACK_PROFILE, args, TABLE_PLAYBACK_PROFILE_ID + "=" + profile.getId(), null );
-	
-		close();
-
-		Log.v( TAG, "updatePlaybackProfile : exit" );
-		return rows > 0;
-	}
-
-	/**
-	 * @param id
-	 * @return
-	 */
-	public boolean setSelectedHomePlaybackProfile( long id ) {
-		Log.v( TAG, "setSelectedHomePlaybackProfile : enter" );
-		Log.v( TAG, "setSelectedHomePlaybackProfile : exit" );
-		return setSelectedPlaybackProfile( id, LocationType.HOME );
-	}
-
-	/**
-	 * @param id
-	 * @return
-	 */
-	public boolean setSelectedAwayPlaybackProfile( long id ) {
-		Log.v( TAG, "setSelectedAwayPlaybackProfile : enter" );
-		Log.v( TAG, "setSelectedAwayPlaybackProfile : exit" );
-		return setSelectedPlaybackProfile( id, LocationType.AWAY );
-	}
-
-	/**
-	 * @return
-	 */
-	public PlaybackProfile fetchSelectedHomePlaybackProfile() {
-		Log.v( TAG, "fetchSelectedHomePlaybackProfile : enter" );
-		Log.v( TAG, "fetchSelectedHomePlaybackProfile : exit" );
-		return fetchSelectedPlaybackProfileByType( LocationType.HOME );
-	}
-
-	/**
-	 * @return
-	 */
-	public PlaybackProfile fetchSelectedAwayPlaybackProfile() {
-		Log.v( TAG, "fetchSelectedAwayPlaybackProfile : enter" );
-		Log.v( TAG, "fetchSelectedAwayPlaybackProfile : exit" );
-		return fetchSelectedPlaybackProfileByType( LocationType.AWAY );
-	}
-
-	// internal helpers
-
-	/**
-	 * @param cursor
-	 * @return
-	 */
-	private LocationProfile convertCursorToLocationProfile( Cursor cursor ) {
-		Log.v( TAG, "convertCursorToLocationProfile : enter" );
-		
-		LocationProfile profile = new LocationProfile();
-		profile.setId( cursor.getInt( 0 ) );
-		profile.setType( LocationType.valueOf( cursor.getString( 1 ) ) );
-		profile.setName( cursor.getString( 2 ) );
-		profile.setUrl( cursor.getString( 3 ) );
-		profile.setSelected( cursor.getInt( 4 ) != 0 );
-		
-		Log.v( TAG, "convertCursorToLocationProfile : exit" );
-		return profile;
-	}
-	
-	/**
-	 * @param cursor
-	 * @return
-	 */
-	private PlaybackProfile convertCursorToPlaybackProfile( Cursor cursor ) {
-		Log.v( TAG, "convertCursorToPlaybackProfile : enter" );
-		
-		PlaybackProfile profile = new PlaybackProfile();
-		profile.setId( cursor.getInt( 0 ) );
-		profile.setType( LocationType.valueOf( cursor.getString( 1 ) ) );
-		profile.setName( cursor.getString( 2 ) );
-		profile.setWidth( cursor.getInt( 3 ) );
-		profile.setHeight( cursor.getInt( 4 ) );
-		profile.setVideoBitrate( cursor.getInt( 5 ) );
-		profile.setAudioBitrate( cursor.getInt( 6 ) );
-		profile.setAudioSampleRate( cursor.getInt( 7 ) );
-		profile.setSelected( cursor.getInt( 8 ) != 0 );
-		
-		Log.v( TAG, "convertCursorToPlaybackProfile : exit" );
-		return profile;
-	}
-
-	/**
-	 * @param type
-	 * @return
-	 */
-	private List<LocationProfile> fetchLocationProfilesByType( LocationType type ) {
-		Log.v( TAG, "fetchLocationProfilesByType : enter" );
-		
-		open();
-		
-		List<LocationProfile> profiles = new ArrayList<LocationProfile>();
-
-		Cursor cursor = db.query( TABLE_LOCATION_PROFILE, new String[] { TABLE_LOCATION_PROFILE_ID, TABLE_LOCATION_PROFILE_TYPE, TABLE_LOCATION_PROFILE_NAME, TABLE_LOCATION_PROFILE_URL, TABLE_LOCATION_PROFILE_SELECTED }, "type=?",	new String[] { type.name() }, null, null, null );
-		
-		int count = cursor.getCount();
-		if( count > 0 && cursor.moveToFirst() ) {
-			Log.v( TAG, "fetchLocationProfilesByType : location profiles found" );
-		
-			for( int i = 0; i < count; i++ ) {
-				Log.v( TAG, "fetchLocationProfilesByType : location profile cursor iteration" );
-				
-				profiles.add( convertCursorToLocationProfile( cursor ) );
-				cursor.moveToNext();
-			}
-		}
-		
-		cursor.close();
-		close();
-		
-		Log.v( TAG, "fetchLocationProfilesByType : exit" );
-		return profiles;
-	}
-
-	/**
-	 * @param type
-	 * @return
-	 */
-	private List<PlaybackProfile> fetchPlaybackProfilesByType( LocationType type ) {
-		Log.v( TAG, "fetchPlaybackProfilesByType : enter" );
-		
-		open();
-		
-		List<PlaybackProfile> profiles = new ArrayList<PlaybackProfile>();
-
-		Cursor cursor = db.query( TABLE_PLAYBACK_PROFILE, new String[] { TABLE_PLAYBACK_PROFILE_ID, TABLE_PLAYBACK_PROFILE_TYPE, TABLE_PLAYBACK_PROFILE_NAME, TABLE_PLAYBACK_PROFILE_WIDTH, TABLE_PLAYBACK_PROFILE_HEIGHT, TABLE_PLAYBACK_PROFILE_BITRATE, TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, TABLE_PLAYBACK_PROFILE_SELECTED }, "type=?",	new String[] { type.name() }, null, null, null );
-		
-		int count = cursor.getCount();
-		if( count > 0 && cursor.moveToFirst() ) {
-			Log.v( TAG, "fetchPlaybackProfilesByType : playback profiles found" );
-		
-			for( int i = 0; i < count; i++ ) {
-				Log.v( TAG, "fetchPlaybackProfilesByType : playback profile cursor iteration" );
-				
-				profiles.add( convertCursorToPlaybackProfile( cursor ) );
-				cursor.moveToNext();
-			}
-		}
-		
-		cursor.close();
-		close();
-		
-		Log.v( TAG, "fetchPlaybackProfilesByType : exit" );
-		return profiles;
-	}
-
-	/**
-	 * @param profile
-	 * @return
-	 */
-	private long createLocationProfile( LocationProfile profile ) {
-		Log.v( TAG, "createLocationProfile : enter" );
-
-		Log.v( TAG, "createLocationProfile : profile=" + profile.toString() );
-		
-		open();
-		
-		ContentValues initialValues = new ContentValues();
-		initialValues.put( TABLE_LOCATION_PROFILE_TYPE, profile.getType().name() );
-		initialValues.put( TABLE_LOCATION_PROFILE_NAME, profile.getName() );
-		initialValues.put( TABLE_LOCATION_PROFILE_URL, profile.getUrl() );
-		initialValues.put( TABLE_LOCATION_PROFILE_SELECTED, 0 );
-
-		long id = db.insert( TABLE_LOCATION_PROFILE, null, initialValues );
-		
-		close();
-		
-		Log.v( TAG, "createLocationProfile : enter" );
-		return id;
-	}
-
-	private boolean setSelectedLocationProfile( long id, LocationType type ) {
-		Log.v( TAG, "setSelectedLocationProfile : enter" );
-
-		open();
-		
-		ContentValues args = new ContentValues();
-		args.put( TABLE_LOCATION_PROFILE_SELECTED, 0 );
-
-		db.update( TABLE_LOCATION_PROFILE, args, TABLE_LOCATION_PROFILE_TYPE + "=?", new String[] { type.name() } );
-
-		args = new ContentValues();
-		args.put( TABLE_LOCATION_PROFILE_SELECTED, 1 );
-
-		int rows = db.update( TABLE_LOCATION_PROFILE, args, TABLE_LOCATION_PROFILE_ID + "=?", new String[] { "" + id } );
-	
-		close();
-
-		Log.v( TAG, "setSelectedLocationProfile : exit" );
-		return rows > 0;
-	}
-
-	private boolean setSelectedPlaybackProfile( long id, LocationType type ) {
-		Log.v( TAG, "setSelectedPlaybackProfile : enter" );
-
-		open();
-		
-		ContentValues args = new ContentValues();
-		args.put( TABLE_PLAYBACK_PROFILE_SELECTED, 0 );
-
-		db.update( TABLE_PLAYBACK_PROFILE, args, TABLE_PLAYBACK_PROFILE_TYPE + "=?", new String[] { type.name() } );
-
-		args = new ContentValues();
-		args.put( TABLE_PLAYBACK_PROFILE_SELECTED, 1 );
-
-		int rows = db.update( TABLE_PLAYBACK_PROFILE, args, TABLE_PLAYBACK_PROFILE_ID + "=?", new String[] { "" + id } );
-	
-		close();
-
-		Log.v( TAG, "setSelectedPlaybackProfile : exit" );
-		return rows > 0;
-	}
-
-	private LocationProfile fetchSelectedLocationProfileByType( LocationType type ) {
-		Log.v( TAG, "fetchSelectedLocationProfileByType : enter" );
-		
-		open();
-		
-		LocationProfile profile = null;
-
-		try {
-			Cursor cursor = db.query( 
-						TABLE_LOCATION_PROFILE, 
-						new String[] { TABLE_LOCATION_PROFILE_ID, TABLE_LOCATION_PROFILE_TYPE, TABLE_LOCATION_PROFILE_NAME, TABLE_LOCATION_PROFILE_URL, TABLE_LOCATION_PROFILE_SELECTED }, 
-						TABLE_LOCATION_PROFILE_TYPE + "=? and " + TABLE_LOCATION_PROFILE_SELECTED + "=?", 
-						new String[] { type.name(), "1" }, 
-						null, null, null 
-					  );
-			
-			if( cursor.getCount() == 1 && cursor.moveToFirst() ) {
-				Log.v( TAG, "fetchSelectedLocationProfileByType : location profile found" );
-
-				profile = convertCursorToLocationProfile( cursor );
-			}
-			
-			cursor.close();
-			
-		} catch( SQLException e ) {
-			Log.e( TAG, "fetchSelectedLocationProfileByType : error", e );
-			
-			AlertDialog.Builder builder = new AlertDialog.Builder( context );
-			builder.setTitle( "DataBase Error" );
-			builder.setMessage( "An error occurred locating profile" );
-			builder.setNeutralButton( R.string.close, new OnClickListener() {
-
-				public void onClick( DialogInterface dialog, int which ) { }
-			
-			});
-		} finally {
-			close();
-		}
-		
-		Log.v( TAG, "fetchSelectedLocationProfileByType : exit" );
-		return profile;
-	}
-
-	private PlaybackProfile fetchSelectedPlaybackProfileByType( LocationType type ) {
-		Log.v( TAG, "fetchSelectedPlaybackProfileByType : enter" );
-		
-		open();
-		
-		PlaybackProfile profile = null;
-
-		try {
-			Cursor cursor = db.query( 
-						TABLE_PLAYBACK_PROFILE, 
-						new String[] { TABLE_PLAYBACK_PROFILE_ID, TABLE_PLAYBACK_PROFILE_TYPE, TABLE_PLAYBACK_PROFILE_NAME, TABLE_PLAYBACK_PROFILE_WIDTH, TABLE_PLAYBACK_PROFILE_HEIGHT, TABLE_PLAYBACK_PROFILE_BITRATE, TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, TABLE_PLAYBACK_PROFILE_SELECTED }, 
-						TABLE_PLAYBACK_PROFILE_TYPE + "=? and " + TABLE_PLAYBACK_PROFILE_SELECTED + "=?", 
-						new String[] { type.name(), "1" }, 
-						null, null, null 
-					  );
-			
-			if( cursor.getCount() == 1 && cursor.moveToFirst() ) {
-				Log.v( TAG, "fetchSelectedPlaybackProfileByType : playback profile found" );
-
-				profile = convertCursorToPlaybackProfile( cursor );
-			}
-			
-			cursor.close();
-			
-		} catch( SQLException e ) {
-			Log.e( TAG, "fetchSelectedPlaybackProfileByType : error", e );
-			
-			AlertDialog.Builder builder = new AlertDialog.Builder( context );
-			builder.setTitle( "DataBase Error" );
-			builder.setMessage( "An error occurred locating profile" );
-			builder.setNeutralButton( R.string.close, new OnClickListener() {
-
-				public void onClick( DialogInterface dialog, int which ) { }
-			
-			});
-		} finally {
-			close();
-		}
-		
-		Log.v( TAG, "fetchSelectedPlaybackProfileByType : exit" );
-		return profile;
-	}
-
-}

File src/org/mythtv/client/ui/LocationActivity.java

View file
 package org.mythtv.client.ui;
 
 import org.mythtv.R;
-import org.mythtv.client.db.MythtvDatabaseManager;
 import org.mythtv.client.ui.preferences.LocationProfile;
 import org.mythtv.client.ui.preferences.MythtvPreferenceActivity;
 import org.mythtv.client.ui.preferences.MythtvPreferenceActivityHC;
 import org.mythtv.client.ui.preferences.PlaybackProfile;
+import org.mythtv.db.MythtvDatabaseManager;
 
 import android.content.Context;
 import android.content.Intent;

File src/org/mythtv/client/ui/preferences/LocationProfileEditor.java

View file
  * This software can be found at <https://github.com/dmfrey/mythtv-for-android/>
  *
  */
+
 package org.mythtv.client.ui.preferences;
 
+import static android.provider.BaseColumns._ID;
+import static org.mythtv.db.preferences.LocationProfileConstants.FIELD_NAME;
+import static org.mythtv.db.preferences.LocationProfileConstants.FIELD_SELECTED;
+import static org.mythtv.db.preferences.LocationProfileConstants.FIELD_TYPE;
+import static org.mythtv.db.preferences.LocationProfileConstants.FIELD_URL;
+
 import org.mythtv.R;
-import org.mythtv.client.db.DatabaseHelper;
-import org.mythtv.client.db.MythtvDatabaseManager;
 import org.mythtv.client.ui.AbstractMythtvFragmentActivity;
 import org.mythtv.client.ui.preferences.LocationProfile.LocationType;
+import org.mythtv.db.MythtvDatabaseManager;
 
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 		setupSaveButtonEvent( R.id.btnPreferenceLocationProfileSave );
 		setupCancelButtonEvent( R.id.btnPreferenceLocationProfileCancel );
 
-		int id = getIntent().getIntExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_ID, -1 );
+		int id = getIntent().getIntExtra( _ID, -1 );
 		//if( id != -1 ) {
 			profile = new LocationProfile();
 			profile.setId( id );
-			profile.setType( LocationType.valueOf( getIntent().getStringExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_TYPE ) ) );
-			profile.setName( getIntent().getStringExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_NAME ) );
-			profile.setUrl( getIntent().getStringExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_URL ) );
-			profile.setSelected( 0 != getIntent().getIntExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_SELECTED, 0 ) );
+			profile.setType( LocationType.valueOf( getIntent().getStringExtra( FIELD_TYPE ) ) );
+			profile.setName( getIntent().getStringExtra( FIELD_NAME ) );
+			profile.setUrl( getIntent().getStringExtra( FIELD_URL ) );
+			profile.setSelected( 0 != getIntent().getIntExtra( FIELD_SELECTED, 0 ) );
 
 			setUiFromLocationProfile();
 		//}

File src/org/mythtv/client/ui/preferences/MythtvPreferenceActivity.java

View file
  */
 package org.mythtv.client.ui.preferences;
 
+import static android.provider.BaseColumns._ID;
+
 import java.io.IOException;
 import java.net.InetAddress;
 import java.util.EventListener;
 import javax.jmdns.ServiceListener;
 
 import org.mythtv.R;
-import org.mythtv.client.db.DatabaseHelper;
-import org.mythtv.client.db.MythtvDatabaseManager;
 import org.mythtv.client.ui.preferences.LocationProfile.LocationType;
+import org.mythtv.db.MythtvDatabaseManager;
+import org.mythtv.db.preferences.LocationProfileConstants;
+import org.mythtv.db.preferences.PlaybackProfileConstants;
 
 import android.app.AlertDialog;
 import android.content.Context;
 
 			// put extra information is needed
 			if( null != profile ) {
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_ID, profile.getId() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_TYPE, profile.getType().name() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_NAME, profile.getName() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_URL, profile.getUrl() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
+				intent.putExtra( _ID, profile.getId() );
+				intent.putExtra( LocationProfileConstants.FIELD_TYPE, profile.getType().name() );
+				intent.putExtra( LocationProfileConstants.FIELD_NAME, profile.getName() );
+				intent.putExtra( LocationProfileConstants.FIELD_URL, profile.getUrl() );
+				intent.putExtra( LocationProfileConstants.FIELD_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
 			}
 
 			// start activity
 
 			// put extra information is needed
 			if( null != profile ) {
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_ID, profile.getId() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_TYPE, profile.getType().name() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_NAME, profile.getName() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_WIDTH, profile.getWidth() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_HEIGHT, profile.getHeight() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_BITRATE, profile.getVideoBitrate() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, profile.getAudioBitrate() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, profile.getAudioSampleRate() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
+				intent.putExtra( _ID, profile.getId() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_TYPE, profile.getType().name() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_NAME, profile.getName() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_WIDTH, profile.getWidth() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_HEIGHT, profile.getHeight() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_BITRATE, profile.getVideoBitrate() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, profile.getAudioBitrate() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_SAMPLE_RATE, profile.getAudioSampleRate() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
 			}
 
 			// start activity

File src/org/mythtv/client/ui/preferences/MythtvPreferenceActivityHC.java

View file
  */
 package org.mythtv.client.ui.preferences;
 
+import static android.provider.BaseColumns._ID;
+
 import java.io.IOException;
 import java.net.InetAddress;
 import java.util.EventListener;
 import javax.jmdns.ServiceListener;
 
 import org.mythtv.R;
-import org.mythtv.client.db.DatabaseHelper;
-import org.mythtv.client.db.MythtvDatabaseManager;
 import org.mythtv.client.ui.LocationActivity;
 import org.mythtv.client.ui.preferences.LocationProfile.LocationType;
+import org.mythtv.db.MythtvDatabaseManager;
+import org.mythtv.db.preferences.LocationProfileConstants;
+import org.mythtv.db.preferences.PlaybackProfileConstants;
 
 import android.app.ActionBar;
 import android.app.AlertDialog;
 
 			// put extra information is needed
 			if( null != profile ) {
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_ID, profile.getId() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_TYPE, profile.getType().name() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_NAME, profile.getName() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_URL, profile.getUrl() );
-				intent.putExtra( DatabaseHelper.TABLE_LOCATION_PROFILE_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
+				intent.putExtra( _ID, profile.getId() );
+				intent.putExtra( LocationProfileConstants.FIELD_TYPE, profile.getType().name() );
+				intent.putExtra( LocationProfileConstants.FIELD_NAME, profile.getName() );
+				intent.putExtra( LocationProfileConstants.FIELD_URL, profile.getUrl() );
+				intent.putExtra( LocationProfileConstants.FIELD_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
 			}
 
 			// start activity
 
 			// put extra information is needed
 			if( null != profile ) {
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_ID, profile.getId() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_TYPE, profile.getType().name() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_NAME, profile.getName() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_WIDTH, profile.getWidth() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_HEIGHT, profile.getHeight() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_BITRATE, profile.getVideoBitrate() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, profile.getAudioBitrate() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, profile.getAudioSampleRate() );
-				intent.putExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
+				intent.putExtra( _ID, profile.getId() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_TYPE, profile.getType().name() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_NAME, profile.getName() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_WIDTH, profile.getWidth() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_HEIGHT, profile.getHeight() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_BITRATE, profile.getVideoBitrate() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, profile.getAudioBitrate() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_SAMPLE_RATE, profile.getAudioSampleRate() );
+				intent.putExtra( PlaybackProfileConstants.FIELD_SELECTED, ( profile.isSelected() ? 1 : 0 ) );
 			}
 
 			// start activity

File src/org/mythtv/client/ui/preferences/PlaybackProfileEditor.java

View file
  */
 package org.mythtv.client.ui.preferences;
 
+import static android.provider.BaseColumns._ID;
+
 import org.mythtv.R;
-import org.mythtv.client.db.DatabaseHelper;
-import org.mythtv.client.db.MythtvDatabaseManager;
 import org.mythtv.client.ui.AbstractMythtvFragmentActivity;
 import org.mythtv.client.ui.preferences.LocationProfile.LocationType;
+import org.mythtv.db.MythtvDatabaseManager;
+import org.mythtv.db.preferences.PlaybackProfileConstants;
 
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 		setupSaveButtonEvent( R.id.btnPreferencePlaybackProfileSave );
 		setupCancelButtonEvent( R.id.btnPreferencePlaybackProfileCancel );
 
-		int id = getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_ID, -1 );
+		int id = getIntent().getIntExtra( _ID, -1 );
 		//if( id != -1 ) {
 			profile = new PlaybackProfile();
 			profile.setId( id );
-			profile.setType( LocationType.valueOf( getIntent().getStringExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_TYPE ) ) );
-			profile.setName( getIntent().getStringExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_NAME ) );
-			profile.setWidth( getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_WIDTH, -1 ) );
-			profile.setHeight( getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_HEIGHT, -1 ) );
-			profile.setVideoBitrate( getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_BITRATE, -1 ) );
-			profile.setAudioBitrate( getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_AUDIO_BITRATE, -1 ) );
-			profile.setAudioSampleRate( getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_SAMPLE_RATE, -1 ) );
-			profile.setSelected( 0 != getIntent().getIntExtra( DatabaseHelper.TABLE_PLAYBACK_PROFILE_SELECTED, 0 ) );
+			profile.setType( LocationType.valueOf( getIntent().getStringExtra( PlaybackProfileConstants.FIELD_TYPE ) ) );
+			profile.setName( getIntent().getStringExtra( PlaybackProfileConstants.FIELD_NAME ) );
+			profile.setWidth( getIntent().getIntExtra( PlaybackProfileConstants.FIELD_WIDTH, -1 ) );
+			profile.setHeight( getIntent().getIntExtra( PlaybackProfileConstants.FIELD_HEIGHT, -1 ) );
+			profile.setVideoBitrate( getIntent().getIntExtra( PlaybackProfileConstants.FIELD_BITRATE, -1 ) );
+			profile.setAudioBitrate( getIntent().getIntExtra( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, -1 ) );
+			profile.setAudioSampleRate( getIntent().getIntExtra( PlaybackProfileConstants.FIELD_SAMPLE_RATE, -1 ) );
+			profile.setSelected( 0 != getIntent().getIntExtra( PlaybackProfileConstants.FIELD_SELECTED, 0 ) );
 
 			setUiFromPlaybackProfile();
 		//}

File src/org/mythtv/db/DatabaseHelper.java

View file
+/**
+ *  This file is part of MythTV for Android
+ * 
+ *  MythTV for Android is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  MythTV for Android is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with MythTV for Android.  If not, see <http://www.gnu.org/licenses/>.
+ *   
+ * @author Daniel Frey <dmfrey at gmail dot com>
+ * @author John Baab <rhpot1991@ubuntu.com>
+ * 
+ * This software can be found at <https://github.com/dmfrey/mythtv-for-android/>
+ *
+ */
+
+package org.mythtv.db;
+
+import static android.provider.BaseColumns._ID;
+
+import org.mythtv.db.dvr.ProgramConstants;
+import org.mythtv.db.preferences.LocationProfileConstants;
+import org.mythtv.db.preferences.PlaybackProfileConstants;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
+
+/**
+ * @author Daniel Frey
+ * @author John Baab
+ *
+ */
+public class DatabaseHelper extends SQLiteOpenHelper {
+
+	private static final String TAG = DatabaseHelper.class.getSimpleName();
+	
+	private static final String DATABASE_NAME = "mythtvdb";
+	private static final int DATABASE_VERSION = 6;
+
+	public DatabaseHelper( Context context ) {
+		super( context, DATABASE_NAME, null, DATABASE_VERSION );
+	}
+	
+	/* (non-Javadoc)
+	 * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
+	 */
+	@Override
+	public void onCreate( SQLiteDatabase db ) {
+		Log.v( TAG, "onCreate : enter" );
+		
+		dropLocationProfiles( db );
+		createLocationProfiles( db );
+		
+		dropPlaybackProfiles( db );
+		createPlaybackProfiles( db );
+		
+		dropProgram( db );
+		createProgram( db );
+		
+		Log.v( TAG, "onCreate : exit" );
+	}
+
+	/* (non-Javadoc)
+	 * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)
+	 */
+	@Override
+	public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ) {
+		Log.v( TAG, "onUpgrade : enter" );
+
+		switch( newVersion ) {
+			case 5:
+				Log.v( TAG, "onUpgrade : upgrading to db version 5" );
+				
+				dropPlaybackProfiles( db );
+				createPlaybackProfiles( db );
+
+				break;
+			case 6:
+				Log.v( TAG, "onUpgrade : upgrading to db version 6" );
+				
+				dropProgram( db );
+				createProgram( db );
+				
+				break;
+		}
+	    
+		Log.v( TAG, "onUpgrade : exit" );
+	}
+
+	// internal helpers
+	
+	private void createLocationProfiles( SQLiteDatabase db ) {
+		Log.v( TAG, "createLocationProfiles : enter" );
+		
+		StringBuilder sqlBuilder = new StringBuilder();
+		sqlBuilder.append( "CREATE TABLE " + LocationProfileConstants.TABLE_NAME + " (" );
+		sqlBuilder.append( _ID ).append( " " ).append( LocationProfileConstants.FIELD_ID_DATA_TYPE ).append( " " ).append( LocationProfileConstants.FIELD_ID_PRIMARY_KEY ).append( ", " );
+		sqlBuilder.append( LocationProfileConstants.FIELD_TYPE ).append( " " ).append( LocationProfileConstants.FIELD_TYPE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( LocationProfileConstants.FIELD_NAME ).append( " " ).append( LocationProfileConstants.FIELD_NAME_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( LocationProfileConstants.FIELD_URL ).append( " " ).append( LocationProfileConstants.FIELD_URL_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( LocationProfileConstants.FIELD_SELECTED ).append( " " ).append( LocationProfileConstants.FIELD_SELECTED_DATA_TYPE ).append( " default" ).append( LocationProfileConstants.FIELD_SELECTED_DEFAULT );
+		sqlBuilder.append( ");" );
+		String sql = sqlBuilder.toString();
+		if( Log.isLoggable( TAG, Log.VERBOSE ) ) {
+			Log.v( TAG, "createLocationProfiles : sql=" + sql );
+		}
+		db.execSQL( sql );
+
+		Log.v( TAG, "createLocationProfiles : exit" );
+	}
+	
+	private void dropLocationProfiles( SQLiteDatabase db ) {
+		Log.v( TAG, "dropLocationProfiles : enter" );
+		
+		db.execSQL( "DROP TABLE IF EXISTS " + LocationProfileConstants.TABLE_NAME );
+		
+		Log.v( TAG, "dropLocationProfiles : exit" );
+	}
+	
+	private void createPlaybackProfiles( SQLiteDatabase db ) {
+		Log.v( TAG, "createPlaybackProfiles : enter" );
+		
+		StringBuilder sqlBuilder = new StringBuilder();
+		sqlBuilder.append( "CREATE TABLE " + PlaybackProfileConstants.TABLE_NAME + " (" );
+		sqlBuilder.append( _ID ).append( " " ).append( PlaybackProfileConstants.FIELD_ID_DATA_TYPE ).append( " " ).append( PlaybackProfileConstants.FIELD_ID_PRIMARY_KEY ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_TYPE ).append( " " ).append( PlaybackProfileConstants.FIELD_TYPE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_NAME ).append( " " ).append( PlaybackProfileConstants.FIELD_NAME_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_WIDTH ).append( " " ).append( PlaybackProfileConstants.FIELD_WIDTH_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_HEIGHT ).append( " " ).append( PlaybackProfileConstants.FIELD_HEIGHT_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_BITRATE ).append( " " ).append( PlaybackProfileConstants.FIELD_BITRATE_DATA_TYPE ).append( " default " ).append( PlaybackProfileConstants.FIELD_BITRATE_DEFAULT ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_AUDIO_BITRATE ).append( " " ).append( PlaybackProfileConstants.FIELD_AUDIO_BITRATE_DATA_TYPE ).append( " default " ).append( PlaybackProfileConstants.FIELD_AUDIO_BITRATE_DEFAULT ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_SAMPLE_RATE ).append( " " ).append( PlaybackProfileConstants.FIELD_SAMPLE_RATE_DATA_TYPE ).append( " default " ).append( PlaybackProfileConstants.FIELD_SAMPLE_RATE_DEFAULT ).append( ", " );
+		sqlBuilder.append( PlaybackProfileConstants.FIELD_SELECTED ).append( " " ).append( PlaybackProfileConstants.FIELD_SELECTED_DATA_TYPE ).append( " default " ).append( PlaybackProfileConstants.FIELD_SELECTED_DEFAULT );
+		sqlBuilder.append( ");" );
+		String sql = sqlBuilder.toString();
+		if( Log.isLoggable( TAG, Log.VERBOSE ) ) {
+			Log.v( TAG, "createPlaybackProfiles : sql=" + sql );
+		}
+		db.execSQL( sql );
+
+		ContentValues values = new ContentValues();
+
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "HOME" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "720p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 1280 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 720 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 2000000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 192000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "AWAY" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "720p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 1280 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 720 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 2000000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 192000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+		
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "HOME" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "630p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 1120 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 630 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 1500000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 192000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "AWAY" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "630p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 1120 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 630 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 1500000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 192000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+		
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "HOME" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "540p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 960 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 540 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 1000000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 128000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 1 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "AWAY" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "540p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 960 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 540 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 1000000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 128000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "HOME" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "480p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 854 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 480 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 800000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 128000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "AWAY" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "480p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 854 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 480 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 800000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 128000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "HOME" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "360p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 640 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 360 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 500000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 96000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "AWAY" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "360p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 640 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 360 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 500000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 96000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 1 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+		
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "HOME" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "270p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 480 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 270 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 300000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 96000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+
+		values = new ContentValues();
+		values.put( PlaybackProfileConstants.FIELD_TYPE, "AWAY" );
+		values.put( PlaybackProfileConstants.FIELD_NAME, "270p" );
+		values.put( PlaybackProfileConstants.FIELD_WIDTH, 480 );
+		values.put( PlaybackProfileConstants.FIELD_HEIGHT, 270 );
+		values.put( PlaybackProfileConstants.FIELD_BITRATE, 300000 );
+		values.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, 96000 );
+		values.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, 48000 );
+		values.put( PlaybackProfileConstants.FIELD_SELECTED, 0 );
+		db.insert( PlaybackProfileConstants.TABLE_NAME, null, values );
+		
+		Log.v( TAG, "createPlaybackProfiles : exit" );
+	}
+
+	private void dropPlaybackProfiles( SQLiteDatabase db ) {
+		Log.v( TAG, "dropPlaybackProfiles : enter" );
+		
+		db.execSQL( "DROP TABLE IF EXISTS " + PlaybackProfileConstants.TABLE_NAME );
+		
+		Log.v( TAG, "dropPlaybackProfiles : exit" );
+	}
+	
+	private void createProgram( SQLiteDatabase db ) {
+		Log.v( TAG, "createProgram : enter" );
+		
+		StringBuilder sqlBuilder = new StringBuilder();
+		sqlBuilder.append( "CREATE TABLE " + ProgramConstants.TABLE_NAME + " (" );
+		sqlBuilder.append( _ID ).append( " " ).append( ProgramConstants.FIELD_ID_DATA_TYPE ).append( " " ).append( ProgramConstants.FIELD_ID_PRIMARY_KEY ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_START_TIME ).append( " " ).append( ProgramConstants.FIELD_START_TIME_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_END_TIME ).append( " " ).append( ProgramConstants.FIELD_END_TIME_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_TITLE ).append( " " ).append( ProgramConstants.FIELD_TITLE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_SUB_TITLE ).append( " " ).append( ProgramConstants.FIELD_SUB_TITLE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_CATEGORY ).append( " " ).append( ProgramConstants.FIELD_CATEGORY_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_CATEGORY_TYPE ).append( " " ).append( ProgramConstants.FIELD_CATEGORY_TYPE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_REPEAT ).append( " " ).append( ProgramConstants.FIELD_REPEAT_DATA_TYPE ).append( " default " ).append( ProgramConstants.FIELD_REPEAT_DEFAULT ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_VIDEO_PROPS ).append( " " ).append( ProgramConstants.FIELD_VIDEO_PROPS_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_AUDIO_PROPS ).append( " " ).append( ProgramConstants.FIELD_AUDIO_PROPS_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_SUB_PROPS ).append( " " ).append( ProgramConstants.FIELD_SUB_PROPS_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_SERIES_ID ).append( " " ).append( ProgramConstants.FIELD_SERIES_ID_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_PROGRAM_ID ).append( " " ).append( ProgramConstants.FIELD_PROGRAM_ID_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_STARS ).append( " " ).append( ProgramConstants.FIELD_STARS_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_FILE_SIZE ).append( " " ).append( ProgramConstants.FIELD_FILE_SIZE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_LAST_MODIFIED ).append( " " ).append( ProgramConstants.FIELD_LAST_MODIFIED_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_PROGRAM_FLAGS ).append( " " ).append( ProgramConstants.FIELD_PROGRAM_FLAGS_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_HOSTNAME ).append( " " ).append( ProgramConstants.FIELD_HOSTNAME_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_FILENAME ).append( " " ).append( ProgramConstants.FIELD_FILENAME_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_AIR_DATE ).append( " " ).append( ProgramConstants.FIELD_AIR_DATE_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_DESCRIPTION ).append( " " ).append( ProgramConstants.FIELD_DESCRIPTION_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_INETREF ).append( " " ).append( ProgramConstants.FIELD_INETREF_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_SEASON ).append( " " ).append( ProgramConstants.FIELD_SEASON_DATA_TYPE ).append( ", " );
+		sqlBuilder.append( ProgramConstants.FIELD_EPISODE ).append( " " ).append( ProgramConstants.FIELD_EPISODE_DATA_TYPE );
+		sqlBuilder.append( ");" );
+		String sql = sqlBuilder.toString();
+		if( Log.isLoggable( TAG, Log.VERBOSE ) ) {
+			Log.v( TAG, "createProgram : sql=" + sql );
+		}
+		db.execSQL( sql );
+	
+		Log.v( TAG, "createProgram : exit" );
+	}
+	
+	private void dropProgram( SQLiteDatabase db ) {
+		Log.v( TAG, "dropProgram : enter" );
+		
+		db.execSQL( "DROP TABLE IF EXISTS " + ProgramConstants.TABLE_NAME );
+		
+		Log.v( TAG, "dropProgram : exit" );
+	}
+	
+}

File src/org/mythtv/db/MythtvDatabaseManager.java

View file
+/**
+ *  This file is part of MythTV for Android
+ * 
+ *  MythTV for Android is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  MythTV for Android is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with MythTV for Android.  If not, see <http://www.gnu.org/licenses/>.
+ *   
+ * @author Daniel Frey <dmfrey at gmail dot com>
+ * 
+ * This software can be found at <https://github.com/dmfrey/mythtv-for-android/>
+ *
+ */
+
+package org.mythtv.db;
+
+import static android.provider.BaseColumns._ID;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.mythtv.R;
+import org.mythtv.client.ui.preferences.LocationProfile;
+import org.mythtv.client.ui.preferences.LocationProfile.LocationType;
+import org.mythtv.client.ui.preferences.PlaybackProfile;
+import org.mythtv.db.preferences.LocationProfileConstants;
+import org.mythtv.db.preferences.PlaybackProfileConstants;
+
+import android.app.AlertDialog;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.util.Log;
+
+/**
+ * @author Daniel Frey
+ * 
+ */
+public class MythtvDatabaseManager {
+
+	private static final String TAG = MythtvDatabaseManager.class.getSimpleName();
+
+	private final Context context;
+
+	private DatabaseHelper helper;
+	private SQLiteDatabase db;
+
+	/**
+	 * @param context
+	 */
+	public MythtvDatabaseManager( final Context context ) {
+		Log.v( TAG, "initialize : enter" );
+
+		this.context = context;
+		this.helper = new DatabaseHelper( context );
+
+		Log.v( TAG, "initialize : exit" );
+	}
+
+	/**
+	 * 
+	 */
+	private void open() {
+		Log.v( TAG, "open : enter" );
+
+		if( null != db ) {
+			close();
+		}
+
+		db = helper.getWritableDatabase();
+
+		Log.v( TAG, "open : exit" );
+	}
+
+	/**
+	 * 
+	 */
+	private void close() {
+		Log.v( TAG, "close : enter" );
+
+		helper.close();
+		db = null;
+
+		Log.v( TAG, "open : exit" );
+
+	}
+
+	/**
+	 * @return
+	 */
+	public List<LocationProfile> fetchHomeLocationProfiles() {
+		Log.v( TAG, "fetchHomeLocationProfiles : enter" );
+		Log.v( TAG, "fetchHomeLocationProfiles : exit" );
+		return fetchLocationProfilesByType( LocationType.HOME );
+	}
+
+	/**
+	 * @return
+	 */
+	public List<LocationProfile> fetchAwayLocationProfiles() {
+		Log.v( TAG, "fetchAwayLocationProfiles : enter" );
+		Log.v( TAG, "fetchAwayLocationProfiles : exit" );
+		return fetchLocationProfilesByType( LocationType.AWAY );
+	}
+
+	public LocationProfile fetchLocationProfile( long id ) {
+		Log.v( TAG, "fetchLocationProfile : enter" );
+		
+		open();
+		
+		LocationProfile profile = null;
+		
+		try {
+			Cursor cursor = db.query( 
+						LocationProfileConstants.TABLE_NAME, 
+						new String[] { _ID, LocationProfileConstants.FIELD_TYPE, LocationProfileConstants.FIELD_NAME, LocationProfileConstants.FIELD_URL, LocationProfileConstants.FIELD_SELECTED }, 
+						_ID + "=" + id, 
+						null, null, null, null 
+					  );
+			
+			if( cursor.getCount() == 1 && cursor.moveToFirst() ) {
+				Log.v( TAG, "fetchLocationProfile : location profile found" );
+
+				profile = convertCursorToLocationProfile( cursor );
+			}
+			
+			cursor.close();
+			
+		} catch( SQLException e ) {
+			Log.e( TAG, "fetchLocationProfile : error", e );
+			
+			AlertDialog.Builder builder = new AlertDialog.Builder( context );
+			builder.setTitle( "DataBase Error" );
+			builder.setMessage( "An error occurred locating profile" );
+			builder.setNeutralButton( R.string.close, new OnClickListener() {
+
+				public void onClick( DialogInterface dialog, int which ) { }
+			
+			});
+		} finally {
+			close();
+		}
+		
+		Log.v( TAG, "fetchLocationProfile : exit" );
+		return profile;
+	}
+
+	/**
+	 * @param profile
+	 * @return
+	 */
+	public long createHomeLocationProfile( LocationProfile profile ) {
+		Log.v( TAG, "createHomeLocationProfile : enter" );
+
+		profile.setType( LocationType.HOME );
+
+		long id = createLocationProfile( profile );
+		
+		if( fetchHomeLocationProfiles().size() == 1 ) {
+			Log.v( TAG, "createHomeLocationProfile : making default" );
+
+			setSelectedHomeLocationProfile( id );
+		}
+		
+		Log.v( TAG, "createHomeLocationProfile : exit" );
+		return id;
+	}
+
+	/**
+	 * @param profile
+	 * @return
+	 */
+	public long createAwayLocationProfile( LocationProfile profile ) {
+		Log.v( TAG, "createAwayLocationProfile : enter" );
+
+		profile.setType( LocationType.AWAY );
+
+		long id = createLocationProfile( profile );
+
+		if( fetchAwayLocationProfiles().size() == 1 ) {
+			Log.v( TAG, "createAwayLocationProfile : making default" );
+
+			setSelectedAwayLocationProfile( id );
+		}
+				
+		Log.v( TAG, "createAwayLocationProfile : enter" );
+		return id;
+	}
+
+	/**
+	 * @param profile
+	 * @return
+	 */
+	public boolean updateLocationProfile( LocationProfile profile ) {
+		Log.v( TAG, "updateLocationProfile : enter" );
+
+		open();
+
+		ContentValues args = new ContentValues();
+		args.put( LocationProfileConstants.FIELD_TYPE, profile.getType().name() );
+		args.put( LocationProfileConstants.FIELD_NAME, profile.getName() );
+		args.put( LocationProfileConstants.FIELD_URL, profile.getUrl() );
+		args.put( LocationProfileConstants.FIELD_SELECTED, profile.isSelected() ? 1 : 0 );
+
+		int rows = db.update( LocationProfileConstants.TABLE_NAME, args, _ID + "=" + profile.getId(), null );
+	
+		close();
+
+		Log.v( TAG, "updateLocationProfile : exit" );
+		return rows > 0;
+	}
+
+	/**
+	 * @param id
+	 * @return
+	 */
+	public boolean deleteLocationProfile( long id ) {
+		Log.v( TAG, "deleteLocationProfile : enter" );
+		
+		open();
+		
+		boolean result = db.delete( LocationProfileConstants.TABLE_NAME, _ID + "=" + id, null ) > 0;
+		
+		close();
+		
+		Log.v( TAG, "deleteLocationProfile : exit" );
+		return result;
+	}
+
+	/**
+	 * @param id
+	 * @return
+	 */
+	public boolean setSelectedHomeLocationProfile( long id ) {
+		Log.v( TAG, "setSelectedHomeLocationProfile : enter" );
+		Log.v( TAG, "setSelectedHomeLocationProfile : exit" );
+		return setSelectedLocationProfile( id, LocationType.HOME );
+	}
+
+	/**
+	 * @param id
+	 * @return
+	 */
+	public boolean setSelectedAwayLocationProfile( long id ) {
+		Log.v( TAG, "setSelectedAwayLocationProfile : enter" );
+		Log.v( TAG, "setSelectedAwayLocationProfile : exit" );
+		return setSelectedLocationProfile( id, LocationType.AWAY );
+	}
+
+	/**
+	 * @return
+	 */
+	public LocationProfile fetchSelectedHomeLocationProfile() {
+		Log.v( TAG, "fetchSelectedHomeLocationProfile : enter" );
+		Log.v( TAG, "fetchSelectedHomeLocationProfile : exit" );
+		return fetchSelectedLocationProfileByType( LocationType.HOME );
+	}
+
+	/**
+	 * @return
+	 */
+	public LocationProfile fetchSelectedAwayLocationProfile() {
+		Log.v( TAG, "fetchSelectedAwayLocationProfile : enter" );
+		Log.v( TAG, "fetchSelectedAwayLocationProfile : exit" );
+		return fetchSelectedLocationProfileByType( LocationType.AWAY );
+	}
+
+	/**
+	 * @return
+	 */
+	public List<PlaybackProfile> fetchHomePlaybackProfiles() {
+		Log.v( TAG, "fetchHomePlaybackProfiles : enter" );
+		Log.v( TAG, "fetchHomePlaybackProfiles : exit" );
+		return fetchPlaybackProfilesByType( LocationType.HOME );
+	}
+
+	/**
+	 * @return
+	 */
+	public List<PlaybackProfile> fetchAwayPlaybackProfiles() {
+		Log.v( TAG, "fetchAwayPlaybackProfiles : enter" );
+		Log.v( TAG, "fetchAwayPlaybackProfiles : exit" );
+		return fetchPlaybackProfilesByType( LocationType.AWAY );
+	}
+
+	public PlaybackProfile fetchPlaybackProfile( long id ) {
+		Log.v( TAG, "fetchPlaybackProfile : enter" );
+		
+		open();
+		
+		PlaybackProfile profile = null;
+		
+		try {
+			Cursor cursor = db.query( 
+						PlaybackProfileConstants.TABLE_NAME, 
+						new String[] { _ID, PlaybackProfileConstants.FIELD_TYPE, PlaybackProfileConstants.FIELD_NAME, PlaybackProfileConstants.FIELD_WIDTH, PlaybackProfileConstants.FIELD_HEIGHT, PlaybackProfileConstants.FIELD_BITRATE, PlaybackProfileConstants.FIELD_AUDIO_BITRATE, PlaybackProfileConstants.FIELD_SAMPLE_RATE, PlaybackProfileConstants.FIELD_SELECTED }, 
+						_ID + "=" + id, 
+						null, null, null, null 
+					  );
+			
+			if( cursor.getCount() == 1 && cursor.moveToFirst() ) {
+				Log.v( TAG, "fetchPlaybackProfile : playback profile found" );
+
+				profile = convertCursorToPlaybackProfile( cursor );
+			}
+			
+			cursor.close();
+			
+		} catch( SQLException e ) {
+			Log.e( TAG, "fetchPlaybackProfile : error", e );
+			
+			AlertDialog.Builder builder = new AlertDialog.Builder( context );
+			builder.setTitle( "DataBase Error" );
+			builder.setMessage( "An error occurred locating profile" );
+			builder.setNeutralButton( R.string.close, new OnClickListener() {
+
+				public void onClick( DialogInterface dialog, int which ) { }
+			
+			});
+		}
+		
+		close();
+		
+		Log.v( TAG, "fetchPlaybackProfile : exit" );
+		return profile;
+	}
+
+	/**
+	 * @param profile
+	 * @return
+	 */
+	public boolean updatePlaybackProfile( PlaybackProfile profile ) {
+		Log.v( TAG, "updatePlaybackProfile : enter" );
+
+		open();
+
+		ContentValues args = new ContentValues();
+		args.put( PlaybackProfileConstants.FIELD_TYPE, profile.getType().name() );
+		args.put( PlaybackProfileConstants.FIELD_NAME, profile.getName() );
+		args.put( PlaybackProfileConstants.FIELD_WIDTH, profile.getWidth() );
+		args.put( PlaybackProfileConstants.FIELD_HEIGHT, profile.getHeight() );
+		args.put( PlaybackProfileConstants.FIELD_BITRATE, profile.getVideoBitrate() );
+		args.put( PlaybackProfileConstants.FIELD_AUDIO_BITRATE, profile.getAudioBitrate() );
+		args.put( PlaybackProfileConstants.FIELD_SAMPLE_RATE, profile.getAudioSampleRate() );
+		args.put( PlaybackProfileConstants.FIELD_SELECTED, profile.isSelected() ? 1 : 0 );
+
+		int rows = db.update( PlaybackProfileConstants.TABLE_NAME, args, _ID + "=" + profile.getId(), null );
+	
+		close();
+
+		Log.v( TAG, "updatePlaybackProfile : exit" );
+		return rows > 0;
+	}
+
+	/**
+	 * @param id