Skip to content

Commit

Permalink
Issue photo#463 (Card 13) (Display name of album in header when viewi…
Browse files Browse the repository at this point in the history
…ng an

album.)
- AlbumsFragment: updated call of the galleryOpenControl with the whole
album object parameter in the onItemClick method
- GalleryFragment: updated type of mAlbum name to Album
- GalleryFragment: updated EXTRA_ALBUM extra read/write to parcelable
type in the onSaveInstanceState, onCreateView, refresh methods
- GalleryFragment: added getAlbum method
- GalleryFragment: updated mAlbum reading from intent and
GalleryAdapterExt constructor call in the refresh method
- MainActivity: updated openGallery method declaration accordingly to
parent interface call
- NavigationHandlerFragment.FragmentWrapper: added new field
dynamicTitleGenerator and renamed field runOnReselect to the
mRunOnReselect
- NavigationHandlerFragment.FragmentWrapper: added getActionbarTitle
method
- NavigationHandlerFragment: added init of dynamicTitleGenerator field
for thw gallery fragment wrapper to the initPager method. Also added
resetting of actionbar title call to the runOnReselect handler for the
gallery fragment.
- NavigationHandlerFragment: added setActionBarTitle method
- NavigationHandlerFragment.FragmentAdapter: extracted actionbar title
setting code to the separate method setActionBarTitle
- GalleryOpenControl: updated type of album field in the openGallery
method declaration
  • Loading branch information
httpdispatch committed Oct 3, 2013
1 parent c379820 commit ad37394
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/src/com/trovebox/android/app/AlbumsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onItemClick(AdapterView<?> adapterView, View view,
{
TrackerUtils.trackButtonClickEvent("album_item", AlbumsFragment.this);
Album album = (Album) mAdapter.getItem(position);
galleryOpenControl.openGallery(null, album.getId());
galleryOpenControl.openGallery(null, album);
}

@Override
Expand Down
15 changes: 10 additions & 5 deletions app/src/com/trovebox/android/app/GalleryFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.trovebox.android.app.bitmapfun.util.ImageCache;
import com.trovebox.android.app.bitmapfun.util.ImageFetcher;
import com.trovebox.android.app.common.CommonRefreshableFragmentWithImageWorker;
import com.trovebox.android.app.model.Album;
import com.trovebox.android.app.model.Photo;
import com.trovebox.android.app.model.utils.PhotoUtils;
import com.trovebox.android.app.model.utils.PhotoUtils.PhotoDeletedHandler;
Expand Down Expand Up @@ -47,7 +48,7 @@ public class GalleryFragment extends CommonRefreshableFragmentWithImageWorker
private StartNowHandler startNowHandler;
private GalleryAdapterExt mAdapter;
private String mTags;
private String mAlbum;
private Album mAlbum;

private ReturnSizes thumbSize;
private ReturnSizes returnSizes;
Expand All @@ -72,7 +73,7 @@ public void onCreate(Bundle savedInstanceState) {
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(EXTRA_TAG, mTags);
outState.putString(EXTRA_ALBUM, mAlbum);
outState.putParcelable(EXTRA_ALBUM, mAlbum);
}

@Override
Expand All @@ -84,7 +85,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
if (savedInstanceState != null)
{
mTags = savedInstanceState.getString(EXTRA_TAG);
mAlbum = savedInstanceState.getString(EXTRA_ALBUM);
mAlbum = savedInstanceState.getParcelable(EXTRA_ALBUM);
} else
{
mTags = null;
Expand All @@ -108,6 +109,10 @@ public void onAttach(Activity activity)

}

public Album getAlbum() {
return mAlbum;
}

@Override
protected void initImageWorker() {
mImageThumbSize = getResources().getDimensionPixelSize(
Expand Down Expand Up @@ -139,11 +144,11 @@ void refresh(View v)
mTags = intent != null ? intent
.getStringExtra(EXTRA_TAG)
: null;
mAlbum = intent != null ? intent.getStringExtra(EXTRA_ALBUM) : null;
mAlbum = intent != null ? (Album) intent.getParcelableExtra(EXTRA_ALBUM) : null;
}
if (mTags != null || mAlbum != null)
{
mAdapter = new GalleryAdapterExt(mTags, mAlbum);
mAdapter = new GalleryAdapterExt(mTags, mAlbum == null ? null : mAlbum.getId());
removeTagsAndAlbumInformationFromActivityIntent();
} else
{
Expand Down
3 changes: 2 additions & 1 deletion app/src/com/trovebox/android/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.trovebox.android.app.bitmapfun.util.ImageCacheUtils;
import com.trovebox.android.app.common.CommonActivity;
import com.trovebox.android.app.facebook.FacebookProvider;
import com.trovebox.android.app.model.Album;
import com.trovebox.android.app.model.Photo;
import com.trovebox.android.app.model.utils.PhotoUtils;
import com.trovebox.android.app.model.utils.PhotoUtils.PhotoDeletedHandler;
Expand Down Expand Up @@ -339,7 +340,7 @@ public Fragment getCurrentFragment()
}

@Override
public void openGallery(String tag, String album)
public void openGallery(String tag, Album album)
{
Intent intent = getIntent();
if (intent == null)
Expand Down
71 changes: 50 additions & 21 deletions app/src/com/trovebox/android/app/NavigationHandlerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.holoeverywhere.widget.LinearLayout;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand All @@ -21,13 +22,15 @@

import com.trovebox.android.app.common.CommonFragment;
import com.trovebox.android.app.common.lifecycle.ViewPagerHandler;
import com.trovebox.android.app.model.Album;
import com.trovebox.android.app.net.SystemVersionResponseUtils;
import com.trovebox.android.app.ui.adapter.FragmentPagerAdapter;
import com.trovebox.android.app.ui.widget.SliderCategorySeparator;
import com.trovebox.android.app.ui.widget.SliderNavigationItem;
import com.trovebox.android.app.util.CommonUtils;
import com.trovebox.android.app.util.GuiUtils;
import com.trovebox.android.app.util.LoadingControl;
import com.trovebox.android.app.util.RunnableWithResult;
import com.trovebox.android.app.util.TrackerUtils;

/**
Expand Down Expand Up @@ -60,7 +63,8 @@ private final class FragmentWrapper<T extends Fragment> implements OnClickListen
private int mIconId;
private final Bundle mArgs;
private Fragment mFragment;
private Runnable runOnReselect;
private Runnable mRunOnReselect;
RunnableWithResult<String> dynamicTitleGenerator;

public FragmentWrapper(int title, int icon, Class<T> clz,
Bundle args,
Expand All @@ -71,7 +75,7 @@ public FragmentWrapper(int title, int icon, Class<T> clz,
mPosition = position;
mClass = clz;
mArgs = args;
this.runOnReselect = runOnReselect;
this.mRunOnReselect = runOnReselect;
}

@Override
Expand All @@ -95,9 +99,9 @@ public void onClick(View v) {
TrackerUtils.trackNavigationItemReselectedEvent(TAG,
NavigationHandlerFragment.this);
CommonUtils.debug(TAG, "onNavigationItemReselected");
if (mCurrentPage == mPosition && runOnReselect != null)
if (mCurrentPage == mPosition && mRunOnReselect != null)
{
runOnReselect.run();
mRunOnReselect.run();
}
}
}
Expand All @@ -116,6 +120,14 @@ void selectFragment()
{
selectTab(mPosition);
}

public String getActionbarTitle() {
String title = dynamicTitleGenerator == null ? null : dynamicTitleGenerator.run();
if (title == null) {
title = CommonUtils.getStringResource(mTitleId);
}
return title;
}
}

private static final String KEY_PAGE = "page";
Expand Down Expand Up @@ -228,20 +240,37 @@ private void rebuildLeftView() {
*/
void initPager()
{
adapter.add(
R.string.tab_gallery,
R.drawable.menu_gallery_2states,
GalleryFragment.class, null,
new Runnable() {
@Override
public void run() {
GalleryFragment gf = getGalleryFragment();
if (gf != null)
{
gf.cleanRefreshIfFiltered();
{
FragmentWrapper<?> wrapper;
wrapper = adapter.add(R.string.tab_gallery, R.drawable.menu_gallery_2states,
GalleryFragment.class, null, new Runnable() {
@Override
public void run() {
GalleryFragment gf = getGalleryFragment();
if (gf != null) {
gf.cleanRefreshIfFiltered();
}
setActionBarTitle(adapter.wrappers.get(GALLERY_INDEX));
}
});
wrapper.dynamicTitleGenerator = new RunnableWithResult<String>() {

@Override
public String run() {
GalleryFragment gf = getGalleryFragment();
Album album = null;
if (gf != null) {
album = gf.getAlbum();
}
if (album == null) {
Intent intent = getActivity().getIntent();
album = intent != null ? (Album) intent
.getParcelableExtra(GalleryFragment.EXTRA_ALBUM) : null;
}
});
return album == null ? null : album.getName();
}
};
}
adapter.add(
R.string.tab_albums,
R.drawable.menu_album_2states,
Expand Down Expand Up @@ -388,6 +417,10 @@ public AccountFragment getAccountFragment()
return (AccountFragment) result;
}

void setActionBarTitle(FragmentWrapper<?> wrapper) {
getSupportActivity().setActionBarTitle(" " + wrapper.getActionbarTitle());
}

/**
* Custom fragment pager adapter
*/
Expand Down Expand Up @@ -463,11 +496,7 @@ public void setPrimaryItem(final ViewGroup container, final int position,
@Override
public void run() {
if (getSupportActivity() != null && !getSupportActivity().isFinishing()) {
getSupportActivity()
.setActionBarTitle(
" "
+ CommonUtils.getStringResource(wrappers
.get(position).mTitleId));
setActionBarTitle(wrappers.get(position));
refreshLeftView();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

package com.trovebox.android.app.util;

import com.trovebox.android.app.model.Album;

/**
* @author Eugene Popovich
*/
public interface GalleryOpenControl
{
void openGallery(String tag, String album);
void openGallery(String tag, Album album);
}

0 comments on commit ad37394

Please sign in to comment.