aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java10
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java6
-rw-r--r--src/github/daneren2005/dsub/domain/Bookmark.java1
-rw-r--r--src/github/daneren2005/dsub/fragments/ChatFragment.java21
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java2
-rw-r--r--src/github/daneren2005/dsub/fragments/SearchFragment.java20
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectArtistFragment.java100
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java1
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java163
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectListFragment.java20
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java13
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidget4x1.java1
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidget4x2.java1
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidget4x3.java1
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidget4x4.java1
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidgetProvider.java1
-rw-r--r--src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java31
-rw-r--r--src/github/daneren2005/dsub/provider/MostRecentStubProvider.java2
-rw-r--r--src/github/daneren2005/dsub/provider/PlaylistStubProvider.java2
-rw-r--r--src/github/daneren2005/dsub/provider/PodcastStubProvider.java2
-rw-r--r--src/github/daneren2005/dsub/provider/StarredStubProvider.java2
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java2
-rw-r--r--src/github/daneren2005/dsub/service/ChromeCastController.java28
-rw-r--r--src/github/daneren2005/dsub/service/DownloadFile.java24
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java33
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java1
-rw-r--r--src/github/daneren2005/dsub/service/JukeboxController.java14
-rw-r--r--src/github/daneren2005/dsub/service/RemoteController.java4
-rw-r--r--src/github/daneren2005/dsub/service/parser/AlbumListParser.java3
-rw-r--r--src/github/daneren2005/dsub/service/parser/BookmarkParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/ChatMessageParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/GenreParser.java3
-rw-r--r--src/github/daneren2005/dsub/service/parser/IndexesParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/LyricsParser.java1
-rw-r--r--src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/MusicFoldersParser.java4
-rw-r--r--src/github/daneren2005/dsub/service/parser/PlaylistParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/PlaylistsParser.java3
-rw-r--r--src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java1
-rw-r--r--src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java1
-rw-r--r--src/github/daneren2005/dsub/service/parser/RandomSongsParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/SearchResultParser.java2
-rw-r--r--src/github/daneren2005/dsub/service/parser/ShareParser.java4
-rw-r--r--src/github/daneren2005/dsub/service/parser/StarredListParser.java3
-rw-r--r--src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java25
-rw-r--r--src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java1
-rw-r--r--src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java6
-rw-r--r--src/github/daneren2005/dsub/util/ImageLoader.java1
-rw-r--r--src/github/daneren2005/dsub/util/MediaRouteManager.java9
-rw-r--r--src/github/daneren2005/dsub/util/SyncUtil.java1
-rw-r--r--src/github/daneren2005/dsub/util/Util.java7
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java19
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java3
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java12
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java82
-rw-r--r--src/github/daneren2005/dsub/view/AlbumCell.java88
-rw-r--r--src/github/daneren2005/dsub/view/AlbumGridAdapter.java55
-rw-r--r--src/github/daneren2005/dsub/view/AlbumListAdapter.java6
-rw-r--r--src/github/daneren2005/dsub/view/AlbumView.java100
-rw-r--r--src/github/daneren2005/dsub/view/ArtistEntryView.java2
-rw-r--r--src/github/daneren2005/dsub/view/ArtistView.java2
-rw-r--r--src/github/daneren2005/dsub/view/AutoRepeatButton.java4
-rw-r--r--src/github/daneren2005/dsub/view/BookmarkAdapter.java2
-rw-r--r--src/github/daneren2005/dsub/view/EntryAdapter.java31
-rw-r--r--src/github/daneren2005/dsub/view/ErrorDialog.java1
-rw-r--r--src/github/daneren2005/dsub/view/SquareImageView.java32
-rw-r--r--src/github/daneren2005/dsub/view/UnscrollableGridView.java81
-rw-r--r--src/github/daneren2005/dsub/view/UpdateView.java2
69 files changed, 671 insertions, 447 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 7d971093..646fa295 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -209,7 +209,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(lastSelectedView == null) {
lastSelectedView = drawerList.getChildAt(lastSelectedPosition);
- lastSelectedView.setBackgroundResource(R.color.dividerColor);
+ if(lastSelectedView != null) {
+ lastSelectedView.setBackgroundResource(R.color.dividerColor);
+ }
}
getSupportActionBar().setTitle(R.string.common_appname);
@@ -321,7 +323,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
- if(drawerOpen == true) {
+ if(drawerOpen) {
menuInflater.inflate(R.menu.drawer_menu, menu);
} else if(currentFragment != null) {
currentFragment.onCreateOptionsMenu(menu, menuInflater);
@@ -348,7 +350,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
boolean isJukebox = getDownloadService() != null && getDownloadService().isRemoteEnabled();
if (isVolumeAdjust && isJukebox) {
- getDownloadService().setRemoteVolume(isVolumeUp);
+ getDownloadService().updateRemoteVolume(isVolumeUp);
return true;
}
return super.onKeyDown(keyCode, event);
@@ -428,7 +430,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
enabledItems[3] = chatEnabled;
String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
- if(fragmentType != null) {
+ if(fragmentType != null && lastSelectedPosition == 0) {
for(int i = 0; i < drawerItemsDescriptions.length; i++) {
if(fragmentType.equals(drawerItemsDescriptions[i])) {
lastSelectedPosition = drawerAdapter.getAdapterPosition(i);
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index eee53d71..0bf770f3 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -320,11 +320,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- } else {
- return false;
- }
+ return super.onOptionsItemSelected(item);
}
@Override
diff --git a/src/github/daneren2005/dsub/domain/Bookmark.java b/src/github/daneren2005/dsub/domain/Bookmark.java
index d1f470ce..4092cec4 100644
--- a/src/github/daneren2005/dsub/domain/Bookmark.java
+++ b/src/github/daneren2005/dsub/domain/Bookmark.java
@@ -22,7 +22,6 @@ import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.List;
import java.util.Locale;
/**
diff --git a/src/github/daneren2005/dsub/fragments/ChatFragment.java b/src/github/daneren2005/dsub/fragments/ChatFragment.java
index 7443c5d9..3e53f2ad 100644
--- a/src/github/daneren2005/dsub/fragments/ChatFragment.java
+++ b/src/github/daneren2005/dsub/fragments/ChatFragment.java
@@ -9,6 +9,7 @@ import java.util.Collections;
import java.util.List;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
@@ -22,6 +23,7 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
+import android.widget.AbsListView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
@@ -127,6 +129,20 @@ public class ChatFragment extends SubsonicFragment {
}
setTitle(R.string.button_bar_chat);
+ refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout);
+ refreshLayout.setOnRefreshListener(this);
+
+ chatListView.setOnScrollListener(new AbsListView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {}
+
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+ int topRowVerticalPosition = (chatListView.getChildCount() == 0) ? 0 : chatListView.getChildAt(0).getTop();
+ refreshLayout.setEnabled(topRowVerticalPosition >= 0);
+ }
+ });
+
return rootView;
}
@@ -175,11 +191,8 @@ public class ChatFragment extends SubsonicFragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
+ return super.onOptionsItemSelected(item);
- return false;
}
@Override
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index d8fa11ac..3a9370a3 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -358,7 +358,7 @@ public class MainFragment extends SubsonicFragment {
progs.add(logcat.getPath());
progs.add("*:I");
- logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[0]));
+ logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[progs.size()]));
logcatProc.waitFor();
} catch(Exception e) {
Util.toast(context, "Failed to gather logs");
diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java
index 5ef8c1dd..9fc35cd2 100644
--- a/src/github/daneren2005/dsub/fragments/SearchFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java
@@ -6,12 +6,14 @@ import java.util.Arrays;
import android.content.Intent;
import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.MenuItem;
+import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
@@ -91,6 +93,9 @@ public class SearchFragment extends SubsonicFragment {
moreAlbumsButton = buttons.findViewById(R.id.search_more_albums);
moreSongsButton = buttons.findViewById(R.id.search_more_songs);
+ refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout);
+ refreshLayout.setEnabled(false);
+
list = (ListView) rootView.findViewById(R.id.fragment_list);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -121,6 +126,16 @@ public class SearchFragment extends SubsonicFragment {
}
});
registerForContextMenu(list);
+ list.setOnScrollListener(new AbsListView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {}
+
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+ int topRowVerticalPosition = (list.getChildCount() == 0) ? 0 : list.getChildAt(0).getTop();
+ refreshLayout.setEnabled(topRowVerticalPosition >= 0);
+ }
+ });
context.onNewIntent(context.getIntent());
if(searchResult != null) {
@@ -138,11 +153,8 @@ public class SearchFragment extends SubsonicFragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
+ return super.onOptionsItemSelected(item);
- return false;
}
@Override
diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
index 5644c059..c38072cf 100644
--- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
@@ -2,6 +2,7 @@ package github.daneren2005.dsub.fragments;
import android.os.Build;
import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -9,7 +10,9 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AbsListView;
import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
@@ -21,6 +24,7 @@ import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.TabBackgroundTask;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.ArtistAdapter;
@@ -29,24 +33,21 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-public class SelectArtistFragment extends SubsonicFragment implements AdapterView.OnItemClickListener {
+public class SelectArtistFragment extends SelectListFragment<Artist> {
private static final String TAG = SelectArtistFragment.class.getSimpleName();
private static final int MENU_GROUP_MUSIC_FOLDER = 10;
- private ListView artistList;
private View folderButtonParent;
private View folderButton;
private TextView folderName;
private List<MusicFolder> musicFolders = null;
private List<MusicDirectory.Entry> entries;
- private List<Artist> artists;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if(bundle != null) {
- artists = (List<Artist>) bundle.getSerializable(Constants.FRAGMENT_LIST);
musicFolders = (List<MusicFolder>) bundle.getSerializable(Constants.FRAGMENT_LIST2);
}
artist = true;
@@ -55,37 +56,21 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) artists);
outState.putSerializable(Constants.FRAGMENT_LIST2, (Serializable) musicFolders);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
- rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
+ super.onCreateView(inflater, container, bundle);
- artistList = (ListView) rootView.findViewById(R.id.fragment_list);
- artistList.setOnItemClickListener(this);
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
- artistList.setFastScrollAlwaysVisible(true);
+ listView.setFastScrollAlwaysVisible(true);
}
- folderButtonParent = inflater.inflate(R.layout.select_artist_header, artistList, false);
- folderName = (TextView) folderButtonParent.findViewById(R.id.select_artist_folder_2);
- artistList.addHeaderView(folderButtonParent);
- folderButton = folderButtonParent.findViewById(R.id.select_artist_folder);
-
- registerForContextMenu(artistList);
- if(artists == null) {
- if(!primaryFragment) {
- invalidated = true;
- } else {
- refresh(false);
- }
- } else {
+ if(objects != null) {
if (Util.isOffline(context) || Util.isTagBrowsing(context)) {
folderButton.setVisibility(View.GONE);
}
- artistList.setAdapter(new ArtistAdapter(context, artists));
setMusicFolders();
}
@@ -93,25 +78,11 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
- menuInflater.inflate(R.menu.select_artist, menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
-
- return false;
- }
-
- @Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- Object entry = artistList.getItemAtPosition(info.position);
+ Object entry = listView.getItemAtPosition(info.position);
if (entry instanceof Artist) {
onCreateContextMenu(menu, view, menuInfo, entry);
@@ -143,7 +114,7 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie
}
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
- Artist artist = (Artist) artistList.getItemAtPosition(info.position);
+ Artist artist = (Artist) listView.getItemAtPosition(info.position);
if (artist != null) {
return onContextItemSelected(menuItem, artist);
@@ -181,19 +152,20 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie
}
@Override
- protected void refresh(boolean refresh) {
- load(refresh);
- }
+ protected void refresh(final boolean refresh) {
+ if(folderButton == null) {
+ folderButtonParent = getLayoutInflater(null).inflate(R.layout.select_artist_header, listView, false);
+ folderName = (TextView) folderButtonParent.findViewById(R.id.select_artist_folder_2);
+ listView.addHeaderView(folderButtonParent);
+ folderButton = folderButtonParent.findViewById(R.id.select_artist_folder);
+ }
- private void load(final boolean refresh) {
- setTitle(R.string.button_bar_browse);
-
if (Util.isOffline(context) || Util.isTagBrowsing(context)) {
folderButton.setVisibility(View.GONE);
} else {
folderButton.setVisibility(View.VISIBLE);
}
- artistList.setVisibility(View.INVISIBLE);
+ listView.setVisibility(View.INVISIBLE);
BackgroundTask<Indexes> task = new TabBackgroundTask<Indexes>(this) {
@Override
@@ -208,20 +180,42 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie
@Override
protected void done(Indexes result) {
- artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
- artists.addAll(result.getShortcuts());
- artists.addAll(result.getArtists());
- artistList.setFastScrollEnabled(false);
- artistList.setAdapter(new ArtistAdapter(context, artists));
- artistList.setFastScrollEnabled(true);
+ objects = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
+ objects.addAll(result.getShortcuts());
+ objects.addAll(result.getArtists());
+ listView.setFastScrollEnabled(false);
+ listView.setAdapter(adapter = getAdapter(objects));
+ listView.setFastScrollEnabled(true);
entries = result.getEntries();
setMusicFolders();
- artistList.setVisibility(View.VISIBLE);
+ listView.setVisibility(View.VISIBLE);
+ refreshLayout.setRefreshing(false);
}
};
task.execute();
}
+
+ @Override
+ public int getOptionsMenu() {
+ return R.menu.select_artist;
+ }
+
+ @Override
+ public ArrayAdapter getAdapter(List<Artist> objects) {
+ return new ArtistAdapter(context, objects);
+ }
+
+ @Override
+ public List<Artist> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
+ return null;
+ }
+
+ @Override
+ public int getTitleResource() {
+ return R.string.button_bar_browse;
+ }
+
private void setMusicFolders() {
// Display selected music folder
if (musicFolders != null) {
diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
index c91c005c..5ea432e5 100644
--- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
@@ -19,7 +19,6 @@
package github.daneren2005.dsub.fragments;
import android.content.DialogInterface;
-import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index c8937ea7..73a67592 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
@@ -14,21 +15,23 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AbsListView;
import android.widget.AdapterView;
+import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.domain.MusicFolder;
import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.util.ImageLoader;
+import github.daneren2005.dsub.view.AlbumGridAdapter;
import github.daneren2005.dsub.view.EntryAdapter;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
-import com.mobeta.android.dslv.*;
+
import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.service.MusicService;
@@ -49,13 +52,16 @@ import java.util.Set;
public class SelectDirectoryFragment extends SubsonicFragment implements AdapterView.OnItemClickListener {
private static final String TAG = SelectDirectoryFragment.class.getSimpleName();
- private DragSortListView entryList;
+ private GridView albumList;
+ private ListView entryList;
private View emptyView;
private boolean hideButtons = false;
private Boolean licenseValid;
private boolean showHeader = true;
private EntryAdapter entryAdapter;
+ private List<MusicDirectory.Entry> albums;
private List<MusicDirectory.Entry> entries;
+ private boolean albumContext = false;
String id;
String name;
@@ -93,30 +99,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
- rootView = inflater.inflate(R.layout.select_album, container, false);
-
- entryList = (DragSortListView) rootView.findViewById(R.id.select_album_entries);
- entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
- entryList.setOnItemClickListener(this);
- entryList.setDropListener(new DragSortListView.DropListener() {
- @Override
- public void drop(int from, int to) {
- int max = entries.size();
- if(to >= max) {
- to = max - 1;
- }
- else if(to < 0) {
- to = 0;
- }
- entries.add(to, entries.remove(from));
- entryAdapter.notifyDataSetChanged();
- }
- });
-
- emptyView = rootView.findViewById(R.id.select_album_empty);
-
- registerForContextMenu(entryList);
-
Bundle args = getArguments();
if(args != null) {
id = args.getString(Constants.INTENT_EXTRA_NAME_ID);
@@ -144,6 +126,71 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
}
+ rootView = inflater.inflate(R.layout.select_album, container, false);
+
+ refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout);
+ refreshLayout.setOnRefreshListener(this);
+
+ entryList = (ListView) rootView.findViewById(R.id.select_album_entries);
+ entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+ entryList.setOnItemClickListener(this);
+
+ entryList.setOnScrollListener(new AbsListView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {}
+
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+ int topRowVerticalPosition = (entryList.getChildCount() == 0) ? 0 : entryList.getChildAt(0).getTop();
+ refreshLayout.setEnabled(topRowVerticalPosition >= 0);
+ }
+ });
+
+ if(albumListType == null || "starred".equals(albumListType)) {
+ albumList = (GridView) inflater.inflate(R.layout.unscrollable_grid_view, entryList, false);
+ entryList.addHeaderView(albumList);
+ } else {
+ ViewGroup rootGroup = (ViewGroup) rootView.findViewById(R.id.select_album_layout);
+ albumList = (GridView) inflater.inflate(R.layout.grid_view, rootGroup, false);
+ rootGroup.removeView(entryList);
+ rootGroup.addView(albumList);
+
+ albumList.setOnScrollListener(new AbsListView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {}
+
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+ int topRowVerticalPosition = (albumList.getChildCount() == 0) ? 0 : albumList.getChildAt(0).getTop();
+ refreshLayout.setEnabled(topRowVerticalPosition >= 0);
+ }
+ });
+ }
+ albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
+ SubsonicFragment fragment = new SelectDirectoryFragment();
+ Bundle args = new Bundle();
+ args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
+ args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
+ if ("newest".equals(albumListType)) {
+ args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true);
+ }
+ if(entry.getArtist() == null && entry.getParent() == null) {
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
+ }
+ fragment.setArguments(args);
+
+ replaceFragment(fragment, true);
+ }
+ });
+
+ emptyView = rootView.findViewById(R.id.select_album_empty);
+
+ registerForContextMenu(entryList);
+ registerForContextMenu(albumList);
+
if(entries == null) {
if(primaryFragment || secondaryFragment) {
load(false);
@@ -169,7 +216,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
else if(hideButtons && !showAll) {
if(albumListType != null) {
- menuInflater.inflate(R.menu.select_album_list, menu);
+ menuInflater.inflate(R.menu.empty, menu);
} else {
menuInflater.inflate(R.menu.select_album, menu);
}
@@ -259,11 +306,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
return true;
}
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
+ return super.onOptionsItemSelected(item);
- return false;
}
@Override
@@ -272,7 +316,18 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
+ MusicDirectory.Entry entry;
+ if(view.getId() == R.id.select_album_entries) {
+ if(info.position == 0) {
+ return;
+ }
+ entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
+ albumContext = false;
+ } else {
+ entry = (MusicDirectory.Entry) albumList.getItemAtPosition(info.position);
+ albumContext = true;
+ }
+
onCreateContextMenu(menu, view, menuInfo, entry);
if(!entry.isVideo() && !Util.isOffline(context) && playlistId == null && (podcastId == null || Util.isOffline(context) && podcastId != null)) {
menu.removeItem(R.id.song_menu_remove_playlist);
@@ -298,7 +353,16 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
- Object selectedItem = entries.get(showHeader ? (info.position - 1) : info.position);
+ Object selectedItem;
+ if(albumContext) {
+ selectedItem = albums.get(showHeader ? (info.position - 1) : info.position);
+ } else {
+ if(info.position == 0) {
+ return false;
+ }
+ info.position--;
+ selectedItem = entries.get(showHeader ? (info.position - 1) : info.position);
+ }
if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PLAY_NOW_AFTER, false) && menuItem.getItemId() == R.id.song_menu_play_now) {
List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
@@ -535,7 +599,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
SelectDirectoryFragment.this.albumListType = "genres-songs";
result = service.getSongsByGenre(albumListExtra, size, 0, context, this);
}
- } else if("genres".equals(albumListType)) {
+ } else if("genres".equals(albumListType) || "genres-songs".equals(albumListType)) {
result = service.getSongsByGenre(albumListExtra, size, 0, context, this);
} else {
result = service.getAlbumList(albumListType, size, 0, context, this);
@@ -563,7 +627,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
@Override
protected void done(Pair<MusicDirectory, Boolean> result) {
- entries = result.getFirst().getChildren();
+ albums = result.getFirst().getChildren(true, false);
+ entries = result.getFirst().getChildren(false, true);
licenseValid = result.getSecond();
finishLoading();
}
@@ -581,7 +646,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
if(showHeader) {
View header = createHeader(entries);
if(header != null) {
+ entryList.removeHeaderView(albumList);
entryList.addHeaderView(header, null, false);
+ entryList.addHeaderView(albumList);
}
}
} else {
@@ -591,13 +658,23 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
}
- emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE);
- entryAdapter = new EntryAdapter(context, getImageLoader(), entries, (podcastId == null) ? true : false);
- if(albumListType == null || "starred".equals(albumListType)) {
- entryList.setAdapter(entryAdapter);
- } else {
- entryList.setAdapter(new AlbumListAdapter(context, entryAdapter, albumListType, albumListExtra, albumListSize));
- }
+ emptyView.setVisibility((entries.isEmpty() && albums.isEmpty()) ? View.VISIBLE : View.GONE);
+ entryAdapter = new EntryAdapter(context, getImageLoader(), entries, (podcastId == null));
+ entryList.setAdapter(entryAdapter);
+ if("genres-songs".equals(albumListType)) {
+ ViewGroup rootGroup = (ViewGroup) rootView.findViewById(R.id.select_album_layout);
+ if(rootGroup.findViewById(R.id.gridview) != null) {
+ rootGroup.removeView(albumList);
+ rootGroup.addView(entryList);
+ }
+
+ entryList.setAdapter(new AlbumListAdapter(context, entryAdapter, albumListType, albumListExtra, albumListSize));
+ }
+ else if(albumListType == null || "starred".equals(albumListType)) {
+ albumList.setAdapter(new AlbumGridAdapter(context, getImageLoader(), albums));
+ } else {
+ albumList.setAdapter(new AlbumListAdapter(context, new AlbumGridAdapter(context, getImageLoader(), albums), albumListType, albumListExtra, albumListSize));
+ }
entryList.setVisibility(View.VISIBLE);
context.supportInvalidateOptionsMenu();
diff --git a/src/github/daneren2005/dsub/fragments/SelectListFragment.java b/src/github/daneren2005/dsub/fragments/SelectListFragment.java
index d44422ce..35bf95c1 100644
--- a/src/github/daneren2005/dsub/fragments/SelectListFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectListFragment.java
@@ -19,6 +19,7 @@
package github.daneren2005.dsub.fragments;
import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -26,6 +27,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AbsListView;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@@ -75,8 +77,21 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
+ refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout);
+ refreshLayout.setOnRefreshListener(this);
+
listView = (ListView)rootView.findViewById(R.id.fragment_list);
listView.setOnItemClickListener(this);
+ listView.setOnScrollListener(new AbsListView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {}
+
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+ int topRowVerticalPosition = (listView.getChildCount() == 0) ? 0 : listView.getChildAt(0).getTop();
+ refreshLayout.setEnabled(topRowVerticalPosition >= 0);
+ }
+ });
registerForContextMenu(listView);
emptyView = rootView.findViewById(R.id.fragment_list_empty);
@@ -100,11 +115,8 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if(super.onOptionsItemSelected(item)) {
- return true;
- }
+ return super.onOptionsItemSelected(item);
- return false;
}
@Override
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index bd0a3f45..45ab87e5 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -30,6 +30,7 @@ import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
+import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.ContextMenu;
import android.view.GestureDetector;
@@ -75,7 +76,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
-public class SubsonicFragment extends Fragment {
+public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = SubsonicFragment.class.getSimpleName();
private static int TAG_INC = 10;
private int tag;
@@ -92,6 +93,7 @@ public class SubsonicFragment extends Fragment {
protected Share share;
protected boolean artist = false;
protected boolean artistOverride = false;
+ protected SwipeRefreshLayout refreshLayout;
public SubsonicFragment() {
super();
@@ -135,9 +137,6 @@ public class SubsonicFragment extends Fragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.menu_refresh:
- refresh(true);
- return true;
case R.id.menu_shuffle:
onShuffleRequested();
return true;
@@ -406,6 +405,12 @@ public class SubsonicFragment extends Fragment {
}
+ @Override
+ public void onRefresh() {
+ refreshLayout.setRefreshing(false);
+ refresh();
+ }
+
protected void exit() {
if(context.getClass() != SubsonicFragmentActivity.class) {
Intent intent = new Intent(context, SubsonicFragmentActivity.class);
diff --git a/src/github/daneren2005/dsub/provider/DSubWidget4x1.java b/src/github/daneren2005/dsub/provider/DSubWidget4x1.java
index e00bf02d..9919eb22 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidget4x1.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidget4x1.java
@@ -18,7 +18,6 @@
*/
package github.daneren2005.dsub.provider;
-import android.appwidget.AppWidgetManager;
import github.daneren2005.dsub.R;
public class DSubWidget4x1 extends DSubWidgetProvider {
diff --git a/src/github/daneren2005/dsub/provider/DSubWidget4x2.java b/src/github/daneren2005/dsub/provider/DSubWidget4x2.java
index 4908f632..2aa6beae 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidget4x2.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidget4x2.java
@@ -18,7 +18,6 @@
*/
package github.daneren2005.dsub.provider;
-import android.appwidget.AppWidgetManager;
import github.daneren2005.dsub.R;
public class DSubWidget4x2 extends DSubWidgetProvider {
diff --git a/src/github/daneren2005/dsub/provider/DSubWidget4x3.java b/src/github/daneren2005/dsub/provider/DSubWidget4x3.java
index f1908d0d..dfe071c0 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidget4x3.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidget4x3.java
@@ -18,7 +18,6 @@
*/
package github.daneren2005.dsub.provider;
-import android.appwidget.AppWidgetManager;
import github.daneren2005.dsub.R;
public class DSubWidget4x3 extends DSubWidgetProvider {
diff --git a/src/github/daneren2005/dsub/provider/DSubWidget4x4.java b/src/github/daneren2005/dsub/provider/DSubWidget4x4.java
index 7fee2747..fa53918d 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidget4x4.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidget4x4.java
@@ -18,7 +18,6 @@
*/
package github.daneren2005.dsub.provider;
-import android.appwidget.AppWidgetManager;
import github.daneren2005.dsub.R;
public class DSubWidget4x4 extends DSubWidgetProvider {
diff --git a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
index be7dedf6..d66bc0ec 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
@@ -46,7 +46,6 @@ import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.Util;
diff --git a/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
index da6e0c2c..0d2a5ff5 100644
--- a/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
+++ b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
@@ -30,13 +30,15 @@ import android.support.v7.media.MediaRouteProviderDescriptor;
import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.RemoteController;
/**
* Created by Scott on 11/28/13.
*/
public class JukeboxRouteProvider extends MediaRouteProvider {
public static final String CATEGORY_JUKEBOX_ROUTE = "github.daneren2005.dsub.SERVER_JUKEBOX";
- private static int MAX_VOLUME = 10;
+ private RemoteController controller;
+ private static final int MAX_VOLUME = 10;
private DownloadService downloadService;
@@ -44,6 +46,10 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
super(context);
this.downloadService = (DownloadService) context;
+ broadcastDescriptor();
+ }
+
+ private void broadcastDescriptor() {
// Create intents
IntentFilter routeIntentFilter = new IntentFilter();
routeIntentFilter.addCategory(CATEGORY_JUKEBOX_ROUTE);
@@ -57,7 +63,7 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
.setPlaybackStream(AudioManager.STREAM_MUSIC)
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
.setDescription("Subsonic Jukebox")
- .setVolume(5)
+ .setVolume(controller == null ? 5 : (int) (controller.getVolume() * 10))
.setVolumeMax(MAX_VOLUME)
.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);
@@ -72,7 +78,7 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
return new JukeboxRouteController(downloadService);
}
- private static class JukeboxRouteController extends RouteController {
+ private class JukeboxRouteController extends RouteController {
private DownloadService downloadService;
public JukeboxRouteController(DownloadService downloadService) {
@@ -91,16 +97,35 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
@Override
public void onRelease() {
downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
+ controller = null;
}
@Override
public void onSelect() {
downloadService.setRemoteEnabled(RemoteControlState.JUKEBOX_SERVER);
+ controller = downloadService.getRemoteController();
}
@Override
public void onUnselect() {
downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
+ controller = null;
+ }
+
+ @Override
+ public void onUpdateVolume(int delta) {
+ if(controller != null) {
+ controller.updateVolume(delta > 0);
+ }
+ broadcastDescriptor();
+ }
+
+ @Override
+ public void onSetVolume(int volume) {
+ if(controller != null) {
+ controller.setVolume(volume);
+ }
+ broadcastDescriptor();
}
}
}
diff --git a/src/github/daneren2005/dsub/provider/MostRecentStubProvider.java b/src/github/daneren2005/dsub/provider/MostRecentStubProvider.java
index 33bc45c3..17447cda 100644
--- a/src/github/daneren2005/dsub/provider/MostRecentStubProvider.java
+++ b/src/github/daneren2005/dsub/provider/MostRecentStubProvider.java
@@ -41,7 +41,7 @@ public class MostRecentStubProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
- return new String();
+ return "";
}
@Override
diff --git a/src/github/daneren2005/dsub/provider/PlaylistStubProvider.java b/src/github/daneren2005/dsub/provider/PlaylistStubProvider.java
index c778e762..e817c047 100644
--- a/src/github/daneren2005/dsub/provider/PlaylistStubProvider.java
+++ b/src/github/daneren2005/dsub/provider/PlaylistStubProvider.java
@@ -41,7 +41,7 @@ public class PlaylistStubProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
- return new String();
+ return "";
}
@Override
diff --git a/src/github/daneren2005/dsub/provider/PodcastStubProvider.java b/src/github/daneren2005/dsub/provider/PodcastStubProvider.java
index 75def009..1c70e7f4 100644
--- a/src/github/daneren2005/dsub/provider/PodcastStubProvider.java
+++ b/src/github/daneren2005/dsub/provider/PodcastStubProvider.java
@@ -41,7 +41,7 @@ public class PodcastStubProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
- return new String();
+ return "";
}
@Override
diff --git a/src/github/daneren2005/dsub/provider/StarredStubProvider.java b/src/github/daneren2005/dsub/provider/StarredStubProvider.java
index bb865096..27a84e3f 100644
--- a/src/github/daneren2005/dsub/provider/StarredStubProvider.java
+++ b/src/github/daneren2005/dsub/provider/StarredStubProvider.java
@@ -41,7 +41,7 @@ public class StarredStubProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
- return new String();
+ return "";
}
@Override
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index d98a67e1..d0740704 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -87,7 +87,7 @@ public class CachedMusicService implements MusicService {
result = musicService.isLicenseValid(context, progressListener);
// Only save a copy license is valid
- if(result == true) {
+ if(result) {
FileUtil.serialize(context, (Boolean) result, getCacheName(context, "license"));
}
}
diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java
index 639c7ebe..7568fe4d 100644
--- a/src/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/src/github/daneren2005/dsub/service/ChromeCastController.java
@@ -54,9 +54,6 @@ public class ChromeCastController extends RemoteController {
private CastDevice castDevice;
private GoogleApiClient apiClient;
- private ConnectionCallbacks connectionCallbacks;
- private ConnectionFailedListener connectionFailedListener;
- private Cast.Listener castClientListener;
private boolean applicationStarted = false;
private boolean waitingForReconnect = false;
@@ -81,9 +78,9 @@ public class ChromeCastController extends RemoteController {
public void create(boolean playing, int seconds) {
downloadService.setPlayerState(PlayerState.PREPARING);
- connectionCallbacks = new ConnectionCallbacks(playing, seconds);
- connectionFailedListener = new ConnectionFailedListener();
- castClientListener = new Cast.Listener() {
+ ConnectionCallbacks connectionCallbacks = new ConnectionCallbacks(playing, seconds);
+ ConnectionFailedListener connectionFailedListener = new ConnectionFailedListener();
+ Cast.Listener castClientListener = new Cast.Listener() {
@Override
public void onApplicationStatusChanged() {
if (apiClient != null && apiClient.isConnected()) {
@@ -96,7 +93,7 @@ public class ChromeCastController extends RemoteController {
if (apiClient != null && applicationStarted) {
try {
gain = Cast.CastApi.getVolume(apiClient);
- } catch(Exception e) {
+ } catch (Exception e) {
Log.w(TAG, "Failed to get volume");
}
}
@@ -203,7 +200,18 @@ public class ChromeCastController extends RemoteController {
}
@Override
- public void setVolume(boolean up) {
+ public void setVolume(int volume) {
+ gain = volume / 10.0;
+
+ getVolumeToast().setVolume((float) gain);
+ try {
+ Cast.CastApi.setVolume(apiClient, gain);
+ } catch(Exception e) {
+ Log.e(TAG, "Failed to the volume");
+ }
+ }
+ @Override
+ public void updateVolume(boolean up) {
double delta = up ? 0.1 : -0.1;
gain += delta;
gain = Math.max(gain, 0.0);
@@ -216,6 +224,10 @@ public class ChromeCastController extends RemoteController {
Log.e(TAG, "Failed to the volume");
}
}
+ @Override
+ public double getVolume() {
+ return Cast.CastApi.getVolume(apiClient);
+ }
@Override
public int getRemotePosition() {
diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java
index 9b7dd45d..dc1c7cbd 100644
--- a/src/github/daneren2005/dsub/service/DownloadFile.java
+++ b/src/github/daneren2005/dsub/service/DownloadFile.java
@@ -31,7 +31,6 @@ import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.util.Log;
import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.service.parser.SubsonicRESTException;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
@@ -67,6 +66,7 @@ public class DownloadFile implements BufferFile {
private boolean completeWhenDone = false;
private Long contentLength = null;
private long currentSpeed = 0;
+ private boolean rateLimit = false;
public DownloadFile(Context context, MusicDirectory.Entry song, boolean save) {
this.context = context;
@@ -150,10 +150,12 @@ public class DownloadFile implements BufferFile {
}
public synchronized void download() {
+ rateLimit = false;
preDownload();
downloadTask.execute();
}
public synchronized void downloadNow(MusicService musicService) {
+ rateLimit = true;
preDownload();
downloadTask.setMusicService(musicService);
try {
@@ -296,10 +298,10 @@ public class DownloadFile implements BufferFile {
public void setPlaying(boolean isPlaying) {
try {
- if(saveWhenDone && isPlaying == false) {
+ if(saveWhenDone && !isPlaying) {
Util.renameFile(completeFile, saveFile);
saveWhenDone = false;
- } else if(completeWhenDone && isPlaying == false) {
+ } else if(completeWhenDone && !isPlaying) {
if(save) {
Util.renameFile(partialFile, saveFile);
mediaStoreService.saveInMediaStore(DownloadFile.this);
@@ -523,6 +525,7 @@ public class DownloadFile implements BufferFile {
long lastLog = System.currentTimeMillis();
long lastCount = 0;
+ boolean activeLimit = rateLimit;
while (!isCancelled() && (n = in.read(buffer)) != -1) {
out.write(buffer, 0, n);
count += n;
@@ -534,6 +537,21 @@ public class DownloadFile implements BufferFile {
currentSpeed = lastCount / ((now - lastLog) / 1000L);
lastLog = now;
lastCount = 0;
+
+ // Re-establish every few seconds whether screen is on or not
+ if(rateLimit) {
+ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ if(pm.isScreenOn()) {
+ activeLimit = true;
+ } else {
+ activeLimit = false;
+ }
+ }
+ }
+
+ // If screen is on and rateLimit is true, stop downloading from exhausting bandwidth
+ if(activeLimit) {
+ Thread.sleep(10L);
}
}
return count;
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 3637f731..66295d5e 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -30,7 +30,6 @@ import static github.daneren2005.dsub.domain.PlayerState.STOPPED;
import github.daneren2005.dsub.audiofx.AudioEffectsController;
import github.daneren2005.dsub.audiofx.EqualizerController;
-import github.daneren2005.dsub.audiofx.LoudnessEnhancerController;
import github.daneren2005.dsub.audiofx.VisualizerController;
import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -70,9 +69,9 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.PowerManager;
import android.support.v7.media.MediaRouteSelector;
+import android.support.v7.media.MediaRouter;
import android.util.Log;
import android.support.v4.util.LruCache;
-import java.net.URLEncoder;
/**
* @author Sindre Mehus
@@ -99,7 +98,6 @@ public class DownloadService extends Service {
private MediaPlayer nextMediaPlayer;
private int audioSessionId;
private boolean nextSetup = false;
- private boolean isPartial = true;
private final List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
private final List<DownloadFile> backgroundDownloadList = new ArrayList<DownloadFile>();
private final List<DownloadFile> toDelete = new ArrayList<DownloadFile>();
@@ -128,7 +126,6 @@ public class DownloadService extends Service {
private PowerManager.WakeLock wakeLock;
private boolean keepScreenOn;
private int cachedPosition = 0;
- private long downloadRevision;
private boolean downloadOngoing = false;
private AudioEffectsController effectsController;
@@ -1115,6 +1112,10 @@ public class DownloadService extends Service {
return remoteState != RemoteControlState.LOCAL;
}
+ public RemoteController getRemoteController() {
+ return remoteController;
+ }
+
public void setRemoteEnabled(RemoteControlState newState) {
if(instance != null) {
setRemoteEnabled(newState, null);
@@ -1229,8 +1230,19 @@ public class DownloadService extends Service {
}
}
- public void setRemoteVolume(boolean up) {
- remoteController.setVolume(up);
+ public void registerRoute(MediaRouter router) {
+ mRemoteControl.registerRoute(router);
+ }
+ public void unregisterRoute(MediaRouter router) {
+ mRemoteControl.unregisterRoute(router);
+ }
+
+ public void updateRemoteVolume(boolean up) {
+ if(remoteState == RemoteControlState.JUKEBOX_SERVER) {
+ mediaRouter.getSelectedRoute().requestUpdateVolume(up ? 1 : -1);
+ } else {
+ remoteController.updateVolume(up);
+ }
}
public void startRemoteScan() {
@@ -1262,7 +1274,7 @@ public class DownloadService extends Service {
try {
downloadFile.setPlaying(true);
final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
- isPartial = file.equals(downloadFile.getPartialFile());
+ boolean isPartial = file.equals(downloadFile.getPartialFile());
downloadFile.updateModificationDate();
mediaPlayer.setOnCompletionListener(null);
@@ -1520,7 +1532,11 @@ public class DownloadService extends Service {
private void handleError(Exception x) {
Log.w(TAG, "Media player error: " + x, x);
if(mediaPlayer != null) {
- mediaPlayer.reset();
+ try {
+ mediaPlayer.reset();
+ } catch(Exception e) {
+ Log.e(TAG, "Failed to reset player in error handler");
+ }
}
setPlayerState(IDLE);
}
@@ -1618,7 +1634,6 @@ public class DownloadService extends Service {
if(!backgroundDownloadList.isEmpty()) {
Util.showDownloadingNotification(this, currentDownloading, backgroundDownloadList.size());
- downloadRevision = revision;
downloadOngoing = true;
} else if(backgroundDownloadList.isEmpty() && downloadOngoing) {
Util.hideDownloadingNotification(this);
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index c4a79ee0..5e8b0f8b 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -21,7 +21,6 @@ package github.daneren2005.dsub.service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.atomic.AtomicBoolean;
diff --git a/src/github/daneren2005/dsub/service/JukeboxController.java b/src/github/daneren2005/dsub/service/JukeboxController.java
index ebebbaf8..da1538be 100644
--- a/src/github/daneren2005/dsub/service/JukeboxController.java
+++ b/src/github/daneren2005/dsub/service/JukeboxController.java
@@ -124,7 +124,15 @@ public class JukeboxController extends RemoteController {
downloadService.setPlayerState(PlayerState.STARTED);
}
@Override
- public void setVolume(boolean up) {
+ public void setVolume(int volume) {
+ gain = volume / 10.0f;
+
+ getVolumeToast().setVolume(gain);
+ tasks.remove(SetGain.class);
+ tasks.add(new SetGain(gain));
+ }
+ @Override
+ public void updateVolume(boolean up) {
float delta = up ? 0.1f : -0.1f;
gain += delta;
gain = Math.max(gain, 0.0f);
@@ -134,6 +142,10 @@ public class JukeboxController extends RemoteController {
tasks.remove(SetGain.class);
tasks.add(new SetGain(gain));
}
+ @Override
+ public double getVolume() {
+ return gain;
+ }
@Override
public int getRemotePosition() {
diff --git a/src/github/daneren2005/dsub/service/RemoteController.java b/src/github/daneren2005/dsub/service/RemoteController.java
index e41a37ad..d5a4d8df 100644
--- a/src/github/daneren2005/dsub/service/RemoteController.java
+++ b/src/github/daneren2005/dsub/service/RemoteController.java
@@ -46,7 +46,9 @@ public abstract class RemoteController {
public abstract void updatePlaylist();
public abstract void changePosition(int seconds);
public abstract void changeTrack(int index, DownloadFile song);
- public abstract void setVolume(boolean up);
+ public abstract void setVolume(int volume);
+ public abstract void updateVolume(boolean up);
+ public abstract double getVolume();
public abstract int getRemotePosition();
public int getRemoteDuration() {
diff --git a/src/github/daneren2005/dsub/service/parser/AlbumListParser.java b/src/github/daneren2005/dsub/service/parser/AlbumListParser.java
index 9cf064e6..880a9a22 100644
--- a/src/github/daneren2005/dsub/service/parser/AlbumListParser.java
+++ b/src/github/daneren2005/dsub/service/parser/AlbumListParser.java
@@ -36,8 +36,6 @@ public class AlbumListParser extends MusicDirectoryEntryParser {
}
public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
-
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory dir = new MusicDirectory();
@@ -57,7 +55,6 @@ public class AlbumListParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
diff --git a/src/github/daneren2005/dsub/service/parser/BookmarkParser.java b/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
index a71e0e8b..23db3a07 100644
--- a/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
+++ b/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
@@ -37,7 +37,6 @@ public class BookmarkParser extends MusicDirectoryEntryParser {
}
public List<Bookmark> parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<Bookmark> bookmarks = new ArrayList<Bookmark>();
@@ -69,7 +68,6 @@ public class BookmarkParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return bookmarks;
}
diff --git a/src/github/daneren2005/dsub/service/parser/ChatMessageParser.java b/src/github/daneren2005/dsub/service/parser/ChatMessageParser.java
index 1425a734..8e37de40 100644
--- a/src/github/daneren2005/dsub/service/parser/ChatMessageParser.java
+++ b/src/github/daneren2005/dsub/service/parser/ChatMessageParser.java
@@ -38,7 +38,6 @@ public class ChatMessageParser extends AbstractParser {
}
public List<ChatMessage> parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<ChatMessage> result = new ArrayList<ChatMessage>();
int eventType;
@@ -60,7 +59,6 @@ public class ChatMessageParser extends AbstractParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return result;
}
diff --git a/src/github/daneren2005/dsub/service/parser/GenreParser.java b/src/github/daneren2005/dsub/service/parser/GenreParser.java
index 35913ba9..e963442c 100644
--- a/src/github/daneren2005/dsub/service/parser/GenreParser.java
+++ b/src/github/daneren2005/dsub/service/parser/GenreParser.java
@@ -45,8 +45,6 @@ public class GenreParser extends AbstractParser {
}
public List<Genre> parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
-
List<Genre> result = new ArrayList<Genre>();
StringReader sr = null;
@@ -118,7 +116,6 @@ public class GenreParser extends AbstractParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return Genre.GenreComparator.sort(result);
}
diff --git a/src/github/daneren2005/dsub/service/parser/IndexesParser.java b/src/github/daneren2005/dsub/service/parser/IndexesParser.java
index 30ea190b..3af76e1d 100644
--- a/src/github/daneren2005/dsub/service/parser/IndexesParser.java
+++ b/src/github/daneren2005/dsub/service/parser/IndexesParser.java
@@ -49,9 +49,7 @@ public class IndexesParser extends MusicDirectoryEntryParser {
}
public Indexes parse(Reader reader, ProgressListener progressListener) throws Exception {
-
long t0 = System.currentTimeMillis();
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<Artist> artists = new ArrayList<Artist>();
diff --git a/src/github/daneren2005/dsub/service/parser/LyricsParser.java b/src/github/daneren2005/dsub/service/parser/LyricsParser.java
index 98b0f6a0..b621d518 100644
--- a/src/github/daneren2005/dsub/service/parser/LyricsParser.java
+++ b/src/github/daneren2005/dsub/service/parser/LyricsParser.java
@@ -36,7 +36,6 @@ public class LyricsParser extends AbstractParser {
}
public Lyrics parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
Lyrics lyrics = null;
diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
index 75f878be..e09aa33b 100644
--- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
+++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
@@ -44,7 +44,6 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser {
public MusicDirectory parse(String artist, Reader reader, ProgressListener progressListener) throws Exception {
long t0 = System.currentTimeMillis();
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory dir = new MusicDirectory();
@@ -74,7 +73,6 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
// Only apply sorting on server version 4.7 and greater, where disc is supported
if(Util.checkServerVersion(context, "1.8.0") && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true)) {
diff --git a/src/github/daneren2005/dsub/service/parser/MusicFoldersParser.java b/src/github/daneren2005/dsub/service/parser/MusicFoldersParser.java
index 5dfebf27..246c3415 100644
--- a/src/github/daneren2005/dsub/service/parser/MusicFoldersParser.java
+++ b/src/github/daneren2005/dsub/service/parser/MusicFoldersParser.java
@@ -27,7 +27,6 @@ import org.xmlpull.v1.XmlPullParser;
import android.content.Context;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicFolder;
-import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.util.ProgressListener;
/**
@@ -40,8 +39,6 @@ public class MusicFoldersParser extends AbstractParser {
}
public List<MusicFolder> parse(Reader reader, ProgressListener progressListener) throws Exception {
-
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<MusicFolder> result = new ArrayList<MusicFolder>();
@@ -61,7 +58,6 @@ public class MusicFoldersParser extends AbstractParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return result;
}
diff --git a/src/github/daneren2005/dsub/service/parser/PlaylistParser.java b/src/github/daneren2005/dsub/service/parser/PlaylistParser.java
index c630eb44..1eda1806 100644
--- a/src/github/daneren2005/dsub/service/parser/PlaylistParser.java
+++ b/src/github/daneren2005/dsub/service/parser/PlaylistParser.java
@@ -36,7 +36,6 @@ public class PlaylistParser extends MusicDirectoryEntryParser {
}
public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory dir = new MusicDirectory();
@@ -57,7 +56,6 @@ public class PlaylistParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
diff --git a/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java b/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java
index a5bf2497..c3b47f47 100644
--- a/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java
+++ b/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java
@@ -39,8 +39,6 @@ public class PlaylistsParser extends AbstractParser {
}
public List<Playlist> parse(Reader reader, ProgressListener progressListener) throws Exception {
-
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<Playlist> result = new ArrayList<Playlist>();
@@ -65,7 +63,6 @@ public class PlaylistsParser extends AbstractParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return PlaylistAdapter.PlaylistComparator.sort(result);
}
diff --git a/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java b/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java
index bfdef7f2..6c83fad6 100644
--- a/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java
+++ b/src/github/daneren2005/dsub/service/parser/PodcastChannelParser.java
@@ -37,7 +37,6 @@ public class PodcastChannelParser extends AbstractParser {
}
public List<PodcastChannel> parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<PodcastChannel> channels = new ArrayList<PodcastChannel>();
diff --git a/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java b/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java
index 58b1432b..c331f7e1 100644
--- a/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java
+++ b/src/github/daneren2005/dsub/service/parser/PodcastEntryParser.java
@@ -39,7 +39,6 @@ public class PodcastEntryParser extends AbstractParser {
}
public MusicDirectory parse(String channel, Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory episodes = new MusicDirectory();
diff --git a/src/github/daneren2005/dsub/service/parser/RandomSongsParser.java b/src/github/daneren2005/dsub/service/parser/RandomSongsParser.java
index 3e62d3dc..88be3662 100644
--- a/src/github/daneren2005/dsub/service/parser/RandomSongsParser.java
+++ b/src/github/daneren2005/dsub/service/parser/RandomSongsParser.java
@@ -36,7 +36,6 @@ public class RandomSongsParser extends MusicDirectoryEntryParser {
}
public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory dir = new MusicDirectory();
@@ -54,7 +53,6 @@ public class RandomSongsParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
diff --git a/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java b/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java
index abf96d7f..ce4a71c8 100644
--- a/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java
+++ b/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java
@@ -40,7 +40,6 @@ public class SearchResult2Parser extends MusicDirectoryEntryParser {
}
public SearchResult parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<Artist> artists = new ArrayList<Artist>();
@@ -69,7 +68,6 @@ public class SearchResult2Parser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return new SearchResult(artists, albums, songs);
}
diff --git a/src/github/daneren2005/dsub/service/parser/SearchResultParser.java b/src/github/daneren2005/dsub/service/parser/SearchResultParser.java
index c8ef4031..952b95bc 100644
--- a/src/github/daneren2005/dsub/service/parser/SearchResultParser.java
+++ b/src/github/daneren2005/dsub/service/parser/SearchResultParser.java
@@ -41,7 +41,6 @@ public class SearchResultParser extends MusicDirectoryEntryParser {
}
public SearchResult parse(Reader reader, ProgressListener progressListener) throws Exception {
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
@@ -59,7 +58,6 @@ public class SearchResultParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return new SearchResult(Collections.<Artist>emptyList(), Collections.<MusicDirectory.Entry>emptyList(), songs);
}
diff --git a/src/github/daneren2005/dsub/service/parser/ShareParser.java b/src/github/daneren2005/dsub/service/parser/ShareParser.java
index 27a53d66..25feb5af 100644
--- a/src/github/daneren2005/dsub/service/parser/ShareParser.java
+++ b/src/github/daneren2005/dsub/service/parser/ShareParser.java
@@ -20,7 +20,6 @@ package github.daneren2005.dsub.service.parser;
import android.content.Context;
import android.content.SharedPreferences;
-import android.util.Log;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.Share;
@@ -44,8 +43,6 @@ public class ShareParser extends MusicDirectoryEntryParser {
}
public List<Share> parse(Reader reader, ProgressListener progressListener) throws Exception {
-
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<Share> dir = new ArrayList<Share>();
@@ -88,7 +85,6 @@ public class ShareParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
diff --git a/src/github/daneren2005/dsub/service/parser/StarredListParser.java b/src/github/daneren2005/dsub/service/parser/StarredListParser.java
index bd2a7888..89addecd 100644
--- a/src/github/daneren2005/dsub/service/parser/StarredListParser.java
+++ b/src/github/daneren2005/dsub/service/parser/StarredListParser.java
@@ -36,8 +36,6 @@ public class StarredListParser extends MusicDirectoryEntryParser {
}
public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception {
-
- updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory dir = new MusicDirectory();
@@ -63,7 +61,6 @@ public class StarredListParser extends MusicDirectoryEntryParser {
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
- updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
index ba4f34c9..f680becf 100644
--- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
+++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
@@ -82,18 +82,16 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
for(MusicDirectory.Entry entry: playlist.getChildren()) {
DownloadFile file = new DownloadFile(context, entry, true);
String path = file.getCompleteFile().getPath();
- if(!cachedPlaylist.synced.contains(path)) {
- while(!file.isSaved() && !file.isFailedMax()) {
- file.downloadNow(musicService);
- if(!updated.contains(playlist.getName())) {
- updated.add(playlist.getName());
- }
+ while(!file.isSaved() && !file.isFailedMax()) {
+ file.downloadNow(musicService);
+ if(file.isSaved() && !updated.contains(playlist.getName())) {
+ updated.add(playlist.getName());
}
+ }
- // Add to cached path set if saved
- if(file.isSaved()) {
- cachedPlaylist.synced.add(path);
- }
+ // Add to cached path set if saved
+ if(file.isSaved() && !cachedPlaylist.synced.contains(path)) {
+ cachedPlaylist.synced.add(path);
}
origPathList.remove(path);
@@ -118,12 +116,13 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
Log.e(TAG, "Failed to get playlist " + id + " for " + serverName, e);
}
- if(updated.size() > 0) {
- SyncUtil.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated));
- }
if(updated.size() > 0 || removed) {
SyncUtil.setSyncedPlaylists(context, instance, playlistList);
}
}
+
+ if(updated.size() > 0) {
+ SyncUtil.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated));
+ }
}
}
diff --git a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java
index a23fa63f..54c10f41 100644
--- a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java
+++ b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java
@@ -25,7 +25,6 @@ import android.util.Log;
import java.io.File;
import java.util.ArrayList;
-import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
diff --git a/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java
index 1f380e90..eccdaee2 100644
--- a/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java
+++ b/src/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java
@@ -149,10 +149,6 @@ public class SubsonicSyncAdapter extends AbstractThreadedSyncAdapter {
private boolean isValidServer(Context context, int instance) {
String url = Util.getRestUrl(context, "null", instance, false);
- if(url.contains("demo.subsonic.org") || url.contains("yourhost")) {
- return false;
- } else {
- return true;
- }
+ return !(url.contains("demo.subsonic.org") || url.contains("yourhost"));
}
}
diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java
index c3008b3a..b1b00cc5 100644
--- a/src/github/daneren2005/dsub/util/ImageLoader.java
+++ b/src/github/daneren2005/dsub/util/ImageLoader.java
@@ -215,7 +215,6 @@ public class ImageLoader {
}
}
imageView.setImageDrawable(drawable);
- return;
}
}
diff --git a/src/github/daneren2005/dsub/util/MediaRouteManager.java b/src/github/daneren2005/dsub/util/MediaRouteManager.java
index 9b4110f3..cad8afe3 100644
--- a/src/github/daneren2005/dsub/util/MediaRouteManager.java
+++ b/src/github/daneren2005/dsub/util/MediaRouteManager.java
@@ -15,7 +15,6 @@
package github.daneren2005.dsub.util;
-import android.support.v7.media.MediaControlIntent;
import android.support.v7.media.MediaRouteProvider;
import android.support.v7.media.MediaRouteSelector;
import android.support.v7.media.MediaRouter;
@@ -86,9 +85,17 @@ public class MediaRouteManager extends MediaRouter.Callback {
downloadService.setRemoteEnabled(RemoteControlState.CHROMECAST, controller);
}
}
+
+ if(downloadService.isRemoteEnabled()) {
+ downloadService.registerRoute(router);
+ }
}
@Override
public void onRouteUnselected(MediaRouter router, RouteInfo info) {
+ if(downloadService.isRemoteEnabled()) {
+ downloadService.unregisterRoute(router);
+ }
+
downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
}
diff --git a/src/github/daneren2005/dsub/util/SyncUtil.java b/src/github/daneren2005/dsub/util/SyncUtil.java
index 3a338543..0c567681 100644
--- a/src/github/daneren2005/dsub/util/SyncUtil.java
+++ b/src/github/daneren2005/dsub/util/SyncUtil.java
@@ -5,7 +5,6 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
-import android.util.Log;
import java.io.File;
import java.io.Serializable;
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 8488420e..10b0a429 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -39,7 +39,6 @@ import android.media.AudioManager.OnAudioFocusChangeListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
-import android.opengl.Visibility;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
@@ -173,11 +172,7 @@ public final class Util {
public static boolean checkServerVersion(Context context, String requiredVersion) {
Version version = Util.getServerRestVersion(context);
Version required = new Version(requiredVersion);
- if(version != null && version.compareTo(required) >= 0) {
- return true;
- } else {
- return false;
- }
+ return version != null && version.compareTo(required) >= 0;
}
public static int getServerCount(Context context) {
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
index c3f3f70c..320092e9 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
@@ -3,6 +3,7 @@ package github.daneren2005.dsub.util.compat;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import android.content.ComponentName;
import android.content.Context;
+import android.support.v7.media.MediaRouter;
import android.util.Log;
public class RemoteControlClientBase extends RemoteControlClientHelper {
@@ -11,22 +12,32 @@ public class RemoteControlClientBase extends RemoteControlClientHelper {
@Override
public void register(Context context, ComponentName mediaButtonReceiverComponent) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
}
@Override
public void unregister(Context context) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
}
@Override
public void setPlaybackState(int state) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
}
@Override
public void updateMetadata(Context context, Entry currentSong) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
+ }
+
+ @Override
+ public void registerRoute(MediaRouter router) {
+
+ }
+
+ @Override
+ public void unregisterRoute(MediaRouter router) {
+
}
}
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java
index 9826851d..93075a28 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java
@@ -3,6 +3,7 @@ package github.daneren2005.dsub.util.compat;
import github.daneren2005.dsub.domain.MusicDirectory;
import android.content.ComponentName;
import android.content.Context;
+import android.support.v7.media.MediaRouter;
import android.os.Build;
public abstract class RemoteControlClientHelper {
@@ -25,5 +26,7 @@ public abstract class RemoteControlClientHelper {
public abstract void unregister(final Context context);
public abstract void setPlaybackState(final int state);
public abstract void updateMetadata(final Context context, final MusicDirectory.Entry currentSong);
+ public abstract void registerRoute(MediaRouter router);
+ public abstract void unregisterRoute(MediaRouter router);
}
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
index 56378a25..50283da6 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
@@ -11,6 +11,7 @@ import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
import android.media.RemoteControlClient;
+import android.support.v7.media.MediaRouter;
import github.daneren2005.dsub.activity.SubsonicActivity;
@@ -68,6 +69,17 @@ public class RemoteControlClientICS extends RemoteControlClientHelper {
imageLoader.loadImage(context, mRemoteControl, currentSong);
}
}
+
+ @Override
+ public void registerRoute(MediaRouter router) {
+ router.addRemoteControlClient(mRemoteControl);
+ }
+
+ @Override
+ public void unregisterRoute(MediaRouter router) {
+ router.removeRemoteControlClient(mRemoteControl);
+ }
+
protected void updateMetadata(final MusicDirectory.Entry currentSong, final RemoteControlClient.MetadataEditor editor) {
editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, (currentSong == null) ? null : currentSong.getArtist())
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, (currentSong == null) ? null : currentSong.getAlbum())
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java
deleted file mode 100644
index 532aec5b..00000000
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package github.daneren2005.dsub.util.compat;
-
-import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.util.ImageLoader;
-import android.annotation.TargetApi;
-import android.app.PendingIntent;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.media.AudioManager;
-import android.media.MediaMetadataEditor;
-import android.media.MediaMetadataRetriever;
-import android.media.Rating;
-import android.media.RemoteControlClient;
-import android.os.AsyncTask;
-import android.util.Log;
-
-import github.daneren2005.dsub.activity.SubsonicActivity;
-import github.daneren2005.dsub.service.DownloadService;
-import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
-import github.daneren2005.dsub.util.SilentBackgroundTask;
-import github.daneren2005.dsub.util.Util;
-import java.io.File;
-import java.util.Arrays;
-
-@TargetApi(19)
-public class RemoteControlClientKK extends RemoteControlClientJB {
- private static String TAG = RemoteControlClientKK.class.getSimpleName();
- protected MusicDirectory.Entry currentSong;
-
- @Override
- public void register(final Context context, final ComponentName mediaButtonReceiverComponent) {
- super.register(context, mediaButtonReceiverComponent);
-
- mRemoteControl.setMetadataUpdateListener(new RemoteControlClient.OnMetadataUpdateListener() {
- @Override
- public void onMetadataUpdate(int key, Object newValue) {
- if(key == MediaMetadataEditor.RATING_KEY_BY_USER) {
- Rating rating = (Rating) newValue;
- setStarred(currentSong, rating.hasHeart());
- }
- }
- });
- }
-
- @Override
- protected void updateMetadata(final MusicDirectory.Entry currentSong, final RemoteControlClient.MetadataEditor editor) {
- super.updateMetadata(currentSong, editor);
- editor.putObject(MediaMetadataEditor.RATING_KEY_BY_USER, Rating.newHeartRating(currentSong.isStarred()));
- editor.addEditableKey(MediaMetadataEditor.RATING_KEY_BY_USER);
- this.currentSong = currentSong;
- }
-
- @Override
- protected int getTransportFlags() {
- return super.getTransportFlags() | RemoteControlClient.FLAG_KEY_MEDIA_RATING;
- }
-
- private void setStarred(final MusicDirectory.Entry entry, final boolean starred) {
- entry.setStarred(starred);
-
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- try {
- MusicService musicService = MusicServiceFactory.getMusicService(downloadService);
- musicService.setStarred(Arrays.asList(entry.getId()), null, null, starred, downloadService, null);
-
- // Make sure to clear parent cache
- String s = Util.getRestUrl(downloadService, null) + entry.getParent();
- String parentCache = "directory-" + s.hashCode() + ".ser";
- File file = new File(downloadService.getCacheDir(), parentCache);
- file.delete();
- } catch(Exception e) {
- Log.w(TAG, "Failed to set star for " + entry.getTitle());
- }
- return null;
- }
- }.execute();
- }
-}
diff --git a/src/github/daneren2005/dsub/view/AlbumCell.java b/src/github/daneren2005/dsub/view/AlbumCell.java
new file mode 100644
index 00000000..9cee0c41
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/AlbumCell.java
@@ -0,0 +1,88 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.io.File;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.ImageLoader;
+
+public class AlbumCell extends UpdateView {
+ private static final String TAG = AlbumCell.class.getSimpleName();
+
+ private Context context;
+ private MusicDirectory.Entry album;
+ private File file;
+
+ private View coverArtView;
+ private TextView titleView;
+ private TextView artistView;
+
+ public AlbumCell(Context context) {
+ super(context);
+ this.context = context;
+ LayoutInflater.from(context).inflate(R.layout.album_cell_item, this, true);
+
+ coverArtView = findViewById(R.id.album_coverart);
+ titleView = (TextView) findViewById(R.id.album_title);
+ artistView = (TextView) findViewById(R.id.album_artist);
+ moreButton = (ImageView) findViewById(R.id.album_more);
+ moreButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ v.showContextMenu();
+ }
+ });
+ }
+
+ protected void setObjectImpl(Object obj1, Object obj2) {
+ this.album = (MusicDirectory.Entry) obj1;
+ if(album.getAlbum() == null) {
+ titleView.setText(album.getTitle());
+ } else {
+ titleView.setText(album.getAlbum());
+ }
+ String artist = album.getArtist();
+ if(artist == null) {
+ artist = "";
+ }
+ if(album.getYear() != null) {
+ artist += " - " + album.getYear();
+ }
+ artistView.setText(artist);
+ artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE);
+ ((ImageLoader)obj2).loadImage(coverArtView, album, false, true);
+ file = null;
+ }
+
+ @Override
+ protected void updateBackground() {
+ if(file == null) {
+ file = FileUtil.getAlbumDirectory(context, album);
+ }
+
+ exists = file.exists();
+ isStarred = album.isStarred();
+ }
+}
diff --git a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java
new file mode 100644
index 00000000..3c81fa9a
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java
@@ -0,0 +1,55 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+
+import java.util.List;
+
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.util.ImageLoader;
+
+public class AlbumGridAdapter extends ArrayAdapter<MusicDirectory.Entry> {
+ private final static String TAG = AlbumGridAdapter.class.getSimpleName();
+ private final Context activity;
+ private final ImageLoader imageLoader;
+ private List<MusicDirectory.Entry> entries;
+
+ public AlbumGridAdapter(Context activity, ImageLoader imageLoader, List<MusicDirectory.Entry> entries) {
+ super(activity, android.R.layout.simple_list_item_1, entries);
+ this.entries = entries;
+ this.activity = activity;
+ this.imageLoader = imageLoader;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ MusicDirectory.Entry entry = getItem(position);
+
+ AlbumCell view;
+ if(convertView instanceof AlbumCell) {
+ view = (AlbumCell) convertView;
+ } else {
+ view = new AlbumCell(activity);
+ }
+
+ view.setObject(entry, imageLoader);
+ return view;
+ }
+}
diff --git a/src/github/daneren2005/dsub/view/AlbumListAdapter.java b/src/github/daneren2005/dsub/view/AlbumListAdapter.java
index f5f3e5fc..308eb7d7 100644
--- a/src/github/daneren2005/dsub/view/AlbumListAdapter.java
+++ b/src/github/daneren2005/dsub/view/AlbumListAdapter.java
@@ -63,11 +63,7 @@ public class AlbumListAdapter extends EndlessAdapter {
result = service.getAlbumList(type, size, offset, context, null);
}
entries = result.getChildren();
- if(entries.size() > 0) {
- return true;
- } else {
- return false;
- }
+ return entries.size() > 0;
}
@Override
diff --git a/src/github/daneren2005/dsub/view/AlbumView.java b/src/github/daneren2005/dsub/view/AlbumView.java
deleted file mode 100644
index be13aa5c..00000000
--- a/src/github/daneren2005/dsub/view/AlbumView.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- 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.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.ImageButton;
-import android.widget.ImageView;
-import android.widget.TextView;
-import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.util.FileUtil;
-import github.daneren2005.dsub.util.ImageLoader;
-import github.daneren2005.dsub.util.Util;
-import java.io.File;
-import java.util.List;
-
-/**
- * Used to display albums in a {@code ListView}.
- *
- * @author Sindre Mehus
- */
-public class AlbumView extends UpdateView {
- private static final String TAG = AlbumView.class.getSimpleName();
-
- private Context context;
- private MusicDirectory.Entry album;
- private File file;
-
- private TextView titleView;
- private TextView artistView;
- private View coverArtView;
-
- public AlbumView(Context context) {
- super(context);
- this.context = context;
- LayoutInflater.from(context).inflate(R.layout.album_list_item, this, true);
-
- titleView = (TextView) findViewById(R.id.album_title);
- artistView = (TextView) findViewById(R.id.album_artist);
- coverArtView = findViewById(R.id.album_coverart);
- starButton = (ImageButton) findViewById(R.id.album_star);
- starButton.setFocusable(false);
-
- moreButton = (ImageView) findViewById(R.id.album_more);
- moreButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- v.showContextMenu();
- }
- });
- }
-
- protected void setObjectImpl(Object obj1, Object obj2) {
- this.album = (MusicDirectory.Entry) obj1;
- if(album.getAlbum() == null) {
- titleView.setText(album.getTitle());
- } else {
- titleView.setText(album.getAlbum());
- }
- String artist = album.getArtist();
- if(artist == null) {
- artist = "";
- }
- if(album.getYear() != null) {
- artist += " - " + album.getYear();
- }
- artistView.setText(artist);
- artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE);
- ((ImageLoader)obj2).loadImage(coverArtView, album, false, true);
- file = null;
- }
-
- @Override
- protected void updateBackground() {
- if(file == null) {
- file = FileUtil.getAlbumDirectory(context, album);
- }
-
- exists = file.exists();
- isStarred = album.isStarred();
- }
-}
diff --git a/src/github/daneren2005/dsub/view/ArtistEntryView.java b/src/github/daneren2005/dsub/view/ArtistEntryView.java
index 958b4b87..86fe7b1f 100644
--- a/src/github/daneren2005/dsub/view/ArtistEntryView.java
+++ b/src/github/daneren2005/dsub/view/ArtistEntryView.java
@@ -37,7 +37,7 @@ import java.io.File;
* @author Sindre Mehus
*/
public class ArtistEntryView extends UpdateView {
- private static final String TAG = AlbumView.class.getSimpleName();
+ private static final String TAG = ArtistEntryView.class.getSimpleName();
private Context context;
private MusicDirectory.Entry artist;
diff --git a/src/github/daneren2005/dsub/view/ArtistView.java b/src/github/daneren2005/dsub/view/ArtistView.java
index 6f54e800..23ce4f9d 100644
--- a/src/github/daneren2005/dsub/view/ArtistView.java
+++ b/src/github/daneren2005/dsub/view/ArtistView.java
@@ -27,7 +27,7 @@ import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.util.FileUtil;
-import github.daneren2005.dsub.util.Util;
+
import java.io.File;
/**
diff --git a/src/github/daneren2005/dsub/view/AutoRepeatButton.java b/src/github/daneren2005/dsub/view/AutoRepeatButton.java
index 798c1649..cb2d2a51 100644
--- a/src/github/daneren2005/dsub/view/AutoRepeatButton.java
+++ b/src/github/daneren2005/dsub/view/AutoRepeatButton.java
@@ -8,8 +8,8 @@ import android.widget.ImageButton;
public class AutoRepeatButton extends ImageButton {
- private long initialRepeatDelay = 1000;
- private long repeatIntervalInMilliseconds = 300;
+ private static final long initialRepeatDelay = 1000;
+ private static final long repeatIntervalInMilliseconds = 300;
private boolean doClick = true;
private Runnable repeatEvent = null;
diff --git a/src/github/daneren2005/dsub/view/BookmarkAdapter.java b/src/github/daneren2005/dsub/view/BookmarkAdapter.java
index bcddc574..b0541397 100644
--- a/src/github/daneren2005/dsub/view/BookmarkAdapter.java
+++ b/src/github/daneren2005/dsub/view/BookmarkAdapter.java
@@ -20,7 +20,7 @@
package github.daneren2005.dsub.view;
import android.content.Context;
-import android.util.Log;
+
import java.util.List;
import android.view.View;
import android.view.ViewGroup;
diff --git a/src/github/daneren2005/dsub/view/EntryAdapter.java b/src/github/daneren2005/dsub/view/EntryAdapter.java
index 22ca384c..7da6e5a1 100644
--- a/src/github/daneren2005/dsub/view/EntryAdapter.java
+++ b/src/github/daneren2005/dsub/view/EntryAdapter.java
@@ -19,7 +19,7 @@
package github.daneren2005.dsub.view;
import android.content.Context;
-import android.util.Log;
+
import java.util.List;
import android.view.View;
@@ -54,26 +54,13 @@ public class EntryAdapter extends ArrayAdapter<MusicDirectory.Entry> {
public View getView(int position, View convertView, ViewGroup parent) {
MusicDirectory.Entry entry = getItem(position);
- if (entry.isDirectory()) {
- if(entry.getArtist() != null || entry.getParent() != null) {
- AlbumView view;
- view = new AlbumView(activity);
- view.setObject(entry, imageLoader);
- return view;
- } else {
- ArtistEntryView view = new ArtistEntryView(activity);
- view.setObject(entry);
- return view;
- }
- } else {
- SongView view;
- if (convertView != null && convertView instanceof SongView) {
- view = (SongView) convertView;
- } else {
- view = new SongView(activity);
- }
- view.setObject(entry, checkable);
- return view;
- }
+ SongView view;
+ if (convertView != null && convertView instanceof SongView) {
+ view = (SongView) convertView;
+ } else {
+ view = new SongView(activity);
+ }
+ view.setObject(entry, checkable);
+ return view;
}
}
diff --git a/src/github/daneren2005/dsub/view/ErrorDialog.java b/src/github/daneren2005/dsub/view/ErrorDialog.java
index e72b1934..0b9d05a0 100644
--- a/src/github/daneren2005/dsub/view/ErrorDialog.java
+++ b/src/github/daneren2005/dsub/view/ErrorDialog.java
@@ -20,7 +20,6 @@ package github.daneren2005.dsub.view;
import android.app.Activity;
import android.app.AlertDialog;
-import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
diff --git a/src/github/daneren2005/dsub/view/SquareImageView.java b/src/github/daneren2005/dsub/view/SquareImageView.java
new file mode 100644
index 00000000..77ca50db
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/SquareImageView.java
@@ -0,0 +1,32 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+public class SquareImageView extends ImageView {
+ public SquareImageView(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public void onMeasure(final int widthSpec, final int heightSpec) {
+ super.onMeasure(widthSpec, heightSpec);
+ setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
+ }
+}
diff --git a/src/github/daneren2005/dsub/view/UnscrollableGridView.java b/src/github/daneren2005/dsub/view/UnscrollableGridView.java
new file mode 100644
index 00000000..a36a7b79
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/UnscrollableGridView.java
@@ -0,0 +1,81 @@
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.AbsListView;
+import android.widget.GridView;
+import android.widget.ListAdapter;
+
+/**
+ * Created by Scott on 4/26/2014.
+ */
+public class UnscrollableGridView extends GridView {
+ public UnscrollableGridView(Context context) {
+ super(context);
+ }
+
+ public UnscrollableGridView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public UnscrollableGridView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public int getColumnWidth() {
+ // This method will be called from onMeasure() too.
+ // It's better to use getMeasuredWidth(), as it is safe in this case.
+ final int totalHorizontalSpacing = getNumColumns() > 0 ? (getNumColumns() - 1) * getHorizontalSpacing() : 0;
+ return (getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - totalHorizontalSpacing) / getNumColumns();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // Sets the padding for this view.
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+ final int measuredWidth = getMeasuredWidth();
+ final int childWidth = getColumnWidth();
+ int childHeight = 0;
+
+ // If there's an adapter, use it to calculate the height of this view.
+ final ListAdapter adapter = getAdapter();
+ final int count;
+
+ // There shouldn't be any inherent size (due to padding) if there are no child views.
+ if (adapter == null || (count = adapter.getCount()) == 0) {
+ setMeasuredDimension(0, 0);
+ return;
+ }
+
+ // Get the first child from the adapter.
+ final View child = adapter.getView(0, null, this);
+ if (child != null) {
+ // Set a default LayoutParams on the child, if it doesn't have one on its own.
+ AbsListView.LayoutParams params = (AbsListView.LayoutParams) child.getLayoutParams();
+ if (params == null) {
+ params = new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT,
+ AbsListView.LayoutParams.WRAP_CONTENT);
+ child.setLayoutParams(params);
+ }
+
+ // Measure the exact width of the child, and the height based on the width.
+ // Note: the child takes care of calculating its height.
+ int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
+ int childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
+ child.measure(childWidthSpec, childHeightSpec);
+ childHeight = child.getMeasuredHeight();
+ }
+
+ // Number of rows required to 'mTotal' items.
+ final int rows = (int) Math.ceil((double) getCount() / getNumColumns());
+ final int childrenHeight = childHeight * rows;
+ final int totalVerticalSpacing = rows > 0 ? (rows - 1) * getVerticalSpacing() : 0;
+
+ // Total height of this view.
+ final int measuredHeight = childrenHeight + getPaddingTop() + getPaddingBottom() + totalVerticalSpacing;
+ setMeasuredDimension(measuredWidth, measuredHeight);
+ }
+}
diff --git a/src/github/daneren2005/dsub/view/UpdateView.java b/src/github/daneren2005/dsub/view/UpdateView.java
index f59cee3f..66f34471 100644
--- a/src/github/daneren2005/dsub/view/UpdateView.java
+++ b/src/github/daneren2005/dsub/view/UpdateView.java
@@ -131,7 +131,7 @@ public class UpdateView extends LinearLayout {
return;
}
- List<UpdateView> views = new ArrayList<UpdateView>();;
+ List<UpdateView> views = new ArrayList<UpdateView>();
for (UpdateView view : INSTANCES.keySet()) {
if (view.isShown()) {
views.add(view);