Skip to content

Commit

Permalink
Show album artwork in list, upgrade dependency, add new screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
markzhai committed Sep 12, 2015
1 parent 7fe9942 commit 8e35e2c
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 64 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ Features
TODO(Pull request is welcomed)
------------------------------

- Show artwork in listview.
- Better implementation for Music player.
- Use Google Design Support UI.
- Better implementation for Music player, show lyric directly.
- Download lyric from server and upload to server.
- Add support lyric file encoding auto-recognize.
- Use Google Design Support UI.

Test
----
Tested
------
- Nexus 6 (5.1.1)
- OnePlus (4.3)

Screenshots
-----------

![Browse local music file](art/Screenshot_2015-03-20-17-07-26.jpg "Browse local music file")
![Fullscreen music player](art/Screenshot_2015-03-20-17-07-30.jpg "Fullscreen music player")
![Lyric explorer](art/Screenshot_2015-03-20-17-09-38.jpg "Lyric explorer")
![Browse local music file](art/Screenshot_2015-09-12-23-14-37.jpg "Browse local music file")
![Fullscreen music player](art/Screenshot_2015-09-12-21-13-22.jpg "Fullscreen music player")
![Lyric explorer](art/Screenshot_2015-09-12-21-13-40.jpg "Lyric explorer")
![Lyric player](art/Screenshot_2015-03-20-17-11-09.jpg "Lyric player")
![Lyric encoding picker](art/Screenshot_2015-03-20-17-11-28.jpg "Lyric encoding picker")
![Notification](art/Screenshot_2015-09-09-23-12-51.jpg "Notification")
![Lock Screen Background](art/Screenshot_2015-09-12-22-43-59.jpg "Lock Screen Background")

CHANGELOG
-------
Expand Down
26 changes: 14 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,23 @@ dependencies {
compile project(':lib_lyricview')

// Android support
compile parent.ext.libSupportV4
compile parent.ext.libCardView
compile parent.ext.libMediaRouter
compile parent.ext.libAppCompat
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:mediarouter-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'

// ButterKnife
compile parent.ext.libButterknife
compile 'com.jakewharton:butterknife:7.0.1'

// DBFlow
apt parent.ext.libDBFlowCompiler
compile parent.ext.libDBFlowCore
compile parent.ext.libDBFlow
apt 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
compile "com.raizlabs.android:DBFlow-Core:2.2.1"
compile "com.raizlabs.android:DBFlow:2.2.1"

compile 'com.hannesdorfmann.mosby:mvp:2.0.0'
compile 'com.hannesdorfmann.mosby:viewstate:2.0.0'

compile 'frankiesardo:icepick:3.1.0'
provided 'frankiesardo:icepick-processor:3.1.0'

compile 'com.hannesdorfmann.mosby:core:1.2.0'
compile 'com.hannesdorfmann.mosby:mvp:1.2.0'
apt 'frankiesardo:icepick-processor:3.0.2'
compile 'com.chrisanderson.mediabrowsercompat:library:0.0.2'
}
9 changes: 9 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@

-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}

-dontwarn com.squareup.okhttp.**

-dontwarn icepick.**
-keep class **$$Icepick { *; }
-keepnames class * { @icepick.State *; }
-keepclasseswithmembernames class * {
@icepick.* <fields>;
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/markzhai/lyrichere/MusicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.markzhai.lyrichere.ui.MusicPlayerActivity;
import com.markzhai.lyrichere.utils.LogUtils;
import com.markzhai.lyrichere.utils.MediaIDHelper;
import com.markzhai.lyrichere.utils.MusicUtils;
import com.markzhai.lyrichere.utils.QueueHelper;

import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -302,6 +303,7 @@ private void loadChildrenImpl(final String parentMediaId, final Result<List<Medi
new MediaDescriptionCompat.Builder()
.setMediaId(createBrowseCategoryMediaID(MEDIA_ID_MUSICS_BY_ALBUM, album))
.setTitle(album)
.setIconUri(Uri.parse(mMusicProvider.getAlbumArt(album)))
.setSubtitle(getString(R.string.browse_musics_by_genre_subtitle, album))
.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public Iterable<String> getGenres() {
}

/**
* Get an iterator over the list of genres
* Get an iterator over the list of albums
*
* @return genres
* @return albums
*/
public Iterable<String> getAlbums() {
if (mCurrentState != State.INITIALIZED) {
Expand All @@ -104,10 +104,22 @@ public Iterable<String> getAlbums() {
return mMusicListByAlbum.keySet();
}

public String getAlbumArt(String album) {
if (mCurrentState != State.INITIALIZED) {
return "";
}
List<MediaMetadataCompat> list = mMusicListByAlbum.get(album);
if (list == null || list.size() == 0) {
return "";
}

return list.get(0).getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI);
}

/**
* Get an iterator over the list of genres
* Get an iterator over the list of artists
*
* @return genres
* @return artists
*/
public Iterable<String> getArtists() {
if (mCurrentState != State.INITIALIZED) {
Expand Down Expand Up @@ -365,7 +377,6 @@ private synchronized void retrieveMedia() {
long totalTrackCount = genreMediaCursor.getLong(6);
String musicId = genreMediaCursor.getString(7);
long albumId = genreMediaCursor.getLong(8);
Uri albumArtUri = ContentUris.withAppendedId(ART_CONTENT_URI, albumId);

MediaMetadataCompat item = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, musicId)
Expand All @@ -374,7 +385,7 @@ private synchronized void retrieveMedia() {
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration)
.putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, albumArtUri.toString())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, MusicUtils.getAlbumArtworkUri(albumId).toString())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber)
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount)
Expand Down Expand Up @@ -403,7 +414,6 @@ private synchronized void retrieveMedia() {
long totalTrackCount = allSongCursor.getLong(6);
String musicId = allSongCursor.getString(7);
long albumId = allSongCursor.getLong(8);
Uri albumArtUri = ContentUris.withAppendedId(ART_CONTENT_URI, albumId);

if (mMusicListById.containsKey(musicId)) {
continue;
Expand All @@ -416,7 +426,7 @@ private synchronized void retrieveMedia() {
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration)
.putString(MediaMetadataCompat.METADATA_KEY_GENRE, UNKNOWN_TAG)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, albumArtUri.toString())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, MusicUtils.getAlbumArtworkUri(albumId).toString())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber)
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount)
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/markzhai/lyrichere/ui/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.markzhai.lyrichere.utils.NetworkHelper;
import com.markzhai.lyrichere.utils.ResourceHelper;

import butterknife.ButterKnife;
import icepick.Icepick;

/**
* Application base activity.
*/
Expand All @@ -40,6 +43,19 @@ public void onCreate(Bundle savedInstanceState) {
ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray));
setTaskDescription(taskDesc);
}
Icepick.restoreInstanceState(this, savedInstanceState);
}


@Override public void onContentChanged() {
super.onContentChanged();
ButterKnife.bind(this);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}

@Override
Expand Down
68 changes: 68 additions & 0 deletions app/src/main/java/com/markzhai/lyrichere/ui/BaseFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.markzhai.lyrichere.ui;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import icepick.Icepick;

/**
* Base Fragment with dependency injection.
* <p/>
* Created by zyf on 2015/9/12.
*/
public class BaseFragment extends Fragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Icepick.restoreInstanceState(this, savedInstanceState);
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

int layoutRes = getLayoutRes();
if (layoutRes == 0) {
throw new IllegalArgumentException(
"getLayoutRes() returned 0, which is not allowed. "
+ "If you don't want to use getLayoutRes() but implement your own view for this "
+ "fragment manually, then you have to override onCreateView();");
} else {
return inflater.inflate(layoutRes, container, false);
}
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
}

@Override
public void onDestroy() {
super.onDestroy();
ButterKnife.unbind(this);
}

/**
* Return the layout resource like R.layout.my_layout
*
* @return the layout resource or zero ("0"), if you don't want to have an UI
*/
@LayoutRes
protected int getLayoutRes() {
return 0;
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/com/markzhai/lyrichere/ui/BaseListFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.markzhai.lyrichere.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
import android.view.View;

import butterknife.ButterKnife;
import icepick.Icepick;

/**
* Base ListFragment with dependency injection.
* <p/>
* Created by zyf on 2015/9/12.
*/
public class BaseListFragment extends ListFragment {

@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Icepick.restoreInstanceState(this, savedInstanceState);
}

@Override public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
}

@Override
public void onDestroy() {
super.onDestroy();
ButterKnife.unbind(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.media.MediaDescriptionCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.markzhai.lyrichere.AlbumArtCache;
import com.markzhai.lyrichere.R;
import com.markzhai.lyrichere.utils.LogUtils;
import com.markzhai.lyrichere.utils.LollipopUtils;

public class MediaItemViewHolder {
Expand All @@ -38,7 +40,7 @@ static View setupView(Activity activity, View convertView, ViewGroup parent,
initializeColorStateLists(activity);
}

MediaItemViewHolder holder;
final MediaItemViewHolder holder;

Integer cachedState = STATE_INVALID;

Expand Down Expand Up @@ -78,14 +80,31 @@ static View setupView(Activity activity, View convertView, ViewGroup parent,
break;
case STATE_PAUSED:
holder.mImageView.setImageDrawable(
ActivityCompat.getDrawable(activity,R.drawable.ic_equalizer1_white_36dp));
ActivityCompat.getDrawable(activity, R.drawable.ic_equalizer1_white_36dp));
LollipopUtils.setImageTintList(holder.mImageView, sColorStateNotPlaying);
holder.mImageView.setVisibility(View.VISIBLE);
break;
default:
if (description.getIconUri() != null) {
holder.mImageView.setImageURI(description.getIconUri());
holder.mImageView.setVisibility(View.VISIBLE);
String artUrl = description.getIconUri().toString();
Bitmap art = description.getIconBitmap();
AlbumArtCache cache = AlbumArtCache.getInstance();
if (art == null) {
art = cache.getIconImage(artUrl);
}
if (art != null) {
holder.mImageView.setImageBitmap(art);
} else {
cache.fetch(artUrl, new AlbumArtCache.FetchListener() {
@Override
public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
if (icon != null) {
holder.mImageView.setImageBitmap(icon);
}
}
}
);
}
} else {
holder.mImageView.setVisibility(View.GONE);
}
Expand Down
Loading

0 comments on commit 8e35e2c

Please sign in to comment.