diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 62ae5354..bd14f310 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -76,6 +76,8 @@ android:name=".client.ui.AwayActivity" /> + + + + \ No newline at end of file diff --git a/src/org/mythtv/client/ui/dvr/EpisodeActivity.java b/src/org/mythtv/client/ui/dvr/EpisodeActivity.java index 9e91defc..f863e01f 100644 --- a/src/org/mythtv/client/ui/dvr/EpisodeActivity.java +++ b/src/org/mythtv/client/ui/dvr/EpisodeActivity.java @@ -1,5 +1,89 @@ package org.mythtv.client.ui.dvr; +import org.mythtv.R; +import org.mythtv.db.dvr.ProgramConstants; + +import android.content.ContentUris; +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.util.Log; +import android.view.MenuItem; + +/** + * @author pot8oe + * @author Daniel Frey + * + */ public class EpisodeActivity extends AbstractDvrActivity { + public static final String EPISODE_KEY = "EPISODE_ID"; + + private static final String TAG = EpisodeActivity.class.getSimpleName(); + + private EpisodeFragment episodeFragment; + + /* (non-Javadoc) + * @see org.mythtv.client.ui.dvr.AbstractDvrActivity#onCreate(android.os.Bundle) + */ + @Override + protected void onCreate( Bundle savedInstanceState ) { + Log.v( TAG, "onCreate : enter" ); + super.onCreate( savedInstanceState ); + + setContentView( R.layout.activity_dvr_episode ); + + Bundle args = getIntent().getExtras(); + Long episodeId = args.getLong( EPISODE_KEY, -1 ); + + episodeFragment = (EpisodeFragment) getSupportFragmentManager().findFragmentById( R.id.fragment_dvr_episode ); + + if( episodeId > 0 ) { + episodeFragment.loadEpisode( episodeId ); + } + + Log.v( TAG, "onCreate : exit" ); + } + + /* (non-Javadoc) + * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) + */ + @Override + 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(); + + switch( item.getItemId() ) { + case android.R.id.home: + + if( null != programGroup ) { + Intent intent = new Intent( this, ProgramGroupActivity.class ); + intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); + intent.putExtra( ProgramGroupActivity.EXTRA_PROGRAM_GROUP_KEY, programGroup ); + startActivity( intent ); + } else { + Intent intent = new Intent( this, RecordingsActivity.class ); + intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); + startActivity( intent ); + } + + return true; + } + + Log.v( TAG, "onOptionsItemSelected : exit" ); + return super.onOptionsItemSelected( item ); + } + } diff --git a/src/org/mythtv/client/ui/dvr/EpisodeFragment.java b/src/org/mythtv/client/ui/dvr/EpisodeFragment.java index 4afa73c3..45cdd4d9 100644 --- a/src/org/mythtv/client/ui/dvr/EpisodeFragment.java +++ b/src/org/mythtv/client/ui/dvr/EpisodeFragment.java @@ -3,32 +3,53 @@ import org.mythtv.R; import org.mythtv.client.ui.AbstractMythFragment; import org.mythtv.db.dvr.ProgramConstants; +import org.mythtv.service.dvr.cache.CoverartLruMemoryCache; import android.content.ContentUris; import android.database.Cursor; +import android.graphics.Bitmap; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; public class EpisodeFragment extends AbstractMythFragment { private static final String TAG = ProgramGroupActivity.class.getSimpleName(); + private CoverartLruMemoryCache cache; + @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + 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; } - - + /* (non-Javadoc) + * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle) + */ + @Override + public void onActivityCreated( Bundle savedInstanceState ) { + Log.v( TAG, "onActivityCreated : enter" ); + super.onActivityCreated( savedInstanceState ); + + cache = new CoverartLruMemoryCache( getActivity() ); + + Log.v( TAG, "onActivityCreated : exit" ); + } + + + public void loadEpisode(long id){ String[] projection = @@ -54,7 +75,14 @@ public void loadEpisode(long id){ //get activity to grab views from FragmentActivity activity = this.getActivity(); - + + //coverart + ImageView iView = (ImageView) activity.findViewById( R.id.imageView_episode_coverart ); + Bitmap coverart = cache.get( title ); + if( null != coverart ) { + iView.setImageBitmap( coverart ); + } + //title TextView tView = (TextView)activity.findViewById(R.id.textView_episode_title); tView.setText(title); diff --git a/src/org/mythtv/client/ui/dvr/ProgramGroupActivity.java b/src/org/mythtv/client/ui/dvr/ProgramGroupActivity.java index 7580b8d3..4623bb36 100644 --- a/src/org/mythtv/client/ui/dvr/ProgramGroupActivity.java +++ b/src/org/mythtv/client/ui/dvr/ProgramGroupActivity.java @@ -92,8 +92,14 @@ public boolean onOptionsItemSelected( MenuItem item ) { * as part of the RecordingsActivity. */ @Override - public void onEpisodeSelected(long id) { - + public void onEpisodeSelected( long id ) { + Log.v( TAG, "onEpisodeSelect : enter" ); + + Log.v( TAG, "onEpisodeSelect : starting episode activity" ); + Intent i = new Intent( this, EpisodeActivity.class ); + i.putExtra( EpisodeActivity.EPISODE_KEY, id ); + startActivity( i ); + /* //Start Video Playback -- this will be moving to the activity bar Intent i = new Intent( activity, VideoActivity.class ); @@ -101,6 +107,7 @@ public void onEpisodeSelected(long id) { startActivity( i ); */ + Log.v( TAG, "onEpisodeSelect : exit" ); } diff --git a/src/org/mythtv/client/ui/dvr/RecordingsActivity.java b/src/org/mythtv/client/ui/dvr/RecordingsActivity.java index f01c8a36..56b5aac9 100644 --- a/src/org/mythtv/client/ui/dvr/RecordingsActivity.java +++ b/src/org/mythtv/client/ui/dvr/RecordingsActivity.java @@ -132,6 +132,8 @@ public void onProgramGroupSelected( Long recordedId ) { startActivity( i ); } + onEpisodeSelected( recordedId ); + Log.d( TAG, "onProgramGroupSelected : exit" ); } @@ -141,7 +143,6 @@ public void onProgramGroupSelected( Long recordedId ) { */ @Override public void onEpisodeSelected(long id) { - Log.v(TAG, "onEpisodeSelect : enter"); //check if we're hosting multiple fragments and have the episode fragment diff --git a/src/org/mythtv/service/dvr/cache/CoverartLruMemoryCache.java b/src/org/mythtv/service/dvr/cache/CoverartLruMemoryCache.java new file mode 100644 index 00000000..ec02055d --- /dev/null +++ b/src/org/mythtv/service/dvr/cache/CoverartLruMemoryCache.java @@ -0,0 +1,106 @@ +/** + * This file is part of MythTV Android Frontend + * + * MythTV Android Frontend 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 Android Frontend 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 Android Frontend. If not, see . + * + * This software can be found at + */ +package org.mythtv.service.dvr.cache; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.mythtv.service.dvr.CoverartDownloadService; +import org.mythtv.service.util.FileHelper; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.support.v4.util.LruCache; +import android.util.Log; + +/** + * @author Daniel Frey + * + */ +public class CoverartLruMemoryCache extends LruCache { + + private static final String TAG = CoverartLruMemoryCache.class.getSimpleName(); + + private final Context mContext; + + private FileHelper mFileHelper; + + public CoverartLruMemoryCache( Context context ) { + super( 12 * 1024 * 1024 ); + Log.v( TAG, "initialize : enter" ); + + mContext = context; + mFileHelper = new FileHelper( mContext ); + + Log.v( TAG, "initialize : exit" ); + } + + /* (non-Javadoc) + * @see android.support.v4.util.LruCache#create(java.lang.Object) + */ + @Override + protected Bitmap create( String key ) { + Log.v( TAG, "create : enter" ); + + File programGroupDirectory = mFileHelper.getProgramGroupDirectory( key ); + if( programGroupDirectory.exists() ) { + + File image = new File( programGroupDirectory, CoverartDownloadService.COVERART_FILE ); + if( image.exists() ) { + try { + InputStream is = new FileInputStream( image ); + Bitmap bitmap = BitmapFactory.decodeStream( is ); + return bitmap; + } catch( Exception e ) { + Log.e( TAG, "create : error reading file" ); + } + } + } + + Log.v( TAG, "create : exit" ); + return super.create( key ); + } + + /* (non-Javadoc) + * @see android.support.v4.util.LruCache#sizeOf(java.lang.Object, java.lang.Object) + */ + @Override + protected int sizeOf( String key, Bitmap value ) { + + File programGroupDirectory = mFileHelper.getProgramGroupDirectory( key ); + if( programGroupDirectory.exists() ) { + + File image = new File( programGroupDirectory, CoverartDownloadService.COVERART_FILE ); + if( image.exists() ) { + return (int) image.length(); + } + + File imageNa = new File( programGroupDirectory, CoverartDownloadService.COVERART_FILE_NA ); + if( imageNa.exists() ) { + return 0; + } + + } + + return super.sizeOf( key, value ); + } + +}