Performance improvements new artist detail

This commit is contained in:
Karim Abou Zeid 2015-03-15 18:12:21 +01:00
commit 0de409a459
16 changed files with 224 additions and 188 deletions

View file

@ -77,7 +77,9 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> {
SongDetailDialogHelper.getDialog(activity, songFile).show();
return true;
case R.id.action_go_to_album:
Pair[] albumPairs = null;
Pair[] albumPairs = new Pair[]{
Pair.create(albumArt, activity.getResources().getString(R.string.transition_album_cover))
};
if (activity instanceof AbsFabActivity)
albumPairs = ((AbsFabActivity) activity).getSharedViewsWithFab(albumPairs);
NavigationUtil.goToAlbum(activity, song.albumId, albumPairs);

View file

@ -104,7 +104,9 @@ public class SongAdapter extends RecyclerView.Adapter<SongAdapter.ViewHolder> {
SongDetailDialogHelper.getDialog(activity, songFile).show();
return true;
case R.id.action_go_to_album:
Pair[] albumPairs = null;
Pair[] albumPairs = new Pair[]{
Pair.create(albumArt, activity.getResources().getString(R.string.transition_album_cover))
};
if (activity instanceof AbsFabActivity)
albumPairs = ((AbsFabActivity) activity).getSharedViewsWithFab(albumPairs);
NavigationUtil.goToAlbum(activity, dataSet.get(getPosition()).albumId, albumPairs);

View file

@ -10,6 +10,8 @@ import android.support.v7.graphics.Palette;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.Spanned;
import android.transition.Transition;
import android.view.LayoutInflater;
import android.view.Menu;
@ -20,12 +22,13 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.AlbumAdapter;
import com.kabouzeid.gramophone.adapter.ArtistAlbumAdapter;
import com.kabouzeid.gramophone.adapter.songadapter.ArtistSongAdapter;
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistBiographyLoader;
import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistImageUrlLoader;
import com.kabouzeid.gramophone.loader.ArtistAlbumLoader;
import com.kabouzeid.gramophone.loader.ArtistLoader;
@ -76,6 +79,8 @@ public class ArtistDetailActivity extends AbsFabActivity {
private View songListHeader;
private RecyclerView albumRecyclerView;
private Spanned biography;
private SmallObservableScrollViewCallbacks observableScrollViewCallbacks = new SmallObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean b, boolean b2) {
@ -134,7 +139,9 @@ public class ArtistDetailActivity extends AbsFabActivity {
artistNameTv = (TextView) findViewById(R.id.artist_name);
songsBackgroundView = findViewById(R.id.list_background);
statusBar = findViewById(R.id.statusBar);
songListHeader = LayoutInflater.from(this).inflate(R.layout.artist_detail_header, songListView, false);
albumRecyclerView = (RecyclerView) songListHeader.findViewById(R.id.recycler_view);
}
private void setUpObservableListViewParams() {
@ -162,6 +169,7 @@ public class ArtistDetailActivity extends AbsFabActivity {
});
setUpSongListView();
setUpAlbumRecyclerView();
loadBiography();
}
private void setUpSongListView() {
@ -196,14 +204,33 @@ public class ArtistDetailActivity extends AbsFabActivity {
});
}
private void setUpAlbumRecyclerView(){
albumRecyclerView = (RecyclerView) songListHeader.findViewById(R.id.recycler_view);
private void setUpAlbumRecyclerView() {
albumRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
List<Album> albums = ArtistAlbumLoader.getArtistAlbumList(this, artist.id);
ArtistAlbumAdapter albumAdapter = new ArtistAlbumAdapter(this, albums);
albumRecyclerView.setAdapter(albumAdapter);
}
private void loadBiography() {
LastFMArtistBiographyLoader.loadArtistBio(this, artist.name, new LastFMArtistBiographyLoader.ArtistBioLoaderCallback() {
@Override
public void onArtistBioLoaded(String bio) {
if (bio != null && !bio.trim().equals("")) {
biography = Html.fromHtml(bio);
} else {
biography = null;
}
}
});
}
private MaterialDialog getBiographyDialog(){
return new MaterialDialog.Builder(ArtistDetailActivity.this)
.title(artist.name)
.content(biography)
.build();
}
private void setListViewPadding() {
if (Util.isInPortraitMode(this) || Util.isTablet(this)) {
songListView.setPadding(0, artistImageViewHeight + titleViewHeight, 0, Util.getNavigationBarHeight(this));
@ -285,6 +312,13 @@ public class ArtistDetailActivity extends AbsFabActivity {
case android.R.id.home:
super.onBackPressed();
return true;
case R.id.action_biography:
if(biography != null){
getBiographyDialog().show();
} else {
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.biography_unavailable), Toast.LENGTH_SHORT).show();
}
return true;
case R.id.action_re_download_artist_image:
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.updating), Toast.LENGTH_SHORT).show();
setUpArtistImageAndApplyPalette(true);
@ -312,7 +346,7 @@ public class ArtistDetailActivity extends AbsFabActivity {
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void fixLollipopTransitionImageWrongSize(){
private void fixLollipopTransitionImageWrongSize() {
getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {

View file

@ -5,7 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.util.Pair;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
@ -37,7 +36,6 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
import com.kabouzeid.gramophone.util.Util;
import com.kabouzeid.gramophone.util.ViewUtil;
import com.nineoldandroids.view.ViewPropertyAnimator;
import com.squareup.otto.Subscribe;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
@ -231,7 +229,6 @@ public class MusicControllerActivity extends AbsFabActivity {
}
private void setUpAlbumArtAndApplyPalette() {
setStandardColors();
Picasso.with(this)
.load(MusicUtil.getAlbumArtUri(song.albumId))
.placeholder(R.drawable.default_album_art)
@ -242,6 +239,12 @@ public class MusicControllerActivity extends AbsFabActivity {
final Bitmap bitmap = ((BitmapDrawable) albumArt.getDrawable()).getBitmap();
if (bitmap != null) applyPalette(bitmap);
}
@Override
public void onError() {
super.onError();
setStandardColors();
}
});
}

View file

@ -6,9 +6,11 @@ import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.PathInterpolator;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
/**
* Created by karim on 06.12.14.
@ -95,4 +97,16 @@ public class ViewUtil {
}
});
}
public static void animateTextViewMaxLines(TextView text, int maxLines) {
try {
ObjectAnimator animation = ObjectAnimator.ofInt(text, "maxLines", maxLines);
animation.setInterpolator(new AccelerateInterpolator());
animation.setDuration(200);
animation.start();
} catch (Exception e) {
// Some devices crash at runtime when using the ObjectAnimator
text.setMaxLines(maxLines);
}
}
}

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<stroke android:width="5px" android:color="#222222" />
<padding android:left="5px" android:top="5px" android:right="5px"
android:bottom="5px" />
</shape>

View file

@ -16,12 +16,9 @@
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:internal="http://schemas.android.com/apk/prv/res/android"
android:layout_width="match_parent"
android:layout_height="64dp"
android:orientation="horizontal"
internal:layout_maxHeight="64dp"
internal:layout_minHeight="64dp">
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"

View file

@ -1,87 +1,81 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/album_art"
android:layout_width="match_parent"
android:layout_height="@dimen/header_image_height"
android:scaleType="centerCrop"
android:src="@drawable/default_album_art"
android:transitionName="@string/transition_album_cover"/>
<ImageView
android:id="@+id/album_art"
<View
android:id="@+id/list_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"/>
<com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/album_title"
android:layout_width="match_parent"
android:layout_height="@dimen/header_image_height"
android:scaleType="centerCrop"
android:src="@drawable/default_album_art"
android:transitionName="@string/transition_album_cover"/>
android:layout_height="@dimen/title_view_height"
android:height="@dimen/title_view_height"
android:background="@color/materialmusic_default_bar_color"
android:elevation="@dimen/toolbar_elevation"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"
android:paddingLeft="72dp"
android:paddingRight="72dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?attr/title_text_color"/>
<View
android:id="@+id/list_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"/>
<com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none"/>
android:background="@android:color/transparent"/>
<LinearLayout
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="@dimen/statusMargin"
android:background="@android:color/transparent"/>
<TextView
android:id="@+id/album_title"
android:layout_width="match_parent"
android:layout_height="@dimen/title_view_height"
android:height="@dimen/title_view_height"
android:background="@color/materialmusic_default_bar_color"
android:elevation="@dimen/toolbar_elevation"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"
android:paddingLeft="72dp"
android:paddingRight="72dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?attr/title_text_color"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
</LinearLayout>
<LinearLayout
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"/>
</LinearLayout>
<ImageView
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="@dimen/statusMargin"
android:background="@android:color/transparent"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"/>
</LinearLayout>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
style="@style/PlayPauseFab"
android:layout_gravity="right"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
</FrameLayout>
</RelativeLayout>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
style="@style/PlayPauseFab"
android:layout_gravity="right"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
</FrameLayout>

View file

@ -1,87 +1,81 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/artist_image"
android:layout_width="match_parent"
android:layout_height="@dimen/header_image_height"
android:scaleType="centerCrop"
android:src="@drawable/default_artist_image"
android:transitionName="@string/transition_artist_image"/>
<ImageView
android:id="@+id/artist_image"
<View
android:id="@+id/list_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"/>
<com.github.ksoichiro.android.observablescrollview.ObservableListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/artist_name"
android:layout_width="match_parent"
android:layout_height="@dimen/header_image_height"
android:scaleType="centerCrop"
android:src="@drawable/default_artist_image"
android:transitionName="@string/transition_artist_image"/>
android:layout_height="@dimen/title_view_height"
android:height="@dimen/title_view_height"
android:background="@color/materialmusic_default_bar_color"
android:elevation="@dimen/toolbar_elevation"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"
android:paddingLeft="72dp"
android:paddingRight="72dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?attr/title_text_color"/>
<View
android:id="@+id/list_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"/>
<com.github.ksoichiro.android.observablescrollview.ObservableListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none"/>
android:background="@android:color/transparent"/>
<LinearLayout
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="@dimen/statusMargin"
android:background="@android:color/transparent"/>
<TextView
android:id="@+id/artist_name"
android:layout_width="match_parent"
android:layout_height="@dimen/title_view_height"
android:height="@dimen/title_view_height"
android:background="@color/materialmusic_default_bar_color"
android:elevation="@dimen/toolbar_elevation"
android:fontFamily="sans-serif-medium"
android:gravity="center_vertical"
android:paddingLeft="72dp"
android:paddingRight="72dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="?attr/title_text_color"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
</LinearLayout>
<LinearLayout
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"/>
</LinearLayout>
<ImageView
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="@dimen/statusMargin"
android:background="@android:color/transparent"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"/>
</LinearLayout>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
style="@style/PlayPauseFab"
android:layout_gravity="right"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
</FrameLayout>
</RelativeLayout>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
style="@style/PlayPauseFab"
android:layout_gravity="right"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
</FrameLayout>

View file

@ -10,8 +10,10 @@
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/albums"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="?title_text_color"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
@ -27,7 +29,9 @@
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/songs"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"/>
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="?title_text_color"/>
</LinearLayout>

View file

@ -12,7 +12,6 @@
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:background="@drawable/image_background"
android:gravity="center"
android:scaleType="centerCrop"
/>

View file

@ -12,7 +12,6 @@
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:background="@drawable/image_background"
android:gravity="center"
android:scaleType="centerCrop"
/>

View file

@ -16,12 +16,9 @@
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:internal="http://schemas.android.com/apk/prv/res/android"
android:layout_width="match_parent"
android:layout_height="64dp"
android:orientation="horizontal"
internal:layout_maxHeight="64dp"
internal:layout_minHeight="64dp">
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"

View file

@ -9,6 +9,11 @@
android:title="@string/action_current_playing"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_biography"
android:title="@string/biography"
app:showAsAction="never"/>
<item
android:id="@+id/action_re_download_artist_image"
android:title="@string/action_re_download_artist_image"

View file

@ -32,9 +32,7 @@
<string name="unplayable_file">Sorry - an error occurred while attempting to play this song</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="biography_unavailable">Sorry, we were not able to find a matching biography for this artist.</string>
<string name="tab_biography">biography</string>
<string name="tab_songs">songs</string>
<string name="tab_albums">albums</string>
<string name="biography">Biography</string>
<string name="audio_focus_denied">We were not able to gain audio focus.</string>
<string name="title_activity_tag_editor">TagEditorActivity</string>
<string name="hello_world">Hello world!</string>
@ -72,5 +70,6 @@
<string name="action_re_download_artist_image">Update artist image</string>
<string name="updated_artist_image_for">Updated artist image for</string>
<string name="updating">Updating…</string>
<string name="loading">Loading…</string>
</resources>