Improved content view of audio player activity
This commit is contained in:
parent
4b9831603b
commit
2d2e8ef627
@ -5,11 +5,66 @@
|
|||||||
android:background="?attr/non_transparent_background"
|
android:background="?attr/non_transparent_background"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<com.viewpagerindicator.TabPageIndicator
|
<RelativeLayout
|
||||||
android:id="@+id/tabs"
|
android:id="@+id/navBar"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_alignParentTop="true" >
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/butNavLeft"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:background="?attr/borderless_button"
|
||||||
|
android:src="?attr/default_cover" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/butNavRight"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:background="?attr/borderless_button"
|
||||||
|
android:src="?attr/default_cover" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtvTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentTop="true" />
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_toLeftOf="@id/butNavRight"
|
||||||
|
android:layout_toRightOf="@id/butNavLeft"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/text_size_medium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtvFeed"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/txtvTitle"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_toLeftOf="@id/butNavRight"
|
||||||
|
android:layout_toRightOf="@id/butNavLeft"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:textSize="@dimen/text_size_small" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_below="@id/navBar"
|
||||||
|
android:background="@color/bright_blue" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/player_control"
|
android:id="@+id/player_control"
|
||||||
@ -91,12 +146,12 @@
|
|||||||
android:max="500" />
|
android:max="500" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<android.support.v4.view.ViewPager
|
<FrameLayout
|
||||||
android:id="@+id/viewpager"
|
android:id="@+id/contentView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0px"
|
android:layout_height="0px"
|
||||||
android:layout_above="@id/playtime_layout"
|
android:layout_above="@id/playtime_layout"
|
||||||
android:layout_below="@id/tabs" >
|
android:layout_below="@id/navBar" >
|
||||||
</android.support.v4.view.ViewPager>
|
</FrameLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -4,13 +4,17 @@ import android.content.Intent;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageButton;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import com.viewpagerindicator.TabPageIndicator;
|
import com.viewpagerindicator.TabPageIndicator;
|
||||||
|
|
||||||
@ -26,14 +30,48 @@ import de.danoeh.antennapod.service.PlaybackService;
|
|||||||
|
|
||||||
/** Activity for playing audio files. */
|
/** Activity for playing audio files. */
|
||||||
public class AudioplayerActivity extends MediaplayerActivity {
|
public class AudioplayerActivity extends MediaplayerActivity {
|
||||||
|
private static final int POS_COVER = 0;
|
||||||
|
private static final int POS_DESCR = 1;
|
||||||
|
private static final int POS_CHAPTERS = 2;
|
||||||
|
private static final int NUM_CONTENT_FRAGMENTS = 3;
|
||||||
|
|
||||||
final String TAG = "AudioplayerActivity";
|
final String TAG = "AudioplayerActivity";
|
||||||
|
|
||||||
|
private Fragment[] detachedFragments;
|
||||||
|
|
||||||
private CoverFragment coverFragment;
|
private CoverFragment coverFragment;
|
||||||
private ItemDescriptionFragment descriptionFragment;
|
private ItemDescriptionFragment descriptionFragment;
|
||||||
ViewPager viewpager;
|
private SherlockListFragment chapterFragment;
|
||||||
TabPageIndicator tabs;
|
|
||||||
MediaPlayerPagerAdapter pagerAdapter;
|
private Fragment currentlyShownFragment;
|
||||||
|
/** Fragment that was shown before the chapter fragment was displayed. */
|
||||||
|
private int leftFragmentPosition = -1;
|
||||||
|
private int currentlyShownPosition = -1;
|
||||||
|
|
||||||
|
private TextView txtvTitle;
|
||||||
|
private TextView txtvFeed;
|
||||||
|
private ImageButton butNavLeft;
|
||||||
|
private ImageButton butNavRight;
|
||||||
|
|
||||||
|
public AudioplayerActivity() {
|
||||||
|
super();
|
||||||
|
detachedFragments = new Fragment[NUM_CONTENT_FRAGMENTS];
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetFragmentView() {
|
||||||
|
currentlyShownFragment = null;
|
||||||
|
coverFragment = null;
|
||||||
|
descriptionFragment = null;
|
||||||
|
chapterFragment = null;
|
||||||
|
currentlyShownPosition = -1;
|
||||||
|
detachedFragments = new Fragment[NUM_CONTENT_FRAGMENTS];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
resetFragmentView();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAwaitingVideoSurface() {
|
protected void onAwaitingVideoSurface() {
|
||||||
@ -50,20 +88,121 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the currently displayed fragment.
|
||||||
|
*
|
||||||
|
* @param Must
|
||||||
|
* be POS_COVER, POS_DESCR, or POS_CHAPTERS
|
||||||
|
* */
|
||||||
|
private void switchToFragment(int pos) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Switching contentView to position " + pos);
|
||||||
|
if (currentlyShownPosition != pos) {
|
||||||
|
FeedMedia media = controller.getMedia();
|
||||||
|
if (media != null) {
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager()
|
||||||
|
.beginTransaction();
|
||||||
|
if (currentlyShownFragment != null) {
|
||||||
|
detachedFragments[currentlyShownPosition] = currentlyShownFragment;
|
||||||
|
ft.detach(currentlyShownFragment);
|
||||||
|
}
|
||||||
|
switch (pos) {
|
||||||
|
case POS_COVER:
|
||||||
|
if (coverFragment == null) {
|
||||||
|
Log.i(TAG, "Using new coverfragment");
|
||||||
|
coverFragment = CoverFragment.newInstance(media
|
||||||
|
.getItem());
|
||||||
|
}
|
||||||
|
currentlyShownFragment = coverFragment;
|
||||||
|
break;
|
||||||
|
case POS_DESCR:
|
||||||
|
if (descriptionFragment == null) {
|
||||||
|
descriptionFragment = ItemDescriptionFragment
|
||||||
|
.newInstance(media.getItem());
|
||||||
|
}
|
||||||
|
currentlyShownFragment = descriptionFragment;
|
||||||
|
break;
|
||||||
|
case POS_CHAPTERS:
|
||||||
|
if (chapterFragment == null) {
|
||||||
|
chapterFragment = new SherlockListFragment() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListItemClick(ListView l, View v,
|
||||||
|
int position, long id) {
|
||||||
|
super.onListItemClick(l, v, position, id);
|
||||||
|
Chapter chapter = (Chapter) this
|
||||||
|
.getListAdapter().getItem(position);
|
||||||
|
controller.seekToChapter(chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
chapterFragment.setListAdapter(new ChapterListAdapter(
|
||||||
|
AudioplayerActivity.this, 0, media.getItem()
|
||||||
|
.getChapters(), media));
|
||||||
|
}
|
||||||
|
currentlyShownFragment = chapterFragment;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (currentlyShownFragment != null) {
|
||||||
|
currentlyShownPosition = pos;
|
||||||
|
if (detachedFragments[pos] != null) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Reattaching fragment at position "
|
||||||
|
+ pos);
|
||||||
|
ft.attach(detachedFragments[pos]);
|
||||||
|
} else {
|
||||||
|
ft.add(R.id.contentView, currentlyShownFragment);
|
||||||
|
}
|
||||||
|
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupGUI() {
|
protected void setupGUI() {
|
||||||
super.setupGUI();
|
super.setupGUI();
|
||||||
viewpager = (ViewPager) findViewById(R.id.viewpager);
|
resetFragmentView();
|
||||||
tabs = (TabPageIndicator) findViewById(R.id.tabs);
|
txtvTitle = (TextView) findViewById(R.id.txtvTitle);
|
||||||
pagerAdapter = new MediaPlayerPagerAdapter(getSupportFragmentManager());
|
txtvFeed = (TextView) findViewById(R.id.txtvFeed);
|
||||||
viewpager.setAdapter(pagerAdapter);
|
butNavLeft = (ImageButton) findViewById(R.id.butNavLeft);
|
||||||
tabs.setViewPager(viewpager);
|
butNavRight = (ImageButton) findViewById(R.id.butNavRight);
|
||||||
|
|
||||||
|
butNavLeft.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (currentlyShownFragment == null
|
||||||
|
|| currentlyShownPosition == POS_DESCR) {
|
||||||
|
switchToFragment(POS_COVER);
|
||||||
|
} else if (currentlyShownPosition == POS_COVER){
|
||||||
|
switchToFragment(POS_DESCR);
|
||||||
|
} else if (currentlyShownPosition == POS_CHAPTERS) {
|
||||||
|
switchToFragment(leftFragmentPosition);
|
||||||
|
leftFragmentPosition = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
butNavRight.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (currentlyShownPosition == POS_CHAPTERS) {
|
||||||
|
switchToFragment(leftFragmentPosition);
|
||||||
|
leftFragmentPosition = -1;
|
||||||
|
} else {
|
||||||
|
leftFragmentPosition = currentlyShownPosition;
|
||||||
|
switchToFragment(POS_CHAPTERS);
|
||||||
|
}
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPositionObserverUpdate() {
|
protected void onPositionObserverUpdate() {
|
||||||
super.onPositionObserverUpdate();
|
super.onPositionObserverUpdate();
|
||||||
pagerAdapter.notifyMediaPositionChanged();
|
notifyMediaPositionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,116 +210,33 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
|||||||
super.loadMediaInfo();
|
super.loadMediaInfo();
|
||||||
final FeedMedia media = controller.getMedia();
|
final FeedMedia media = controller.getMedia();
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
if (media.getItem().getChapters() != null
|
txtvTitle.setText(media.getItem().getTitle());
|
||||||
&& pagerAdapter.getCount() < MediaPlayerPagerAdapter.NUM_ITEMS_WITH_CHAPTERS) {
|
txtvFeed.setText(media.getItem().getFeed().getTitle());
|
||||||
pagerAdapter
|
if (media.getItem().getChapters() != null) {
|
||||||
.setNumItems(MediaPlayerPagerAdapter.NUM_ITEMS_WITH_CHAPTERS);
|
butNavRight.setVisibility(View.VISIBLE);
|
||||||
}
|
|
||||||
pagerAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MediaPlayerPagerAdapter extends FragmentStatePagerAdapter {
|
|
||||||
private int numItems;
|
|
||||||
|
|
||||||
private SherlockListFragment sCChapterFragment;
|
|
||||||
|
|
||||||
private static final int POS_COVER = 0;
|
|
||||||
private static final int POS_DESCR = 1;
|
|
||||||
private static final int POS_CHAPTERS = 2;
|
|
||||||
|
|
||||||
public static final int NUM_ITEMS_WITH_CHAPTERS = 3;
|
|
||||||
public static final int NUM_ITEMS_WITHOUT_CHAPTERS = 2;
|
|
||||||
|
|
||||||
public MediaPlayerPagerAdapter(FragmentManager fm) {
|
|
||||||
super(fm);
|
|
||||||
numItems = NUM_ITEMS_WITHOUT_CHAPTERS;
|
|
||||||
FeedMedia media = AudioplayerActivity.this.controller.getMedia();
|
|
||||||
if (media != null && media.getItem().getChapters() != null) {
|
|
||||||
numItems = NUM_ITEMS_WITH_CHAPTERS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
FeedMedia media = controller.getMedia();
|
|
||||||
if (media != null) {
|
|
||||||
switch (position) {
|
|
||||||
case POS_COVER:
|
|
||||||
AudioplayerActivity.this.coverFragment = CoverFragment
|
|
||||||
.newInstance(media.getItem());
|
|
||||||
return AudioplayerActivity.this.coverFragment;
|
|
||||||
case POS_DESCR:
|
|
||||||
AudioplayerActivity.this.descriptionFragment = ItemDescriptionFragment
|
|
||||||
.newInstance(media.getItem());
|
|
||||||
return AudioplayerActivity.this.descriptionFragment;
|
|
||||||
case POS_CHAPTERS:
|
|
||||||
sCChapterFragment = new SherlockListFragment() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onListItemClick(ListView l, View v,
|
|
||||||
int position, long id) {
|
|
||||||
super.onListItemClick(l, v, position, id);
|
|
||||||
Chapter chapter = (Chapter) this.getListAdapter()
|
|
||||||
.getItem(position);
|
|
||||||
controller.seekToChapter(chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
sCChapterFragment.setListAdapter(new ChapterListAdapter(
|
|
||||||
AudioplayerActivity.this, 0, media.getItem()
|
|
||||||
.getChapters(), media));
|
|
||||||
|
|
||||||
return sCChapterFragment;
|
|
||||||
default:
|
|
||||||
return CoverFragment.newInstance(null);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return CoverFragment.newInstance(null);
|
butNavRight.setVisibility(View.GONE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getPageTitle(int position) {
|
|
||||||
switch (position) {
|
|
||||||
case POS_COVER:
|
|
||||||
return AudioplayerActivity.this.getString(R.string.cover_label);
|
|
||||||
case POS_DESCR:
|
|
||||||
return AudioplayerActivity.this
|
|
||||||
.getString(R.string.shownotes_label);
|
|
||||||
case POS_CHAPTERS:
|
|
||||||
return AudioplayerActivity.this
|
|
||||||
.getString(R.string.chapters_label);
|
|
||||||
default:
|
|
||||||
return super.getPageTitle(position);
|
|
||||||
}
|
}
|
||||||
|
if (currentlyShownPosition == -1) {
|
||||||
|
switchToFragment(POS_COVER);
|
||||||
|
}
|
||||||
|
if (currentlyShownFragment instanceof AudioplayerContentFragment) {
|
||||||
|
((AudioplayerContentFragment) currentlyShownFragment)
|
||||||
|
.onDataSetChanged(media);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return numItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumItems(int numItems) {
|
|
||||||
this.numItems = numItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemPosition(Object object) {
|
|
||||||
return POSITION_UNCHANGED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyMediaPositionChanged() {
|
public void notifyMediaPositionChanged() {
|
||||||
if (sCChapterFragment != null) {
|
if (chapterFragment != null) {
|
||||||
ArrayAdapter<SimpleChapter> adapter = (ArrayAdapter<SimpleChapter>) sCChapterFragment
|
ArrayAdapter<SimpleChapter> adapter = (ArrayAdapter<SimpleChapter>) chapterFragment
|
||||||
.getListAdapter();
|
.getListAdapter();
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onReloadNotification(int notificationCode) {
|
protected void onReloadNotification(int notificationCode) {
|
||||||
if (notificationCode == PlaybackService.EXTRA_CODE_VIDEO) {
|
if (notificationCode == PlaybackService.EXTRA_CODE_VIDEO) {
|
||||||
@ -202,4 +258,8 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
|||||||
clearStatusMsg();
|
clearStatusMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface AudioplayerContentFragment {
|
||||||
|
public void onDataSetChanged(FeedMedia media);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.danoeh.antennapod.fragment;
|
package de.danoeh.antennapod.fragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore.Audio.AudioColumns;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -12,6 +13,7 @@ import com.actionbarsherlock.app.SherlockFragment;
|
|||||||
|
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.activity.AudioplayerActivity.AudioplayerContentFragment;
|
||||||
import de.danoeh.antennapod.asynctask.FeedImageLoader;
|
import de.danoeh.antennapod.asynctask.FeedImageLoader;
|
||||||
import de.danoeh.antennapod.feed.Feed;
|
import de.danoeh.antennapod.feed.Feed;
|
||||||
import de.danoeh.antennapod.feed.FeedItem;
|
import de.danoeh.antennapod.feed.FeedItem;
|
||||||
@ -19,7 +21,8 @@ import de.danoeh.antennapod.feed.FeedManager;
|
|||||||
import de.danoeh.antennapod.feed.FeedMedia;
|
import de.danoeh.antennapod.feed.FeedMedia;
|
||||||
|
|
||||||
/** Displays the cover and the title of a FeedItem. */
|
/** Displays the cover and the title of a FeedItem. */
|
||||||
public class CoverFragment extends SherlockFragment {
|
public class CoverFragment extends SherlockFragment implements
|
||||||
|
AudioplayerContentFragment {
|
||||||
private static final String TAG = "CoverFragment";
|
private static final String TAG = "CoverFragment";
|
||||||
private static final String ARG_FEED_ID = "arg.feedId";
|
private static final String ARG_FEED_ID = "arg.feedId";
|
||||||
private static final String ARG_FEEDITEM_ID = "arg.feedItem";
|
private static final String ARG_FEEDITEM_ID = "arg.feedItem";
|
||||||
@ -30,6 +33,8 @@ public class CoverFragment extends SherlockFragment {
|
|||||||
private TextView txtvFeed;
|
private TextView txtvFeed;
|
||||||
private ImageView imgvCover;
|
private ImageView imgvCover;
|
||||||
|
|
||||||
|
private boolean viewCreated = false;
|
||||||
|
|
||||||
public static CoverFragment newInstance(FeedItem item) {
|
public static CoverFragment newInstance(FeedItem item) {
|
||||||
CoverFragment f = new CoverFragment();
|
CoverFragment f = new CoverFragment();
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
@ -44,7 +49,7 @@ public class CoverFragment extends SherlockFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setRetainInstance(true);
|
||||||
FeedManager manager = FeedManager.getInstance();
|
FeedManager manager = FeedManager.getInstance();
|
||||||
FeedItem item = null;
|
FeedItem item = null;
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
@ -70,10 +75,12 @@ public class CoverFragment extends SherlockFragment {
|
|||||||
txtvTitle = (TextView) root.findViewById(R.id.txtvTitle);
|
txtvTitle = (TextView) root.findViewById(R.id.txtvTitle);
|
||||||
txtvFeed = (TextView) root.findViewById(R.id.txtvFeed);
|
txtvFeed = (TextView) root.findViewById(R.id.txtvFeed);
|
||||||
imgvCover = (ImageView) root.findViewById(R.id.imgvCover);
|
imgvCover = (ImageView) root.findViewById(R.id.imgvCover);
|
||||||
|
viewCreated = true;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMediaInfo() {
|
private void loadMediaInfo() {
|
||||||
|
if (media != null) {
|
||||||
imgvCover.post(new Runnable() {
|
imgvCover.post(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,10 +92,15 @@ public class CoverFragment extends SherlockFragment {
|
|||||||
|
|
||||||
txtvTitle.setText(media.getItem().getTitle());
|
txtvTitle.setText(media.getItem().getTitle());
|
||||||
txtvFeed.setText(media.getItem().getFeed().getTitle());
|
txtvFeed.setText(media.getItem().getFeed().getTitle());
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "loadMediaInfo was called while media was null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "On Start");
|
||||||
super.onStart();
|
super.onStart();
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
@ -99,4 +111,13 @@ public class CoverFragment extends SherlockFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataSetChanged(FeedMedia media) {
|
||||||
|
this.media = media;
|
||||||
|
if (viewCreated) {
|
||||||
|
loadMediaInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user