Replaced Ion with Glide. Big performance boost, and should also fix the FCs many people get because of recycled bitmaps. Fixed the ripple flickering by using ?selectableItemBackground on Lollipop again instead of custom ripple. Search is broken for now, remake in progress.
This commit is contained in:
parent
c75ab6bf15
commit
ee2b661eb4
34 changed files with 448 additions and 667 deletions
|
|
@ -4,6 +4,7 @@ import android.annotation.TargetApi;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.Pair;
|
||||
|
|
@ -17,6 +18,11 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.util.DialogUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
|
||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
|
@ -37,8 +43,6 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.koushikdutta.async.future.FutureCallback;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
import com.nineoldandroids.view.ViewHelper;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
|
|
@ -170,51 +174,54 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
}
|
||||
|
||||
private void setUpAlbumArtAndApplyPalette() {
|
||||
albumArtImageView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Ion.with(AlbumDetailActivity.this)
|
||||
.load(MusicUtil.getAlbumArtUri(album.id).toString())
|
||||
.withBitmap()
|
||||
.smartSize(false)
|
||||
.asBitmap()
|
||||
.setCallback(new FutureCallback<Bitmap>() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onCompleted(Exception e, Bitmap result) {
|
||||
if (result != null) {
|
||||
albumArtImageView.setImageBitmap(result);
|
||||
applyPalette(result);
|
||||
} else {
|
||||
albumArtImageView.setImageResource(R.drawable.default_album_art);
|
||||
resetColors();
|
||||
}
|
||||
if (Util.isAtLeastLollipop()) startPostponedEnterTransition();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Glide.with(AlbumDetailActivity.this)
|
||||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(album.id))
|
||||
.error(R.drawable.default_album_art)
|
||||
.listener(new RequestListener<Uri, GlideDrawable>() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
applyPalette(null);
|
||||
if (Util.isAtLeastLollipop()) startPostponedEnterTransition();
|
||||
return false;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
applyPalette(((GlideBitmapDrawable) resource).getBitmap());
|
||||
if (Util.isAtLeastLollipop()) startPostponedEnterTransition();
|
||||
// workaround for glide not working well with shared element, dont remove this redundant looking call!
|
||||
albumArtImageView.setImageDrawable(resource);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(albumArtImageView);
|
||||
}
|
||||
|
||||
private void applyPalette(Bitmap bitmap) {
|
||||
Palette.from(bitmap)
|
||||
.generate(new Palette.PaletteAsyncListener() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||
if (vibrantSwatch != null) {
|
||||
toolbarColor = vibrantSwatch.getRgb();
|
||||
albumTitleView.setBackgroundColor(toolbarColor);
|
||||
albumTitleView.setTextColor(vibrantSwatch.getTitleTextColor());
|
||||
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(AlbumDetailActivity.this).coloredNavigationBarAlbumEnabled())
|
||||
getWindow().setNavigationBarColor(toolbarColor);
|
||||
notifyTaskColorChange(toolbarColor);
|
||||
} else {
|
||||
resetColors();
|
||||
if (bitmap != null) {
|
||||
Palette.from(bitmap)
|
||||
.generate(new Palette.PaletteAsyncListener() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||
if (vibrantSwatch != null) {
|
||||
toolbarColor = vibrantSwatch.getRgb();
|
||||
albumTitleView.setBackgroundColor(toolbarColor);
|
||||
albumTitleView.setTextColor(vibrantSwatch.getTitleTextColor());
|
||||
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(AlbumDetailActivity.this).coloredNavigationBarAlbumEnabled())
|
||||
getWindow().setNavigationBarColor(toolbarColor);
|
||||
notifyTaskColorChange(toolbarColor);
|
||||
} else {
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ import android.widget.Toast;
|
|||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.util.DialogUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
|
||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
|
@ -47,8 +52,6 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.koushikdutta.async.future.FutureCallback;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
import com.nineoldandroids.view.ViewHelper;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
|
|
@ -265,51 +268,50 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
LastFMArtistImageUrlLoader.loadArtistImageUrl(this, artist.name, forceDownload, new LastFMArtistImageUrlLoader.ArtistImageUrlLoaderCallback() {
|
||||
@Override
|
||||
public void onArtistImageUrlLoaded(final String url) {
|
||||
artistImage.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Ion.with(ArtistDetailActivity.this)
|
||||
.load(url)
|
||||
.withBitmap()
|
||||
.smartSize(false)
|
||||
.asBitmap()
|
||||
.setCallback(new FutureCallback<Bitmap>() {
|
||||
@Override
|
||||
public void onCompleted(Exception e, Bitmap result) {
|
||||
if (result != null) {
|
||||
artistImage.setImageBitmap(result);
|
||||
applyPalette(result);
|
||||
} else {
|
||||
artistImage.setImageResource(R.drawable.default_artist_image);
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Glide.with(ArtistDetailActivity.this)
|
||||
.load(url)
|
||||
.error(R.drawable.default_artist_image)
|
||||
.listener(new RequestListener<String, GlideDrawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
applyPalette(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
applyPalette(((GlideBitmapDrawable) resource).getBitmap());
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(artistImage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void applyPalette(Bitmap bitmap) {
|
||||
Palette.from(bitmap)
|
||||
.generate(new Palette.PaletteAsyncListener() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||
if (vibrantSwatch != null) {
|
||||
toolbarColor = vibrantSwatch.getRgb();
|
||||
artistNameTv.setBackgroundColor(vibrantSwatch.getRgb());
|
||||
artistNameTv.setTextColor(vibrantSwatch.getTitleTextColor());
|
||||
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(ArtistDetailActivity.this).coloredNavigationBarArtistEnabled())
|
||||
getWindow().setNavigationBarColor(vibrantSwatch.getRgb());
|
||||
notifyTaskColorChange(toolbarColor);
|
||||
} else {
|
||||
resetColors();
|
||||
if (bitmap != null) {
|
||||
Palette.from(bitmap)
|
||||
.generate(new Palette.PaletteAsyncListener() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||
if (vibrantSwatch != null) {
|
||||
toolbarColor = vibrantSwatch.getRgb();
|
||||
artistNameTv.setBackgroundColor(vibrantSwatch.getRgb());
|
||||
artistNameTv.setTextColor(vibrantSwatch.getTitleTextColor());
|
||||
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(ArtistDetailActivity.this).coloredNavigationBarArtistEnabled())
|
||||
getWindow().setNavigationBarColor(vibrantSwatch.getRgb());
|
||||
notifyTaskColorChange(toolbarColor);
|
||||
} else {
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.kabouzeid.gramophone.ui.activities;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
|
@ -28,6 +27,7 @@ import android.widget.FrameLayout;
|
|||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.PagerAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.AboutDialog;
|
||||
|
|
@ -49,8 +49,6 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.koushikdutta.async.future.FutureCallback;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -204,22 +202,13 @@ public class MainActivity extends AbsFabActivity
|
|||
if (navigationDrawerFragment != null) {
|
||||
Song song = MusicPlayerRemote.getCurrentSong();
|
||||
if (song.id != -1) {
|
||||
Ion.with(this)
|
||||
.load(MusicUtil.getAlbumArtUri(song.albumId).toString())
|
||||
.withBitmap()
|
||||
.smartSize(false)
|
||||
.asBitmap()
|
||||
.setCallback(new FutureCallback<Bitmap>() {
|
||||
@Override
|
||||
public void onCompleted(Exception e, Bitmap result) {
|
||||
if (result != null)
|
||||
navigationDrawerFragment.getAlbumArtImageView().setImageBitmap(result);
|
||||
else
|
||||
navigationDrawerFragment.getAlbumArtImageView().setImageResource(R.drawable.default_album_art);
|
||||
}
|
||||
});
|
||||
navigationDrawerFragment.getSongTitle().setText(song.title);
|
||||
navigationDrawerFragment.getSongArtist().setText(song.artistName);
|
||||
Glide.with(this)
|
||||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(song.albumId))
|
||||
.error(R.drawable.default_album_art)
|
||||
.placeholder(R.drawable.default_album_art)
|
||||
.into(navigationDrawerFragment.getAlbumArtImageView());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.graphics.Palette;
|
||||
|
|
@ -22,6 +23,11 @@ import android.widget.Toast;
|
|||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.afollestad.materialdialogs.util.DialogUtils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
|
||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
|
|
@ -41,8 +47,6 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.koushikdutta.async.future.FutureCallback;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
import com.nineoldandroids.view.ViewPropertyAnimator;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
|
|
@ -56,7 +60,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
|
||||
private Song song;
|
||||
private ImageView albumArt;
|
||||
private ImageView artistArt;
|
||||
private ImageView artistImage;
|
||||
private TextView songTitle;
|
||||
private TextView songArtist;
|
||||
private TextView currentSongProgress;
|
||||
|
|
@ -118,7 +122,7 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
repeatButton = (ImageButton) findViewById(R.id.repeat_button);
|
||||
shuffleButton = (ImageButton) findViewById(R.id.shuffle_button);
|
||||
albumArt = (ImageView) findViewById(R.id.album_art);
|
||||
artistArt = (ImageView) findViewById(R.id.artist_image);
|
||||
artistImage = (ImageView) findViewById(R.id.artist_image);
|
||||
songTitle = (TextView) findViewById(R.id.song_title);
|
||||
songArtist = (TextView) findViewById(R.id.song_artist);
|
||||
currentSongProgress = (TextView) findViewById(R.id.song_current_progress);
|
||||
|
|
@ -294,48 +298,47 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
}
|
||||
|
||||
private void setUpAlbumArtAndApplyPalette() {
|
||||
albumArt.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Ion.with(MusicControllerActivity.this)
|
||||
.load(MusicUtil.getAlbumArtUri(song.albumId).toString())
|
||||
.withBitmap()
|
||||
.smartSize(false)
|
||||
.asBitmap()
|
||||
.setCallback(new FutureCallback<Bitmap>() {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onCompleted(Exception e, Bitmap result) {
|
||||
if (result != null) {
|
||||
albumArt.setImageBitmap(result);
|
||||
applyPalette(result);
|
||||
} else {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Glide.with(this)
|
||||
.loadFromMediaStore(MusicUtil.getAlbumArtUri(song.albumId))
|
||||
.error(R.drawable.default_album_art)
|
||||
.placeholder(R.drawable.default_album_art)
|
||||
.listener(new RequestListener<Uri, GlideDrawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
applyPalette(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
applyPalette(((GlideBitmapDrawable) resource).getBitmap());
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(albumArt);
|
||||
}
|
||||
|
||||
private void applyPalette(Bitmap bitmap) {
|
||||
Palette.from(bitmap)
|
||||
.generate(new Palette.PaletteAsyncListener() {
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||
if (vibrantSwatch != null) {
|
||||
final int swatchRgb = vibrantSwatch.getRgb();
|
||||
animateColorChange(swatchRgb);
|
||||
songTitle.setTextColor(vibrantSwatch.getTitleTextColor());
|
||||
songArtist.setTextColor(vibrantSwatch.getBodyTextColor());
|
||||
notifyTaskColorChange(swatchRgb);
|
||||
} else {
|
||||
resetColors();
|
||||
if (bitmap != null) {
|
||||
Palette.from(bitmap)
|
||||
.generate(new Palette.PaletteAsyncListener() {
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
|
||||
if (vibrantSwatch != null) {
|
||||
final int swatchRgb = vibrantSwatch.getRgb();
|
||||
animateColorChange(swatchRgb);
|
||||
songTitle.setTextColor(vibrantSwatch.getTitleTextColor());
|
||||
songArtist.setTextColor(vibrantSwatch.getBodyTextColor());
|
||||
notifyTaskColorChange(swatchRgb);
|
||||
} else {
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
resetColors();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetColors() {
|
||||
|
|
@ -364,14 +367,15 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
}
|
||||
|
||||
private void setUpArtistArt() {
|
||||
if (artistArt != null) {
|
||||
artistArt.setImageResource(R.drawable.default_artist_image);
|
||||
if (artistImage != null) {
|
||||
artistImage.setImageResource(R.drawable.default_artist_image);
|
||||
LastFMArtistImageUrlLoader.loadArtistImageUrl(this, song.artistName, false, new LastFMArtistImageUrlLoader.ArtistImageUrlLoaderCallback() {
|
||||
@Override
|
||||
public void onArtistImageUrlLoaded(String url) {
|
||||
Ion.with(artistArt)
|
||||
Glide.with(MusicControllerActivity.this)
|
||||
.load(url)
|
||||
.error(R.drawable.default_artist_image)
|
||||
.load(url);
|
||||
.into(artistImage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,49 +2,33 @@ package com.kabouzeid.gramophone.ui.activities;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.SearchAdapter;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.loader.AlbumLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistLoader;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.SearchEntry;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchActivity extends AbsBaseActivity {
|
||||
|
||||
public static final String TAG = SearchActivity.class.getSimpleName();
|
||||
private ListView listView;
|
||||
private RecyclerView recyclerView;
|
||||
private SearchView searchView;
|
||||
private SearchAdapter searchAdapter;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
|
|
@ -54,38 +38,11 @@ public class SearchActivity extends AbsBaseActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_search);
|
||||
|
||||
listView = (ListView) findViewById(R.id.list);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Object item = parent.getItemAtPosition(position);
|
||||
if (item instanceof SearchEntry) {
|
||||
if (item instanceof Song) {
|
||||
ArrayList<Song> playList = new ArrayList<>();
|
||||
playList.add((Song) item);
|
||||
MusicPlayerRemote.openQueue(playList, 0, true);
|
||||
} else if (item instanceof Album) {
|
||||
NavigationUtil.goToAlbum(SearchActivity.this,
|
||||
((Album) item).id,
|
||||
new Pair[]{
|
||||
Pair.create(view.findViewById(R.id.image),
|
||||
getResources().getString(R.string.transition_album_cover)
|
||||
)
|
||||
});
|
||||
} else if (item instanceof Artist) {
|
||||
NavigationUtil.goToArtist(SearchActivity.this,
|
||||
((Artist) item).id,
|
||||
new Pair[]{
|
||||
Pair.create(view.findViewById(R.id.image),
|
||||
getResources().getString(R.string.transition_artist_image)
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
searchAdapter = new SearchAdapter(this);
|
||||
recyclerView.setAdapter(searchAdapter);
|
||||
|
||||
listView.setOnTouchListener(new View.OnTouchListener() {
|
||||
recyclerView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Util.hideSoftKeyboard(SearchActivity.this);
|
||||
|
|
@ -120,13 +77,13 @@ public class SearchActivity extends AbsBaseActivity {
|
|||
@Override
|
||||
public void enableViews() {
|
||||
super.enableViews();
|
||||
listView.setEnabled(true);
|
||||
recyclerView.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableViews() {
|
||||
super.disableViews();
|
||||
listView.setEnabled(false);
|
||||
recyclerView.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -192,65 +149,6 @@ public class SearchActivity extends AbsBaseActivity {
|
|||
}
|
||||
|
||||
private void search(String query) {
|
||||
List<SearchEntry> results = new ArrayList<>();
|
||||
if (!query.trim().equals("")) {
|
||||
LabelEntry songLabel = new LabelEntry(getResources().getString(R.string.songs).toUpperCase());
|
||||
results.add(songLabel);
|
||||
List<Song> songs = SongLoader.getSongs(this, query);
|
||||
results.addAll(songs);
|
||||
songLabel.setNumber(songs.size());
|
||||
|
||||
LabelEntry artistLabel = new LabelEntry(getResources().getString(R.string.artists).toUpperCase());
|
||||
results.add(artistLabel);
|
||||
List<Artist> artists = ArtistLoader.getArtists(this, query);
|
||||
results.addAll(artists);
|
||||
artistLabel.setNumber(artists.size());
|
||||
|
||||
LabelEntry albumLabel = new LabelEntry(getResources().getString(R.string.albums).toUpperCase());
|
||||
results.add(albumLabel);
|
||||
List<Album> albums = AlbumLoader.getAlbums(this, query);
|
||||
results.addAll(albums);
|
||||
albumLabel.setNumber(albums.size());
|
||||
}
|
||||
if (results.size() <= 3) {
|
||||
results.clear();
|
||||
results.add(new LabelEntry(getResources().getString(R.string.no_results).toUpperCase()));
|
||||
}
|
||||
ArrayAdapter adapter = new SearchAdapter(this, results);
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
public static class LabelEntry implements SearchEntry {
|
||||
final String title;
|
||||
String label;
|
||||
|
||||
public LabelEntry(String label) {
|
||||
this.label = label;
|
||||
this.title = label;
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
if (number != -1) {
|
||||
label = title + " (" + number + ")";
|
||||
} else {
|
||||
label = title;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubTitle() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(Context context, ImageView imageView) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import com.kabouzeid.gramophone.util.MusicUtil;
|
|||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import com.nineoldandroids.view.ViewHelper;
|
||||
import com.nineoldandroids.view.ViewPropertyAnimator;
|
||||
|
|
@ -378,11 +377,9 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
|||
}
|
||||
if (deleteArtwork) {
|
||||
MusicUtil.deleteAlbumArt(AbsTagEditorActivity.this, getId());
|
||||
Ion.getDefault(AbsTagEditorActivity.this).getBitmapCache().clear();
|
||||
Ion.getDefault(AbsTagEditorActivity.this).getCache().clear();
|
||||
//Glide.get(AbsTagEditorActivity.this).clearMemory();
|
||||
} else if (artwork != null) {
|
||||
Ion.getDefault(AbsTagEditorActivity.this).getBitmapCache().clear();
|
||||
Ion.getDefault(AbsTagEditorActivity.this).getCache().clear();
|
||||
//Glide.get(AbsTagEditorActivity.this).clearMemory();
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -9,14 +9,15 @@ import android.util.Log;
|
|||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.lastfm.album.LastFMAlbumImageUrlLoader;
|
||||
import com.kabouzeid.gramophone.loader.AlbumSongLoader;
|
||||
import com.kabouzeid.gramophone.loader.SongFilePathLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.koushikdutta.async.future.FutureCallback;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
|
||||
import org.jaudiotagger.tag.FieldKey;
|
||||
import org.jaudiotagger.tag.images.Artwork;
|
||||
|
|
@ -94,17 +95,22 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
|||
LastFMAlbumImageUrlLoader.loadAlbumImageUrl(this, albumTitleStr, albumArtistNameStr, new LastFMAlbumImageUrlLoader.AlbumImageUrlLoaderCallback() {
|
||||
@Override
|
||||
public void onAlbumImageUrlLoaded(String url) {
|
||||
Ion.with(AlbumTagEditorActivity.this)
|
||||
Glide.with(AlbumTagEditorActivity.this)
|
||||
.load(url)
|
||||
.withBitmap()
|
||||
.resize(500, 500)
|
||||
.centerCrop()
|
||||
.asBitmap()
|
||||
.setCallback(new FutureCallback<Bitmap>() {
|
||||
.centerCrop()
|
||||
.listener(new RequestListener<String, Bitmap>() {
|
||||
@Override
|
||||
public void onCompleted(Exception e, Bitmap result) {
|
||||
if (result != null) {
|
||||
albumArtBitmap = result;
|
||||
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
|
||||
Toast.makeText(AlbumTagEditorActivity.this,
|
||||
R.string.failed_download_albumart, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
if (resource != null) {
|
||||
albumArtBitmap = resource;
|
||||
setImageBitmap(albumArtBitmap);
|
||||
deleteAlbumArt = false;
|
||||
dataChanged();
|
||||
|
|
@ -113,8 +119,10 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
|||
Toast.makeText(AlbumTagEditorActivity.this,
|
||||
R.string.failed_download_albumart, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
})
|
||||
.into(500, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -183,24 +191,29 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text
|
|||
|
||||
@Override
|
||||
protected void loadImageFromFile(final Uri selectedFileUri) {
|
||||
Ion.with(this)
|
||||
.load(selectedFileUri.toString())
|
||||
.withBitmap()
|
||||
.resize(500, 500)
|
||||
.centerCrop()
|
||||
Glide.with(this)
|
||||
.load(selectedFileUri)
|
||||
.asBitmap()
|
||||
.setCallback(new FutureCallback<Bitmap>() {
|
||||
.centerCrop()
|
||||
.listener(new RequestListener<Uri, Bitmap>() {
|
||||
@Override
|
||||
public void onCompleted(Exception e, Bitmap result) {
|
||||
if (result != null) {
|
||||
albumArtBitmap = result;
|
||||
public boolean onException(Exception e, Uri model, Target<Bitmap> target, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Bitmap resource, Uri model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
if (resource != null) {
|
||||
albumArtBitmap = resource;
|
||||
setImageBitmap(albumArtBitmap);
|
||||
deleteAlbumArt = false;
|
||||
dataChanged();
|
||||
setResult(RESULT_OK);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
})
|
||||
.into(500, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue