-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented episode activity for phones. updated episode to load
coverart from coverart cache
- Loading branch information
Daniel Frey
committed
Oct 26, 2012
1 parent
b3a2e58
commit 2a1aaf5
Showing
7 changed files
with
264 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/org/mythtv/service/dvr/cache/CoverartLruMemoryCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
|
||
} |