aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-10-06 09:52:19 -0700
committerScott Jackson <daneren2005@gmail.com>2012-10-06 09:52:19 -0700
commitb67ae0a75069d001faf9afe311c7fd1a8c3235f0 (patch)
tree8827c341c0d0d757b0277d10df3daba561093dfd /subsonic-android/src
parentf9a6738054febd93932cd3f6ab66e985777d45f1 (diff)
downloaddsub-b67ae0a75069d001faf9afe311c7fd1a8c3235f0.tar.gz
dsub-b67ae0a75069d001faf9afe311c7fd1a8c3235f0.tar.bz2
dsub-b67ae0a75069d001faf9afe311c7fd1a8c3235f0.zip
Abstracted out updating of view to UpdateView, moved Song/Album views to View folder
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java (renamed from subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java)51
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/SongView.java (renamed from subsonic-android/src/github/daneren2005/dsub/util/SongView.java)51
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java75
6 files changed, 92 insertions, 90 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index bbd4ba2e..0349b017 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -70,7 +70,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.HorizontalSlider;
import github.daneren2005.dsub.util.SilentBackgroundTask;
-import github.daneren2005.dsub.util.SongView;
+import github.daneren2005.dsub.view.SongView;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.VisualizerView;
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java
index 05ad2f4b..7d54908b 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java
@@ -203,6 +203,7 @@ public class SubsonicTabActivity extends SherlockActivity {
@Override
protected void done(Void result) {
+ // UpdateView
Util.toast(SubsonicTabActivity.this, getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle()));
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java b/subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java
index e66c95cd..bca05e00 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/EntryAdapter.java
@@ -18,6 +18,8 @@
*/
package github.daneren2005.dsub.util;
+import github.daneren2005.dsub.view.AlbumView;
+import github.daneren2005.dsub.view.SongView;
import java.util.List;
import android.view.View;
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java b/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java
index 124f551d..ea8f5110 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/AlbumView.java
+++ b/subsonic-android/src/github/daneren2005/dsub/view/AlbumView.java
@@ -16,29 +16,26 @@
Copyright 2009 (C) Sindre Mehus
*/
-package github.daneren2005.dsub.util;
+package github.daneren2005.dsub.view;
import android.content.Context;
-import android.os.Handler;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
-import android.widget.LinearLayout;
import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
-import java.util.WeakHashMap;
+import github.daneren2005.dsub.util.ImageLoader;
+import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.UpdateView;
/**
* Used to display albums in a {@code ListView}.
*
* @author Sindre Mehus
*/
-public class AlbumView extends LinearLayout {
+public class AlbumView extends UpdateView {
private static final String TAG = AlbumView.class.getSimpleName();
- private static final WeakHashMap<AlbumView, ?> INSTANCES = new WeakHashMap<AlbumView, Object>();
- private static Handler handler;
private MusicDirectory.Entry album;
@@ -55,13 +52,6 @@ public class AlbumView extends LinearLayout {
artistView = (TextView) findViewById(R.id.album_artist);
coverArtView = findViewById(R.id.album_coverart);
starButton = (ImageButton) findViewById(R.id.album_star);
-
- INSTANCES.put(this, null);
- int instanceCount = INSTANCES.size();
- if (instanceCount > 50) {
- Log.w(TAG, instanceCount + " live AlbumView instances");
- }
- startUpdater();
}
public void setAlbum(MusicDirectory.Entry album, ImageLoader imageLoader) {
@@ -78,35 +68,8 @@ public class AlbumView extends LinearLayout {
update();
}
- private void update() {
+ @Override
+ protected void update() {
starButton.setVisibility((Util.isOffline(getContext()) || !album.isStarred()) ? View.GONE : View.VISIBLE);
}
-
- private static synchronized void startUpdater() {
- if (handler != null) {
- return;
- }
-
- handler = new Handler();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- updateAll();
- handler.postDelayed(this, 1000L);
- }
- };
- handler.postDelayed(runnable, 1000L);
- }
-
- private static void updateAll() {
- try {
- for (AlbumView view : INSTANCES.keySet()) {
- if (view.isShown()) {
- view.update();
- }
- }
- } catch (Throwable x) {
- Log.w(TAG, "Error when updating song views.", x);
- }
- }
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/SongView.java b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java
index 24c483dc..13f88a3e 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/SongView.java
+++ b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java
@@ -16,37 +16,32 @@
Copyright 2009 (C) Sindre Mehus
*/
-package github.daneren2005.dsub.util;
+package github.daneren2005.dsub.view;
import android.content.Context;
-import android.os.Handler;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Checkable;
import android.widget.CheckedTextView;
import android.widget.ImageButton;
-import android.widget.LinearLayout;
import android.widget.TextView;
import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.activity.SubsonicTabActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.service.DownloadFile;
+import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.UpdateView;
import java.io.File;
-import java.util.WeakHashMap;
/**
* Used to display songs in a {@code ListView}.
*
* @author Sindre Mehus
*/
-public class SongView extends LinearLayout implements Checkable {
+public class SongView extends UpdateView implements Checkable {
private static final String TAG = SongView.class.getSimpleName();
- private static final WeakHashMap<SongView, ?> INSTANCES = new WeakHashMap<SongView, Object>();
- private static Handler handler;
private MusicDirectory.Entry song;
@@ -67,13 +62,6 @@ public class SongView extends LinearLayout implements Checkable {
durationTextView = (TextView) findViewById(R.id.song_duration);
statusTextView = (TextView) findViewById(R.id.song_status);
starButton = (ImageButton) findViewById(R.id.song_star);
-
- INSTANCES.put(this, null);
- int instanceCount = INSTANCES.size();
- if (instanceCount > 50) {
- Log.w(TAG, instanceCount + " live SongView instances");
- }
- startUpdater();
}
public void setSong(MusicDirectory.Entry song, boolean checkable) {
@@ -106,7 +94,8 @@ public class SongView extends LinearLayout implements Checkable {
update();
}
- private void update() {
+ @Override
+ protected void update() {
DownloadService downloadService = DownloadServiceImpl.getInstance();
if (downloadService == null) {
return;
@@ -140,34 +129,6 @@ public class SongView extends LinearLayout implements Checkable {
starButton.setVisibility((Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE);
}
- private static synchronized void startUpdater() {
- if (handler != null) {
- return;
- }
-
- handler = new Handler();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- updateAll();
- handler.postDelayed(this, 1000L);
- }
- };
- handler.postDelayed(runnable, 1000L);
- }
-
- private static void updateAll() {
- try {
- for (SongView view : INSTANCES.keySet()) {
- if (view.isShown()) {
- view.update();
- }
- }
- } catch (Throwable x) {
- Log.w(TAG, "Error when updating song views.", x);
- }
- }
-
@Override
public void setChecked(boolean b) {
checkedTextView.setChecked(b);
diff --git a/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java b/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java
new file mode 100644
index 00000000..d4d6081c
--- /dev/null
+++ b/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java
@@ -0,0 +1,75 @@
+/*
+ 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
+ */
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.os.Handler;
+import android.util.Log;
+import android.widget.LinearLayout;
+import java.util.WeakHashMap;
+
+public class UpdateView extends LinearLayout {
+ private static final String TAG = UpdateView.class.getSimpleName();
+ private static final WeakHashMap<UpdateView, ?> INSTANCES = new WeakHashMap<UpdateView, Object>();
+ private static Handler handler;
+
+ public UpdateView(Context context) {
+ super(context);
+
+ INSTANCES.put(this, null);
+ int instanceCount = INSTANCES.size();
+ if (instanceCount > 50) {
+ Log.w(TAG, instanceCount + " live UpdateView instances");
+ }
+
+ startUpdater();
+ }
+
+ private static synchronized void startUpdater() {
+ if (handler != null) {
+ return;
+ }
+
+ handler = new Handler();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ updateAll();
+ handler.postDelayed(this, 1000L);
+ }
+ };
+ handler.postDelayed(runnable, 1000L);
+ }
+
+ private static void updateAll() {
+ try {
+ for (UpdateView view : INSTANCES.keySet()) {
+ if (view.isShown()) {
+ view.update();
+ }
+ }
+ } catch (Throwable x) {
+ Log.w(TAG, "Error when updating song views.", x);
+ }
+ }
+
+ protected void update() {
+
+ }
+}