Skip to content

Commit

Permalink
Moved the logic to set the actionbar icon into the fragments.
Browse files Browse the repository at this point in the history
The activities provide the interface to interact with the actionbar.
  • Loading branch information
Robert Siebert committed Apr 22, 2014
1 parent 03229bf commit 18b3e19
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 30 deletions.
14 changes: 14 additions & 0 deletions src/org/tvheadend/tvhclient/ChannelListTabsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import org.tvheadend.tvhclient.ChangeLogDialog.ChangeLogDialogInterface;
import org.tvheadend.tvhclient.ChannelListFragment.OnChannelListListener;
import org.tvheadend.tvhclient.interfaces.ActionBarInterface;
import org.tvheadend.tvhclient.model.Channel;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
Expand Down Expand Up @@ -313,6 +315,18 @@ public void setActionBarSubtitle(final String subtitle, final String tag) {
}
}

@Override
public void setActionBarIcon(Channel channel, String tag) {
if (actionBar != null && channel != null) {
// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}
}
}

@Override
public void dialogDismissed() {
createTabListeners(null);
Expand Down
37 changes: 28 additions & 9 deletions src/org/tvheadend/tvhclient/ProgramDetailsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.tvheadend.tvhclient;

import org.tvheadend.tvhclient.interfaces.ActionBarInterface;
import org.tvheadend.tvhclient.model.Channel;
import org.tvheadend.tvhclient.model.Program;

Expand All @@ -29,7 +30,7 @@
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;

public class ProgramDetailsActivity extends ActionBarActivity {
public class ProgramDetailsActivity extends ActionBarActivity implements ActionBarInterface {

@SuppressWarnings("unused")
private final static String TAG = ProgramDetailsActivity.class.getSimpleName();
Expand Down Expand Up @@ -68,14 +69,6 @@ public void onCreate(Bundle savedInstanceState) {
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(channel.name);

// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}

// Show the fragment
Bundle args = new Bundle();
Expand All @@ -96,4 +89,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}

@Override
public void setActionBarTitle(final String title, final String tag) {
if (actionBar != null) {
actionBar.setTitle(title);
}
}

@Override
public void setActionBarSubtitle(final String subtitle, final String tag) {
if (actionBar != null) {
actionBar.setSubtitle(subtitle);
}
}

@Override
public void setActionBarIcon(Channel channel, String tag) {
if (actionBar != null && channel != null) {
// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}
}
}
}
17 changes: 16 additions & 1 deletion src/org/tvheadend/tvhclient/ProgramDetailsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.tvheadend.tvhclient.htsp.HTSListener;
import org.tvheadend.tvhclient.intent.SearchEPGIntent;
import org.tvheadend.tvhclient.intent.SearchIMDbIntent;
import org.tvheadend.tvhclient.interfaces.ActionBarInterface;
import org.tvheadend.tvhclient.model.Channel;
import org.tvheadend.tvhclient.model.Program;

Expand All @@ -42,10 +43,10 @@

public class ProgramDetailsFragment extends Fragment implements HTSListener {

@SuppressWarnings("unused")
private final static String TAG = ProgramDetailsFragment.class.getSimpleName();

private FragmentActivity activity;
private ActionBarInterface actionBarInterface;
private Program program;
private Channel channel;

Expand Down Expand Up @@ -128,6 +129,15 @@ public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);

if (activity instanceof ActionBarInterface) {
actionBarInterface = (ActionBarInterface) activity;
}

// If the channel or program is null exit
if (channel == null || program == null) {
activity.finish();
}

title.setText(program.title);
channelName.setText(channel.name);
Utils.setState(state, program.recording);
Expand Down Expand Up @@ -156,6 +166,11 @@ public void onResume() {
super.onResume();
TVHClientApplication app = (TVHClientApplication) activity.getApplication();
app.addListener(this);

if (actionBarInterface != null) {
actionBarInterface.setActionBarTitle(channel.name, TAG);
actionBarInterface.setActionBarIcon(channel, TAG);
}
}

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/org/tvheadend/tvhclient/ProgramGuideTabsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
Expand Down Expand Up @@ -355,6 +356,18 @@ public void setActionBarSubtitle(final String subtitle, final String tag) {
}
}

@Override
public void setActionBarIcon(Channel channel, String tag) {
if (actionBar != null && channel != null) {
// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}
}
}

/**
* This activity does not know how many items are in the channel list and
* which are selected by the given channel tag. Use the channel list
Expand Down
21 changes: 17 additions & 4 deletions src/org/tvheadend/tvhclient/ProgramListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.tvheadend.tvhclient.interfaces.ProgramLoadingInterface;
import org.tvheadend.tvhclient.model.Channel;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
Expand Down Expand Up @@ -51,7 +52,6 @@ public void onCreate(Bundle icicle) {
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(channel.name);

// Show the fragment
Bundle args = new Bundle();
Expand All @@ -74,9 +74,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public void setActionBarTitle(final String string, final String tag) {
// TODO Auto-generated method stub

public void setActionBarTitle(final String title, final String tag) {
if (actionBar != null) {
actionBar.setTitle(title);
}
}

@Override
Expand All @@ -90,4 +91,16 @@ public void setActionBarSubtitle(final String subtitle, final String tag) {
public void loadMorePrograms(Channel channel) {
Utils.loadMorePrograms(this, channel);
}

@Override
public void setActionBarIcon(Channel channel, String tag) {
if (actionBar != null && channel != null) {
// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}
}
}
}
11 changes: 8 additions & 3 deletions src/org/tvheadend/tvhclient/ProgramListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public void onActivityCreated(Bundle savedInstanceState) {
loadMoreProgramsInterface = (ProgramLoadingInterface) activity;
}

// If the channel is null exit
if (channel == null) {
activity.finish();
}

listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Expand Down Expand Up @@ -157,14 +162,14 @@ public void onResume() {
// a program to the schedule or has deleted one from it we need to
// update the list to reflect these changes.
prList.clear();
if (channel != null) {
prList.addAll(channel.epg);
}
prList.addAll(channel.epg);
adapter.sort();
adapter.notifyDataSetChanged();

if (actionBarInterface != null) {
actionBarInterface.setActionBarTitle(channel.name, TAG);
actionBarInterface.setActionBarSubtitle(adapter.getCount() + " " + getString(R.string.programs), TAG);
actionBarInterface.setActionBarIcon(channel, TAG);
}
}

Expand Down
41 changes: 29 additions & 12 deletions src/org/tvheadend/tvhclient/RecordingDetailsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.tvheadend.tvhclient;

import org.tvheadend.tvhclient.htsp.HTSListener;
import org.tvheadend.tvhclient.interfaces.ActionBarInterface;
import org.tvheadend.tvhclient.model.Channel;
import org.tvheadend.tvhclient.model.Recording;

import android.graphics.drawable.BitmapDrawable;
Expand All @@ -29,7 +31,7 @@
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;

public class RecordingDetailsActivity extends ActionBarActivity implements HTSListener {
public class RecordingDetailsActivity extends ActionBarActivity implements HTSListener, ActionBarInterface {

@SuppressWarnings("unused")
private final static String TAG = RecordingDetailsActivity.class.getSimpleName();
Expand All @@ -55,17 +57,6 @@ public void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

if (rec.channel != null) {
actionBar.setTitle(rec.channel.name);

// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon && rec.channel.iconBitmap != null) {
actionBar.setIcon(new BitmapDrawable(getResources(), rec.channel.iconBitmap));
}
}

// Show the fragment
Bundle args = new Bundle();
args.putLong("id", id);
Expand Down Expand Up @@ -115,4 +106,30 @@ public void run() {
});
}
}

@Override
public void setActionBarTitle(final String title, final String tag) {
if (actionBar != null) {
actionBar.setTitle(title);
}
}

@Override
public void setActionBarSubtitle(final String subtitle, final String tag) {
if (actionBar != null) {
actionBar.setSubtitle(subtitle);
}
}

@Override
public void setActionBarIcon(Channel channel, String tag) {
if (actionBar != null && channel != null) {
// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}
}
}
}
17 changes: 16 additions & 1 deletion src/org/tvheadend/tvhclient/RecordingDetailsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.tvheadend.tvhclient.htsp.HTSListener;
import org.tvheadend.tvhclient.intent.SearchEPGIntent;
import org.tvheadend.tvhclient.intent.SearchIMDbIntent;
import org.tvheadend.tvhclient.interfaces.ActionBarInterface;
import org.tvheadend.tvhclient.model.Recording;

import android.app.Activity;
Expand All @@ -40,10 +41,10 @@

public class RecordingDetailsFragment extends Fragment implements HTSListener {

@SuppressWarnings("unused")
private final static String TAG = RecordingDetailsFragment.class.getSimpleName();

private FragmentActivity activity;
private ActionBarInterface actionBarInterface;
private Recording rec;

private TextView title;
Expand Down Expand Up @@ -98,6 +99,15 @@ public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);

if (activity instanceof ActionBarInterface) {
actionBarInterface = (ActionBarInterface) activity;
}

// If the recording is null exit
if (rec == null) {
activity.finish();
}

title.setText(rec.title);
channelName.setText(rec.channel.name);
Utils.setState(state, rec);
Expand All @@ -113,6 +123,11 @@ public void onResume() {
super.onResume();
TVHClientApplication app = (TVHClientApplication) activity.getApplication();
app.addListener(this);

if (actionBarInterface != null) {
actionBarInterface.setActionBarTitle(rec.channel.name, TAG);
actionBarInterface.setActionBarIcon(rec.channel, TAG);
}
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions src/org/tvheadend/tvhclient/RecordingListTabsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.lang.reflect.Field;

import org.tvheadend.tvhclient.interfaces.ActionBarInterface;
import org.tvheadend.tvhclient.model.Channel;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand Down Expand Up @@ -288,4 +290,16 @@ public void setActionBarSubtitle(final String subtitle, final String tag) {
actionBar.setSubtitle(subtitle);
}
}

@Override
public void setActionBarIcon(final Channel channel, String tag) {
if (actionBar != null && channel != null) {
// Show or hide the channel icon if required
boolean showIcon = Utils.showChannelIcons(this);
actionBar.setDisplayUseLogoEnabled(showIcon);
if (showIcon) {
actionBar.setIcon(new BitmapDrawable(getResources(), channel.iconBitmap));
}
}
}
}

0 comments on commit 18b3e19

Please sign in to comment.