From 09904d68c624a067c828a9c281c6b5fe03a6ad0f Mon Sep 17 00:00:00 2001 From: David Development Date: Wed, 27 Jan 2016 08:24:21 +0100 Subject: [PATCH] Fix #435 --- .../owncloudnewsreader/PodcastFragment.java | 26 ++++++++++++-- .../PodcastFragmentActivity.java | 34 +++++++++---------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java index a6e70af5..1a894030 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java @@ -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 diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java index 7f29b1b4..3ffbf46f 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java @@ -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() {