Skip to content

Commit

Permalink
added channel download service
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Frey committed Oct 25, 2012
1 parent 603f9ee commit 5b075c1
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 173 deletions.
8 changes: 6 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,19 @@
android:name=".client.ui.setup.capture.CaptureCardsActivity" />

<!-- MythTV Android Services -->
<service android:name=".service.dvr.DvrService" />

<service android:name=".service.UpgradeCleanupService" android:process=":upgrade" android:exported="false">
<intent-filter>
<action android:name="org.mythtv.background.upgradeCleanup.PROGRAM_GUIDE_CLEANUP" />
<action android:name="org.mythtv.background.upgradeCleanup.PROGRAMS_CLEANUP" />
</intent-filter>
</service>

<service android:name=".service.channel.ChannelDownloadService" android:process=":channel" android:exported="false">
<intent-filter>
<action android:name="org.mythtv.background.channelDownload.ACTION_DOWNLOAD" />
</intent-filter>
</service>

<service android:name=".service.dvr.RecordedDownloadService" android:process=":recorded" android:exported="false">
<intent-filter>
<action android:name="org.mythtv.background.recordedDownload.ACTION_DOWNLOAD" />
Expand Down
3 changes: 2 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,6 @@
<string name="notification_sync_program_guide">Syncing Program Guide</string>
<string name="notification_sync_recordings">Syncing Recorded Programs</string>
<string name="notification_sync_upcoming">Syncing Upcoming Programs</string>

<string name="notification_sync_channels">Syncing Channels</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;

import org.mythtv.service.channel.ChannelDownloadService;
import org.mythtv.service.guide.ProgramGuideCleanupService;
import org.mythtv.service.guide.ProgramGuideDownloadService;
import org.mythtv.service.util.FileHelper;
Expand All @@ -45,6 +46,7 @@ public abstract class AbstractLocationAwareFragmentActivity extends AbstractMyth
private FileHelper mFileHelper;
private RunningServiceHelper mRunningServiceHelper;

private ChannelDownloadReceiver channelDownloadReceiver = new ChannelDownloadReceiver();
private ProgramGuideDownloadReceiver programGuideDownloadReceiver = new ProgramGuideDownloadReceiver();
private ProgramGuideCleanupReceiver programGuideCleanupReceiver = new ProgramGuideCleanupReceiver();

Expand Down Expand Up @@ -80,7 +82,11 @@ protected void onStart() {
Log.v( TAG, "onStart : enter" );
super.onStart();

IntentFilter programGuideCleanupFilter = new IntentFilter();
IntentFilter channelDownloadFilter = new IntentFilter();
channelDownloadFilter.addAction( ChannelDownloadService.ACTION_COMPLETE );
registerReceiver( channelDownloadReceiver, channelDownloadFilter );

IntentFilter programGuideCleanupFilter = new IntentFilter();
programGuideCleanupFilter.addAction( ProgramGuideCleanupService.ACTION_COMPLETE );
registerReceiver( programGuideCleanupReceiver, programGuideCleanupFilter );

Expand All @@ -100,6 +106,7 @@ protected void onResume() {
Log.v( TAG, "onResume : enter" );
super.onResume();

startService( new Intent( ChannelDownloadService.ACTION_DOWNLOAD ) );
startService( new Intent( ProgramGuideCleanupService.ACTION_CLEANUP ) );

Log.v( TAG, "onResume : exit" );
Expand All @@ -114,6 +121,15 @@ protected void onStop() {
super.onStop();

// Unregister for broadcast
if( null != channelDownloadReceiver ) {
try {
unregisterReceiver( channelDownloadReceiver );
channelDownloadReceiver = null;
} catch( IllegalArgumentException e ) {
Log.e( TAG, "onStop : error", e );
}
}

if( null != programGuideCleanupReceiver ) {
try {
unregisterReceiver( programGuideCleanupReceiver );
Expand Down Expand Up @@ -158,6 +174,25 @@ public boolean onOptionsItemSelected( MenuItem item ) {

// internal helpers

private class ChannelDownloadReceiver extends BroadcastReceiver {

@Override
public void onReceive( Context context, Intent intent ) {

if ( intent.getAction().equals( ChannelDownloadService.ACTION_PROGRESS ) ) {
Log.i( TAG, "ProgramGuideDownloadReceiver.onReceive : progress=" + intent.getStringExtra( ProgramGuideDownloadService.EXTRA_PROGRESS ) );
}

if ( intent.getAction().equals( ChannelDownloadService.ACTION_COMPLETE ) ) {
Log.i( TAG, "ProgramGuideDownloadReceiver.onReceive : " + intent.getStringExtra( ProgramGuideDownloadService.EXTRA_COMPLETE ) );

// Toast.makeText( AbstractLocationAwareFragmentActivity.this, "Channels Loaded!", Toast.LENGTH_SHORT ).show();
}

}

}

private class ProgramGuideDownloadReceiver extends BroadcastReceiver {

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/org/mythtv/client/ui/dvr/RecordingRuleEditFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ private void setupForm( RecRule rule ) {
// - should we move this to a utility?
// - slow
String channel = "[Any]";
//Cursor cursor = this.getActivity().getContentResolver().query( ChannelConstants.CONTENT_URI, new String[] { ChannelConstants.FIELD_CHAN_NUM }, ChannelConstants.FIELD_CHAN_ID + " = ?", new String[] { "" + rule.getChanId() }, null );
//if( cursor.moveToFirst() ) {
// channel = cursor.getString( cursor.getColumnIndexOrThrow( ChannelConstants.FIELD_CHAN_NUM ) );
//}
//cursor.close();
Cursor cursor = this.getActivity().getContentResolver().query( ChannelConstants.CONTENT_URI, new String[] { ChannelConstants.FIELD_CHAN_NUM }, ChannelConstants.FIELD_CHAN_ID + " = ?", new String[] { String.valueOf( rule.getChanId() ) }, null );
if( cursor.moveToFirst() ) {
channel = cursor.getString( cursor.getColumnIndexOrThrow( ChannelConstants.FIELD_CHAN_NUM ) );
}
cursor.close();

tView = (TextView) getActivity().findViewById( R.id.recording_rule_channel );
tView.setText( channel );
Expand Down
10 changes: 5 additions & 5 deletions src/org/mythtv/client/ui/dvr/RecordingRuleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ private void setup( RecRule rule ) {
// - should we move this to a utility?
// - slow
String channel = "[Any]";
//Cursor cursor = this.getActivity().getContentResolver().query( ChannelConstants.CONTENT_URI, new String[] { ChannelConstants.FIELD_CHAN_NUM }, ChannelConstants.FIELD_CHAN_ID + " = ?", new String[] { "" + rule.getChanId() }, null );
//if( cursor.moveToFirst() ) {
// channel = cursor.getString( cursor.getColumnIndexOrThrow( ChannelConstants.FIELD_CHAN_NUM ) );
//}
//cursor.close();
Cursor cursor = this.getActivity().getContentResolver().query( ChannelConstants.CONTENT_URI, new String[] { ChannelConstants.FIELD_CHAN_NUM }, ChannelConstants.FIELD_CHAN_ID + " = ?", new String[] { String.valueOf( rule.getChanId() ) }, null );
if( cursor.moveToFirst() ) {
channel = cursor.getString( cursor.getColumnIndexOrThrow( ChannelConstants.FIELD_CHAN_NUM ) );
}
cursor.close();

tView = (TextView) getActivity().findViewById( R.id.recording_rule_channel );
tView.setText( channel );
Expand Down
10 changes: 5 additions & 5 deletions src/org/mythtv/client/ui/dvr/RecordingRulesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ public View getView( int position, View convertView, ViewGroup parent ) {
RecRule rule = getItem( position );

String channel = "[Any]";
//Cursor cursor = mContext.getContentResolver().query( ChannelConstants.CONTENT_URI, new String[] { ChannelConstants.FIELD_CHAN_NUM }, ChannelConstants.FIELD_CHAN_ID + " = ?", new String[] { "" + rule.getChanId() }, null );
//if( cursor.moveToFirst() ) {
// channel = cursor.getString( cursor.getColumnIndexOrThrow( ChannelConstants.FIELD_CHAN_NUM ) );
//}
//cursor.close();
Cursor cursor = mContext.getContentResolver().query( ChannelConstants.CONTENT_URI, new String[] { ChannelConstants.FIELD_CHAN_NUM }, ChannelConstants.FIELD_CHAN_ID + " = ?", new String[] { String.valueOf( rule.getChanId() ) }, null );
if( cursor.moveToFirst() ) {
channel = cursor.getString( cursor.getColumnIndexOrThrow( ChannelConstants.FIELD_CHAN_NUM ) );
}
cursor.close();

mHolder.category.setBackgroundColor( mProgramHelper.getCategoryColor( rule.getCategory() ) );
mHolder.title.setText( rule.getTitle() );
Expand Down
94 changes: 50 additions & 44 deletions src/org/mythtv/db/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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 = 46;
private static final int DATABASE_VERSION = 49;

public DatabaseHelper( Context context ) {
super( context, DATABASE_NAME, null, DATABASE_VERSION );
Expand All @@ -66,6 +66,9 @@ public void onCreate( SQLiteDatabase db ) {
dropEtag( db );
createEtag( db );

dropChannel( db );
createChannel( db );

dropProgram( db, ProgramConstants.TABLE_NAME_RECORDED );
createProgram( db, ProgramConstants.TABLE_NAME_RECORDED );

Expand All @@ -85,11 +88,14 @@ public void onCreate( SQLiteDatabase db ) {
public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ) {
Log.v( TAG, "onUpgrade : enter" );

if( oldVersion < 46 ) {
Log.v( TAG, "onUpgrade : upgrading to db version 46" );
if( oldVersion < 49 ) {
Log.v( TAG, "onUpgrade : upgrading to db version 49" );

dropEtag( db );
createEtag( db );

dropChannel( db );
createChannel( db );

}

Expand Down Expand Up @@ -461,47 +467,47 @@ private void dropRecording( SQLiteDatabase db ) {
Log.v( TAG, "dropRecording : exit" );
}

// private void createChannel( SQLiteDatabase db ) {
// Log.v( TAG, "createChannel : enter" );
//
// StringBuilder sqlBuilder = new StringBuilder();
// sqlBuilder.append( "CREATE TABLE " + ChannelConstants.TABLE_NAME + " (" );
// sqlBuilder.append( _ID ).append( " " ).append( ChannelConstants.FIELD_ID_DATA_TYPE ).append( " " ).append( ChannelConstants.FIELD_ID_PRIMARY_KEY ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_CHAN_ID ).append( " " ).append( ChannelConstants.FIELD_CHAN_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_CHAN_NUM ).append( " " ).append( ChannelConstants.FIELD_CHAN_NUM_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_CALLSIGN ).append( " " ).append( ChannelConstants.FIELD_CALLSIGN_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_ICON_URL ).append( " " ).append( ChannelConstants.FIELD_ICON_URL_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_CHANNEL_NAME ).append( " " ).append( ChannelConstants.FIELD_CHANNEL_NAME_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_MPLEX_ID ).append( " " ).append( ChannelConstants.FIELD_MPLEX_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_TRANSPORT_ID ).append( " " ).append( ChannelConstants.FIELD_TRANSPORT_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_SERVICE_ID ).append( " " ).append( ChannelConstants.FIELD_SERVICE_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_NETWORK_ID ).append( " " ).append( ChannelConstants.FIELD_NETWORK_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_ATSC_MAJOR_CHAN ).append( " " ).append( ChannelConstants.FIELD_ATSC_MAJOR_CHAN_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_ATSC_MINOR_CHAN ).append( " " ).append( ChannelConstants.FIELD_ATSC_MINOR_CHAN_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_FORMAT ).append( " " ).append( ChannelConstants.FIELD_FORMAT_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_MODULATION ).append( " " ).append( ChannelConstants.FIELD_MODULATION_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_FREQUENCY ).append( " " ).append( ChannelConstants.FIELD_FREQUENCY_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_FREQUENCY_ID ).append( " " ).append( ChannelConstants.FIELD_FREQUENCY_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_FREQUENCY_TABLE ).append( " " ).append( ChannelConstants.FIELD_FREQUENCY_TABLE_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_FINE_TUNE ).append( " " ).append( ChannelConstants.FIELD_FINE_TUNE_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_SIS_STANDARD ).append( " " ).append( ChannelConstants.FIELD_SIS_STANDARD_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_CHAN_FILTERS ).append( " " ).append( ChannelConstants.FIELD_CHAN_FILTERS_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_SOURCE_ID ).append( " " ).append( ChannelConstants.FIELD_SOURCE_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_INPUT_ID ).append( " " ).append( ChannelConstants.FIELD_INPUT_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_COMM_FREE ).append( " " ).append( ChannelConstants.FIELD_COMM_FREE_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_USE_EIT ).append( " " ).append( ChannelConstants.FIELD_USE_EIT_DATA_TYPE ).append( " default " ).append( ChannelConstants.FIELD_USE_EIT_DEFAULT ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_VISIBLE ).append( " " ).append( ChannelConstants.FIELD_VISIBLE_DATA_TYPE ).append( " default " ).append( ChannelConstants.FIELD_VISIBLE_DEFAULT ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_XMLTV_ID ).append( " " ).append( ChannelConstants.FIELD_XMLTV_ID_DATA_TYPE ).append( ", " );
// sqlBuilder.append( ChannelConstants.FIELD_DEFAULT_AUTH ).append( " " ).append( ChannelConstants.FIELD_DEFAULT_AUTH_DATA_TYPE );
// sqlBuilder.append( ");" );
// String sql = sqlBuilder.toString();
// if( Log.isLoggable( TAG, Log.VERBOSE ) ) {
// Log.v( TAG, "createChannel : sql=" + sql );
// }
// db.execSQL( sql );
//
// Log.v( TAG, "createChannel : exit" );
// }
private void createChannel( SQLiteDatabase db ) {
Log.v( TAG, "createChannel : enter" );

StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append( "CREATE TABLE " + ChannelConstants.TABLE_NAME + " (" );
sqlBuilder.append( _ID ).append( " " ).append( ChannelConstants.FIELD_ID_DATA_TYPE ).append( " " ).append( ChannelConstants.FIELD_ID_PRIMARY_KEY ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_CHAN_ID ).append( " " ).append( ChannelConstants.FIELD_CHAN_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_CHAN_NUM ).append( " " ).append( ChannelConstants.FIELD_CHAN_NUM_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_CALLSIGN ).append( " " ).append( ChannelConstants.FIELD_CALLSIGN_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_ICON_URL ).append( " " ).append( ChannelConstants.FIELD_ICON_URL_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_CHANNEL_NAME ).append( " " ).append( ChannelConstants.FIELD_CHANNEL_NAME_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_MPLEX_ID ).append( " " ).append( ChannelConstants.FIELD_MPLEX_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_TRANSPORT_ID ).append( " " ).append( ChannelConstants.FIELD_TRANSPORT_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_SERVICE_ID ).append( " " ).append( ChannelConstants.FIELD_SERVICE_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_NETWORK_ID ).append( " " ).append( ChannelConstants.FIELD_NETWORK_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_ATSC_MAJOR_CHAN ).append( " " ).append( ChannelConstants.FIELD_ATSC_MAJOR_CHAN_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_ATSC_MINOR_CHAN ).append( " " ).append( ChannelConstants.FIELD_ATSC_MINOR_CHAN_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_FORMAT ).append( " " ).append( ChannelConstants.FIELD_FORMAT_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_MODULATION ).append( " " ).append( ChannelConstants.FIELD_MODULATION_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_FREQUENCY ).append( " " ).append( ChannelConstants.FIELD_FREQUENCY_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_FREQUENCY_ID ).append( " " ).append( ChannelConstants.FIELD_FREQUENCY_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_FREQUENCY_TABLE ).append( " " ).append( ChannelConstants.FIELD_FREQUENCY_TABLE_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_FINE_TUNE ).append( " " ).append( ChannelConstants.FIELD_FINE_TUNE_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_SIS_STANDARD ).append( " " ).append( ChannelConstants.FIELD_SIS_STANDARD_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_CHAN_FILTERS ).append( " " ).append( ChannelConstants.FIELD_CHAN_FILTERS_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_SOURCE_ID ).append( " " ).append( ChannelConstants.FIELD_SOURCE_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_INPUT_ID ).append( " " ).append( ChannelConstants.FIELD_INPUT_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_COMM_FREE ).append( " " ).append( ChannelConstants.FIELD_COMM_FREE_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_USE_EIT ).append( " " ).append( ChannelConstants.FIELD_USE_EIT_DATA_TYPE ).append( " default " ).append( ChannelConstants.FIELD_USE_EIT_DEFAULT ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_VISIBLE ).append( " " ).append( ChannelConstants.FIELD_VISIBLE_DATA_TYPE ).append( " default " ).append( ChannelConstants.FIELD_VISIBLE_DEFAULT ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_XMLTV_ID ).append( " " ).append( ChannelConstants.FIELD_XMLTV_ID_DATA_TYPE ).append( ", " );
sqlBuilder.append( ChannelConstants.FIELD_DEFAULT_AUTH ).append( " " ).append( ChannelConstants.FIELD_DEFAULT_AUTH_DATA_TYPE );
sqlBuilder.append( ");" );
String sql = sqlBuilder.toString();
if( Log.isLoggable( TAG, Log.VERBOSE ) ) {
Log.v( TAG, "createChannel : sql=" + sql );
}
db.execSQL( sql );

Log.v( TAG, "createChannel : exit" );
}

private void dropChannel( SQLiteDatabase db ) {
Log.v( TAG, "dropChannel : enter" );
Expand Down
Loading

0 comments on commit 5b075c1

Please sign in to comment.