diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-07-27 23:29:47 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-07-30 12:42:01 +0200 |
commit | 09c4736867acafee9c008caa8ab78f7b3c4cef68 (patch) | |
tree | 04b5ca6258c3449a9ee89fc832edc44c652fe0de /src/de/danoeh/antennapod/fragment | |
parent | 460e061d35e45268d3dcfebeba00e7231ce8cfd0 (diff) | |
download | AntennaPod-09c4736867acafee9c008caa8ab78f7b3c4cef68.zip |
Replaced ImageLoader and DiskCache with Picasso
Implemented Picasso Downloaders
Replaced ImageLoader and DiskCache with Picasso
Removed ImageLoader, DiskCache code
Diffstat (limited to 'src/de/danoeh/antennapod/fragment')
3 files changed, 290 insertions, 275 deletions
diff --git a/src/de/danoeh/antennapod/fragment/CoverFragment.java b/src/de/danoeh/antennapod/fragment/CoverFragment.java index 0e1fe35e0..ffce518bf 100644 --- a/src/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/src/de/danoeh/antennapod/fragment/CoverFragment.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.fragment; +import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; @@ -7,91 +8,98 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.AudioplayerActivity.AudioplayerContentFragment; -import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.asynctask.PicassoProvider; import de.danoeh.antennapod.util.playback.Playable; -/** Displays the cover and the title of a FeedItem. */ +/** + * Displays the cover and the title of a FeedItem. + */ public class CoverFragment extends Fragment implements - AudioplayerContentFragment { - private static final String TAG = "CoverFragment"; - private static final String ARG_PLAYABLE = "arg.playable"; + AudioplayerContentFragment { + private static final String TAG = "CoverFragment"; + private static final String ARG_PLAYABLE = "arg.playable"; - private Playable media; + private Playable media; - private ImageView imgvCover; + private ImageView imgvCover; - private boolean viewCreated = false; + private boolean viewCreated = false; - public static CoverFragment newInstance(Playable item) { - CoverFragment f = new CoverFragment(); - if (item != null) { - Bundle args = new Bundle(); - args.putParcelable(ARG_PLAYABLE, item); - f.setArguments(args); - } - return f; - } + public static CoverFragment newInstance(Playable item) { + CoverFragment f = new CoverFragment(); + if (item != null) { + Bundle args = new Bundle(); + args.putParcelable(ARG_PLAYABLE, item); + f.setArguments(args); + } + return f; + } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setRetainInstance(true); - Bundle args = getArguments(); - if (args != null) { - media = args.getParcelable(ARG_PLAYABLE); - } else { - Log.e(TAG, TAG + " was called with invalid arguments"); - } - } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRetainInstance(true); + Bundle args = getArguments(); + if (args != null) { + media = args.getParcelable(ARG_PLAYABLE); + } else { + Log.e(TAG, TAG + " was called with invalid arguments"); + } + } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View root = inflater.inflate(R.layout.cover_fragment, container, false); - imgvCover = (ImageView) root.findViewById(R.id.imgvCover); - viewCreated = true; - return root; - } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.cover_fragment, container, false); + imgvCover = (ImageView) root.findViewById(R.id.imgvCover); + viewCreated = true; + return root; + } - private void loadMediaInfo() { - if (media != null) { - imgvCover.post(new Runnable() { + private void loadMediaInfo() { + if (media != null) { + imgvCover.post(new Runnable() { - @Override - public void run() { - ImageLoader.getInstance().loadCoverBitmap( - media, imgvCover); - } - }); - } else { - Log.w(TAG, "loadMediaInfo was called while media was null"); - } - } + @Override + public void run() { + Context c = getActivity(); + if (c != null) { + PicassoProvider.getMediaMetadataPicassoInstance(c) + .load(media.getImageUri()) + .into(imgvCover); + } + } + }); + } else { + Log.w(TAG, "loadMediaInfo was called while media was null"); + } + } - @Override - public void onStart() { - if (BuildConfig.DEBUG) - Log.d(TAG, "On Start"); - super.onStart(); - if (media != null) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Loading media info"); - loadMediaInfo(); - } else { - Log.w(TAG, "Unable to load media info: media was null"); - } - } + @Override + public void onStart() { + if (BuildConfig.DEBUG) + Log.d(TAG, "On Start"); + super.onStart(); + if (media != null) { + if (BuildConfig.DEBUG) + Log.d(TAG, "Loading media info"); + loadMediaInfo(); + } else { + Log.w(TAG, "Unable to load media info: media was null"); + } + } - @Override - public void onDataSetChanged(Playable media) { - this.media = media; - if (viewCreated) { - loadMediaInfo(); - } + @Override + public void onDataSetChanged(Playable media) { + this.media = media; + if (viewCreated) { + loadMediaInfo(); + } - } + } } diff --git a/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index db47cd8a4..77587194b 100644 --- a/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -10,9 +10,10 @@ import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.asynctask.PicassoProvider; import de.danoeh.antennapod.service.playback.PlaybackService; import de.danoeh.antennapod.util.Converter; import de.danoeh.antennapod.util.playback.Playable; @@ -23,215 +24,216 @@ import de.danoeh.antennapod.util.playback.PlaybackController; * if the PlaybackService is running */ public class ExternalPlayerFragment extends Fragment { - private static final String TAG = "ExternalPlayerFragment"; - - private ViewGroup fragmentLayout; - private ImageView imgvCover; - private ViewGroup layoutInfo; - private TextView txtvTitle; - private ImageButton butPlay; - - private PlaybackController controller; - - public ExternalPlayerFragment() { - super(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View root = inflater.inflate(R.layout.external_player_fragment, - container, false); - fragmentLayout = (ViewGroup) root.findViewById(R.id.fragmentLayout); - imgvCover = (ImageView) root.findViewById(R.id.imgvCover); - layoutInfo = (ViewGroup) root.findViewById(R.id.layoutInfo); - txtvTitle = (TextView) root.findViewById(R.id.txtvTitle); - butPlay = (ImageButton) root.findViewById(R.id.butPlay); - - layoutInfo.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (BuildConfig.DEBUG) - Log.d(TAG, "layoutInfo was clicked"); - - if (controller.getMedia() != null) { - startActivity(PlaybackService.getPlayerActivityIntent( - getActivity(), controller.getMedia())); - } - } - }); - return root; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - controller = setupPlaybackController(); - butPlay.setOnClickListener(controller.newOnPlayButtonClickListener()); - } - - private PlaybackController setupPlaybackController() { - return new PlaybackController(getActivity(), true) { - - @Override - public void setupGUI() { - } - - @Override - public void onPositionObserverUpdate() { - } - - @Override - public void onReloadNotification(int code) { - } - - @Override - public void onBufferStart() { - // TODO Auto-generated method stub - - } - - @Override - public void onBufferEnd() { - // TODO Auto-generated method stub - - } - - @Override - public void onBufferUpdate(float progress) { - } - - @Override - public void onSleepTimerUpdate() { - } - - @Override - public void handleError(int code) { - } - - @Override - public ImageButton getPlayButton() { - return butPlay; - } - - @Override - public void postStatusMsg(int msg) { - } - - @Override - public void clearStatusMsg() { - } - - @Override - public boolean loadMediaInfo() { + private static final String TAG = "ExternalPlayerFragment"; + + private ViewGroup fragmentLayout; + private ImageView imgvCover; + private ViewGroup layoutInfo; + private TextView txtvTitle; + private ImageButton butPlay; + + private PlaybackController controller; + + public ExternalPlayerFragment() { + super(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.external_player_fragment, + container, false); + fragmentLayout = (ViewGroup) root.findViewById(R.id.fragmentLayout); + imgvCover = (ImageView) root.findViewById(R.id.imgvCover); + layoutInfo = (ViewGroup) root.findViewById(R.id.layoutInfo); + txtvTitle = (TextView) root.findViewById(R.id.txtvTitle); + butPlay = (ImageButton) root.findViewById(R.id.butPlay); + + layoutInfo.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + if (BuildConfig.DEBUG) + Log.d(TAG, "layoutInfo was clicked"); + + if (controller.getMedia() != null) { + startActivity(PlaybackService.getPlayerActivityIntent( + getActivity(), controller.getMedia())); + } + } + }); + return root; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + controller = setupPlaybackController(); + butPlay.setOnClickListener(controller.newOnPlayButtonClickListener()); + } + + private PlaybackController setupPlaybackController() { + return new PlaybackController(getActivity(), true) { + + @Override + public void setupGUI() { + } + + @Override + public void onPositionObserverUpdate() { + } + + @Override + public void onReloadNotification(int code) { + } + + @Override + public void onBufferStart() { + // TODO Auto-generated method stub + + } + + @Override + public void onBufferEnd() { + // TODO Auto-generated method stub + + } + + @Override + public void onBufferUpdate(float progress) { + } + + @Override + public void onSleepTimerUpdate() { + } + + @Override + public void handleError(int code) { + } + + @Override + public ImageButton getPlayButton() { + return butPlay; + } + + @Override + public void postStatusMsg(int msg) { + } + + @Override + public void clearStatusMsg() { + } + + @Override + public boolean loadMediaInfo() { ExternalPlayerFragment fragment = ExternalPlayerFragment.this; if (fragment != null) { - return fragment.loadMediaInfo(); + return fragment.loadMediaInfo(); } else { return false; } - } - - @Override - public void onAwaitingVideoSurface() { - } - - @Override - public void onServiceQueried() { - } - - @Override - public void onShutdownNotification() { - if (fragmentLayout != null) { - fragmentLayout.setVisibility(View.GONE); - } - controller = setupPlaybackController(); - if (butPlay != null) { - butPlay.setOnClickListener(controller - .newOnPlayButtonClickListener()); - } - - } - - @Override - public void onPlaybackEnd() { - if (fragmentLayout != null) { - fragmentLayout.setVisibility(View.GONE); - } - controller = setupPlaybackController(); - if (butPlay != null) { - butPlay.setOnClickListener(controller - .newOnPlayButtonClickListener()); - } - } - - @Override - public void onPlaybackSpeedChange() { - // TODO Auto-generated method stub - - } - }; - } - - @Override - public void onResume() { - super.onResume(); - controller.init(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (BuildConfig.DEBUG) - Log.d(TAG, "Fragment is about to be destroyed"); - if (controller != null) { - controller.release(); - } - } - - @Override - public void onPause() { - super.onPause(); - if (controller != null) { - controller.pause(); - } - } - - private boolean loadMediaInfo() { - if (BuildConfig.DEBUG) - Log.d(TAG, "Loading media info"); - if (controller.serviceAvailable()) { - Playable media = controller.getMedia(); - if (media != null) { - txtvTitle.setText(media.getEpisodeTitle()); - ImageLoader.getInstance().loadThumbnailBitmap( - media, - imgvCover, - (int) getActivity().getResources().getDimension( - R.dimen.external_player_height)); - - fragmentLayout.setVisibility(View.VISIBLE); - if (controller.isPlayingVideo()) { - butPlay.setVisibility(View.GONE); - } else { - butPlay.setVisibility(View.VISIBLE); - } + } + + @Override + public void onAwaitingVideoSurface() { + } + + @Override + public void onServiceQueried() { + } + + @Override + public void onShutdownNotification() { + if (fragmentLayout != null) { + fragmentLayout.setVisibility(View.GONE); + } + controller = setupPlaybackController(); + if (butPlay != null) { + butPlay.setOnClickListener(controller + .newOnPlayButtonClickListener()); + } + + } + + @Override + public void onPlaybackEnd() { + if (fragmentLayout != null) { + fragmentLayout.setVisibility(View.GONE); + } + controller = setupPlaybackController(); + if (butPlay != null) { + butPlay.setOnClickListener(controller + .newOnPlayButtonClickListener()); + } + } + + @Override + public void onPlaybackSpeedChange() { + // TODO Auto-generated method stub + + } + }; + } + + @Override + public void onResume() { + super.onResume(); + controller.init(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (BuildConfig.DEBUG) + Log.d(TAG, "Fragment is about to be destroyed"); + if (controller != null) { + controller.release(); + } + } + + @Override + public void onPause() { + super.onPause(); + if (controller != null) { + controller.pause(); + } + } + + private boolean loadMediaInfo() { + if (BuildConfig.DEBUG) + Log.d(TAG, "Loading media info"); + if (controller.serviceAvailable()) { + Playable media = controller.getMedia(); + if (media != null) { + txtvTitle.setText(media.getEpisodeTitle()); + + int imageSize = (int) getResources().getDimension(R.dimen.external_player_height); + PicassoProvider.getMediaMetadataPicassoInstance(getActivity()) + .load(media.getImageUri()) + .resize(imageSize, imageSize) + .into(imgvCover); + + fragmentLayout.setVisibility(View.VISIBLE); + if (controller.isPlayingVideo()) { + butPlay.setVisibility(View.GONE); + } else { + butPlay.setVisibility(View.VISIBLE); + } return true; - } else { - Log.w(TAG, - "loadMediaInfo was called while the media object of playbackService was null!"); + } else { + Log.w(TAG, + "loadMediaInfo was called while the media object of playbackService was null!"); return false; - } - } else { - Log.w(TAG, - "loadMediaInfo was called while playbackService was null!"); + } + } else { + Log.w(TAG, + "loadMediaInfo was called while playbackService was null!"); return false; - } - } + } + } - private String getPositionString(int position, int duration) { - return Converter.getDurationStringLong(position) + " / " - + Converter.getDurationStringLong(duration); - } + private String getPositionString(int position, int duration) { + return Converter.getDurationStringLong(position) + " / " + + Converter.getDurationStringLong(duration); + } } diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index d37f17b6d..5ef914f6c 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -34,7 +34,7 @@ import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.FeedItemlistAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; import de.danoeh.antennapod.asynctask.FeedRemover; -import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.asynctask.PicassoProvider; import de.danoeh.antennapod.dialog.ConfirmationDialog; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.dialog.FeedItemDialog; @@ -349,8 +349,13 @@ public class ItemlistFragment extends ListFragment { txtvTitle.setText(feed.getTitle()); txtvAuthor.setText(feed.getAuthor()); - ImageLoader.getInstance().loadThumbnailBitmap(feed.getImage(), imgvCover, - (int) getResources().getDimension(R.dimen.thumbnail_length_onlinefeedview)); + + int imageSize = (int) getResources().getDimension(R.dimen.thumbnail_length_onlinefeedview); + PicassoProvider.getDefaultPicassoInstance(getActivity()) + .load(feed.getImageUri()) + .resize(imageSize, imageSize) + .into(imgvCover); + if (feed.getLink() == null) { butVisitWebsite.setVisibility(View.INVISIBLE); } else { |