diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-12-16 09:14:15 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-12-16 09:14:15 -0800 |
commit | 98e55d9ca288af5dc0d645fe4ced29f964db77f6 (patch) | |
tree | 39997d78f4bc09613d1d0481821424c6e8136355 /src/github | |
parent | 15612997174a9cce9566166775de1c42f71f18e7 (diff) | |
parent | c6d492a890edac8e0556340f8f20e519da3837f8 (diff) | |
download | dsub-98e55d9ca288af5dc0d645fe4ced29f964db77f6.tar.gz dsub-98e55d9ca288af5dc0d645fe4ced29f964db77f6.tar.bz2 dsub-98e55d9ca288af5dc0d645fe4ced29f964db77f6.zip |
Merge branch 'master' into DLNA
Diffstat (limited to 'src/github')
9 files changed, 582 insertions, 197 deletions
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index d8a938cd..56a89fd2 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -33,9 +32,9 @@ import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; -import android.preference.PreferenceActivity; import android.preference.PreferenceCategory; import android.preference.PreferenceScreen; +import android.support.v7.app.ActionBarActivity; import android.text.InputType; import android.util.Log; import android.view.MenuItem; @@ -43,8 +42,10 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import android.widget.FrameLayout; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.fragments.PreferenceCompatFragment; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; @@ -59,16 +60,15 @@ import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.net.URL; -import java.security.acl.Group; import java.text.DecimalFormat; import java.util.LinkedHashMap; -import java.util.Locale; import java.util.Map; -public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { +public class SettingsActivity extends SubsonicActivity implements SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = SettingsActivity.class.getSimpleName(); private final Map<String, ServerSettings> serverSettings = new LinkedHashMap<String, ServerSettings>(); private boolean testingConnection; + private PreferenceCompatFragment fragment; private ListPreference theme; private ListPreference maxBitrateWifi; private ListPreference maxBitrateMobile; @@ -96,7 +96,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private String internalSSID; private String internalSSIDDisplay; private EditTextPreference cacheSize; - + private int serverCount = 3; private SharedPreferences settings; private DecimalFormat megabyteFromat; @@ -104,46 +104,114 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) @Override public void onCreate(Bundle savedInstanceState) { - applyTheme(); super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.settings); + setContentView(0); + + fragment = new PreferenceCompatFragment() { + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + this.setTitle(getResources().getString(R.string.settings_title)); + initSettings(); + } + }; + Bundle args = new Bundle(); + args.putInt(Constants.INTENT_EXTRA_FRAGMENT_TYPE, R.xml.settings); + + fragment.setArguments(args); + this.getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, null).commit(); + currentFragment = fragment; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + SharedPreferences prefs = Util.getPreferences(this); + prefs.unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if(item.getItemId() == android.R.id.home) { + onBackPressed(); + return true; + } + + return false; + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + // Random error I have no idea how to reproduce + if(sharedPreferences == null) { + return; + } + update(); + + if (Constants.PREFERENCES_KEY_HIDE_MEDIA.equals(key)) { + setHideMedia(sharedPreferences.getBoolean(key, false)); + } + else if (Constants.PREFERENCES_KEY_MEDIA_BUTTONS.equals(key)) { + setMediaButtonsEnabled(sharedPreferences.getBoolean(key, true)); + } + else if (Constants.PREFERENCES_KEY_CACHE_LOCATION.equals(key)) { + setCacheLocation(sharedPreferences.getString(key, "")); + } + else if (Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION.equals(key)){ + DownloadService downloadService = DownloadService.getInstance(); + downloadService.setSleepTimerDuration(Integer.parseInt(sharedPreferences.getString(key, "60"))); + } + else if(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT.equals(key)) { + SyncUtil.removeMostRecentSyncFiles(this); + } else if(Constants.PREFERENCES_KEY_REPLAY_GAIN.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED.equals(key)) { + DownloadService downloadService = DownloadService.getInstance(); + if(downloadService != null) { + downloadService.reapplyVolume(); + } + } + + scheduleBackup(); + } + + private void initSettings() { internalSSID = Util.getSSID(this); if(internalSSID == null) { internalSSID = ""; } internalSSIDDisplay = this.getResources().getString(R.string.settings_server_local_network_ssid_hint, internalSSID); - theme = (ListPreference) findPreference(Constants.PREFERENCES_KEY_THEME); - maxBitrateWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI); - maxBitrateMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE); - maxVideoBitrateWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI); - maxVideoBitrateMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE); - networkTimeout = (ListPreference) findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT); - cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION); - preloadCountWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI); - preloadCountMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE); - tempLoss = (ListPreference) findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS); - pauseDisconnect = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT); - serversCategory = (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_SERVER_KEY); - addServerPreference = findPreference(Constants.PREFERENCES_KEY_SERVER_ADD); - videoPlayer = (ListPreference) findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER); - syncInterval = (ListPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL); - syncEnabled = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED); - syncWifi = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_WIFI); - syncNotification = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION); - syncStarred = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_STARRED); - syncMostRecent = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT); - replayGain = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN); - replayGainType = (ListPreference) findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_TYPE); - replayGainBump = findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP); - replayGainUntagged = findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED); - cacheSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE); - + theme = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_THEME); + maxBitrateWifi = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI); + maxBitrateMobile = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE); + maxVideoBitrateWifi = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI); + maxVideoBitrateMobile = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE); + networkTimeout = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT); + cacheLocation = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION); + preloadCountWifi = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI); + preloadCountMobile = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE); + tempLoss = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS); + pauseDisconnect = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT); + serversCategory = (PreferenceCategory) fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_KEY); + addServerPreference = fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_ADD); + videoPlayer = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_VIDEO_PLAYER); + syncInterval = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_INTERVAL); + syncEnabled = (CheckBoxPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED); + syncWifi = (CheckBoxPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_WIFI); + syncNotification = (CheckBoxPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_NOTIFICATION); + syncStarred = (CheckBoxPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_STARRED); + syncMostRecent = (CheckBoxPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT); + replayGain = (CheckBoxPreference) fragment.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN); + replayGainType = (ListPreference) fragment.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_TYPE); + replayGainBump = fragment.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP); + replayGainUntagged = fragment.findPreference(Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED); + cacheSize = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE); + settings = Util.getPreferences(this); serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1); - findPreference("clearCache").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + fragment.findPreference("clearCache").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(SettingsActivity.this, R.string.common_delete, R.string.common_confirm_message_cache, new DialogInterface.OnClickListener() { @@ -179,7 +247,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverCount++; String instance = String.valueOf(serverCount); - Preference addServerPreference = findPreference(Constants.PREFERENCES_KEY_SERVER_ADD); + Preference addServerPreference = fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_ADD); serversCategory.addPreference(addServer(serverCount)); SharedPreferences.Editor editor = settings.edit(); @@ -189,12 +257,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer editor.commit(); serverSettings.put(instance, new ServerSettings(instance)); - - return true; - } - }); - findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + return true; + } + }); + + fragment.findPreference(Constants.PREFERENCES_KEY_SYNC_ENABLED).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Boolean syncEnabled = (Boolean) newValue; @@ -220,75 +288,18 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer }); serversCategory.setOrderingAsAdded(false); - for (int i = 1; i <= serverCount; i++) { - String instance = String.valueOf(i); + for (int i = 1; i <= serverCount; i++) { + String instance = String.valueOf(i); serversCategory.addPreference(addServer(i)); - serverSettings.put(instance, new ServerSettings(instance)); - } - - SharedPreferences prefs = Util.getPreferences(this); - prefs.registerOnSharedPreferenceChangeListener(this); - - update(); - - if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH && getActionBar() != null) { - getActionBar().setDisplayHomeAsUpEnabled(true); - getActionBar().setHomeButtonEnabled(true); + serverSettings.put(instance, new ServerSettings(instance)); } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - SharedPreferences prefs = Util.getPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if(item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } + SharedPreferences prefs = Util.getPreferences(this); + prefs.registerOnSharedPreferenceChangeListener(this); - return false; + update(); } - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - // Random error I have no idea how to reproduce - if(sharedPreferences == null) { - return; - } - - update(); - - if (Constants.PREFERENCES_KEY_HIDE_MEDIA.equals(key)) { - setHideMedia(sharedPreferences.getBoolean(key, false)); - } - else if (Constants.PREFERENCES_KEY_MEDIA_BUTTONS.equals(key)) { - setMediaButtonsEnabled(sharedPreferences.getBoolean(key, true)); - } - else if (Constants.PREFERENCES_KEY_CACHE_LOCATION.equals(key)) { - setCacheLocation(sharedPreferences.getString(key, "")); - } - else if (Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION.equals(key)){ - DownloadService downloadService = DownloadService.getInstance(); - downloadService.setSleepTimerDuration(Integer.parseInt(sharedPreferences.getString(key, "60"))); - } - else if(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT.equals(key)) { - SyncUtil.removeMostRecentSyncFiles(this); - } else if(Constants.PREFERENCES_KEY_REPLAY_GAIN.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP.equals(key) || Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED.equals(key)) { - DownloadService downloadService = DownloadService.getInstance(); - if(downloadService != null) { - downloadService.reapplyVolume(); - } - } - - scheduleBackup(); - } - private void scheduleBackup() { try { Class managerClass = Class.forName("android.app.backup.BackupManager"); @@ -364,9 +375,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer ss.update(); } } - + private PreferenceScreen addServer(final int instance) { - final PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this); + final PreferenceScreen screen = fragment.getPreferenceManager().createPreferenceScreen(this); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); @@ -395,7 +406,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); - + final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(this) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { @@ -442,13 +453,13 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary); serverTagPreference.setTitle(R.string.settings_browse_by_tags); serverPasswordPreference.setDialogTitle(R.string.settings_server_password); - + final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(this); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(this, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); - + final Preference serverOpenBrowser = new Preference(this); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); @@ -492,7 +503,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer screen.getDialog().dismiss(); } }); - + return true; } }); @@ -542,7 +553,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer } catch(Exception e) { Log.w(TAG, "Failed to create " + nomediaDir, e); } - + try { if(!musicNoMedia.createNewFile()) { Log.w(TAG, "Failed to create " + musicNoMedia); @@ -636,17 +647,17 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer }; task.execute(); } - + private void openInBrowser(final int instance) { - SharedPreferences prefs = Util.getPreferences(this); + SharedPreferences prefs = Util.getPreferences(this); String url = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); if(url == null) { new ErrorDialog(SettingsActivity.this, R.string.settings_invalid_url, false); return; } Uri uriServer = Uri.parse(url); - - Intent browserIntent = new Intent(Intent.ACTION_VIEW, uriServer); + + Intent browserIntent = new Intent(Intent.ACTION_VIEW, uriServer); startActivity(browserIntent); } @@ -660,12 +671,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private ServerSettings(String instance) { - screen = (PreferenceScreen) findPreference("server" + instance); - serverName = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_NAME + instance); - serverUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_URL + instance); - serverLocalNetworkSSID = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); - serverInternalUrl = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); - username = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_USERNAME + instance); + screen = (PreferenceScreen) fragment.findPreference("server" + instance); + serverName = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_NAME + instance); + serverUrl = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_URL + instance); + serverLocalNetworkSSID = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); + serverInternalUrl = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); + username = (EditTextPreference) fragment.findPreference(Constants.PREFERENCES_KEY_USERNAME + instance); serverUrl.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index a1e4d9ae..09a1995e 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -164,8 +164,13 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte @Override
public void startActivity(Intent intent) {
- if(intent.getComponent() != null && "github.daneren2005.dsub.activity.DownloadActivity".equals(intent.getComponent().getClassName())) {
- intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ if(intent.getComponent() != null) {
+ String name = intent.getComponent().getClassName();
+ if(name != null && name.indexOf("DownloadActivity") != -1) {
+ intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ } else if(name != null && name.indexOf("SettingsActivity") != -1) {
+ intent.putExtra(Constants.FRAGMENT_POSITION, drawerItems.length - 1);
+ }
}
super.startActivity(intent);
}
@@ -174,9 +179,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte public void setContentView(int viewId) {
super.setContentView(R.layout.abstract_activity);
rootView = (ViewGroup) findViewById(R.id.content_frame);
- LayoutInflater layoutInflater = getLayoutInflater();
- layoutInflater.inflate(viewId, rootView);
+ if(viewId != 0) {
+ LayoutInflater layoutInflater = getLayoutInflater();
+ layoutInflater.inflate(viewId, rootView);
+ }
drawerList = (ListView) findViewById(R.id.left_drawer);
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 3d1f8aab..74ef4894 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -442,16 +442,16 @@ public class SubsonicFragmentActivity extends SubsonicActivity { currentState = state;
}
- if(current == null) {
+ MusicDirectory.Entry song = null;
+ if(current != null) {
+ song = current.getSong();
+ trackView.setText(song.getTitle());
+ artistView.setText(song.getArtist());
+ } else {
trackView.setText("Title");
artistView.setText("Artist");
- getImageLoader().loadImage(coverArtView, null, false, false);
- return;
}
- MusicDirectory.Entry song = current.getSong();
- trackView.setText(song.getTitle());
- artistView.setText(song.getArtist());
getImageLoader().loadImage(coverArtView, song, false, false);
int[] attrs = new int[] {(state == PlayerState.STARTED) ? R.attr.media_button_pause : R.attr.media_button_start};
TypedArray typedArray = this.obtainStyledAttributes(attrs);
diff --git a/src/github/daneren2005/dsub/fragments/PreferenceCompatFragment.java b/src/github/daneren2005/dsub/fragments/PreferenceCompatFragment.java new file mode 100644 index 00000000..9f413b3b --- /dev/null +++ b/src/github/daneren2005/dsub/fragments/PreferenceCompatFragment.java @@ -0,0 +1,313 @@ +/* + 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.fragments; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.util.Constants; + +public class PreferenceCompatFragment extends SubsonicFragment { + private static final int FIRST_REQUEST_CODE = 100; + private static final int MSG_BIND_PREFERENCES = 1; + private static final String PREFERENCES_TAG = "android:preferences"; + private boolean mHavePrefs; + private boolean mInitDone; + private ListView mList; + private PreferenceManager mPreferenceManager; + + private Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + + case MSG_BIND_PREFERENCES: + bindPreferences(); + break; + } + } + }; + + final private Runnable mRequestFocus = new Runnable() { + public void run() { + mList.focusableViewAvailable(mList); + } + }; + + private void bindPreferences() { + PreferenceScreen localPreferenceScreen = getPreferenceScreen(); + if (localPreferenceScreen != null) { + ListView localListView = getListView(); + localPreferenceScreen.bind(localListView); + } + } + + private void ensureList() { + if (mList == null) { + View view = getView(); + if (view == null) { + throw new IllegalStateException("Content view not yet created"); + } + + View listView = view.findViewById(android.R.id.list); + if (!(listView instanceof ListView)) { + throw new RuntimeException("Content has view with id attribute 'android.R.id.list' that is not a ListView class"); + } + + mList = (ListView)listView; + if (mList == null) { + throw new RuntimeException("Your content must have a ListView whose id attribute is 'android.R.id.list'"); + } + + mHandler.post(mRequestFocus); + } + } + + private void postBindPreferences() { + if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) { + mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget(); + } + } + + private void requirePreferenceManager() { + if (this.mPreferenceManager == null) { + throw new RuntimeException("This should be called after super.onCreate."); + } + } + + public void addPreferencesFromIntent(Intent intent) { + requirePreferenceManager(); + PreferenceScreen screen = inflateFromIntent(intent, getPreferenceScreen()); + setPreferenceScreen(screen); + } + + public void addPreferencesFromResource(int resId) { + requirePreferenceManager(); + PreferenceScreen screen = inflateFromResource(getActivity(), resId, getPreferenceScreen()); + setPreferenceScreen(screen); + } + + public Preference findPreference(CharSequence key) { + if (mPreferenceManager == null) { + return null; + } + return mPreferenceManager.findPreference(key); + } + + public ListView getListView() { + ensureList(); + return mList; + } + + public PreferenceManager getPreferenceManager() { + return mPreferenceManager; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + getListView().setScrollBarStyle(0); + if (mHavePrefs) { + bindPreferences(); + } + mInitDone = true; + if (savedInstanceState != null) { + Bundle localBundle = savedInstanceState.getBundle(PREFERENCES_TAG); + if (localBundle != null) { + PreferenceScreen screen = getPreferenceScreen(); + if (screen != null) { + screen.restoreHierarchyState(localBundle); + } + } + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + dispatchActivityResult(requestCode, resultCode, data); + } + + @Override + public void onCreate(Bundle paramBundle) { + super.onCreate(paramBundle); + mPreferenceManager = createPreferenceManager(); + + int res = this.getArguments().getInt(Constants.INTENT_EXTRA_FRAGMENT_TYPE, 0); + if(res != 0) { + addPreferencesFromResource(res); + } + } + + @Override + public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) { + return paramLayoutInflater.inflate(R.layout.preferences, paramViewGroup, false); + } + + @Override + public void onDestroy() { + super.onDestroy(); + dispatchActivityDestroy(); + } + + @Override + public void onDestroyView() { + mList = null; + mHandler.removeCallbacks(mRequestFocus); + mHandler.removeMessages(MSG_BIND_PREFERENCES); + super.onDestroyView(); + } + + @Override + public void onSaveInstanceState(Bundle bundle) { + super.onSaveInstanceState(bundle); + PreferenceScreen screen = getPreferenceScreen(); + if (screen != null) { + Bundle localBundle = new Bundle(); + screen.saveHierarchyState(localBundle); + bundle.putBundle(PREFERENCES_TAG, localBundle); + } + } + + @Override + public void onStop() { + super.onStop(); + dispatchActivityStop(); + } + + /** Access methods with visibility private **/ + + private PreferenceManager createPreferenceManager() { + try { + Constructor<PreferenceManager> c = PreferenceManager.class.getDeclaredConstructor(Activity.class, int.class); + c.setAccessible(true); + return c.newInstance(this.getActivity(), FIRST_REQUEST_CODE); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private PreferenceScreen getPreferenceScreen() { + try { + Method m = PreferenceManager.class.getDeclaredMethod("getPreferenceScreen"); + m.setAccessible(true); + return (PreferenceScreen) m.invoke(mPreferenceManager); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void setPreferenceScreen(PreferenceScreen preferenceScreen) { + try { + Method m = PreferenceManager.class.getDeclaredMethod("setPreferences", PreferenceScreen.class); + m.setAccessible(true); + boolean result = (Boolean) m.invoke(mPreferenceManager, preferenceScreen); + if (result && preferenceScreen != null) { + mHavePrefs = true; + if (mInitDone) { + postBindPreferences(); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void dispatchActivityResult(int requestCode, int resultCode, Intent data) { + try { + Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityResult", int.class, int.class, Intent.class); + m.setAccessible(true); + m.invoke(mPreferenceManager, requestCode, resultCode, data); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void dispatchActivityDestroy() { + try { + Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityDestroy"); + m.setAccessible(true); + m.invoke(mPreferenceManager); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void dispatchActivityStop() { + try { + Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityStop"); + m.setAccessible(true); + m.invoke(mPreferenceManager); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + + private void setFragment(PreferenceFragment preferenceFragment) { + try { + Method m = PreferenceManager.class.getDeclaredMethod("setFragment", PreferenceFragment.class); + m.setAccessible(true); + m.invoke(mPreferenceManager, preferenceFragment); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public PreferenceScreen inflateFromResource(Context context, int resId, PreferenceScreen rootPreferences) { + PreferenceScreen preferenceScreen ; + try { + Method m = PreferenceManager.class.getDeclaredMethod("inflateFromResource", Context.class, int.class, PreferenceScreen.class); + m.setAccessible(true); + preferenceScreen = (PreferenceScreen) m.invoke(mPreferenceManager, context, resId, rootPreferences); + } catch (Exception e) { + throw new RuntimeException(e); + } + return preferenceScreen; + } + + public PreferenceScreen inflateFromIntent(Intent queryIntent, PreferenceScreen rootPreferences) { + PreferenceScreen preferenceScreen ; + try { + Method m = PreferenceManager.class.getDeclaredMethod("inflateFromIntent", Intent.class, PreferenceScreen.class); + m.setAccessible(true); + preferenceScreen = (PreferenceScreen) m.invoke(mPreferenceManager, queryIntent, rootPreferences); + } catch (Exception e) { + throw new RuntimeException(e); + } + return preferenceScreen; + } +} diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index a71924cf..3fbb90cf 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -203,7 +203,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
else if(hideButtons && !showAll) {
if(albumListType != null) {
- menuInflater.inflate(R.menu.empty, menu);
+ menuInflater.inflate(R.menu.select_album_list, menu);
} else {
menuInflater.inflate(R.menu.select_album, menu);
@@ -802,6 +802,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if (hasSubFolders && (id != null || share != null || "starred".equals(albumListType))) {
downloadRecursively(id, false, append, !append, shuffle, false);
+ } else if(hasSubFolders && albumListType != null) {
+ downloadRecursively(albums, shuffle, append);
} else {
selectAll(true, false);
download(append, false, !append, false, shuffle);
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 5cb7c32f..6e588ec4 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -847,12 +847,7 @@ 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<Boolean> task = new LoadingTask<Boolean>(context) {
- private MusicService musicService;
- private static final int MAX_SONGS = 500;
- private boolean playNowOverride = false;
- private List<Entry> songs;
-
+ new RecursiveLoader(context) {
@Override
protected Boolean doInBackground() throws Throwable {
musicService = MusicServiceFactory.getMusicService(context);
@@ -904,48 +899,47 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR return transition;
}
+ }.execute();
+ }
- private void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception {
- if (songs.size() > MAX_SONGS) {
- return;
- }
+ protected void downloadRecursively(final List<Entry> albums, final boolean shuffle, final boolean append) {
+ new RecursiveLoader(context) {
+ @Override
+ protected Boolean doInBackground() throws Throwable {
+ musicService = MusicServiceFactory.getMusicService(context);
- for (Entry song : parent.getChildren(false, true)) {
- if (!song.isVideo() && song.getRating() != 1) {
- songs.add(song);
- }
+ if(shuffle) {
+ Collections.shuffle(albums);
}
- for (Entry dir : parent.getChildren(true, false)) {
- if(dir.getRating() == 1) {
- continue;
- }
- MusicDirectory musicDirectory;
- if(Util.isTagBrowsing(context) && !Util.isOffline(context)) {
- musicDirectory = musicService.getAlbum(dir.getId(), dir.getTitle(), false, context, this);
- } else {
- musicDirectory = musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this);
+ songs = new LinkedList<Entry>();
+ MusicDirectory root = new MusicDirectory();
+ root.addChildren(albums);
+ getSongsRecursively(root, songs);
+
+ DownloadService downloadService = getDownloadService();
+ boolean transition = false;
+ if (!songs.isEmpty() && downloadService != null) {
+ // Conditions for a standard play now operation
+ if(!append && !shuffle) {
+ playNowOverride = true;
+ return false;
}
- getSongsRecursively(musicDirectory, songs);
- }
- }
- @Override
- protected void done(Boolean result) {
- warnIfStorageUnavailable();
+ if (!append) {
+ downloadService.clear();
+ }
- if(playNowOverride) {
- playNow(songs);
- return;
+ downloadService.download(songs, false, true, false, false);
+ if(!append) {
+ transition = true;
+ }
}
+ artistOverride = false;
- if(result) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
- }
+ return transition;
}
- };
-
- task.execute();
+ }.execute();
}
protected MusicDirectory getMusicDirectory(String id, String name, boolean refresh, MusicService service, ProgressListener listener) throws Exception {
@@ -1732,4 +1726,54 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public abstract class OnStarChange {
abstract void starChange(boolean starred);
}
+
+ public abstract class RecursiveLoader extends LoadingTask<Boolean> {
+ protected MusicService musicService;
+ protected static final int MAX_SONGS = 500;
+ protected boolean playNowOverride = false;
+ protected List<Entry> songs;
+
+ public RecursiveLoader(Activity context) {
+ super(context);
+ }
+
+ protected void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception {
+ if (songs.size() > MAX_SONGS) {
+ return;
+ }
+
+ for (Entry song : parent.getChildren(false, true)) {
+ if (!song.isVideo() && song.getRating() != 1) {
+ songs.add(song);
+ }
+ }
+ for (Entry dir : parent.getChildren(true, false)) {
+ if(dir.getRating() == 1) {
+ continue;
+ }
+
+ MusicDirectory musicDirectory;
+ if(Util.isTagBrowsing(context) && !Util.isOffline(context)) {
+ musicDirectory = musicService.getAlbum(dir.getId(), dir.getTitle(), false, context, this);
+ } else {
+ musicDirectory = musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this);
+ }
+ getSongsRecursively(musicDirectory, songs);
+ }
+ }
+
+ @Override
+ protected void done(Boolean result) {
+ warnIfStorageUnavailable();
+
+ if(playNowOverride) {
+ playNow(songs);
+ return;
+ }
+
+ if(result) {
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ }
+ }
+ }
}
diff --git a/src/github/daneren2005/dsub/provider/DSubSearchProvider.java b/src/github/daneren2005/dsub/provider/DSubSearchProvider.java index 30490f17..63bbaaa4 100644 --- a/src/github/daneren2005/dsub/provider/DSubSearchProvider.java +++ b/src/github/daneren2005/dsub/provider/DSubSearchProvider.java @@ -24,6 +24,7 @@ import android.content.ContentValues; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; +import android.util.Log; import java.util.ArrayList; import java.util.Collections; @@ -45,6 +46,8 @@ import github.daneren2005.dsub.util.Util; * @author Sindre Mehus */ public class DSubSearchProvider extends ContentProvider { + private static final String TAG = DSubSearchProvider.class.getSimpleName(); + private static final String RESOURCE_PREFIX = "android.resource://github.daneren2005.dsub/"; private static final String[] COLUMNS = {"_id", SearchManager.SUGGEST_COLUMN_TEXT_1, diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index a1bf7b52..f23b0995 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -28,6 +28,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARED; 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 static github.daneren2005.dsub.domain.RemoteControlState.LOCAL; import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.AudioEffectsController; @@ -140,7 +141,7 @@ public class DownloadService extends Service { private float volume = 1.0f; private AudioEffectsController effectsController; - private RemoteControlState remoteState = RemoteControlState.LOCAL; + private RemoteControlState remoteState = LOCAL; private PositionCache positionCache; private BufferProxy proxy; @@ -405,7 +406,7 @@ public class DownloadService extends Service { } private void updateJukeboxPlaylist() { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.updatePlaylist(); } } @@ -413,7 +414,7 @@ public class DownloadService extends Service { public synchronized void restore(List<MusicDirectory.Entry> songs, List<MusicDirectory.Entry> toDelete, int currentPlayingIndex, int currentPlayingPosition) { SharedPreferences prefs = Util.getPreferences(this); remoteState = RemoteControlState.values()[prefs.getInt(Constants.PREFERENCES_KEY_CONTROL_MODE, 0)]; - if(remoteState != RemoteControlState.LOCAL) { + if(remoteState != LOCAL) { String id = prefs.getString(Constants.PREFERENCES_KEY_CONTROL_ID, null); setRemoteState(remoteState, null, id); } @@ -828,10 +829,10 @@ public class DownloadService extends Service { nextPlayingTask = null; } setCurrentPlaying(index, start); - if (start && remoteState != RemoteControlState.LOCAL) { + if (start && remoteState != LOCAL) { remoteController.changeTrack(index, currentPlaying); } - if (remoteState == RemoteControlState.LOCAL) { + if (remoteState == LOCAL) { bufferAndPlay(position, start); checkDownloads(); setNextPlaying(); @@ -900,7 +901,7 @@ public class DownloadService extends Service { } try { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.changePosition(position / 1000); } else { mediaPlayer.seekTo(position); @@ -989,7 +990,7 @@ public class DownloadService extends Service { public synchronized void pause(boolean temp) { try { if (playerState == STARTED) { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.stop(); } else { mediaPlayer.pause(); @@ -1006,7 +1007,7 @@ public class DownloadService extends Service { public synchronized void stop() { try { if (playerState == STARTED) { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.stop(); setPlayerState(STOPPED); handler.post(new Runnable() { @@ -1029,7 +1030,7 @@ public class DownloadService extends Service { public synchronized void start() { try { - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { remoteController.start(); } else { // Only start if done preparing @@ -1053,7 +1054,7 @@ public class DownloadService extends Service { } try { // Only set to idle if it's not being killed to start RemoteController - if(remoteState == RemoteControlState.LOCAL) { + if(remoteState == LOCAL) { setPlayerState(IDLE); } mediaPlayer.setOnErrorListener(null); @@ -1093,7 +1094,7 @@ public class DownloadService extends Service { if (playerState == IDLE || playerState == DOWNLOADING || playerState == PREPARING) { return 0; } - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { return remoteController.getRemotePosition() * 1000; } else { return Math.max(0, cachedPosition - subtractPosition); @@ -1112,7 +1113,7 @@ public class DownloadService extends Service { } } if (playerState != IDLE && playerState != DOWNLOADING && playerState != PlayerState.PREPARING) { - if(remoteState == RemoteControlState.LOCAL) { + if(remoteState == LOCAL) { try { return mediaPlayer.getDuration(); } catch (Exception x) { @@ -1169,7 +1170,7 @@ public class DownloadService extends Service { scrobbler.scrobble(this, currentPlaying, true); } - if(playerState == STARTED && positionCache == null && remoteState == RemoteControlState.LOCAL) { + if(playerState == STARTED && positionCache == null && remoteState == LOCAL) { positionCache = new PositionCache(); Thread thread = new Thread(positionCache, "PositionCache"); thread.start(); @@ -1303,7 +1304,7 @@ public class DownloadService extends Service { } public boolean isRemoteEnabled() { - return remoteState != RemoteControlState.LOCAL; + return remoteState != LOCAL; } public RemoteController getRemoteController() { @@ -1339,7 +1340,7 @@ public class DownloadService extends Service { remoteController.shutdown(); remoteController = null; - if(newState == RemoteControlState.LOCAL) { + if(newState == LOCAL) { mediaRouter.setDefaultRoute(); } } @@ -1351,7 +1352,7 @@ public class DownloadService extends Service { break; case CHROMECAST: case DLNA: if(ref == null) { - remoteState = RemoteControlState.LOCAL; + remoteState = LOCAL; break; } remoteController = (RemoteController) ref; @@ -1366,7 +1367,7 @@ public class DownloadService extends Service { play(getCurrentPlayingIndex(), isPlaying, position); } - if (remoteState != RemoteControlState.LOCAL) { + if (remoteState != LOCAL) { reset(); // Cancel current download, if necessary. @@ -1385,7 +1386,7 @@ public class DownloadService extends Service { } } - if(remoteState == RemoteControlState.LOCAL) { + if(remoteState == LOCAL) { checkDownloads(); } @@ -1395,7 +1396,7 @@ public class DownloadService extends Service { public void run() { RouteInfo info = mediaRouter.getRouteForId(routeId); if(info == null) { - setRemoteState(RemoteControlState.LOCAL, null); + setRemoteState(LOCAL, null); } else if(newState == RemoteControlState.CHROMECAST) { RemoteController controller = mediaRouter.getRemoteController(info); if(controller != null) { @@ -1551,7 +1552,7 @@ public class DownloadService extends Service { resetNext(); // Exit when using remote controllers - if(remoteState != RemoteControlState.LOCAL) { + if(remoteState != LOCAL) { return; } @@ -1719,7 +1720,7 @@ public class DownloadService extends Service { DownloadFile movedSong = list.remove(from); list.add(to, movedSong); currentPlayingIndex = downloadList.indexOf(currentPlaying); - if(remoteState != RemoteControlState.LOCAL && mainList) { + if(remoteState != LOCAL && mainList) { updateJukeboxPlaylist(); } else if(mainList && (movedSong == nextPlaying || movedSong == currentPlaying || (currentPlayingIndex + 1) == to)) { // Moving next playing, current playing, or moving a song to be next playing @@ -1766,7 +1767,7 @@ public class DownloadService extends Service { checkShufflePlay(); } - if (remoteState != RemoteControlState.LOCAL || !Util.isNetworkConnected(this, true) || Util.isOffline(this)) { + if (!Util.isNetworkConnected(this, true) || Util.isOffline(this)) { return; } @@ -1774,8 +1775,8 @@ public class DownloadService extends Service { return; } - // Need to download current playing? - if (currentPlaying != null && currentPlaying != currentDownloading && !currentPlaying.isWorkDone()) { + // Need to download current playing and not casting? + if (currentPlaying != null && remoteState == LOCAL && currentPlaying != currentDownloading && !currentPlaying.isWorkDone()) { // Cancel current download, if necessary. if (currentDownloading != null) { currentDownloading.cancelDownload(); @@ -1787,13 +1788,13 @@ public class DownloadService extends Service { } // Find a suitable target for download. - else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed() && (!downloadList.isEmpty() || !backgroundDownloadList.isEmpty())) { + else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed() && ((!downloadList.isEmpty() && remoteState == LOCAL) || !backgroundDownloadList.isEmpty())) { currentDownloading = null; int n = size(); int preloaded = 0; - if(n != 0) { + if(n != 0 && remoteState == LOCAL) { int start = currentPlaying == null ? 0 : getCurrentPlayingIndex(); if(start == -1) { start = 0; @@ -1819,7 +1820,7 @@ public class DownloadService extends Service { } while (i != start); } - if((preloaded + 1 == n || preloaded >= Util.getPreloadCount(this) || downloadList.isEmpty()) && !backgroundDownloadList.isEmpty()) { + if((preloaded + 1 == n || preloaded >= Util.getPreloadCount(this) || downloadList.isEmpty() || remoteState != LOCAL) && !backgroundDownloadList.isEmpty()) { for(int i = 0; i < backgroundDownloadList.size(); i++) { DownloadFile downloadFile = backgroundDownloadList.get(i); if(downloadFile.isWorkDone() && (!downloadFile.shouldSave() || downloadFile.isSaved()) || downloadFile.isFailedMax()) { diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 205690f8..626b1d91 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -887,6 +887,10 @@ public final class Util { throw new IllegalArgumentException("Strings must not be null"); } + if(t.toString().toLowerCase().indexOf(s.toString().toLowerCase()) != -1) { + return 1; + } + int n = s.length(); int m = t.length(); |