2013-02-08 10:09:55 +01:00
|
|
|
/*
|
|
|
|
This file is part of Subsonic.
|
|
|
|
|
|
|
|
Subsonic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Subsonic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2009 (C) Sindre Mehus
|
|
|
|
*/
|
2015-07-26 18:15:07 +02:00
|
|
|
package org.moire.ultrasonic.view;
|
2013-02-08 10:09:55 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
2013-07-20 10:28:08 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2013-02-08 10:09:55 +01:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2015-07-26 18:15:07 +02:00
|
|
|
import org.moire.ultrasonic.R;
|
2020-09-18 09:37:19 +02:00
|
|
|
import org.moire.ultrasonic.data.ActiveServerProvider;
|
2015-07-26 18:15:07 +02:00
|
|
|
import org.moire.ultrasonic.domain.MusicDirectory;
|
|
|
|
import org.moire.ultrasonic.service.MusicService;
|
|
|
|
import org.moire.ultrasonic.service.MusicServiceFactory;
|
|
|
|
import org.moire.ultrasonic.util.ImageLoader;
|
|
|
|
import org.moire.ultrasonic.util.Util;
|
2013-02-08 10:09:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to display albums in a {@code ListView}.
|
|
|
|
*
|
|
|
|
* @author Sindre Mehus
|
|
|
|
*/
|
2013-12-04 07:36:02 +01:00
|
|
|
public class AlbumView extends UpdateView
|
|
|
|
{
|
2013-02-08 10:09:55 +01:00
|
|
|
private static final String TAG = AlbumView.class.getSimpleName();
|
2013-12-04 07:36:02 +01:00
|
|
|
private static Drawable starDrawable;
|
|
|
|
private static Drawable starHollowDrawable;
|
|
|
|
private static String theme;
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private MusicDirectory.Entry entry;
|
2014-01-23 09:50:49 +01:00
|
|
|
private EntryAdapter.AlbumViewHolder viewHolder;
|
|
|
|
private ImageLoader imageLoader;
|
2016-02-09 23:50:34 +01:00
|
|
|
private boolean maximized = false;
|
2013-12-04 07:36:02 +01:00
|
|
|
|
2014-01-23 09:50:49 +01:00
|
|
|
public AlbumView(Context context, ImageLoader imageLoader)
|
2013-12-04 07:36:02 +01:00
|
|
|
{
|
|
|
|
super(context);
|
|
|
|
this.context = context;
|
2014-01-23 09:50:49 +01:00
|
|
|
this.imageLoader = imageLoader;
|
2013-12-04 07:36:02 +01:00
|
|
|
|
|
|
|
String theme = Util.getTheme(context);
|
|
|
|
boolean themesMatch = theme.equals(AlbumView.theme);
|
|
|
|
AlbumView.theme = theme;
|
|
|
|
|
|
|
|
if (starHollowDrawable == null || !themesMatch)
|
|
|
|
{
|
|
|
|
starHollowDrawable = Util.getDrawableFromAttribute(context, R.attr.star_hollow);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (starDrawable == null || !themesMatch)
|
|
|
|
{
|
|
|
|
starDrawable = Util.getDrawableFromAttribute(context, R.attr.star_full);
|
|
|
|
}
|
2014-01-23 09:50:49 +01:00
|
|
|
}
|
2013-12-04 07:36:02 +01:00
|
|
|
|
2014-01-23 09:50:49 +01:00
|
|
|
public void setLayout()
|
|
|
|
{
|
|
|
|
LayoutInflater.from(context).inflate(R.layout.album_list_item, this, true);
|
|
|
|
viewHolder = new EntryAdapter.AlbumViewHolder();
|
|
|
|
viewHolder.title = (TextView) findViewById(R.id.album_title);
|
|
|
|
viewHolder.artist = (TextView) findViewById(R.id.album_artist);
|
|
|
|
viewHolder.cover_art = (ImageView) findViewById(R.id.album_coverart);
|
|
|
|
viewHolder.star = (ImageView) findViewById(R.id.album_star);
|
|
|
|
setTag(viewHolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setViewHolder(EntryAdapter.AlbumViewHolder viewHolder)
|
|
|
|
{
|
|
|
|
this.viewHolder = viewHolder;
|
|
|
|
this.viewHolder.cover_art.invalidate();
|
|
|
|
setTag(this.viewHolder);
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public MusicDirectory.Entry getEntry()
|
|
|
|
{
|
|
|
|
return this.entry;
|
|
|
|
}
|
|
|
|
|
2016-02-10 21:55:32 +01:00
|
|
|
public boolean isMaximized() {
|
|
|
|
return maximized;
|
|
|
|
}
|
|
|
|
|
2016-02-09 23:50:34 +01:00
|
|
|
public void maximizeOrMinimize() {
|
|
|
|
if (maximized) {
|
|
|
|
maximized = false;
|
|
|
|
} else {
|
|
|
|
maximized = true;
|
|
|
|
}
|
|
|
|
if (this.viewHolder.title != null) {
|
|
|
|
this.viewHolder.title.setSingleLine(!maximized);
|
|
|
|
}
|
|
|
|
if (this.viewHolder.artist != null) {
|
|
|
|
this.viewHolder.artist.setSingleLine(!maximized);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 09:50:49 +01:00
|
|
|
public void setAlbum(final MusicDirectory.Entry album)
|
2013-12-04 07:36:02 +01:00
|
|
|
{
|
2014-01-24 05:18:33 +01:00
|
|
|
viewHolder.cover_art.setTag(album);
|
|
|
|
imageLoader.loadImage(viewHolder.cover_art, album, false, 0, false, true);
|
2013-12-04 07:36:02 +01:00
|
|
|
this.entry = album;
|
|
|
|
|
|
|
|
String title = album.getTitle();
|
|
|
|
String artist = album.getArtist();
|
|
|
|
boolean starred = album.getStarred();
|
|
|
|
|
2014-01-23 09:50:49 +01:00
|
|
|
viewHolder.title.setText(title);
|
|
|
|
viewHolder.artist.setText(artist);
|
|
|
|
viewHolder.artist.setVisibility(artist == null ? View.GONE : View.VISIBLE);
|
|
|
|
viewHolder.star.setImageDrawable(starred ? starDrawable : starHollowDrawable);
|
2013-12-04 07:36:02 +01:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
if (ActiveServerProvider.Companion.isOffline(this.context) || "-1".equals(album.getId()))
|
2013-12-04 07:36:02 +01:00
|
|
|
{
|
2014-01-23 09:50:49 +01:00
|
|
|
viewHolder.star.setVisibility(View.GONE);
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-23 09:50:49 +01:00
|
|
|
viewHolder.star.setOnClickListener(new View.OnClickListener()
|
2013-12-04 07:36:02 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View view)
|
|
|
|
{
|
|
|
|
final boolean isStarred = album.getStarred();
|
|
|
|
final String id = album.getId();
|
|
|
|
|
|
|
|
if (!isStarred)
|
|
|
|
{
|
2014-01-23 09:50:49 +01:00
|
|
|
viewHolder.star.setImageDrawable(starDrawable);
|
2013-12-04 07:36:02 +01:00
|
|
|
album.setStarred(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-23 09:50:49 +01:00
|
|
|
viewHolder.star.setImageDrawable(starHollowDrawable);
|
2013-12-04 07:36:02 +01:00
|
|
|
album.setStarred(false);
|
|
|
|
}
|
|
|
|
|
2017-08-17 22:38:23 +02:00
|
|
|
final MusicService musicService = MusicServiceFactory.getMusicService(view.getContext());
|
2013-12-04 07:36:02 +01:00
|
|
|
new Thread(new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
boolean useId3 = Util.getShouldUseId3Tags(getContext());
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!isStarred)
|
|
|
|
{
|
|
|
|
musicService.star(!useId3 ? id : null, useId3 ? id : null, null, getContext(), null);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
musicService.unstar(!useId3 ? id : null, useId3 ? id : null, null, getContext(), null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.e(TAG, e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-07-20 10:28:08 +02:00
|
|
|
}
|