Skip to content

Commit

Permalink
refactored recorded and upcoming programs to use new dao's
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Frey committed Nov 18, 2012
1 parent fc39ec8 commit ac52b13
Show file tree
Hide file tree
Showing 28 changed files with 1,531 additions and 683 deletions.
7 changes: 0 additions & 7 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,6 @@
</intent-filter>
</service>

<service android:name=".service.dvr.ProgramGroupRecordedDownloadService" android:process=":programGroupRecorded" android:exported="false">
<intent-filter>
<action
android:name="org.mythtv.background.programGroupRecordedDownload.ACTION_DOWNLOAD" />
</intent-filter>
</service>

<service android:name=".service.dvr.BannerDownloadService" android:process=":banner" android:exported="false">
<intent-filter>
<action
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<joda-time-version>2.1</joda-time-version>
<org.joda.joda-convert-version>1.2</org.joda.joda-convert-version>
<commons-io-version>1.3.2</commons-io-version>
<mythtv.service.api-version>0.0.21-SNAPSHOT</mythtv.service.api-version>
<mythtv.service.api-version>0.0.21</mythtv.service.api-version>
</properties>

<url>https://github.com/MythTV-Clients/mythtv-for-android</url>
Expand Down
3 changes: 1 addition & 2 deletions res/layout-large/activity_setup_capture_cards.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<FrameLayout
android:id="@+id/setup_frame_capture_card"
android:layout_width="0px"
android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />
android:layout_height="match_parent" />

</FrameLayout>
60 changes: 34 additions & 26 deletions src/org/mythtv/client/ui/dvr/EpisodeActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.mythtv.client.ui.dvr;

import org.joda.time.DateTime;
import org.mythtv.R;
import org.mythtv.db.dvr.ProgramConstants;
import org.mythtv.db.dvr.RecordedDaoHelper;
import org.mythtv.service.util.FileHelper;
import org.mythtv.service.util.image.ImageCache;
import org.mythtv.service.util.image.ImageFetcher;
import org.mythtv.services.api.dvr.Program;
import org.mythtv.services.utils.ArticleCleaner;

import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
Expand All @@ -21,12 +23,13 @@
*/
public class EpisodeActivity extends AbstractDvrActivity implements EpisodeFragment.OnEpisodeActionListener {

public static final String EPISODE_KEY = "EPISODE_ID";
public static final String CHANNEL_ID = "CHANNEL_ID";
public static final String START_TIME = "START_TIME";

private static final String TAG = EpisodeActivity.class.getSimpleName();

private RecordedDaoHelper mRecordedDaoHelper;
private ImageFetcher mImageFetcher;
private FileHelper mFileHelper;

private EpisodeFragment episodeFragment;

Expand All @@ -38,10 +41,10 @@ protected void onCreate( Bundle savedInstanceState ) {
Log.v( TAG, "onCreate : enter" );
super.onCreate( savedInstanceState );

mRecordedDaoHelper = new RecordedDaoHelper( this );

setContentView( R.layout.activity_dvr_episode );

mFileHelper = new FileHelper( this );

// Fetch screen height and width, to use as our max size when loading images as this activity runs full screen
final DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( displayMetrics );
Expand All @@ -52,6 +55,7 @@ protected void onCreate( Bundle savedInstanceState ) {

final int longest = width; //( height < width ? height : width );

FileHelper mFileHelper = new FileHelper( this );
ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams( mFileHelper.getProgramRecordedDataDirectory() );
cacheParams.setMemCacheSizePercent( this, 0.25f ); // Set memory cache to 25% of mem class

Expand All @@ -60,14 +64,13 @@ protected void onCreate( Bundle savedInstanceState ) {
mImageFetcher.setImageFadeIn( false );

Bundle args = getIntent().getExtras();
Long episodeId = args.getLong( EPISODE_KEY, -1 );
Long channelId = args.getLong( CHANNEL_ID, -1 );
Long startTime = args.getLong( START_TIME, -1 );

episodeFragment = (EpisodeFragment) getSupportFragmentManager().findFragmentById( R.id.fragment_dvr_episode );
episodeFragment.setOnEpisodeActionListener( this );

if( episodeId > 0 ) {
episodeFragment.loadEpisode( episodeId );
}
episodeFragment.loadEpisode( channelId, new DateTime( startTime ) );

Log.v( TAG, "onCreate : exit" );
}
Expand All @@ -80,17 +83,11 @@ public boolean onOptionsItemSelected( MenuItem item ) {
Log.v( TAG, "onOptionsItemSelected : enter" );

Bundle args = getIntent().getExtras();
Long episodeId = args.getLong( EPISODE_KEY, -1 );

String programGroup = null;
// Cursor cursor = getContentResolver().query(
// ContentUris.withAppendedId( ProgramConstants.CONTENT_URI_RECORDED, episodeId ),
// new String[] { ProgramConstants.FIELD_PROGRAM_GROUP },
// null, null, null );
// if( cursor.moveToFirst() ) {
// programGroup = cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_PROGRAM_GROUP ) );
// }
// cursor.close();
Long channelId = args.getLong( CHANNEL_ID, -1 );
Long startTime = args.getLong( START_TIME, -1 );
Program program = mRecordedDaoHelper.findOne( channelId, new DateTime( startTime ) );

String programGroup = ArticleCleaner.clean( program.getTitle() );

switch( item.getItemId() ) {
case android.R.id.home:
Expand Down Expand Up @@ -153,10 +150,6 @@ protected void onDestroy() {
Log.v( TAG, "onDestroy : exit" );
}

public ImageFetcher getImageFetcher() {
return mImageFetcher;
}

/* (non-Javadoc)
* @see org.mythtv.client.ui.dvr.EpisodeFragment.OnEpisodeActionListener#onEpisodeDeleted(java.lang.String)
*/
Expand All @@ -182,9 +175,24 @@ public void onEpisodeDeleted( String programGroup ) {
//
// }
// cursor.close();


finish();

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

/**
* @return
*/
public ImageFetcher getImageFetcher() {
return mImageFetcher;
}

/**
* @return
*/
public RecordedDaoHelper getRecordedDaoHelper() {
return mRecordedDaoHelper;
}

}
107 changes: 56 additions & 51 deletions src/org/mythtv/client/ui/dvr/EpisodeFragment.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package org.mythtv.client.ui.dvr;

import java.util.List;

import org.joda.time.DateTime;
import org.mythtv.R;
import org.mythtv.client.ui.AbstractMythFragment;
import org.mythtv.db.dvr.ProgramConstants;
import org.mythtv.service.dvr.cache.CoverartLruMemoryCache;
import org.mythtv.db.dvr.RecordedDaoHelper;
import org.mythtv.db.dvr.programGroup.ProgramGroup;
import org.mythtv.db.dvr.programGroup.ProgramGroupDaoHelper;
import org.mythtv.service.util.DateUtils;
import org.mythtv.service.util.image.ImageFetcher;
import org.mythtv.services.api.Bool;
import org.mythtv.services.api.dvr.Program;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.ContentUris;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -41,22 +43,18 @@ public class EpisodeFragment extends AbstractMythFragment {

private OnEpisodeActionListener listener = null;

private ProgramGroupDaoHelper mProgramGroupDaoHelper;
private RecordedDaoHelper mRecordedDaoHelper;
private ImageFetcher mImageFetcher;
// private CoverartLruMemoryCache cache;

private String programGroup, title, subTitle, inetref;
private Long episodeId;
private Integer channelId;
private DateTime startTime;
private Program program;

@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
Log.v( TAG, "onCreateView : enter" );

View root = inflater.inflate( R.layout.fragment_dvr_episode, container, false );

// cache = new CoverartLruMemoryCache( getActivity() );

Log.v( TAG, "onCreateView : exit" );
return root;
}
Expand All @@ -71,6 +69,9 @@ public void onActivityCreated( Bundle savedInstanceState ) {
Log.v( TAG, "onActivityCreated : enter" );
super.onActivityCreated( savedInstanceState );

mProgramGroupDaoHelper = new ProgramGroupDaoHelper( getActivity() );
mRecordedDaoHelper = new RecordedDaoHelper( getActivity() );

setHasOptionsMenu( true );
setRetainInstance( true );

Expand Down Expand Up @@ -125,7 +126,8 @@ public boolean onOptionsItemSelected( MenuItem item ) {
if( isMasterBackendConnected() ) {

Intent playerIntent = new Intent( getActivity(), VideoActivity.class );
playerIntent.putExtra( VideoActivity.EXTRA_PROGRAM_KEY, episodeId );
playerIntent.putExtra( VideoActivity.EXTRA_CHANNEL_ID, program.getChannelInfo().getChannelId() );
playerIntent.putExtra( VideoActivity.EXTRA_START_TIME, program.getStartTime().getMillis() );
startActivity( playerIntent );

} else {
Expand Down Expand Up @@ -177,78 +179,65 @@ public void onClick( DialogInterface dialog, int which ) {
return super.onOptionsItemSelected( item );
}

public void loadEpisode( long id ) {
public void loadEpisode( Long channelId, DateTime startTime ) {
Log.v( TAG, "loadEpisode : enter" );

if( null == mRecordedDaoHelper ) {
mRecordedDaoHelper = new RecordedDaoHelper( getActivity() );
}

if( RecordingsActivity.class.isInstance( getActivity() ) ) {
mImageFetcher = ( (RecordingsActivity) getActivity() ).getImageFetcher();
// mRecordedDaoHelper = ( (RecordingsActivity) getActivity() ).getRecordedDaoHelper();
}

if( EpisodeActivity.class.isInstance( getActivity() ) ) {
mImageFetcher = ( (EpisodeActivity) getActivity() ).getImageFetcher();
// mRecordedDaoHelper = ( (EpisodeActivity) getActivity() ).getRecordedDaoHelper();
}

episodeId = id;

String[] projection = {
ProgramConstants._ID, ProgramConstants.FIELD_TITLE, ProgramConstants.FIELD_SUB_TITLE, ProgramConstants.FIELD_INETREF,
ProgramConstants.FIELD_DESCRIPTION, ProgramConstants.FIELD_AIR_DATE,
ProgramConstants.FIELD_CATEGORY, ProgramConstants.FIELD_START_TIME, ProgramConstants.FIELD_END_TIME,
ProgramConstants.FIELD_CHANNEL_ID
};

Cursor cursor = getActivity().getContentResolver().query( ContentUris.withAppendedId( ProgramConstants.CONTENT_URI_RECORDED, id ), projection, null, null, null );
if( cursor.moveToFirst() ) {

// programGroup = cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_PROGRAM_GROUP ) );
inetref = cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_INETREF ) );
channelId = Integer.parseInt( cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_CHANNEL_ID ) ) );
startTime = new DateTime( cursor.getLong( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_START_TIME ) ) );

title = cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_TITLE ) );
Log.d( TAG, "loadEpisode : Episode_Title=" + title );
Log.v( TAG, "loadEpisode : channelId=" + channelId + ", startTime=" + DateUtils.dateTimeFormatterPretty.print( startTime ) );
program = mRecordedDaoHelper.findOne( channelId, startTime );
if( null != program ) {

// get activity to grab views from
FragmentActivity activity = this.getActivity();

// coverart
ImageView iView = (ImageView) activity.findViewById( R.id.imageView_episode_coverart );
if( null != inetref && !"".equals( inetref ) ) {
mImageFetcher.loadImage( inetref, "Coverart", iView, null );
if( null != program.getInetref() && !"".equals( program.getInetref() ) ) {
if( null != mImageFetcher ) {
mImageFetcher.loadImage( program.getInetref(), "Coverart", iView, null );
}
} else {
iView.setImageDrawable( null );
}
// BitmapDrawable coverart = cache.get( title );
// if( null != coverart ) {
// iView.setImageDrawable( coverart );
// } else {
// iView.setImageDrawable( null );
// }

// title
TextView tView = (TextView) activity.findViewById( R.id.textView_episode_title );
tView.setText( title );
tView.setText( program.getTitle() );

// subtitle
subTitle = cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_SUB_TITLE ) );
tView = (TextView) activity.findViewById( R.id.textView_episode_subtitle );
tView.setText( subTitle );
tView.setText( program.getSubTitle() );

// description
tView = (TextView) activity.findViewById( R.id.textView_episode_description );
tView.setText( cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_DESCRIPTION ) ) );
tView.setText( program.getDescription() );

// channel number
tView = (TextView) activity.findViewById( R.id.textView_episode_ch_num );
// tView.setText( cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_CHANNEL_NUMBER ) ) );
tView.setText( program.getChannelInfo().getChannelNumber() );

// airdate
tView = (TextView) activity.findViewById( R.id.textView_episode_airdate );
tView.setText( cursor.getString( cursor.getColumnIndexOrThrow( ProgramConstants.FIELD_AIR_DATE ) ) );
tView.setText( DateUtils.dateTimeFormatterPretty.print( program.getStartTime() ) );

} else {
Log.d( TAG, "loadEpisode: Empty Cursor Returned" );
}
cursor.close();

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

public void setOnEpisodeActionListener( OnEpisodeActionListener listener ) {
Expand Down Expand Up @@ -305,7 +294,7 @@ protected ResponseEntity<Bool> doInBackground( Void... params ) {
try {
Log.v( TAG, "RemoveRecordingTask : api" );

removed = getMainApplication().getMythServicesApi().dvrOperations().removeRecorded( channelId, startTime );
removed = getMainApplication().getMythServicesApi().dvrOperations().removeRecorded( program.getChannelInfo().getChannelId(), program.getStartTime() );
} catch( Exception e ) {
Log.v( TAG, "CreateStreamTask : error" );

Expand All @@ -327,8 +316,24 @@ protected void onPostExecute( ResponseEntity<Bool> result ) {
Bool bool = result.getBody();
if( bool.getBool().equals( Boolean.TRUE ) ) {

getActivity().getContentResolver().delete( ContentUris.withAppendedId( ProgramConstants.CONTENT_URI_RECORDED, episodeId ), null, null );
listener.onEpisodeDeleted( programGroup );
String title = program.getTitle();
ProgramGroup programGroup = mProgramGroupDaoHelper.findByTitle( title );

String programGroupName = programGroup.getProgramGroup();

mRecordedDaoHelper.delete( program );

List<Program> programs = mRecordedDaoHelper.findAllByTitle( title );
if( null == programs || programs.isEmpty() ) {
mProgramGroupDaoHelper.delete( programGroup );

List<ProgramGroup> programGroups = mProgramGroupDaoHelper.findAll();
if( null != programGroups && !programGroups.isEmpty() ) {
programGroupName = programGroups.get( 0 ).getProgramGroup();
}
}

listener.onEpisodeDeleted( programGroupName );

}

Expand Down
Loading

0 comments on commit ac52b13

Please sign in to comment.