Skip to content

Commit

Permalink
implemented episode activity for phones. updated episode to load
Browse files Browse the repository at this point in the history
coverart from coverart cache
  • Loading branch information
Daniel Frey committed Oct 26, 2012
1 parent b3a2e58 commit 2a1aaf5
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 8 deletions.
2 changes: 2 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
android:name=".client.ui.AwayActivity" />

<!-- DVR Activities -->
<activity
android:name=".client.ui.dvr.EpisodeActivity" />
<activity
android:name=".client.ui.dvr.ProgramGroupActivity" />
<activity
Expand Down
28 changes: 28 additions & 0 deletions res/layout/activity_dvr_episode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
This software can be found at <https://github.com/MythTV-Clients/MythTV-Android-Frontend/>
-->

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
class="org.mythtv.client.ui.dvr.EpisodeFragment"
android:id="@+id/fragment_dvr_episode"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
84 changes: 84 additions & 0 deletions src/org/mythtv/client/ui/dvr/EpisodeActivity.java
Original file line number Diff line number Diff line change
@@ -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 );
}

}
38 changes: 33 additions & 5 deletions src/org/mythtv/client/ui/dvr/EpisodeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/org/mythtv/client/ui/dvr/ProgramGroupActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,22 @@ 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 );
i.putExtra( VideoActivity.EXTRA_PROGRAM_KEY, id );
startActivity( i );
*/

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


Expand Down
3 changes: 2 additions & 1 deletion src/org/mythtv/client/ui/dvr/RecordingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public void onProgramGroupSelected( Long recordedId ) {
startActivity( i );
}

onEpisodeSelected( recordedId );

Log.d( TAG, "onProgramGroupSelected : exit" );
}

Expand All @@ -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
Expand Down
106 changes: 106 additions & 0 deletions src/org/mythtv/service/dvr/cache/CoverartLruMemoryCache.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* This software can be found at <https://github.com/MythTV-Clients/MythTV-Android-Frontend/>
*/
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<String, Bitmap> {

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 );
}

}

0 comments on commit 2a1aaf5

Please sign in to comment.