This commit is contained in:
David Development 2016-01-27 08:24:21 +01:00
parent eabde3b322
commit 09904d68c6
2 changed files with 40 additions and 20 deletions

View file

@ -21,6 +21,8 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import java.io.File;
@ -133,6 +135,7 @@ public class PodcastFragment extends Fragment {
}
}
long lastPodcastRssItemId = -1;
public void onEventMainThread(UpdatePodcastStatusEvent podcast) {
this.podcast = podcast;
@ -148,6 +151,12 @@ public class PodcastFragment extends Fragment {
btnPlayPausePodcastSlider.setImageResource(drawableId);
}
if(lastPodcastRssItemId != podcast.getRssItemId() && imgFavIcon != null) {
if(loadPodcastFavIcon()) { //Returns false if PodcastItem is not found (e.g. Service is not connected to Activity yet)
lastPodcastRssItemId = podcast.getRssItemId();
}
}
int hours = (int)(podcast.getCurrent() / (1000*60*60));
int minutes = (int)(podcast.getCurrent() % (1000*60*60)) / (1000*60);
int seconds = (int) ((podcast.getCurrent() % (1000*60*60)) % (1000*60) / 1000);
@ -184,6 +193,21 @@ public class PodcastFragment extends Fragment {
}
}
private boolean loadPodcastFavIcon() {
PodcastItem podcastItem = ((PodcastFragmentActivity) getActivity()).getCurrentPlayingPodcast();
if(podcastItem != null) {
String favIconUrl = podcastItem.favIcon;
DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder().
showImageOnLoading(R.drawable.default_feed_icon_light).
showImageForEmptyUri(R.drawable.default_feed_icon_light).
showImageOnFail(R.drawable.default_feed_icon_light).
build();
ImageLoader.getInstance().displayImage(favIconUrl, imgFavIcon, displayImageOptions);
}
return podcastItem != null;
}
@InjectView(R.id.btn_playPausePodcast) ImageButton btnPlayPausePodcast;
@InjectView(R.id.btn_playPausePodcastSlider) ImageButton btnPlayPausePodcastSlider;
@ -245,8 +269,6 @@ public class PodcastFragment extends Fragment {
PodcastSlidingUpPanelLayout sliding_layout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// create ContextThemeWrapper from the original Activity Context with the custom theme
Context context = new ContextThemeWrapper(getActivity(), R.style.Theme_AppCompat_Light_DarkActionBar);
// clone the inflater using the ContextThemeWrapper

View file

@ -23,8 +23,6 @@ import android.view.animation.Animation;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import java.io.File;
@ -51,7 +49,7 @@ import de.luhmer.owncloudnewsreader.widget.WidgetProvider;
public class PodcastFragmentActivity extends AppCompatActivity implements IPlayPausePodcastClicked {
PodcastPlaybackService mPodcastPlaybackService;
private PodcastPlaybackService mPodcastPlaybackService;
boolean mBound = false;
@ -80,7 +78,7 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
public void onGlobalLayout() {
rlVideoPodcastSurfaceWrapper.readVideoPosition();
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
rlVideoPodcastSurfaceWrapper.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
rlVideoPodcastSurfaceWrapper.getViewTreeObserver().removeOnGlobalLayoutListener(this);
@ -101,12 +99,22 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
};
*/
if(isMyServiceRunning(PodcastPlaybackService.class)) {
Intent intent = new Intent(this, PodcastPlaybackService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
super.onPostCreate(savedInstanceState);
}
@Override
protected void onStop() {
super.onStop();
unbindPodcastService();
}
private void unbindPodcastService() {
// Unbind from the service
if (mBound) {
unbindService(mConnection);
@ -175,9 +183,6 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
// We've bound to LocalService, cast the IBinder and get LocalService instance
PodcastPlaybackService.LocalBinder binder = (PodcastPlaybackService.LocalBinder) service;
mPodcastPlaybackService = binder.getService();
loadPodcastFavIcon();
mBound = true;
}
@ -187,17 +192,10 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
}
};
public void loadPodcastFavIcon() {
if(mPodcastPlaybackService.getCurrentlyPlayingPodcast() != null && mPodcastPlaybackService.getCurrentlyPlayingPodcast().favIcon != null) {
String favIconUrl = mPodcastPlaybackService.getCurrentlyPlayingPodcast().favIcon;
DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder().
showImageOnLoading(R.drawable.default_feed_icon_light).
showImageForEmptyUri(R.drawable.default_feed_icon_light).
showImageOnFail(R.drawable.default_feed_icon_light).
build();
ImageLoader.getInstance().displayImage(favIconUrl,mPodcastFragment.imgFavIcon,displayImageOptions);
}
public PodcastItem getCurrentPlayingPodcast() {
if(mPodcastPlaybackService != null)
return mPodcastPlaybackService.getCurrentlyPlayingPodcast();
return null;
}
public PodcastSlidingUpPanelLayout getSlidingLayout() {