diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-07-08 19:17:50 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-07-08 19:17:50 -0700 |
commit | 4e15d54835fa9e7eda0e3b21df42d3bf6af81186 (patch) | |
tree | 92cdeae3f6f5feabd09a1478d2ee1aa9c32faad8 /src/github | |
parent | 9f1cca9eb0ed3e88d37f239c21fc808ab155bb4f (diff) | |
parent | 1486d1bf9f42a9bbefe15d66eb7b4095d939c4cb (diff) | |
download | dsub-4e15d54835fa9e7eda0e3b21df42d3bf6af81186.tar.gz dsub-4e15d54835fa9e7eda0e3b21df42d3bf6af81186.tar.bz2 dsub-4e15d54835fa9e7eda0e3b21df42d3bf6af81186.zip |
Merge branch 'master' of https://github.com/daneren2005/Subsonic into MediaStore
Diffstat (limited to 'src/github')
37 files changed, 283 insertions, 166 deletions
diff --git a/src/github/daneren2005/dsub/activity/QueryReceiverActivity.java b/src/github/daneren2005/dsub/activity/QueryReceiverActivity.java index 4678bbc5..eefb9c56 100644 --- a/src/github/daneren2005/dsub/activity/QueryReceiverActivity.java +++ b/src/github/daneren2005/dsub/activity/QueryReceiverActivity.java @@ -24,6 +24,7 @@ import android.app.SearchManager; import android.content.Intent; import android.os.Bundle; import android.provider.SearchRecentSuggestions; +import android.util.Log; import github.daneren2005.dsub.fragments.SubsonicFragment; import github.daneren2005.dsub.util.Constants; @@ -37,7 +38,9 @@ import github.daneren2005.dsub.provider.DSubSearchProvider; */ public class QueryReceiverActivity extends Activity { - @Override + private static final String TAG = QueryReceiverActivity.class.getSimpleName(); + + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -68,6 +71,9 @@ public class QueryReceiverActivity extends Activity { if(albumId.indexOf("ar-") == 0) { intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, true); albumId = albumId.replace("ar-", ""); + } else if(albumId.indexOf("so-") == 0) { + intent.putExtra(Constants.INTENT_EXTRA_SEARCH_SONG, name); + albumId = albumId.replace("so-", ""); } intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, albumId); if (name != null) { diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index 56c3e387..48f67dd5 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -245,7 +245,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - Log.d(TAG, "Preference changed: " + key); + // Random error I have no idea how to reproduce + if(sharedPreferences == null) { + return; + } + update(); if (Constants.PREFERENCES_KEY_HIDE_MEDIA.equals(key)) { @@ -468,22 +472,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private void applyTheme() { String activeTheme = Util.getTheme(this); - if ("dark".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Dark); - } else if ("black".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Black); - } else if ("light".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Light); - } else { - setTheme(R.style.Theme_DSub_Holo); - } - - SharedPreferences prefs = Util.getPreferences(this); - if(prefs.getBoolean(Constants.PREFERENCES_KEY_OVERRIDE_SYSTEM_LANGUAGE, false)) { - Configuration config = new Configuration(); - config.locale = Locale.ENGLISH; - getResources().updateConfiguration(config,getResources().getDisplayMetrics()); - } + Util.applyTheme(this, activeTheme); } private void setHideMedia(boolean hide) { diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 7aec30c4..395a347e 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -50,6 +50,7 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
+import android.widget.TextView;
import java.io.File;
import java.io.PrintWriter;
@@ -90,7 +91,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte ActionBarDrawerToggle drawerToggle;
DrawerAdapter drawerAdapter;
ListView drawerList;
- View lastSelectedView = null;
+ TextView lastSelectedView = null;
int lastSelectedPosition = 0;
boolean drawerOpen = false;
@@ -113,6 +114,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte getSupportActionBar().setCustomView(actionbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
+
+ if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
+ lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
+ }
}
@Override
@@ -156,6 +161,14 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte }
@Override
+ public void startActivity(Intent intent) {
+ if("github.daneren2005.dsub.activity.DownloadActivity".equals(intent.getComponent().getClassName())) {
+ intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ }
+ super.startActivity(intent);
+ }
+
+ @Override
public void setContentView(int viewId) {
super.setContentView(R.layout.abstract_activity);
rootView = (ViewGroup) findViewById(R.id.content_frame);
@@ -177,10 +190,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(lastSelectedView != view) {
if(lastSelectedView != null) {
- lastSelectedView.setBackgroundResource(android.R.color.transparent);
+ lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle);
}
- view.setBackgroundResource(R.color.dividerColor);
- lastSelectedView = view;
+ lastSelectedView = (TextView) view.findViewById(R.id.drawer_name);
+ lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold);
lastSelectedPosition = position;
}
}
@@ -209,9 +222,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte }
if(lastSelectedView == null) {
- lastSelectedView = drawerList.getChildAt(lastSelectedPosition);
+ lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition).findViewById(R.id.drawer_name);
if(lastSelectedView != null) {
- lastSelectedView.setBackgroundResource(R.color.dividerColor);
+ lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold);
}
}
@@ -444,6 +457,15 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte }
}
}
+
+ if(drawerList.getChildAt(lastSelectedPosition) == null) {
+ drawerAdapter.setSelectedPosition(lastSelectedPosition);
+ } else {
+ lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition).findViewById(R.id.drawer_name);
+ if(lastSelectedView != null) {
+ lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold);
+ }
+ }
}
}
@@ -629,22 +651,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte Util.setTheme(this, theme);
}
- if ("dark".equals(theme)) {
- setTheme(R.style.Theme_DSub_Dark);
- } else if ("black".equals(theme)) {
- setTheme(R.style.Theme_DSub_Black);
- } else if ("light".equals(theme)) {
- setTheme(R.style.Theme_DSub_Light);
- } else {
- setTheme(R.style.Theme_DSub_Holo);
- }
-
- SharedPreferences prefs = Util.getPreferences(this);
- if(prefs.getBoolean(Constants.PREFERENCES_KEY_OVERRIDE_SYSTEM_LANGUAGE, false)) {
- Configuration config = new Configuration();
- config.locale = Locale.ENGLISH;
- getResources().updateConfiguration(config,getResources().getDisplayMetrics());
- }
+ Util.applyTheme(this, theme);
}
private void applyFullscreen() {
fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false);
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index aa977c2c..9845411a 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -282,6 +282,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID));
args.putString(Constants.INTENT_EXTRA_NAME_NAME, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_NAME));
+ args.putString(Constants.INTENT_EXTRA_SEARCH_SONG, getIntent().getStringExtra(Constants.INTENT_EXTRA_SEARCH_SONG));
if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_ARTIST)) {
args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
}
diff --git a/src/github/daneren2005/dsub/fragments/AdminFragment.java b/src/github/daneren2005/dsub/fragments/AdminFragment.java index 5e14aff5..08a78fd6 100644 --- a/src/github/daneren2005/dsub/fragments/AdminFragment.java +++ b/src/github/daneren2005/dsub/fragments/AdminFragment.java @@ -70,7 +70,7 @@ public class AdminFragment extends SelectListFragment<User> { MenuInflater inflater = context.getMenuInflater();
if(UserUtil.isCurrentAdmin()) {
inflater.inflate(R.menu.admin_context, menu);
- } else {
+ } else if(UserUtil.isCurrentRole(User.SETTINGS)) {
inflater.inflate(R.menu.admin_context_user, menu);
}
}
@@ -114,7 +114,9 @@ public class AdminFragment extends SelectListFragment<User> { try {
// Will only work if user is admin
List<User> users = musicService.getUsers(refresh, context, listener);
- UserUtil.refreshCurrentUser(context);
+ if(refresh) {
+ UserUtil.refreshCurrentUser(context, true);
+ }
return users;
} catch(SubsonicRESTException e) {
// Delete cached users if not allowed to get them
@@ -126,7 +128,7 @@ public class AdminFragment extends SelectListFragment<User> { List<User> users = new ArrayList<User>();
users.add(musicService.getUser(refresh, UserUtil.getCurrentUsername(context), context, listener));
- UserUtil.refreshCurrentUser(context);
+ UserUtil.refreshCurrentUser(context, false);
return users;
}
}
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index c673fc12..fc86ad36 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -209,7 +209,7 @@ public class MainFragment extends SubsonicFragment { }
Util.setActiveServer(context, instance);
context.invalidate();
- UserUtil.refreshCurrentUser(context);
+ UserUtil.refreshCurrentUser(context, false);
}
}
diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index e7c34d9a..3486f154 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -69,6 +69,7 @@ import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.view.DownloadFileAdapter;
import github.daneren2005.dsub.view.FadeOutAnimation;
import github.daneren2005.dsub.view.SongView;
+import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.VisualizerView;
@@ -1008,6 +1009,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_up_in));
playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.push_up_out));
playlistFlipper.setDisplayedChild(1);
+
+ UpdateView.triggerUpdate();
}
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 08d9c13a..4817967f 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -64,6 +64,10 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
folderButton = null;
super.onCreateView(inflater, container, bundle);
+
+ if("4.4.2".equals(Build.VERSION.RELEASE)) {
+ listView.setFastScrollAlwaysVisible(true);
+ }
if(objects != null) {
if (Util.isOffline(context) || Util.isTagBrowsing(context)) {
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index e372bf51..d40f8fad 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -80,6 +80,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter boolean restoredInstance = false;
boolean lookupParent = false;
boolean largeAlbums = false;
+ String lookupEntry;
public SelectDirectoryFragment() {
super();
@@ -121,6 +122,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter albumListSize = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
refreshListing = args.getBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS);
artist = args.getBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, false);
+ lookupEntry = args.getString(Constants.INTENT_EXTRA_SEARCH_SONG);
String childId = args.getString(Constants.INTENT_EXTRA_NAME_CHILD_ID);
if(childId != null) {
@@ -680,9 +682,11 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
listAdapter = new AlbumListAdapter(context, entryAdapter, albumListType, albumListExtra, albumListSize);
- } else if((albumListType == null || "starred".equals(albumListType)) && largeAlbums) {
+ } else if(albumListType == null || "starred".equals(albumListType)) {
// Only set standard album adapter if not album list and largeAlbums is true
- albumList.setAdapter(new AlbumGridAdapter(context, getImageLoader(), albums, !artist));
+ if(largeAlbums) {
+ albumList.setAdapter(new AlbumGridAdapter(context, getImageLoader(), albums, !artist));
+ }
} else {
// If album list, use infinite adapters for either depending on whether or not largeAlbums is true
if(largeAlbums) {
@@ -697,6 +701,16 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
context.supportInvalidateOptionsMenu();
+ if(lookupEntry != null) {
+ for(int i = 0; i < entries.size(); i++) {
+ if(lookupEntry.equals(entries.get(i).getTitle())) {
+ entryList.setSelection(i + entryList.getHeaderViewsCount());
+ lookupEntry = null;
+ break;
+ }
+ }
+ }
+
Bundle args = getArguments();
boolean playAll = args.getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
if (playAll && !restoredInstance) {
@@ -1164,6 +1178,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
if(songCount == 0) {
showHeader = false;
+ hideButtons = true;
return null;
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index b07be642..7f6de2d8 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -56,7 +56,7 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> { if(!Util.checkServerVersion(context, "1.8")) {
menu.removeItem(R.id.playlist_update_info);
- } else if(playlist.getPublic() != null && playlist.getPublic() == true && !UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) {
+ } else if(playlist.getPublic() != null && playlist.getPublic() == true && playlist.getId().indexOf(".m3u") == -1 && !UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) {
menu.removeItem(R.id.playlist_update_info);
menu.removeItem(R.id.playlist_menu_delete);
}
@@ -155,7 +155,7 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> { Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
- if(Util.checkServerVersion(context, "1.8") && UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) {
+ if(Util.checkServerVersion(context, "1.8") && playlist.getOwner() != null && playlist.getOwner().equals(UserUtil.getCurrentUsername(context))) {
args.putBoolean(Constants.INTENT_EXTRA_NAME_PLAYLIST_OWNER, true);
}
fragment.setArguments(args);
diff --git a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 616af757..73a415ba 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -238,7 +238,7 @@ public class SelectPodcastsFragment extends SelectListFragment<PodcastChannel> { "\nURL: " + channel.getUrl() +
"\nStatus: " + channel.getStatus() +
((channel.getErrorMessage()) == null ? "" : "\nError Message: " + channel.getErrorMessage()) +
- ((channel.getDescription()) == null ? "" : "\nDescription: " + channel.getDescription());
+ ((channel.getDescription()) == null ? "" : "\n\nDescription: " + channel.getDescription());
Util.info(context, channel.getName(), message);
}
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 1e3f832d..54709ec0 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -67,6 +67,8 @@ import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.UserUtil;
import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.UpdateView;
+
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -124,6 +126,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR @Override
public void onResume() {
super.onResume();
+ UpdateView.triggerUpdate();
}
@Override
@@ -729,11 +732,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR downloadRecursively(id, name, isDirectory, save, append, autoplay, shuffle, background, false);
}
protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background, final boolean playNext) {
- LoadingTask<List<MusicDirectory.Entry>> task = new LoadingTask<List<MusicDirectory.Entry>>(context) {
+ LoadingTask<Boolean> task = new LoadingTask<Boolean>(context) {
private static final int MAX_SONGS = 500;
@Override
- protected List<MusicDirectory.Entry> doInBackground() throws Throwable {
+ protected Boolean doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory root;
if(share != null) {
@@ -752,7 +755,26 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR List<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
getSongsRecursively(root, songs);
- return songs;
+
+ DownloadService downloadService = getDownloadService();
+ boolean transition = false;
+ if (!songs.isEmpty() && downloadService != null) {
+ if (!append) {
+ downloadService.clear();
+ }
+ if(!background) {
+ downloadService.download(songs, save, autoplay, playNext, false);
+ if(!append) {
+ transition = true;
+ }
+ }
+ else {
+ downloadService.downloadBackground(songs, save);
+ }
+ }
+ artistOverride = false;
+
+ return transition;
}
private void getSongsRecursively(MusicDirectory parent, List<MusicDirectory.Entry> songs) throws Exception {
@@ -779,24 +801,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
@Override
- protected void done(List<MusicDirectory.Entry> songs) {
- DownloadService downloadService = getDownloadService();
- if (!songs.isEmpty() && downloadService != null) {
- if (!append) {
- downloadService.clear();
- }
- warnIfNetworkOrStorageUnavailable();
- if(!background) {
- downloadService.download(songs, save, autoplay, playNext, false);
- if(!append) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
- }
- }
- else {
- downloadService.downloadBackground(songs, save);
- }
+ protected void done(Boolean result) {
+ warnIfNetworkOrStorageUnavailable();
+
+ if(result) {
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
}
- artistOverride = false;
}
};
@@ -832,7 +842,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR Iterator<Playlist> it = playlists.iterator();
while(it.hasNext()) {
Playlist playlist = it.next();
- if(playlist.getPublic() == true && !UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) {
+ if(playlist.getPublic() == true && playlist.getId().indexOf(".m3u") == -1 && !UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) {
it.remove();
}
}
diff --git a/src/github/daneren2005/dsub/fragments/UserFragment.java b/src/github/daneren2005/dsub/fragments/UserFragment.java index 1ad62d87..9bf26baf 100644 --- a/src/github/daneren2005/dsub/fragments/UserFragment.java +++ b/src/github/daneren2005/dsub/fragments/UserFragment.java @@ -70,7 +70,7 @@ public class UserFragment extends SubsonicFragment{ @Override
public void onAttach(Activity activity) {
super.onAttach(activity);
- activity.invalidateOptionsMenu();
+ ((SubsonicActivity) activity).supportInvalidateOptionsMenu();
}
@Override
@@ -82,8 +82,10 @@ public class UserFragment extends SubsonicFragment{ if(UserUtil.isCurrentAdmin() && Util.checkServerVersion(context, "1.10")) {
menuInflater.inflate(R.menu.user, menu);
- } else {
+ } else if(UserUtil.isCurrentRole(User.SETTINGS)) {
menuInflater.inflate(R.menu.user_user, menu);
+ } else {
+ menuInflater.inflate(R.menu.empty, menu);
}
}
diff --git a/src/github/daneren2005/dsub/provider/DSubSearchProvider.java b/src/github/daneren2005/dsub/provider/DSubSearchProvider.java index 4fd4b218..6c23a5d0 100644 --- a/src/github/daneren2005/dsub/provider/DSubSearchProvider.java +++ b/src/github/daneren2005/dsub/provider/DSubSearchProvider.java @@ -83,7 +83,7 @@ public class DSubSearchProvider extends ContentProvider { } for (MusicDirectory.Entry song : searchResult.getSongs()) { String icon = RESOURCE_PREFIX + R.drawable.ic_action_song; - cursor.addRow(new Object[]{song.getId().hashCode(), song.getTitle(), song.getArtist(), song.getParent(), song.getTitle(), icon}); + cursor.addRow(new Object[]{song.getId().hashCode(), song.getTitle(), song.getArtist(), "so-" + song.getParent(), song.getTitle(), icon}); } return cursor; } diff --git a/src/github/daneren2005/dsub/receiver/AudioNoisyReceiver.java b/src/github/daneren2005/dsub/receiver/AudioNoisyReceiver.java index 058d04b4..b4ace297 100644 --- a/src/github/daneren2005/dsub/receiver/AudioNoisyReceiver.java +++ b/src/github/daneren2005/dsub/receiver/AudioNoisyReceiver.java @@ -39,7 +39,7 @@ public class AudioNoisyReceiver extends BroadcastReceiver { }
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals (intent.getAction ())) {
- if(!downloadService.isRemoteEnabled() && downloadService.getPlayerState() == PlayerState.STARTED) {
+ if(!downloadService.isRemoteEnabled() && (downloadService.getPlayerState() == PlayerState.STARTED || downloadService.getPlayerState() == PlayerState.PAUSED_TEMP)) {
SharedPreferences prefs = Util.getPreferences(downloadService);
int pausePref = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT, "0"));
if(pausePref == 0) {
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index bd43fbed..31280b19 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -511,13 +511,15 @@ public class CachedMusicService implements MusicService { public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception { User result = null; - if(!refresh) { - result = FileUtil.deserialize(context, getCacheName(context, "user-" + username), User.class); - } - - if(result == null) { + try { result = musicService.getUser(refresh, username, context, progressListener); FileUtil.serialize(context, result, getCacheName(context, "user-" + username)); + } catch(Exception e) { + // Don't care + } + + if(result == null && !refresh) { + result = FileUtil.deserialize(context, getCacheName(context, "user-" + username), User.class); } return result; diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index b1c78b24..908598f3 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -237,7 +237,7 @@ public class DownloadFile implements BufferFile { @Override public synchronized void onResume() { - if(!isFailedMax() && !isDownloading()) { + if(!isWorkDone() && !isFailedMax() && !isDownloading() && !isDownloadCancelled()) { download(); } } @@ -503,8 +503,10 @@ public class DownloadFile implements BufferFile { } // Only run these if not interrupted, ie: cancelled - new CacheCleaner(context, DownloadService.getInstance()).cleanSpace(); - checkDownloads(); + if(!isCancelled()) { + new CacheCleaner(context, DownloadService.getInstance()).cleanSpace(); + checkDownloads(); + } return null; } diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 4c0c9151..f28c38dc 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -29,6 +29,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARING; import static github.daneren2005.dsub.domain.PlayerState.STARTED; import static github.daneren2005.dsub.domain.PlayerState.STOPPED; +import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.AudioEffectsController; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.audiofx.VisualizerController; @@ -45,6 +46,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.MediaRouteManager; import github.daneren2005.dsub.util.ShufflePlayBuffer; import github.daneren2005.dsub.util.SimpleServiceBinder; +import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.util.compat.RemoteControlClientHelper; import github.daneren2005.serverproxy.BufferProxy; @@ -263,9 +265,11 @@ public class DownloadService extends Service { if(bufferTask != null) { bufferTask.cancel(); + bufferTask = null; } if(nextPlayingTask != null) { nextPlayingTask.cancel(); + nextPlayingTask = null; } if(remoteController != null) { remoteController.stop(); @@ -410,6 +414,7 @@ public class DownloadService extends Service { removePlayed = enabled; if(removePlayed) { checkDownloads(); + lifecycleSupport.serializeDownloadQueue(); } SharedPreferences.Editor editor = Util.getPreferences(this).edit(); editor.putBoolean(Constants.PREFERENCES_KEY_REMOVE_PLAYED, enabled); @@ -588,7 +593,7 @@ public class DownloadService extends Service { reset(); downloadList.clear(); revision++; - if (currentDownloading != null) { + if (currentDownloading != null && !backgroundDownloadList.contains(currentDownloading)) { currentDownloading.cancelDownload(); currentDownloading = null; } @@ -974,6 +979,7 @@ public class DownloadService extends Service { public synchronized void reset() { if (bufferTask != null) { bufferTask.cancel(); + bufferTask = null; } try { // Only set to idle if it's not being killed to start RemoteController @@ -1600,7 +1606,7 @@ public class DownloadService extends Service { checkShufflePlay(); } - if (remoteState != RemoteControlState.LOCAL || !Util.isNetworkConnected(this) || Util.isOffline(this)) { + if (remoteState != RemoteControlState.LOCAL || !Util.isNetworkConnected(this, true) || Util.isOffline(this)) { return; } diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index ed092328..76c9abeb 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -326,7 +326,7 @@ public class DownloadServiceLifecycleSupport { case TelephonyManager.CALL_STATE_OFFHOOK: if (downloadService.getPlayerState() == PlayerState.STARTED) { resumeAfterCall = true; - downloadService.pause(); + downloadService.pause(true); } break; case TelephonyManager.CALL_STATE_IDLE: diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 3299ec4b..43d443d2 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -92,6 +92,7 @@ import github.daneren2005.dsub.service.parser.UserParser; import github.daneren2005.dsub.service.parser.VersionParser; import github.daneren2005.dsub.service.ssl.SSLSocketFactory; import github.daneren2005.dsub.service.ssl.TrustSelfSignedStrategy; +import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; @@ -1526,7 +1527,7 @@ public class RESTMusicService implements MusicService { HttpConnectionParams.setSoTimeout(newParams, networkTimeout); httpClient.setParams(newParams); - final AtomicReference<Boolean> cancelled = new AtomicReference<Boolean>(false); + final AtomicReference<Boolean> isCancelled = new AtomicReference<Boolean>(false); int attempts = 0; while (true) { attempts++; @@ -1535,10 +1536,11 @@ public class RESTMusicService implements MusicService { if (task != null) { // Attempt to abort the HTTP request if the task is cancelled. - task.setOnCancelListener(new SilentBackgroundTask.OnCancelListener() { + task.setOnCancelListener(new BackgroundTask.OnCancelListener() { @Override public void onCancel() { try { + isCancelled.set(true); request.abort(); } catch(Exception e) { Log.e(TAG, "Failed to stop http task"); @@ -1579,14 +1581,14 @@ public class RESTMusicService implements MusicService { return response; } catch (IOException x) { request.abort(); - if (attempts >= HTTP_REQUEST_MAX_ATTEMPTS || cancelled.get()) { + if (attempts >= HTTP_REQUEST_MAX_ATTEMPTS || isCancelled.get()) { throw x; } if (progressListener != null) { String msg = context.getResources().getString(R.string.music_service_retry, attempts, HTTP_REQUEST_MAX_ATTEMPTS - 1); progressListener.updateProgress(msg); } - Log.w(TAG, "Got IOException (" + attempts + "), will retry", x); + Log.w(TAG, "Got IOException " + x + " (" + attempts + "), will retry"); increaseTimeouts(requestParams); Thread.sleep(2000L); } diff --git a/src/github/daneren2005/dsub/service/Scrobbler.java b/src/github/daneren2005/dsub/service/Scrobbler.java index 1f831a80..9958ff9e 100644 --- a/src/github/daneren2005/dsub/service/Scrobbler.java +++ b/src/github/daneren2005/dsub/service/Scrobbler.java @@ -24,6 +24,11 @@ public class Scrobbler { if (song == null || !Util.isScrobblingEnabled(context)) { return; } + + // Ignore if online with no network access + if(!Util.isOffline(context) && !Util.isNetworkConnected(context)) { + return; + } // Ignore podcasts if(song.getSong() instanceof PodcastEpisode) { diff --git a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java index 0801bf7c..6dfbbbe4 100644 --- a/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java @@ -32,6 +32,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.Notifications;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.SyncUtil.SyncSet;
import github.daneren2005.dsub.util.Util;
@@ -89,7 +90,7 @@ public class MostRecentSyncAdapter extends SubsonicSyncAdapter { musicService.getIndexes(Util.getSelectedMusicFolderId(context), true, context, null);
}
- SyncUtil.showSyncNotification(context, R.string.sync_new_albums, SyncUtil.joinNames(updated));
+ Notifications.showSyncNotification(context, R.string.sync_new_albums, SyncUtil.joinNames(updated));
} else if(firstRun) {
FileUtil.serialize(context, syncedList, SyncUtil.getMostRecentSyncFile(context, instance));
}
diff --git a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java index f680becf..68bfdcb6 100644 --- a/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java @@ -32,6 +32,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.parser.SubsonicRESTException;
import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.Notifications;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.SyncUtil.SyncSet;
import github.daneren2005.dsub.util.Util;
@@ -122,7 +123,7 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter { }
if(updated.size() > 0) {
- SyncUtil.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated));
+ Notifications.showSyncNotification(context, R.string.sync_new_playlists, SyncUtil.joinNames(updated));
}
}
}
diff --git a/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java index bd9f26c7..a1878cad 100644 --- a/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java @@ -32,6 +32,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.parser.SubsonicRESTException;
+import github.daneren2005.dsub.util.Notifications;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.SyncUtil.SyncSet;
import github.daneren2005.dsub.util.FileUtil;
@@ -104,7 +105,7 @@ public class PodcastSyncAdapter extends SubsonicSyncAdapter { // Make sure there are is at least one change before re-syncing
if(updated.size() > 0) {
FileUtil.serialize(context, podcastList, SyncUtil.getPodcastSyncFile(context, instance));
- SyncUtil.showSyncNotification(context, R.string.sync_new_podcasts, SyncUtil.joinNames(updated));
+ Notifications.showSyncNotification(context, R.string.sync_new_podcasts, SyncUtil.joinNames(updated));
}
} catch(Exception e) {
Log.w(TAG, "Failed to get podcasts for " + Util.getServerName(context, instance));
diff --git a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java index 54c10f41..b99c501d 100644 --- a/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java +++ b/src/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.service.sync;
import android.annotation.TargetApi;
+import android.app.Notification;
import android.content.Context;
import android.util.Log;
@@ -29,6 +30,7 @@ import java.util.ArrayList; import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.Notifications;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.Util;
@@ -69,7 +71,7 @@ public class StarredSyncAdapter extends SubsonicSyncAdapter { SyncUtil.setSyncedStarred(syncedList, context, instance);
if(updated) {
- SyncUtil.showSyncNotification(context, R.string.sync_new_starred, null);
+ Notifications.showSyncNotification(context, R.string.sync_new_starred, null);
}
} catch(Exception e) {
Log.e(TAG, "Failed to get starred list for " + Util.getServerName(context, instance));
diff --git a/src/github/daneren2005/dsub/util/BackgroundTask.java b/src/github/daneren2005/dsub/util/BackgroundTask.java index 63515f19..f64acbff 100644 --- a/src/github/daneren2005/dsub/util/BackgroundTask.java +++ b/src/github/daneren2005/dsub/util/BackgroundTask.java @@ -44,7 +44,7 @@ public abstract class BackgroundTask<T> implements ProgressListener { private static final String TAG = BackgroundTask.class.getSimpleName(); private final Context context; - protected boolean cancelled = false; + protected AtomicBoolean cancelled = new AtomicBoolean(false); protected OnCancelListener cancelListener; protected Task task; @@ -135,17 +135,20 @@ public abstract class BackgroundTask<T> implements ProgressListener { } public void cancel() { - cancelled = true; - if(task != null) { - task.cancel(); - } + if(cancelled.compareAndSet(false, true)) { + if(task != null && task.isRunning()) { + if(cancelListener != null) { + cancelListener.onCancel(); + } else { + task.cancel(); + } - if(cancelListener != null) { - cancelListener.onCancel(); + task = null; + } } } public boolean isCancelled() { - return cancelled; + return cancelled.get(); } public void setOnCancelListener(OnCancelListener listener) { cancelListener = listener; diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index 0c263d3a..f566c78c 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -61,6 +61,7 @@ public final class Constants { public static final String INTENT_EXTRA_NAME_SHARE = "subsonic.share"; public static final String INTENT_EXTRA_FRAGMENT_TYPE = "fragmentType"; public static final String INTENT_EXTRA_REFRESH_LISTINGS = "refreshListings"; + public static final String INTENT_EXTRA_SEARCH_SONG = "searchSong"; // Preferences keys. public static final String PREFERENCES_KEY_SERVER_KEY = "server"; @@ -73,6 +74,7 @@ public final class Constants { public static final String PREFERENCES_KEY_SERVER_INTERNAL_URL = "serverInternalUrl"; public static final String PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID = "serverLocalNetworkSSID"; public static final String PREFERENCES_KEY_SERVER_VERSION = "serverVersion"; + public static final String PREFERENCES_KEY_SERVER_TYPE = "serverType"; public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection"; public static final String PREFERENCES_KEY_OPEN_BROWSER = "openBrowser"; public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"; diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java index f9c5fed5..dc10ebba 100644 --- a/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/src/github/daneren2005/dsub/util/ImageLoader.java @@ -292,7 +292,7 @@ public class ImageLoader { mDrawable = Util.createDrawableFromBitmap(mContext, bitmap); } catch (Throwable x) { Log.e(TAG, "Failed to download album art.", x); - cancelled = true; + cancelled.set(true); } return null; @@ -358,7 +358,7 @@ public class ImageLoader { } } catch (Throwable x) { Log.e(TAG, "Failed to download album art.", x); - cancelled = true; + cancelled.set(true); } return null; diff --git a/src/github/daneren2005/dsub/util/LoadingTask.java b/src/github/daneren2005/dsub/util/LoadingTask.java index f774aa5b..6c3385d2 100644 --- a/src/github/daneren2005/dsub/util/LoadingTask.java +++ b/src/github/daneren2005/dsub/util/LoadingTask.java @@ -52,12 +52,12 @@ public abstract class LoadingTask<T> extends BackgroundTask<T> { @Override
public boolean isCancelled() {
- return (tabActivity instanceof SubsonicActivity && ((SubsonicActivity) tabActivity).isDestroyedCompat()) || cancelled;
+ return (tabActivity instanceof SubsonicActivity && ((SubsonicActivity) tabActivity).isDestroyedCompat()) || cancelled.get();
}
@Override
public void updateProgress(final String message) {
- if(!cancelled) {
+ if(!cancelled.get()) {
getHandler().post(new Runnable() {
@Override
public void run() {
diff --git a/src/github/daneren2005/dsub/util/Notifications.java b/src/github/daneren2005/dsub/util/Notifications.java index 3eec7517..de4129e9 100644 --- a/src/github/daneren2005/dsub/util/Notifications.java +++ b/src/github/daneren2005/dsub/util/Notifications.java @@ -48,6 +48,7 @@ public final class Notifications { // Notification IDs.
public static final int NOTIFICATION_ID_PLAYING = 100;
public static final int NOTIFICATION_ID_DOWNLOADING = 102;
+ public static final String NOTIFICATION_SYNC_GROUP = "github.daneren2005.dsub.sync";
private static boolean playShowing = false;
private static boolean downloadShowing = false;
@@ -66,6 +67,7 @@ public final class Notifications { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
setupViews(expandedContentView,context,song, playing, remote);
notification.bigContentView = expandedContentView;
+ notification.priority = Notification.PRIORITY_HIGH;
}
RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
@@ -286,6 +288,29 @@ public final class Notifications { }
}
+ public static void showSyncNotification(final Context context, int stringId, String extra) {
+ if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION, true)) {
+ String content = (extra != null) ? context.getResources().getString(stringId, extra) : context.getResources().getString(stringId);
+
+ NotificationCompat.Builder builder;
+ builder = new NotificationCompat.Builder(context)
+ .setSmallIcon(R.drawable.stat_notify_sync)
+ .setContentTitle(context.getResources().getString(R.string.sync_title))
+ .setContentText(content)
+ .setStyle(new NotificationCompat.BigTextStyle().bigText(content.replace(", ", "\n")))
+ .setOngoing(false)
+ .setGroup(NOTIFICATION_SYNC_GROUP)
+ .setPriority(NotificationCompat.PRIORITY_LOW);
+
+ Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
+ notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ builder.setContentIntent(PendingIntent.getActivity(context, 2, notificationIntent, 0));
+
+ NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ notificationManager.notify(stringId, builder.build());
+ }
+ }
+
/**
* Resolves the default text color for notifications.
*
diff --git a/src/github/daneren2005/dsub/util/SyncUtil.java b/src/github/daneren2005/dsub/util/SyncUtil.java index 0c567681..15fa2d47 100644 --- a/src/github/daneren2005/dsub/util/SyncUtil.java +++ b/src/github/daneren2005/dsub/util/SyncUtil.java @@ -181,27 +181,6 @@ public final class SyncUtil { return "sync-most_recent-" + (Util.getRestUrl(context, null, instance, false)).hashCode() + ".ser";
}
- public static void showSyncNotification(final Context context, int stringId, String extra) {
- if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION, true)) {
- String content = (extra != null) ? context.getResources().getString(stringId, extra) : context.getResources().getString(stringId);
-
- NotificationCompat.Builder builder;
- builder = new NotificationCompat.Builder(context)
- .setSmallIcon(R.drawable.stat_notify_sync)
- .setContentTitle(context.getResources().getString(R.string.sync_title))
- .setContentText(content)
- .setStyle(new NotificationCompat.BigTextStyle().bigText(content.replace(", ", "\n")))
- .setOngoing(false);
-
- Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
- notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- builder.setContentIntent(PendingIntent.getActivity(context, 2, notificationIntent, 0));
-
- NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.notify(stringId, builder.build());
- }
- }
-
public static String joinNames(List<String> names) {
StringBuilder builder = new StringBuilder();
for (String val : names) {
diff --git a/src/github/daneren2005/dsub/util/TabBackgroundTask.java b/src/github/daneren2005/dsub/util/TabBackgroundTask.java index 022bcaa7..b0a24b28 100644 --- a/src/github/daneren2005/dsub/util/TabBackgroundTask.java +++ b/src/github/daneren2005/dsub/util/TabBackgroundTask.java @@ -36,7 +36,7 @@ public abstract class TabBackgroundTask<T> extends BackgroundTask<T> { @Override
public boolean isCancelled() {
- return !tabFragment.isAdded() || cancelled;
+ return !tabFragment.isAdded() || cancelled.get();
}
@Override
diff --git a/src/github/daneren2005/dsub/util/UserUtil.java b/src/github/daneren2005/dsub/util/UserUtil.java index baa56935..2d1b097a 100644 --- a/src/github/daneren2005/dsub/util/UserUtil.java +++ b/src/github/daneren2005/dsub/util/UserUtil.java @@ -46,11 +46,15 @@ public final class UserUtil { private static int instance = -1;
private static User currentUser;
- public static void refreshCurrentUser(Context context) {
+ public static void refreshCurrentUser(Context context, boolean forceRefresh) {
currentUser = null;
- seedCurrentUser(context);
+ seedCurrentUser(context, forceRefresh);
}
- public static void seedCurrentUser(final Context context) {
+
+ public static void seedCurrentUser(Context context) {
+ seedCurrentUser(context, false);
+ }
+ public static void seedCurrentUser(final Context context, final boolean refresh) {
// Only try to seed if online
if(Util.isOffline(context)) {
currentUser = null;
@@ -67,7 +71,7 @@ public final class UserUtil { new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
- currentUser = MusicServiceFactory.getMusicService(context).getUser(false, getCurrentUsername(context, instance), context, null);
+ currentUser = MusicServiceFactory.getMusicService(context).getUser(refresh, getCurrentUsername(context, instance), context, null);
// If running, redo cast selector
DownloadService downloadService = DownloadService.getInstance();
@@ -107,17 +111,17 @@ public final class UserUtil { }
public static boolean isCurrentAdmin() {
- return isCurrentRole("adminRole");
+ return isCurrentRole(User.ADMIN);
}
public static boolean canPodcast() {
- return isCurrentRole("podcastRole");
+ return isCurrentRole(User.PODCAST);
}
public static boolean canShare() {
- return isCurrentRole("shareRole");
+ return isCurrentRole(User.SHARE);
}
public static boolean canJukebox() {
- return isCurrentRole("jukeboxRole");
+ return isCurrentRole(User.JUKEBOX);
}
public static boolean isCurrentRole(String role) {
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 72fc8511..cea5813e 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -8,7 +8,6 @@ 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 @@ -29,6 +28,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -62,6 +62,7 @@ import github.daneren2005.dsub.activity.SubsonicFragmentActivity; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.RepeatMode; +import github.daneren2005.dsub.domain.User; import github.daneren2005.dsub.domain.Version; import github.daneren2005.dsub.provider.DSubWidgetProvider; import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver; @@ -84,6 +85,7 @@ import java.lang.reflect.Method; import java.security.MessageDigest; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -154,7 +156,7 @@ public final class Util { public static boolean isScrobblingEnabled(Context context) { SharedPreferences prefs = getPreferences(context); - return prefs.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, true) && (isOffline(context) || UserUtil.isCurrentRole("scrobblingEnabled")); + return prefs.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, true) && (isOffline(context) || UserUtil.isCurrentRole(User.SCROBBLING)); } public static void setActiveServer(Context context, int instance) { @@ -274,6 +276,25 @@ public final class Util { editor.putString(Constants.PREFERENCES_KEY_THEME, theme); editor.commit(); } + + public static void applyTheme(Context context, String theme) { + if ("dark".equals(theme)) { + context.setTheme(R.style.Theme_DSub_Dark); + } else if ("black".equals(theme)) { + context.setTheme(R.style.Theme_DSub_Black); + } else if ("holo".equals(theme)) { + context.setTheme(R.style.Theme_DSub_Holo); + } else { + context.setTheme(R.style.Theme_DSub_Light); + } + + SharedPreferences prefs = Util.getPreferences(context); + if(prefs.getBoolean(Constants.PREFERENCES_KEY_OVERRIDE_SYSTEM_LANGUAGE, false)) { + Configuration config = new Configuration(); + config.locale = Locale.ENGLISH; + context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); + } + } public static boolean getDisplayTrack(Context context) { SharedPreferences prefs = getPreferences(context); @@ -873,15 +894,22 @@ public final class Util { return Util.getScaledHeight((double) bitmap.getHeight(), (double) bitmap.getWidth(), width); } - public static boolean isNetworkConnected(Context context) { + public static boolean isNetworkConnected(Context context) { + return isNetworkConnected(context, false); + } + public static boolean isNetworkConnected(Context context, boolean streaming) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); boolean connected = networkInfo != null && networkInfo.isConnected(); - boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; - boolean wifiRequired = isWifiRequiredForDownload(context); + if(streaming) { + boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; + boolean wifiRequired = isWifiRequiredForDownload(context); - return connected && (!wifiRequired || wifiConnected); + return connected && (!wifiRequired || wifiConnected); + } else { + return connected; + } } public static boolean isWifiConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); diff --git a/src/github/daneren2005/dsub/view/DrawerAdapter.java b/src/github/daneren2005/dsub/view/DrawerAdapter.java index 345ca34c..924df743 100644 --- a/src/github/daneren2005/dsub/view/DrawerAdapter.java +++ b/src/github/daneren2005/dsub/view/DrawerAdapter.java @@ -41,6 +41,7 @@ public class DrawerAdapter extends ArrayAdapter<String> { private List<String> items;
private List<Integer> icons;
private List<Boolean> visible;
+ private int selectedPosition = -1;
public DrawerAdapter(Context context, List<String> items, List<Integer> icons, List<Boolean> visible) {
super(context, R.layout.drawer_list_item, items);
@@ -63,6 +64,12 @@ public class DrawerAdapter extends ArrayAdapter<String> { TextView textView = (TextView) convertView.findViewById(R.id.drawer_name);
textView.setText(item);
+
+ if(selectedPosition == position) {
+ textView.setTextAppearance(context, R.style.DSub_TextViewStyle_Bold);
+ selectedPosition = -1;
+ }
+
ImageView iconView = (ImageView) convertView.findViewById(R.id.drawer_icon);
iconView.setImageResource(icon);
@@ -109,4 +116,8 @@ public class DrawerAdapter extends ArrayAdapter<String> { public void setDownloadVisible(boolean visible) {
setItemVisible(items.size() - 2, visible);
}
+
+ public void setSelectedPosition(int position) {
+ selectedPosition = position;
+ }
}
diff --git a/src/github/daneren2005/dsub/view/SongView.java b/src/github/daneren2005/dsub/view/SongView.java index 2176b768..3e423877 100644 --- a/src/github/daneren2005/dsub/view/SongView.java +++ b/src/github/daneren2005/dsub/view/SongView.java @@ -88,18 +88,6 @@ public class SongView extends UpdateView implements Checkable { StringBuilder artist = new StringBuilder(40); - String bitRate = null; - if (song.getBitRate() != null) { - bitRate = String.format(getContext().getString(R.string.song_details_kbps), song.getBitRate()); - } - - String fileFormat = null; - if (song.getTranscodedSuffix() != null && !song.getTranscodedSuffix().equals(song.getSuffix())) { - fileFormat = String.format("%s > %s", song.getSuffix(), song.getTranscodedSuffix()); - } else { - fileFormat = song.getSuffix(); - } - if(!song.isVideo()) { if(song instanceof PodcastEpisode) { String date = ((PodcastEpisode)song).getDate(); @@ -112,20 +100,29 @@ public class SongView extends UpdateView implements Checkable { artist.append(song.getArtist()); } - String status = (song instanceof PodcastEpisode) ? ((PodcastEpisode)song).getStatus() : ""; - artist.append(" ("); - if("error".equals(status)) { - artist.append(getContext().getString(R.string.song_details_error)); - } else if("skipped".equals(status)) { - artist.append(getContext().getString(R.string.song_details_skipped)); - } else if("downloading".equals(status)) { - artist.append(getContext().getString(R.string.song_details_downloading)); - } else { - artist.append(String.format(getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat)); + if(song instanceof PodcastEpisode) { + String status = ((PodcastEpisode) song).getStatus(); + int statusRes = -1; + + if("error".equals(status)) { + statusRes = R.string.song_details_error; + } else if("skipped".equals(status)) { + statusRes = R.string.song_details_skipped; + } else if("downloading".equals(status)) { + statusRes = R.string.song_details_downloading; + } + + if(statusRes != -1) { + artist.append(" ("); + artist.append(getContext().getString(statusRes)); + artist.append(")"); + } } - artist.append(")"); + + durationTextView.setText(Util.formatDuration(song.getDuration())); } else { - artist.append(String.format(getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat)); + findViewById(R.id.song_bottom).setVisibility(View.GONE); + statusTextView.setText(Util.formatDuration(song.getDuration())); } String title = song.getTitle(); @@ -136,7 +133,6 @@ public class SongView extends UpdateView implements Checkable { titleTextView.setText(title); artistTextView.setText(artist); - durationTextView.setText(Util.formatDuration(song.getDuration())); checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE); revision = -1; diff --git a/src/github/daneren2005/dsub/view/UpdateView.java b/src/github/daneren2005/dsub/view/UpdateView.java index 66f34471..5278f83a 100644 --- a/src/github/daneren2005/dsub/view/UpdateView.java +++ b/src/github/daneren2005/dsub/view/UpdateView.java @@ -123,6 +123,14 @@ public class UpdateView extends LinearLayout { }, "UpdateView").start();
}
+ public static synchronized void triggerUpdate() {
+ if(backgroundHandler != null) {
+ uiHandler.removeCallbacksAndMessages(null);
+ backgroundHandler.removeCallbacksAndMessages(null);
+ uiHandler.post(updateRunnable);
+ }
+ }
+
private static void updateAll() {
try {
// If nothing can see this, stop updating
|