diff --git a/app/src/main/java/net/nullsum/audinaut/activity/EditPlayActionActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/EditPlayActionActivity.java
index 8e42329..5cf4cc8 100644
--- a/app/src/main/java/net/nullsum/audinaut/activity/EditPlayActionActivity.java
+++ b/app/src/main/java/net/nullsum/audinaut/activity/EditPlayActionActivity.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2014 (C) Scott Jackson
+ 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 .
+ Copyright 2014 (C) Scott Jackson
*/
package net.nullsum.audinaut.activity;
@@ -46,200 +46,200 @@ import net.nullsum.audinaut.util.LoadingTask;
import net.nullsum.audinaut.util.Util;
public class EditPlayActionActivity extends SubsonicActivity {
- private CheckBox shuffleCheckbox;
- private CheckBox startYearCheckbox;
- private EditText startYearBox;
- private CheckBox endYearCheckbox;
- private EditText endYearBox;
- private Button genreButton;
- private Spinner offlineSpinner;
-
- private String doNothing;
+ private CheckBox shuffleCheckbox;
+ private CheckBox startYearCheckbox;
+ private EditText startYearBox;
+ private CheckBox endYearCheckbox;
+ private EditText endYearBox;
+ private Button genreButton;
+ private Spinner offlineSpinner;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setTitle(R.string.tasker_start_playing_title);
- setContentView(R.layout.edit_play_action);
- final Activity context = this;
- doNothing = context.getResources().getString(R.string.tasker_edit_do_nothing);
+ private String doNothing;
- shuffleCheckbox = (CheckBox) findViewById(R.id.edit_shuffle_checkbox);
- shuffleCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton view, boolean isChecked) {
- startYearCheckbox.setEnabled(isChecked);
- endYearCheckbox.setEnabled(isChecked);
- genreButton.setEnabled(isChecked);
- }
- });
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setTitle(R.string.tasker_start_playing_title);
+ setContentView(R.layout.edit_play_action);
+ final Activity context = this;
+ doNothing = context.getResources().getString(R.string.tasker_edit_do_nothing);
- startYearCheckbox = (CheckBox) findViewById(R.id.edit_start_year_checkbox);
- startYearBox = (EditText) findViewById(R.id.edit_start_year);
- // Disable/enable number box if checked
- startYearCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton view, boolean isChecked) {
- startYearBox.setEnabled(isChecked);
- }
- });
-
- endYearCheckbox = (CheckBox) findViewById(R.id.edit_end_year_checkbox);
- endYearBox = (EditText) findViewById(R.id.edit_end_year);
- endYearCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton view, boolean isChecked) {
- endYearBox.setEnabled(isChecked);
- }
- });
+ shuffleCheckbox = (CheckBox) findViewById(R.id.edit_shuffle_checkbox);
+ shuffleCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton view, boolean isChecked) {
+ startYearCheckbox.setEnabled(isChecked);
+ endYearCheckbox.setEnabled(isChecked);
+ genreButton.setEnabled(isChecked);
+ }
+ });
- genreButton = (Button) findViewById(R.id.edit_genre_spinner);
- genreButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- new LoadingTask>(context, true) {
- @Override
- protected List doInBackground() throws Throwable {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- return musicService.getGenres(false, context, this);
- }
+ startYearCheckbox = (CheckBox) findViewById(R.id.edit_start_year_checkbox);
+ startYearBox = (EditText) findViewById(R.id.edit_start_year);
+ // Disable/enable number box if checked
+ startYearCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton view, boolean isChecked) {
+ startYearBox.setEnabled(isChecked);
+ }
+ });
- @Override
- protected void done(final List genres) {
- List names = new ArrayList();
- String blank = context.getResources().getString(R.string.select_genre_blank);
- names.add(doNothing);
- names.add(blank);
- for(Genre genre: genres) {
- names.add(genre.getName());
- }
- final List finalNames = names;
+ endYearCheckbox = (CheckBox) findViewById(R.id.edit_end_year_checkbox);
+ endYearBox = (EditText) findViewById(R.id.edit_end_year);
+ endYearCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton view, boolean isChecked) {
+ endYearBox.setEnabled(isChecked);
+ }
+ });
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(R.string.shuffle_pick_genre)
- .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if(which == 1) {
- genreButton.setText("");
- } else {
- genreButton.setText(finalNames.get(which));
- }
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
+ genreButton = (Button) findViewById(R.id.edit_genre_spinner);
+ genreButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ new LoadingTask>(context, true) {
+ @Override
+ protected List doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ return musicService.getGenres(false, context, this);
+ }
- @Override
- protected void error(Throwable error) {
- String msg;
- if (error instanceof OfflineException) {
- msg = getErrorMessage(error);
- } else {
- msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error);
- }
+ @Override
+ protected void done(final List genres) {
+ List names = new ArrayList();
+ String blank = context.getResources().getString(R.string.select_genre_blank);
+ names.add(doNothing);
+ names.add(blank);
+ for(Genre genre: genres) {
+ names.add(genre.getName());
+ }
+ final List finalNames = names;
- Util.toast(context, msg, false);
- }
- }.execute();
- }
- });
- genreButton.setText(doNothing);
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.shuffle_pick_genre)
+ .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if(which == 1) {
+ genreButton.setText("");
+ } else {
+ genreButton.setText(finalNames.get(which));
+ }
+ }
+ });
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
- offlineSpinner = (Spinner) findViewById(R.id.edit_offline_spinner);
- ArrayAdapter offlineAdapter = ArrayAdapter.createFromResource(this, R.array.editServerOptions, android.R.layout.simple_spinner_item);
- offlineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- offlineSpinner.setAdapter(offlineAdapter);
-
- // Setup default for everything
- Bundle extras = getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE);
- if(extras != null) {
- if(extras.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE)) {
- shuffleCheckbox.setChecked(true);
- }
-
- String startYear = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, null);
- if(startYear != null) {
- startYearCheckbox.setEnabled(true);
- startYearBox.setText(startYear);
- }
- String endYear = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, null);
- if(endYear != null) {
- endYearCheckbox.setEnabled(true);
- endYearBox.setText(endYear);
- }
-
- String genre = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, doNothing);
- if(genre != null) {
- genreButton.setText(genre);
- }
-
- int offline = extras.getInt(Constants.PREFERENCES_KEY_OFFLINE, 0);
- if(offline != 0) {
- offlineSpinner.setSelection(offline);
- }
- }
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error);
+ }
- drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
- }
+ Util.toast(context, msg, false);
+ }
+ }.execute();
+ }
+ });
+ genreButton.setText(doNothing);
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater menuInflater = getMenuInflater();
- menuInflater.inflate(R.menu.tasker_configuration, menu);
- return true;
- }
+ offlineSpinner = (Spinner) findViewById(R.id.edit_offline_spinner);
+ ArrayAdapter offlineAdapter = ArrayAdapter.createFromResource(this, R.array.editServerOptions, android.R.layout.simple_spinner_item);
+ offlineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ offlineSpinner.setAdapter(offlineAdapter);
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(item.getItemId() == android.R.id.home) {
- cancel();
- return true;
- } else if(item.getItemId() == R.id.menu_accept) {
- accept();
- return true;
- } else if(item.getItemId() == R.id.menu_cancel) {
- cancel();
- return true;
- }
+ // Setup default for everything
+ Bundle extras = getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE);
+ if(extras != null) {
+ if(extras.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE)) {
+ shuffleCheckbox.setChecked(true);
+ }
- return false;
- }
+ String startYear = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, null);
+ if(startYear != null) {
+ startYearCheckbox.setEnabled(true);
+ startYearBox.setText(startYear);
+ }
+ String endYear = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, null);
+ if(endYear != null) {
+ endYearCheckbox.setEnabled(true);
+ endYearBox.setText(endYear);
+ }
- private void accept() {
- Intent intent = new Intent();
+ String genre = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, doNothing);
+ if(genre != null) {
+ genreButton.setText(genre);
+ }
- String blurb = getResources().getString(shuffleCheckbox.isChecked() ? R.string.tasker_start_playing_shuffled : R.string.tasker_start_playing);
- intent.putExtra("com.twofortyfouram.locale.intent.extra.BLURB", blurb);
+ int offline = extras.getInt(Constants.PREFERENCES_KEY_OFFLINE, 0);
+ if(offline != 0) {
+ offlineSpinner.setSelection(offline);
+ }
+ }
- // Get settings user specified
- Bundle data = new Bundle();
- boolean shuffle = shuffleCheckbox.isChecked();
- data.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, shuffle);
- if(shuffle) {
- if(startYearCheckbox.isChecked()) {
- data.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYearBox.getText().toString());
- }
- if(endYearCheckbox.isChecked()) {
- data.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYearBox.getText().toString());
- }
- String genre = genreButton.getText().toString();
- if(!genre.equals(doNothing)) {
- data.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
- }
- }
-
- int offline = offlineSpinner.getSelectedItemPosition();
- if(offline != 0) {
- data.putInt(Constants.PREFERENCES_KEY_OFFLINE, offline);
- }
-
- intent.putExtra(Constants.TASKER_EXTRA_BUNDLE, data);
+ drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+ }
- setResult(Activity.RESULT_OK, intent);
- finish();
- }
- private void cancel() {
- setResult(Activity.RESULT_CANCELED);
- finish();
- }
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater menuInflater = getMenuInflater();
+ menuInflater.inflate(R.menu.tasker_configuration, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(item.getItemId() == android.R.id.home) {
+ cancel();
+ return true;
+ } else if(item.getItemId() == R.id.menu_accept) {
+ accept();
+ return true;
+ } else if(item.getItemId() == R.id.menu_cancel) {
+ cancel();
+ return true;
+ }
+
+ return false;
+ }
+
+ private void accept() {
+ Intent intent = new Intent();
+
+ String blurb = getResources().getString(shuffleCheckbox.isChecked() ? R.string.tasker_start_playing_shuffled : R.string.tasker_start_playing);
+ intent.putExtra("com.twofortyfouram.locale.intent.extra.BLURB", blurb);
+
+ // Get settings user specified
+ Bundle data = new Bundle();
+ boolean shuffle = shuffleCheckbox.isChecked();
+ data.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, shuffle);
+ if(shuffle) {
+ if(startYearCheckbox.isChecked()) {
+ data.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYearBox.getText().toString());
+ }
+ if(endYearCheckbox.isChecked()) {
+ data.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYearBox.getText().toString());
+ }
+ String genre = genreButton.getText().toString();
+ if(!genre.equals(doNothing)) {
+ data.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
+ }
+ }
+
+ int offline = offlineSpinner.getSelectedItemPosition();
+ if(offline != 0) {
+ data.putInt(Constants.PREFERENCES_KEY_OFFLINE, offline);
+ }
+
+ intent.putExtra(Constants.TASKER_EXTRA_BUNDLE, data);
+
+ setResult(Activity.RESULT_OK, intent);
+ finish();
+ }
+ private void cancel() {
+ setResult(Activity.RESULT_CANCELED);
+ finish();
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/activity/QueryReceiverActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/QueryReceiverActivity.java
index cb627bb..e4107e9 100644
--- a/app/src/main/java/net/nullsum/audinaut/activity/QueryReceiverActivity.java
+++ b/app/src/main/java/net/nullsum/audinaut/activity/QueryReceiverActivity.java
@@ -38,48 +38,48 @@ import net.nullsum.audinaut.provider.AudinautSearchProvider;
*/
public class QueryReceiverActivity extends Activity {
- private static final String TAG = QueryReceiverActivity.class.getSimpleName();
+ private static final String TAG = QueryReceiverActivity.class.getSimpleName();
- @Override
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Intent intent = getIntent();
- if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
- doSearch();
- } else if(Intent.ACTION_VIEW.equals(intent.getAction())) {
- showResult(intent.getDataString(), intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
- }
+ Intent intent = getIntent();
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ doSearch();
+ } else if(Intent.ACTION_VIEW.equals(intent.getAction())) {
+ showResult(intent.getDataString(), intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
+ }
finish();
Util.disablePendingTransition(this);
}
- private void doSearch() {
- String query = getIntent().getStringExtra(SearchManager.QUERY);
- if (query != null) {
- Intent intent = new Intent(QueryReceiverActivity.this, SubsonicFragmentActivity.class);
- intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query);
- intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- Util.startActivityWithoutTransition(QueryReceiverActivity.this, intent);
- }
- }
- private void showResult(String albumId, String name) {
- if (albumId != null) {
- Intent intent = new Intent(this, SubsonicFragmentActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.putExtra(Constants.INTENT_EXTRA_VIEW_ALBUM, true);
- 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) {
- intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, name);
- }
- Util.startActivityWithoutTransition(this, intent);
- }
- }
+ private void doSearch() {
+ String query = getIntent().getStringExtra(SearchManager.QUERY);
+ if (query != null) {
+ Intent intent = new Intent(QueryReceiverActivity.this, SubsonicFragmentActivity.class);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query);
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ Util.startActivityWithoutTransition(QueryReceiverActivity.this, intent);
+ }
+ }
+ private void showResult(String albumId, String name) {
+ if (albumId != null) {
+ Intent intent = new Intent(this, SubsonicFragmentActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.putExtra(Constants.INTENT_EXTRA_VIEW_ALBUM, true);
+ 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) {
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, name);
+ }
+ Util.startActivityWithoutTransition(this, intent);
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/activity/SettingsActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/SettingsActivity.java
index b459b9a..399e80c 100644
--- a/app/src/main/java/net/nullsum/audinaut/activity/SettingsActivity.java
+++ b/app/src/main/java/net/nullsum/audinaut/activity/SettingsActivity.java
@@ -28,29 +28,29 @@ import net.nullsum.audinaut.fragments.SettingsFragment;
import net.nullsum.audinaut.util.Constants;
public class SettingsActivity extends SubsonicActivity {
- private static final String TAG = SettingsActivity.class.getSimpleName();
- private PreferenceCompatFragment fragment;
+ private static final String TAG = SettingsActivity.class.getSimpleName();
+ private PreferenceCompatFragment fragment;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- lastSelectedPosition = R.id.drawer_settings;
- setContentView(R.layout.settings_activity);
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ lastSelectedPosition = R.id.drawer_settings;
+ setContentView(R.layout.settings_activity);
- if (savedInstanceState == null) {
- fragment = new SettingsFragment();
- Bundle args = new Bundle();
- args.putInt(Constants.INTENT_EXTRA_FRAGMENT_TYPE, R.xml.settings);
+ if (savedInstanceState == null) {
+ fragment = new SettingsFragment();
+ Bundle args = new Bundle();
+ args.putInt(Constants.INTENT_EXTRA_FRAGMENT_TYPE, R.xml.settings);
- fragment.setArguments(args);
- fragment.setRetainInstance(true);
+ fragment.setArguments(args);
+ fragment.setRetainInstance(true);
- currentFragment = fragment;
- currentFragment.setPrimaryFragment(true);
- getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit();
- }
+ currentFragment = fragment;
+ currentFragment.setPrimaryFragment(true);
+ getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit();
+ }
- Toolbar mainToolbar = (Toolbar) findViewById(R.id.main_toolbar);
- setSupportActionBar(mainToolbar);
- }
+ Toolbar mainToolbar = (Toolbar) findViewById(R.id.main_toolbar);
+ setSupportActionBar(mainToolbar);
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java
index 7d9913b..672c595 100644
--- a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java
+++ b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java
@@ -85,222 +85,222 @@ import net.nullsum.audinaut.util.UserUtil;
import static android.Manifest.*;
public class SubsonicActivity extends AppCompatActivity implements OnItemSelectedListener {
- private static final String TAG = SubsonicActivity.class.getSimpleName();
- private static ImageLoader IMAGE_LOADER;
- protected static String theme;
- protected static boolean fullScreen;
- protected static boolean actionbarColored;
- private static final int MENU_GROUP_SERVER = 10;
- private static final int MENU_ITEM_SERVER_BASE = 100;
- private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
+ private static final String TAG = SubsonicActivity.class.getSimpleName();
+ private static ImageLoader IMAGE_LOADER;
+ protected static String theme;
+ protected static boolean fullScreen;
+ protected static boolean actionbarColored;
+ private static final int MENU_GROUP_SERVER = 10;
+ private static final int MENU_ITEM_SERVER_BASE = 100;
+ private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
- private final List afterServiceAvailable = new ArrayList<>();
- private boolean drawerIdle = true;
- private boolean destroyed = false;
- private boolean finished = false;
- protected List backStack = new ArrayList();
- protected SubsonicFragment currentFragment;
- protected View primaryContainer;
- protected View secondaryContainer;
- protected boolean touchscreen = true;
- protected Handler handler = new Handler();
- Spinner actionBarSpinner;
- ArrayAdapter spinnerAdapter;
- ViewGroup rootView;
- DrawerLayout drawer;
- ActionBarDrawerToggle drawerToggle;
- NavigationView drawerList;
- View drawerHeader;
- ImageView drawerHeaderToggle;
- TextView drawerServerName;
- TextView drawerUserName;
- int lastSelectedPosition = 0;
- boolean showingTabs = true;
- boolean drawerOpen = false;
- SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
+ private final List afterServiceAvailable = new ArrayList<>();
+ private boolean drawerIdle = true;
+ private boolean destroyed = false;
+ private boolean finished = false;
+ protected List backStack = new ArrayList();
+ protected SubsonicFragment currentFragment;
+ protected View primaryContainer;
+ protected View secondaryContainer;
+ protected boolean touchscreen = true;
+ protected Handler handler = new Handler();
+ Spinner actionBarSpinner;
+ ArrayAdapter spinnerAdapter;
+ ViewGroup rootView;
+ DrawerLayout drawer;
+ ActionBarDrawerToggle drawerToggle;
+ NavigationView drawerList;
+ View drawerHeader;
+ ImageView drawerHeaderToggle;
+ TextView drawerServerName;
+ TextView drawerUserName;
+ int lastSelectedPosition = 0;
+ boolean showingTabs = true;
+ boolean drawerOpen = false;
+ SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
- static {
- AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
- }
+ static {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
+ }
- @Override
- protected void onCreate(Bundle bundle) {
- UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
- PackageManager pm = getPackageManager();
- if(!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
- touchscreen = false;
- }
+ @Override
+ protected void onCreate(Bundle bundle) {
+ UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
+ PackageManager pm = getPackageManager();
+ if(!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
+ touchscreen = false;
+ }
- setUncaughtExceptionHandler();
- applyTheme();
- applyFullscreen();
- super.onCreate(bundle);
- startService(new Intent(this, DownloadService.class));
- setVolumeControlStream(AudioManager.STREAM_MUSIC);
+ setUncaughtExceptionHandler();
+ applyTheme();
+ applyFullscreen();
+ super.onCreate(bundle);
+ startService(new Intent(this, DownloadService.class));
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
- if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
- lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
- }
+ if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
+ lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
+ }
- if(preferencesListener == null) {
- Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
- }
+ if(preferencesListener == null) {
+ Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
+ }
- if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(this, new String[]{ permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
- }
- }
+ if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this, new String[]{ permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
+ }
+ }
- @Override
- public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
- switch (requestCode) {
- case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
- // If request is cancelled, the result arrays are empty.
- if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ switch (requestCode) {
+ case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
+ // If request is cancelled, the result arrays are empty.
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- } else {
- Util.toast(this, R.string.permission_external_storage_failed);
- finish();
- }
- }
- }
- }
+ } else {
+ Util.toast(this, R.string.permission_external_storage_failed);
+ finish();
+ }
+ }
+ }
+ }
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
+ @Override
+ protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
- if(spinnerAdapter == null) {
- createCustomActionBarView();
- }
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setHomeButtonEnabled(true);
+ if(spinnerAdapter == null) {
+ createCustomActionBarView();
+ }
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setHomeButtonEnabled(true);
- if(Util.shouldStartOnHeadphones(this)) {
- Intent serviceIntent = new Intent();
- serviceIntent.setClassName(this.getPackageName(), HeadphoneListenerService.class.getName());
- this.startService(serviceIntent);
- }
- }
+ if(Util.shouldStartOnHeadphones(this)) {
+ Intent serviceIntent = new Intent();
+ serviceIntent.setClassName(this.getPackageName(), HeadphoneListenerService.class.getName());
+ this.startService(serviceIntent);
+ }
+ }
- protected void createCustomActionBarView() {
- actionBarSpinner = (Spinner) getLayoutInflater().inflate(R.layout.actionbar_spinner, null);
- if((this instanceof SubsonicFragmentActivity || this instanceof SettingsActivity) && (Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true) || ThemeUtil.getThemeRes(this) != R.style.Theme_Audinaut_Light_No_Color)) {
- actionBarSpinner.setBackgroundDrawable(DrawableTint.getTintedDrawableFromColor(this, R.drawable.abc_spinner_mtrl_am_alpha, android.R.color.white));
- }
- spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
- spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- actionBarSpinner.setOnItemSelectedListener(this);
- actionBarSpinner.setAdapter(spinnerAdapter);
+ protected void createCustomActionBarView() {
+ actionBarSpinner = (Spinner) getLayoutInflater().inflate(R.layout.actionbar_spinner, null);
+ if((this instanceof SubsonicFragmentActivity || this instanceof SettingsActivity) && (Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true) || ThemeUtil.getThemeRes(this) != R.style.Theme_Audinaut_Light_No_Color)) {
+ actionBarSpinner.setBackgroundDrawable(DrawableTint.getTintedDrawableFromColor(this, R.drawable.abc_spinner_mtrl_am_alpha, android.R.color.white));
+ }
+ spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
+ spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ actionBarSpinner.setOnItemSelectedListener(this);
+ actionBarSpinner.setAdapter(spinnerAdapter);
- getSupportActionBar().setCustomView(actionBarSpinner);
- }
+ getSupportActionBar().setCustomView(actionBarSpinner);
+ }
- @Override
- protected void onResume() {
- super.onResume();
- Util.registerMediaButtonEventReceiver(this);
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Util.registerMediaButtonEventReceiver(this);
- // Make sure to update theme
- SharedPreferences prefs = Util.getPreferences(this);
- if (theme != null && !theme.equals(ThemeUtil.getTheme(this)) || fullScreen != prefs.getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false) || actionbarColored != prefs.getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
- restart();
- overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
- DrawableTint.wipeTintCache();
- }
+ // Make sure to update theme
+ SharedPreferences prefs = Util.getPreferences(this);
+ if (theme != null && !theme.equals(ThemeUtil.getTheme(this)) || fullScreen != prefs.getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false) || actionbarColored != prefs.getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
+ restart();
+ overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
+ DrawableTint.wipeTintCache();
+ }
- populateTabs();
- getImageLoader().onUIVisible();
- UpdateView.addActiveActivity();
- }
+ populateTabs();
+ getImageLoader().onUIVisible();
+ UpdateView.addActiveActivity();
+ }
- @Override
- protected void onPause() {
- super.onPause();
+ @Override
+ protected void onPause() {
+ super.onPause();
- UpdateView.removeActiveActivity();
- }
+ UpdateView.removeActiveActivity();
+ }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- destroyed = true;
- Util.getPreferences(this).unregisterOnSharedPreferenceChangeListener(preferencesListener);
- }
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ destroyed = true;
+ Util.getPreferences(this).unregisterOnSharedPreferenceChangeListener(preferencesListener);
+ }
- @Override
- public void finish() {
- super.finish();
- Util.disablePendingTransition(this);
- }
+ @Override
+ public void finish() {
+ super.finish();
+ Util.disablePendingTransition(this);
+ }
- @Override
- public void setContentView(int viewId) {
+ @Override
+ public void setContentView(int viewId) {
super.setContentView(R.layout.abstract_activity);
- rootView = (ViewGroup) findViewById(R.id.content_frame);
+ rootView = (ViewGroup) findViewById(R.id.content_frame);
- if(viewId != 0) {
- LayoutInflater layoutInflater = getLayoutInflater();
- layoutInflater.inflate(viewId, rootView);
- }
+ if(viewId != 0) {
+ LayoutInflater layoutInflater = getLayoutInflater();
+ layoutInflater.inflate(viewId, rootView);
+ }
- drawerList = (NavigationView) findViewById(R.id.left_drawer);
- drawerList.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
- @Override
- public boolean onNavigationItemSelected(final MenuItem menuItem) {
- if(showingTabs) {
- // Settings are on a different selectable track
- if (menuItem.getItemId() != R.id.drawer_settings && menuItem.getItemId() != R.id.drawer_offline) {
- menuItem.setChecked(true);
- lastSelectedPosition = menuItem.getItemId();
- }
+ drawerList = (NavigationView) findViewById(R.id.left_drawer);
+ drawerList.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
+ @Override
+ public boolean onNavigationItemSelected(final MenuItem menuItem) {
+ if(showingTabs) {
+ // Settings are on a different selectable track
+ if (menuItem.getItemId() != R.id.drawer_settings && menuItem.getItemId() != R.id.drawer_offline) {
+ menuItem.setChecked(true);
+ lastSelectedPosition = menuItem.getItemId();
+ }
- switch (menuItem.getItemId()) {
- case R.id.drawer_library:
- drawerItemSelected("Artist");
- return true;
- case R.id.drawer_playlists:
- drawerItemSelected("Playlist");
- return true;
- case R.id.drawer_downloading:
- drawerItemSelected("Download");
- return true;
- case R.id.drawer_offline:
- toggleOffline();
- return true;
- case R.id.drawer_settings:
- startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class));
- drawer.closeDrawers();
- return true;
- }
- } else {
- int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE;
- SubsonicActivity.this.setActiveServer(activeServer);
- populateTabs();
- return true;
- }
+ switch (menuItem.getItemId()) {
+ case R.id.drawer_library:
+ drawerItemSelected("Artist");
+ return true;
+ case R.id.drawer_playlists:
+ drawerItemSelected("Playlist");
+ return true;
+ case R.id.drawer_downloading:
+ drawerItemSelected("Download");
+ return true;
+ case R.id.drawer_offline:
+ toggleOffline();
+ return true;
+ case R.id.drawer_settings:
+ startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class));
+ drawer.closeDrawers();
+ return true;
+ }
+ } else {
+ int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE;
+ SubsonicActivity.this.setActiveServer(activeServer);
+ populateTabs();
+ return true;
+ }
- return false;
- }
- });
+ return false;
+ }
+ });
- drawerHeader = drawerList.inflateHeaderView(R.layout.drawer_header);
- drawerHeader.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(showingTabs) {
- populateServers();
- } else {
- populateTabs();
- }
- }
- });
+ drawerHeader = drawerList.inflateHeaderView(R.layout.drawer_header);
+ drawerHeader.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(showingTabs) {
+ populateServers();
+ } else {
+ populateTabs();
+ }
+ }
+ });
- drawerHeaderToggle = (ImageView) drawerHeader.findViewById(R.id.header_select_image);
- drawerServerName = (TextView) drawerHeader.findViewById(R.id.header_server_name);
- drawerUserName = (TextView) drawerHeader.findViewById(R.id.header_user_name);
+ drawerHeaderToggle = (ImageView) drawerHeader.findViewById(R.id.header_select_image);
+ drawerServerName = (TextView) drawerHeader.findViewById(R.id.header_server_name);
+ drawerUserName = (TextView) drawerHeader.findViewById(R.id.header_user_name);
- updateDrawerHeader();
+ updateDrawerHeader();
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
@@ -349,685 +349,685 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
}
});
- // Check whether this is a tablet or not
- secondaryContainer = findViewById(R.id.fragment_second_container);
- if(secondaryContainer != null) {
- primaryContainer = findViewById(R.id.fragment_container);
- }
- }
+ // Check whether this is a tablet or not
+ secondaryContainer = findViewById(R.id.fragment_second_container);
+ if(secondaryContainer != null) {
+ primaryContainer = findViewById(R.id.fragment_container);
+ }
+ }
- @Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- super.onSaveInstanceState(savedInstanceState);
- String[] ids = new String[backStack.size() + 1];
- ids[0] = currentFragment.getTag();
- int i = 1;
- for(SubsonicFragment frag: backStack) {
- ids[i] = frag.getTag();
- i++;
- }
- savedInstanceState.putStringArray(Constants.MAIN_BACK_STACK, ids);
- savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE, backStack.size() + 1);
- savedInstanceState.putInt(Constants.FRAGMENT_POSITION, lastSelectedPosition);
- }
- @Override
- public void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
- int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
- String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
- FragmentManager fm = getSupportFragmentManager();
- currentFragment = (SubsonicFragment)fm.findFragmentByTag(ids[0]);
- currentFragment.setPrimaryFragment(true);
- currentFragment.setSupportTag(ids[0]);
- supportInvalidateOptionsMenu();
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- for(int i = 1; i < size; i++) {
- SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i]);
- frag.setSupportTag(ids[i]);
- if(secondaryContainer != null) {
- frag.setPrimaryFragment(false, true);
- }
- trans.hide(frag);
- backStack.add(frag);
- }
- trans.commit();
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+ String[] ids = new String[backStack.size() + 1];
+ ids[0] = currentFragment.getTag();
+ int i = 1;
+ for(SubsonicFragment frag: backStack) {
+ ids[i] = frag.getTag();
+ i++;
+ }
+ savedInstanceState.putStringArray(Constants.MAIN_BACK_STACK, ids);
+ savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE, backStack.size() + 1);
+ savedInstanceState.putInt(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ }
+ @Override
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
+ String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
+ FragmentManager fm = getSupportFragmentManager();
+ currentFragment = (SubsonicFragment)fm.findFragmentByTag(ids[0]);
+ currentFragment.setPrimaryFragment(true);
+ currentFragment.setSupportTag(ids[0]);
+ supportInvalidateOptionsMenu();
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ for(int i = 1; i < size; i++) {
+ SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i]);
+ frag.setSupportTag(ids[i]);
+ if(secondaryContainer != null) {
+ frag.setPrimaryFragment(false, true);
+ }
+ trans.hide(frag);
+ backStack.add(frag);
+ }
+ trans.commit();
- // Current fragment is hidden in secondaryContainer
- if(secondaryContainer == null && !currentFragment.isVisible()) {
- trans = getSupportFragmentManager().beginTransaction();
- trans.remove(currentFragment);
- trans.commit();
- getSupportFragmentManager().executePendingTransactions();
+ // Current fragment is hidden in secondaryContainer
+ if(secondaryContainer == null && !currentFragment.isVisible()) {
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(currentFragment);
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
- trans = getSupportFragmentManager().beginTransaction();
- trans.add(R.id.fragment_container, currentFragment, ids[0]);
- trans.commit();
- }
- // Current fragment needs to be moved over to secondaryContainer
- else if(secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null && backStack.size() > 0) {
- trans = getSupportFragmentManager().beginTransaction();
- trans.remove(currentFragment);
- trans.show(backStack.get(backStack.size() - 1));
- trans.commit();
- getSupportFragmentManager().executePendingTransactions();
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.add(R.id.fragment_container, currentFragment, ids[0]);
+ trans.commit();
+ }
+ // Current fragment needs to be moved over to secondaryContainer
+ else if(secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null && backStack.size() > 0) {
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(currentFragment);
+ trans.show(backStack.get(backStack.size() - 1));
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
- trans = getSupportFragmentManager().beginTransaction();
- trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
- trans.commit();
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
+ trans.commit();
- secondaryContainer.setVisibility(View.VISIBLE);
- }
+ secondaryContainer.setVisibility(View.VISIBLE);
+ }
- lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
- if(lastSelectedPosition != 0) {
- MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
- if(item != null) {
- item.setChecked(true);
- }
- }
- recreateSpinner();
- }
+ lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
+ if(lastSelectedPosition != 0) {
+ MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
+ if(item != null) {
+ item.setChecked(true);
+ }
+ }
+ recreateSpinner();
+ }
- @Override
- public void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- }
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater menuInflater = getMenuInflater();
- SubsonicFragment currentFragment = getCurrentFragment();
- if(currentFragment != null) {
- try {
- SubsonicFragment fragment = getCurrentFragment();
- fragment.setContext(this);
- fragment.onCreateOptionsMenu(menu, menuInflater);
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater menuInflater = getMenuInflater();
+ SubsonicFragment currentFragment = getCurrentFragment();
+ if(currentFragment != null) {
+ try {
+ SubsonicFragment fragment = getCurrentFragment();
+ fragment.setContext(this);
+ fragment.onCreateOptionsMenu(menu, menuInflater);
- if(isTouchscreen()) {
- menu.setGroupVisible(R.id.not_touchscreen, false);
- }
- } catch(Exception e) {
- Log.w(TAG, "Error on creating options menu", e);
- }
- }
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(drawerToggle != null && drawerToggle.onOptionsItemSelected(item)) {
- return true;
- } else if(item.getItemId() == android.R.id.home) {
- onBackPressed();
- return true;
- }
+ if(isTouchscreen()) {
+ menu.setGroupVisible(R.id.not_touchscreen, false);
+ }
+ } catch(Exception e) {
+ Log.w(TAG, "Error on creating options menu", e);
+ }
+ }
+ return true;
+ }
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(drawerToggle != null && drawerToggle.onOptionsItemSelected(item)) {
+ return true;
+ } else if(item.getItemId() == android.R.id.home) {
+ onBackPressed();
+ return true;
+ }
- return getCurrentFragment().onOptionsItemSelected(item);
- }
+ return getCurrentFragment().onOptionsItemSelected(item);
+ }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
- boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP;
- boolean isVolumeAdjust = isVolumeDown || isVolumeUp;
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
+ boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP;
+ boolean isVolumeAdjust = isVolumeDown || isVolumeUp;
- return super.onKeyDown(keyCode, event);
- }
+ return super.onKeyDown(keyCode, event);
+ }
- @Override
- public void setTitle(CharSequence title) {
- if(title != null && getSupportActionBar() != null && !title.equals(getSupportActionBar().getTitle())) {
- getSupportActionBar().setTitle(title);
- recreateSpinner();
- }
- }
- public void setSubtitle(CharSequence title) {
- getSupportActionBar().setSubtitle(title);
- }
+ @Override
+ public void setTitle(CharSequence title) {
+ if(title != null && getSupportActionBar() != null && !title.equals(getSupportActionBar().getTitle())) {
+ getSupportActionBar().setTitle(title);
+ recreateSpinner();
+ }
+ }
+ public void setSubtitle(CharSequence title) {
+ getSupportActionBar().setSubtitle(title);
+ }
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- int top = spinnerAdapter.getCount() - 1;
- if(position < top) {
- for(int i = top; i > position && i >= 0; i--) {
- removeCurrent();
- }
- }
- }
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
+ int top = spinnerAdapter.getCount() - 1;
+ if(position < top) {
+ for(int i = top; i > position && i >= 0; i--) {
+ removeCurrent();
+ }
+ }
+ }
- @Override
- public void onNothingSelected(AdapterView> parent) {
+ @Override
+ public void onNothingSelected(AdapterView> parent) {
- }
+ }
- private void populateTabs() {
- drawerList.getMenu().clear();
- drawerList.inflateMenu(R.menu.drawer_navigation);
+ private void populateTabs() {
+ drawerList.getMenu().clear();
+ drawerList.inflateMenu(R.menu.drawer_navigation);
- SharedPreferences prefs = Util.getPreferences(this);
- boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this);
+ SharedPreferences prefs = Util.getPreferences(this);
+ boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this);
- MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline);
- if(Util.isOffline(this)) {
- if(lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_library) {
- String newFragment = Util.openToTab(this);
- if(newFragment == null || "Library".equals(newFragment)) {
- newFragment = "Artist";
- }
+ MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline);
+ if(Util.isOffline(this)) {
+ if(lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_library) {
+ String newFragment = Util.openToTab(this);
+ if(newFragment == null || "Library".equals(newFragment)) {
+ newFragment = "Artist";
+ }
- lastSelectedPosition = getDrawerItemId(newFragment);
- drawerItemSelected(newFragment);
- }
+ lastSelectedPosition = getDrawerItemId(newFragment);
+ drawerItemSelected(newFragment);
+ }
- offlineMenuItem.setTitle(R.string.main_online);
- } else {
- offlineMenuItem.setTitle(R.string.main_offline);
- }
+ offlineMenuItem.setTitle(R.string.main_online);
+ } else {
+ offlineMenuItem.setTitle(R.string.main_offline);
+ }
- if(lastSelectedPosition != 0) {
- MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
- if(item != null) {
- item.setChecked(true);
- }
- }
- drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark);
+ if(lastSelectedPosition != 0) {
+ MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
+ if(item != null) {
+ item.setChecked(true);
+ }
+ }
+ drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark);
- showingTabs = true;
- }
- private void populateServers() {
- drawerList.getMenu().clear();
+ showingTabs = true;
+ }
+ private void populateServers() {
+ drawerList.getMenu().clear();
- int serverCount = Util.getServerCount(this);
- int activeServer = Util.getActiveServer(this);
- for(int i = 1; i <= serverCount; i++) {
- MenuItem item = drawerList.getMenu().add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_BASE + i, MENU_ITEM_SERVER_BASE + i, Util.getServerName(this, i));
- if(activeServer == i) {
- item.setChecked(true);
- }
- }
- drawerList.getMenu().setGroupCheckable(MENU_GROUP_SERVER, true, true);
- drawerHeaderToggle.setImageResource(R.drawable.main_select_tabs_dark);
+ int serverCount = Util.getServerCount(this);
+ int activeServer = Util.getActiveServer(this);
+ for(int i = 1; i <= serverCount; i++) {
+ MenuItem item = drawerList.getMenu().add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_BASE + i, MENU_ITEM_SERVER_BASE + i, Util.getServerName(this, i));
+ if(activeServer == i) {
+ item.setChecked(true);
+ }
+ }
+ drawerList.getMenu().setGroupCheckable(MENU_GROUP_SERVER, true, true);
+ drawerHeaderToggle.setImageResource(R.drawable.main_select_tabs_dark);
- showingTabs = false;
- }
- private void setDrawerItemVisible(int id, boolean visible) {
- MenuItem item = drawerList.getMenu().findItem(id);
- if(item != null) {
- item.setVisible(visible);
- }
- }
+ showingTabs = false;
+ }
+ private void setDrawerItemVisible(int id, boolean visible) {
+ MenuItem item = drawerList.getMenu().findItem(id);
+ if(item != null) {
+ item.setVisible(visible);
+ }
+ }
- protected void drawerItemSelected(String fragmentType) {
- if(currentFragment != null) {
- currentFragment.stopActionMode();
- }
- startFragmentActivity(fragmentType);
- }
+ protected void drawerItemSelected(String fragmentType) {
+ if(currentFragment != null) {
+ currentFragment.stopActionMode();
+ }
+ startFragmentActivity(fragmentType);
+ }
- public void startFragmentActivity(String fragmentType) {
- Intent intent = new Intent();
- intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- if(!"".equals(fragmentType)) {
- intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
- }
- if(lastSelectedPosition != 0) {
- intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
- }
- startActivity(intent);
- finish();
- }
+ public void startFragmentActivity(String fragmentType) {
+ Intent intent = new Intent();
+ intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ if(!"".equals(fragmentType)) {
+ intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
+ }
+ if(lastSelectedPosition != 0) {
+ intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ }
+ startActivity(intent);
+ finish();
+ }
- protected void exit() {
- if(((Object) this).getClass() != SubsonicFragmentActivity.class) {
- Intent intent = new Intent(this, SubsonicFragmentActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true);
- Util.startActivityWithoutTransition(this, intent);
- } else {
- finished = true;
- this.stopService(new Intent(this, DownloadService.class));
- this.finish();
- }
- }
+ protected void exit() {
+ if(((Object) this).getClass() != SubsonicFragmentActivity.class) {
+ Intent intent = new Intent(this, SubsonicFragmentActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true);
+ Util.startActivityWithoutTransition(this, intent);
+ } else {
+ finished = true;
+ this.stopService(new Intent(this, DownloadService.class));
+ this.finish();
+ }
+ }
- public boolean onBackPressedSupport() {
- if(drawerOpen) {
- drawer.closeDrawers();
- return false;
- } else if(backStack.size() > 0) {
- removeCurrent();
- return false;
- } else {
- return true;
- }
- }
+ public boolean onBackPressedSupport() {
+ if(drawerOpen) {
+ drawer.closeDrawers();
+ return false;
+ } else if(backStack.size() > 0) {
+ removeCurrent();
+ return false;
+ } else {
+ return true;
+ }
+ }
- @Override
- public void onBackPressed() {
- if(onBackPressedSupport()) {
- super.onBackPressed();
- }
- }
+ @Override
+ public void onBackPressed() {
+ if(onBackPressedSupport()) {
+ super.onBackPressed();
+ }
+ }
- public SubsonicFragment getCurrentFragment() {
- return this.currentFragment;
- }
+ public SubsonicFragment getCurrentFragment() {
+ return this.currentFragment;
+ }
- public void replaceFragment(SubsonicFragment fragment, int tag) {
- replaceFragment(fragment, tag, false);
- }
- public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
- SubsonicFragment oldFragment = currentFragment;
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false, secondaryContainer != null);
- }
- backStack.add(currentFragment);
+ public void replaceFragment(SubsonicFragment fragment, int tag) {
+ replaceFragment(fragment, tag, false);
+ }
+ public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
+ SubsonicFragment oldFragment = currentFragment;
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false, secondaryContainer != null);
+ }
+ backStack.add(currentFragment);
- currentFragment = fragment;
- currentFragment.setPrimaryFragment(true);
- supportInvalidateOptionsMenu();
+ currentFragment = fragment;
+ currentFragment.setPrimaryFragment(true);
+ supportInvalidateOptionsMenu();
- if(secondaryContainer == null || oldFragment.isAlwaysFullscreen() || currentFragment.isAlwaysStartFullscreen()) {
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
- trans.hide(oldFragment);
- trans.add(R.id.fragment_container, fragment, tag + "");
- trans.commit();
- } else {
- // Make sure secondary container is visible now
- secondaryContainer.setVisibility(View.VISIBLE);
+ if(secondaryContainer == null || oldFragment.isAlwaysFullscreen() || currentFragment.isAlwaysStartFullscreen()) {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
+ trans.hide(oldFragment);
+ trans.add(R.id.fragment_container, fragment, tag + "");
+ trans.commit();
+ } else {
+ // Make sure secondary container is visible now
+ secondaryContainer.setVisibility(View.VISIBLE);
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- // Check to see if you need to put on top of old left or not
- if(backStack.size() > 1) {
- // Move old right to left if there is a backstack already
- SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
- if(replaceCurrent) {
- // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
- }
- trans.remove(newLeftFragment);
+ // Check to see if you need to put on top of old left or not
+ if(backStack.size() > 1) {
+ // Move old right to left if there is a backstack already
+ SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
+ if(replaceCurrent) {
+ // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
+ }
+ trans.remove(newLeftFragment);
- // Only move right to left if replaceCurrent is false
- if(!replaceCurrent) {
- SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2);
- oldLeftFragment.setSecondaryFragment(false);
- // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
- trans.hide(oldLeftFragment);
+ // Only move right to left if replaceCurrent is false
+ if(!replaceCurrent) {
+ SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2);
+ oldLeftFragment.setSecondaryFragment(false);
+ // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
+ trans.hide(oldLeftFragment);
- // Make sure remove is finished before adding
- trans.commit();
- getSupportFragmentManager().executePendingTransactions();
+ // Make sure remove is finished before adding
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
- trans = getSupportFragmentManager().beginTransaction();
- // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
- trans.add(R.id.fragment_container, newLeftFragment, newLeftFragment.getSupportTag() + "");
- } else {
- backStack.remove(backStack.size() - 1);
- }
- }
+ trans = getSupportFragmentManager().beginTransaction();
+ // trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
+ trans.add(R.id.fragment_container, newLeftFragment, newLeftFragment.getSupportTag() + "");
+ } else {
+ backStack.remove(backStack.size() - 1);
+ }
+ }
- // Add fragment to the right container
- trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
- trans.add(R.id.fragment_second_container, fragment, tag + "");
+ // Add fragment to the right container
+ trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
+ trans.add(R.id.fragment_second_container, fragment, tag + "");
- // Commit it all
- trans.commit();
+ // Commit it all
+ trans.commit();
- oldFragment.setIsOnlyVisible(false);
- currentFragment.setIsOnlyVisible(false);
- }
- recreateSpinner();
- }
- public void removeCurrent() {
- // Don't try to remove current if there is no backstack to remove from
- if(backStack.isEmpty()) {
- return;
- }
+ oldFragment.setIsOnlyVisible(false);
+ currentFragment.setIsOnlyVisible(false);
+ }
+ recreateSpinner();
+ }
+ public void removeCurrent() {
+ // Don't try to remove current if there is no backstack to remove from
+ if(backStack.isEmpty()) {
+ return;
+ }
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
- }
- SubsonicFragment oldFragment = currentFragment;
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false);
+ }
+ SubsonicFragment oldFragment = currentFragment;
- currentFragment = backStack.remove(backStack.size() - 1);
- currentFragment.setPrimaryFragment(true, false);
- supportInvalidateOptionsMenu();
+ currentFragment = backStack.remove(backStack.size() - 1);
+ currentFragment.setPrimaryFragment(true, false);
+ supportInvalidateOptionsMenu();
- if(secondaryContainer == null || currentFragment.isAlwaysFullscreen() || oldFragment.isAlwaysStartFullscreen()) {
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
- trans.remove(oldFragment);
- trans.show(currentFragment);
- trans.commit();
- } else {
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ if(secondaryContainer == null || currentFragment.isAlwaysFullscreen() || oldFragment.isAlwaysStartFullscreen()) {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
+ trans.remove(oldFragment);
+ trans.show(currentFragment);
+ trans.commit();
+ } else {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- // Remove old right fragment
- trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
- trans.remove(oldFragment);
+ // Remove old right fragment
+ trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
+ trans.remove(oldFragment);
- // Only switch places if there is a backstack, otherwise primary container is correct
- if(backStack.size() > 0 && !backStack.get(backStack.size() - 1).isAlwaysFullscreen() && !currentFragment.isAlwaysStartFullscreen()) {
- trans.setCustomAnimations(0, 0, 0, 0);
- // Add current left fragment to right side
- trans.remove(currentFragment);
+ // Only switch places if there is a backstack, otherwise primary container is correct
+ if(backStack.size() > 0 && !backStack.get(backStack.size() - 1).isAlwaysFullscreen() && !currentFragment.isAlwaysStartFullscreen()) {
+ trans.setCustomAnimations(0, 0, 0, 0);
+ // Add current left fragment to right side
+ trans.remove(currentFragment);
- // Make sure remove is finished before adding
- trans.commit();
- getSupportFragmentManager().executePendingTransactions();
+ // Make sure remove is finished before adding
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
- trans = getSupportFragmentManager().beginTransaction();
- // trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
- trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");
+ trans = getSupportFragmentManager().beginTransaction();
+ // trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
+ trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");
- SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
- newLeftFragment.setSecondaryFragment(true);
- trans.show(newLeftFragment);
- } else {
- secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right));
- secondaryContainer.setVisibility(View.GONE);
+ SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
+ newLeftFragment.setSecondaryFragment(true);
+ trans.show(newLeftFragment);
+ } else {
+ secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right));
+ secondaryContainer.setVisibility(View.GONE);
- currentFragment.setIsOnlyVisible(true);
- }
+ currentFragment.setIsOnlyVisible(true);
+ }
- trans.commit();
- }
- recreateSpinner();
- }
- public void replaceExistingFragment(SubsonicFragment fragment, int tag) {
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.remove(currentFragment);
- trans.add(R.id.fragment_container, fragment, tag + "");
- trans.commit();
+ trans.commit();
+ }
+ recreateSpinner();
+ }
+ public void replaceExistingFragment(SubsonicFragment fragment, int tag) {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(currentFragment);
+ trans.add(R.id.fragment_container, fragment, tag + "");
+ trans.commit();
- currentFragment = fragment;
- currentFragment.setPrimaryFragment(true);
- supportInvalidateOptionsMenu();
- }
+ currentFragment = fragment;
+ currentFragment.setPrimaryFragment(true);
+ supportInvalidateOptionsMenu();
+ }
- public void invalidate() {
- if(currentFragment != null) {
- while(backStack.size() > 0) {
- removeCurrent();
- }
+ public void invalidate() {
+ if(currentFragment != null) {
+ while(backStack.size() > 0) {
+ removeCurrent();
+ }
currentFragment.invalidate();
- populateTabs();
- }
+ populateTabs();
+ }
- supportInvalidateOptionsMenu();
- }
+ supportInvalidateOptionsMenu();
+ }
- protected void recreateSpinner() {
- if(currentFragment == null || currentFragment.getTitle() == null) {
- return;
- }
- if(spinnerAdapter == null || getSupportActionBar().getCustomView() == null) {
- createCustomActionBarView();
- }
+ protected void recreateSpinner() {
+ if(currentFragment == null || currentFragment.getTitle() == null) {
+ return;
+ }
+ if(spinnerAdapter == null || getSupportActionBar().getCustomView() == null) {
+ createCustomActionBarView();
+ }
- if(backStack.size() > 0) {
- createCustomActionBarView();
- spinnerAdapter.clear();
- for(int i = 0; i < backStack.size(); i++) {
- CharSequence title = backStack.get(i).getTitle();
- if(title != null) {
- spinnerAdapter.add(title);
- } else {
- spinnerAdapter.add("null");
- }
- }
- if(currentFragment.getTitle() != null) {
- spinnerAdapter.add(currentFragment.getTitle());
- } else {
- spinnerAdapter.add("null");
- }
- spinnerAdapter.notifyDataSetChanged();
- actionBarSpinner.setSelection(spinnerAdapter.getCount() - 1);
+ if(backStack.size() > 0) {
+ createCustomActionBarView();
+ spinnerAdapter.clear();
+ for(int i = 0; i < backStack.size(); i++) {
+ CharSequence title = backStack.get(i).getTitle();
+ if(title != null) {
+ spinnerAdapter.add(title);
+ } else {
+ spinnerAdapter.add("null");
+ }
+ }
+ if(currentFragment.getTitle() != null) {
+ spinnerAdapter.add(currentFragment.getTitle());
+ } else {
+ spinnerAdapter.add("null");
+ }
+ spinnerAdapter.notifyDataSetChanged();
+ actionBarSpinner.setSelection(spinnerAdapter.getCount() - 1);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowCustomEnabled(true);
- if(drawerToggle.isDrawerIndicatorEnabled()) {
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- drawerToggle.setDrawerIndicatorEnabled(false);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- }
- } else {
- getSupportActionBar().setDisplayShowTitleEnabled(true);
- getSupportActionBar().setTitle(currentFragment.getTitle());
- getSupportActionBar().setDisplayShowCustomEnabled(false);
- drawerToggle.setDrawerIndicatorEnabled(true);
- }
- }
+ if(drawerToggle.isDrawerIndicatorEnabled()) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);
+ drawerToggle.setDrawerIndicatorEnabled(false);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ } else {
+ getSupportActionBar().setDisplayShowTitleEnabled(true);
+ getSupportActionBar().setTitle(currentFragment.getTitle());
+ getSupportActionBar().setDisplayShowCustomEnabled(false);
+ drawerToggle.setDrawerIndicatorEnabled(true);
+ }
+ }
- protected void restart() {
- restart(true);
- }
- protected void restart(boolean resumePosition) {
- Intent intent = new Intent(this, this.getClass());
- intent.putExtras(getIntent());
- if(resumePosition) {
- intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
- } else {
- String fragmentType = Util.openToTab(this);
- intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
- intent.putExtra(Constants.FRAGMENT_POSITION, getDrawerItemId(fragmentType));
- }
- finish();
- Util.startActivityWithoutTransition(this, intent);
- }
+ protected void restart() {
+ restart(true);
+ }
+ protected void restart(boolean resumePosition) {
+ Intent intent = new Intent(this, this.getClass());
+ intent.putExtras(getIntent());
+ if(resumePosition) {
+ intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ } else {
+ String fragmentType = Util.openToTab(this);
+ intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
+ intent.putExtra(Constants.FRAGMENT_POSITION, getDrawerItemId(fragmentType));
+ }
+ finish();
+ Util.startActivityWithoutTransition(this, intent);
+ }
- private void applyTheme() {
- theme = ThemeUtil.getTheme(this);
+ private void applyTheme() {
+ theme = ThemeUtil.getTheme(this);
- if(theme != null && theme.indexOf("fullscreen") != -1) {
- theme = theme.substring(0, theme.indexOf("_fullscreen"));
- ThemeUtil.setTheme(this, theme);
- }
+ if(theme != null && theme.indexOf("fullscreen") != -1) {
+ theme = theme.substring(0, theme.indexOf("_fullscreen"));
+ ThemeUtil.setTheme(this, theme);
+ }
- ThemeUtil.applyTheme(this, theme);
- actionbarColored = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true);
- }
- private void applyFullscreen() {
- fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false);
- if(fullScreen ) {
+ ThemeUtil.applyTheme(this, theme);
+ actionbarColored = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true);
+ }
+ private void applyFullscreen() {
+ fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false);
+ if(fullScreen ) {
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(flags);
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- }
- }
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
+ }
- public boolean isDestroyedCompat() {
- return destroyed;
- }
+ public boolean isDestroyedCompat() {
+ return destroyed;
+ }
- public synchronized ImageLoader getImageLoader() {
- if (IMAGE_LOADER == null) {
- IMAGE_LOADER = new ImageLoader(this);
- }
- return IMAGE_LOADER;
- }
- public synchronized static ImageLoader getStaticImageLoader(Context context) {
- if (IMAGE_LOADER == null) {
- IMAGE_LOADER = new ImageLoader(context);
- }
- return IMAGE_LOADER;
- }
+ public synchronized ImageLoader getImageLoader() {
+ if (IMAGE_LOADER == null) {
+ IMAGE_LOADER = new ImageLoader(this);
+ }
+ return IMAGE_LOADER;
+ }
+ public synchronized static ImageLoader getStaticImageLoader(Context context) {
+ if (IMAGE_LOADER == null) {
+ IMAGE_LOADER = new ImageLoader(context);
+ }
+ return IMAGE_LOADER;
+ }
- public DownloadService getDownloadService() {
- if(finished) {
- return null;
- }
+ public DownloadService getDownloadService() {
+ if(finished) {
+ return null;
+ }
- // If service is not available, request it to start and wait for it.
- for (int i = 0; i < 5; i++) {
- DownloadService downloadService = DownloadService.getInstance();
- if (downloadService != null) {
- break;
- }
- Log.w(TAG, "DownloadService not running. Attempting to start it.");
- startService(new Intent(this, DownloadService.class));
- Util.sleepQuietly(50L);
- }
+ // If service is not available, request it to start and wait for it.
+ for (int i = 0; i < 5; i++) {
+ DownloadService downloadService = DownloadService.getInstance();
+ if (downloadService != null) {
+ break;
+ }
+ Log.w(TAG, "DownloadService not running. Attempting to start it.");
+ startService(new Intent(this, DownloadService.class));
+ Util.sleepQuietly(50L);
+ }
- final DownloadService downloadService = DownloadService.getInstance();
- if(downloadService != null && afterServiceAvailable.size() > 0) {
- for(Runnable runnable: afterServiceAvailable) {
- handler.post(runnable);
- }
- afterServiceAvailable.clear();
- }
- return downloadService;
- }
- public void runWhenServiceAvailable(Runnable runnable) {
- if(getDownloadService() != null) {
- runnable.run();
- } else {
- afterServiceAvailable.add(runnable);
- checkIfServiceAvailable();
- }
- }
- private void checkIfServiceAvailable() {
- if(getDownloadService() == null) {
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- checkIfServiceAvailable();
- }
- }, 50);
- } else if(afterServiceAvailable.size() > 0) {
- for(Runnable runnable: afterServiceAvailable) {
- handler.post(runnable);
- }
- afterServiceAvailable.clear();
- }
- }
+ final DownloadService downloadService = DownloadService.getInstance();
+ if(downloadService != null && afterServiceAvailable.size() > 0) {
+ for(Runnable runnable: afterServiceAvailable) {
+ handler.post(runnable);
+ }
+ afterServiceAvailable.clear();
+ }
+ return downloadService;
+ }
+ public void runWhenServiceAvailable(Runnable runnable) {
+ if(getDownloadService() != null) {
+ runnable.run();
+ } else {
+ afterServiceAvailable.add(runnable);
+ checkIfServiceAvailable();
+ }
+ }
+ private void checkIfServiceAvailable() {
+ if(getDownloadService() == null) {
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ checkIfServiceAvailable();
+ }
+ }, 50);
+ } else if(afterServiceAvailable.size() > 0) {
+ for(Runnable runnable: afterServiceAvailable) {
+ handler.post(runnable);
+ }
+ afterServiceAvailable.clear();
+ }
+ }
- public static String getThemeName() {
- return theme;
- }
+ public static String getThemeName() {
+ return theme;
+ }
- public boolean isTouchscreen() {
- return touchscreen;
- }
+ public boolean isTouchscreen() {
+ return touchscreen;
+ }
- public void openNowPlaying() {
+ public void openNowPlaying() {
- }
- public void closeNowPlaying() {
+ }
+ public void closeNowPlaying() {
- }
+ }
- public void setActiveServer(int instance) {
- if (Util.getActiveServer(this) != instance) {
- final DownloadService service = getDownloadService();
- if (service != null) {
- new SilentBackgroundTask(this) {
- @Override
- protected Void doInBackground() throws Throwable {
- service.clearIncomplete();
- return null;
- }
- }.execute();
+ public void setActiveServer(int instance) {
+ if (Util.getActiveServer(this) != instance) {
+ final DownloadService service = getDownloadService();
+ if (service != null) {
+ new SilentBackgroundTask(this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ service.clearIncomplete();
+ return null;
+ }
+ }.execute();
- }
- Util.setActiveServer(this, instance);
- invalidate();
- UserUtil.refreshCurrentUser(this, false, true);
- updateDrawerHeader();
- }
- }
- public void updateDrawerHeader() {
- if(Util.isOffline(this)) {
- drawerServerName.setText(R.string.select_album_offline);
- drawerUserName.setText("");
- drawerHeader.setClickable(false);
- drawerHeaderToggle.setVisibility(View.GONE);
- } else {
- drawerServerName.setText(Util.getServerName(this));
- drawerUserName.setText(UserUtil.getCurrentUsername(this));
- drawerHeader.setClickable(true);
- drawerHeaderToggle.setVisibility(View.VISIBLE);
- }
- }
+ }
+ Util.setActiveServer(this, instance);
+ invalidate();
+ UserUtil.refreshCurrentUser(this, false, true);
+ updateDrawerHeader();
+ }
+ }
+ public void updateDrawerHeader() {
+ if(Util.isOffline(this)) {
+ drawerServerName.setText(R.string.select_album_offline);
+ drawerUserName.setText("");
+ drawerHeader.setClickable(false);
+ drawerHeaderToggle.setVisibility(View.GONE);
+ } else {
+ drawerServerName.setText(Util.getServerName(this));
+ drawerUserName.setText(UserUtil.getCurrentUsername(this));
+ drawerHeader.setClickable(true);
+ drawerHeaderToggle.setVisibility(View.VISIBLE);
+ }
+ }
- public void toggleOffline() {
- boolean isOffline = Util.isOffline(this);
- Util.setOffline(this, !isOffline);
- invalidate();
- DownloadService service = getDownloadService();
- if (service != null) {
- service.setOnline(isOffline);
- }
+ public void toggleOffline() {
+ boolean isOffline = Util.isOffline(this);
+ Util.setOffline(this, !isOffline);
+ invalidate();
+ DownloadService service = getDownloadService();
+ if (service != null) {
+ service.setOnline(isOffline);
+ }
- UserUtil.seedCurrentUser(this);
- this.updateDrawerHeader();
- drawer.closeDrawers();
- }
+ UserUtil.seedCurrentUser(this);
+ this.updateDrawerHeader();
+ drawer.closeDrawers();
+ }
- public int getDrawerItemId(String fragmentType) {
- if(fragmentType == null) {
- return R.id.drawer_library;
- }
+ public int getDrawerItemId(String fragmentType) {
+ if(fragmentType == null) {
+ return R.id.drawer_library;
+ }
- switch(fragmentType) {
- case "Artist":
- return R.id.drawer_library;
- case "Playlist":
- return R.id.drawer_playlists;
- default:
- return R.id.drawer_library;
- }
- }
+ switch(fragmentType) {
+ case "Artist":
+ return R.id.drawer_library;
+ case "Playlist":
+ return R.id.drawer_playlists;
+ default:
+ return R.id.drawer_library;
+ }
+ }
- private void setUncaughtExceptionHandler() {
- Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
- if (!(handler instanceof SubsonicActivity.SubsonicUncaughtExceptionHandler)) {
- Thread.setDefaultUncaughtExceptionHandler(new SubsonicActivity.SubsonicUncaughtExceptionHandler(this));
- }
- }
+ private void setUncaughtExceptionHandler() {
+ Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
+ if (!(handler instanceof SubsonicActivity.SubsonicUncaughtExceptionHandler)) {
+ Thread.setDefaultUncaughtExceptionHandler(new SubsonicActivity.SubsonicUncaughtExceptionHandler(this));
+ }
+ }
- /**
- * Logs the stack trace of uncaught exceptions to a file on the SD card.
- */
- private static class SubsonicUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+ /**
+ * Logs the stack trace of uncaught exceptions to a file on the SD card.
+ */
+ private static class SubsonicUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
- private final Thread.UncaughtExceptionHandler defaultHandler;
- private final Context context;
+ private final Thread.UncaughtExceptionHandler defaultHandler;
+ private final Context context;
- private SubsonicUncaughtExceptionHandler(Context context) {
- this.context = context;
- defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
- }
+ private SubsonicUncaughtExceptionHandler(Context context) {
+ this.context = context;
+ defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
+ }
- @Override
- public void uncaughtException(Thread thread, Throwable throwable) {
- File file = null;
- PrintWriter printWriter = null;
- try {
+ @Override
+ public void uncaughtException(Thread thread, Throwable throwable) {
+ File file = null;
+ PrintWriter printWriter = null;
+ try {
- PackageInfo packageInfo = context.getPackageManager().getPackageInfo("net.nullsum.audinaut", 0);
- file = new File(Environment.getExternalStorageDirectory(), "audinaut-stacktrace.txt");
- printWriter = new PrintWriter(file);
- printWriter.println("Android API level: " + Build.VERSION.SDK);
- printWriter.println("Subsonic version name: " + packageInfo.versionName);
- printWriter.println("Subsonic version code: " + packageInfo.versionCode);
- printWriter.println();
- throwable.printStackTrace(printWriter);
- Log.i(TAG, "Stack trace written to " + file);
- } catch (Throwable x) {
- Log.e(TAG, "Failed to write stack trace to " + file, x);
- } finally {
- Util.close(printWriter);
- if (defaultHandler != null) {
- defaultHandler.uncaughtException(thread, throwable);
- }
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo("net.nullsum.audinaut", 0);
+ file = new File(Environment.getExternalStorageDirectory(), "audinaut-stacktrace.txt");
+ printWriter = new PrintWriter(file);
+ printWriter.println("Android API level: " + Build.VERSION.SDK);
+ printWriter.println("Subsonic version name: " + packageInfo.versionName);
+ printWriter.println("Subsonic version code: " + packageInfo.versionCode);
+ printWriter.println();
+ throwable.printStackTrace(printWriter);
+ Log.i(TAG, "Stack trace written to " + file);
+ } catch (Throwable x) {
+ Log.e(TAG, "Failed to write stack trace to " + file, x);
+ } finally {
+ Util.close(printWriter);
+ if (defaultHandler != null) {
+ defaultHandler.uncaughtException(thread, throwable);
+ }
- }
- }
- }
+ }
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java
index 05d9623..c1839dc 100644
--- a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java
@@ -79,120 +79,120 @@ import net.nullsum.audinaut.util.Util;
* Created by Scott on 10/14/13.
*/
public class SubsonicFragmentActivity extends SubsonicActivity implements DownloadService.OnSongChangedListener {
- private static String TAG = SubsonicFragmentActivity.class.getSimpleName();
- private static boolean infoDialogDisplayed;
- private static boolean sessionInitialized = false;
- private static long ALLOWED_SKEW = 30000L;
+ private static String TAG = SubsonicFragmentActivity.class.getSimpleName();
+ private static boolean infoDialogDisplayed;
+ private static boolean sessionInitialized = false;
+ private static long ALLOWED_SKEW = 30000L;
- private SlidingUpPanelLayout slideUpPanel;
- private SlidingUpPanelLayout.PanelSlideListener panelSlideListener;
- private boolean isPanelClosing = false;
- private NowPlayingFragment nowPlayingFragment;
- private SubsonicFragment secondaryFragment;
- private Toolbar mainToolbar;
- private Toolbar nowPlayingToolbar;
+ private SlidingUpPanelLayout slideUpPanel;
+ private SlidingUpPanelLayout.PanelSlideListener panelSlideListener;
+ private boolean isPanelClosing = false;
+ private NowPlayingFragment nowPlayingFragment;
+ private SubsonicFragment secondaryFragment;
+ private Toolbar mainToolbar;
+ private Toolbar nowPlayingToolbar;
- private View bottomBar;
- private ImageView coverArtView;
- private TextView trackView;
- private TextView artistView;
- private ImageButton startButton;
- private long lastBackPressTime = 0;
- private DownloadFile currentPlaying;
- private PlayerState currentState;
- private ImageButton previousButton;
- private ImageButton nextButton;
- private ImageButton rewindButton;
- private ImageButton fastforwardButton;
+ private View bottomBar;
+ private ImageView coverArtView;
+ private TextView trackView;
+ private TextView artistView;
+ private ImageButton startButton;
+ private long lastBackPressTime = 0;
+ private DownloadFile currentPlaying;
+ private PlayerState currentState;
+ private ImageButton previousButton;
+ private ImageButton nextButton;
+ private ImageButton rewindButton;
+ private ImageButton fastforwardButton;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- if(savedInstanceState == null) {
- String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
- boolean firstRun = false;
- if (fragmentType == null) {
- fragmentType = Util.openToTab(this);
- if (fragmentType != null) {
- firstRun = true;
- }
- }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ if(savedInstanceState == null) {
+ String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
+ boolean firstRun = false;
+ if (fragmentType == null) {
+ fragmentType = Util.openToTab(this);
+ if (fragmentType != null) {
+ firstRun = true;
+ }
+ }
- if ("".equals(fragmentType) || fragmentType == null || firstRun) {
- // Initial startup stuff
- if (!sessionInitialized) {
- loadSession();
- }
- }
- }
+ if ("".equals(fragmentType) || fragmentType == null || firstRun) {
+ // Initial startup stuff
+ if (!sessionInitialized) {
+ loadSession();
+ }
+ }
+ }
- super.onCreate(savedInstanceState);
- if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
- stopService(new Intent(this, DownloadService.class));
- finish();
- getImageLoader().clearCache();
- } else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
- getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, "Download");
- lastSelectedPosition = R.id.drawer_downloading;
- }
- setContentView(R.layout.abstract_fragment_activity);
+ super.onCreate(savedInstanceState);
+ if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
+ stopService(new Intent(this, DownloadService.class));
+ finish();
+ getImageLoader().clearCache();
+ } else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
+ getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, "Download");
+ lastSelectedPosition = R.id.drawer_downloading;
+ }
+ setContentView(R.layout.abstract_fragment_activity);
- if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) {
- String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
- if(fragmentType == null) {
- fragmentType = Util.openToTab(this);
- if(fragmentType != null) {
- getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
- lastSelectedPosition = getDrawerItemId(fragmentType);
- } else {
- lastSelectedPosition = R.id.drawer_library;
- }
+ if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) {
+ String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
+ if(fragmentType == null) {
+ fragmentType = Util.openToTab(this);
+ if(fragmentType != null) {
+ getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
+ lastSelectedPosition = getDrawerItemId(fragmentType);
+ } else {
+ lastSelectedPosition = R.id.drawer_library;
+ }
- MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
- if(item != null) {
- item.setChecked(true);
- }
- } else {
- lastSelectedPosition = getDrawerItemId(fragmentType);
- }
+ MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
+ if(item != null) {
+ item.setChecked(true);
+ }
+ } else {
+ lastSelectedPosition = getDrawerItemId(fragmentType);
+ }
- currentFragment = getNewFragment(fragmentType);
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_ID)) {
- Bundle currentArguments = currentFragment.getArguments();
- if(currentArguments == null) {
- currentArguments = new Bundle();
- }
- currentArguments.putString(Constants.INTENT_EXTRA_NAME_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID));
- currentFragment.setArguments(currentArguments);
- }
- currentFragment.setPrimaryFragment(true);
- getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit();
+ currentFragment = getNewFragment(fragmentType);
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_ID)) {
+ Bundle currentArguments = currentFragment.getArguments();
+ if(currentArguments == null) {
+ currentArguments = new Bundle();
+ }
+ currentArguments.putString(Constants.INTENT_EXTRA_NAME_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID));
+ currentFragment.setArguments(currentArguments);
+ }
+ currentFragment.setPrimaryFragment(true);
+ getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit();
- if(getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
- SearchFragment fragment = new SearchFragment();
- replaceFragment(fragment, fragment.getSupportTag());
- }
+ if(getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
+ SearchFragment fragment = new SearchFragment();
+ replaceFragment(fragment, fragment.getSupportTag());
+ }
- // If a album type is set, switch to that album type view
- String albumType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
- if(albumType != null) {
- SubsonicFragment fragment = new SelectDirectoryFragment();
+ // If a album type is set, switch to that album type view
+ String albumType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
+ if(albumType != null) {
+ SubsonicFragment fragment = new SelectDirectoryFragment();
- Bundle args = new Bundle();
- args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, albumType);
- args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
- args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
+ Bundle args = new Bundle();
+ args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, albumType);
+ args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
+ args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
- fragment.setArguments(args);
- replaceFragment(fragment, fragment.getSupportTag());
- }
- }
+ fragment.setArguments(args);
+ replaceFragment(fragment, fragment.getSupportTag());
+ }
+ }
- slideUpPanel = (SlidingUpPanelLayout) findViewById(R.id.slide_up_panel);
- panelSlideListener = new SlidingUpPanelLayout.PanelSlideListener() {
- @Override
- public void onPanelSlide(View panel, float slideOffset) {
+ slideUpPanel = (SlidingUpPanelLayout) findViewById(R.id.slide_up_panel);
+ panelSlideListener = new SlidingUpPanelLayout.PanelSlideListener() {
+ @Override
+ public void onPanelSlide(View panel, float slideOffset) {
- }
+ }
@Override
public void onPanelStateChanged(View panel, PanelState previousState, PanelState newState) {
@@ -227,633 +227,633 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
- };
- slideUpPanel.addPanelSlideListener(panelSlideListener);
+ };
+ slideUpPanel.addPanelSlideListener(panelSlideListener);
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) {
- // Post this later so it actually runs
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- openNowPlaying();
- }
- }, 200);
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) {
+ // Post this later so it actually runs
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ openNowPlaying();
+ }
+ }, 200);
- getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD);
- }
+ getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD);
+ }
- bottomBar = findViewById(R.id.bottom_bar);
- mainToolbar = (Toolbar) findViewById(R.id.main_toolbar);
- nowPlayingToolbar = (Toolbar) findViewById(R.id.now_playing_toolbar);
- coverArtView = (ImageView) bottomBar.findViewById(R.id.album_art);
- trackView = (TextView) bottomBar.findViewById(R.id.track_name);
- artistView = (TextView) bottomBar.findViewById(R.id.artist_name);
+ bottomBar = findViewById(R.id.bottom_bar);
+ mainToolbar = (Toolbar) findViewById(R.id.main_toolbar);
+ nowPlayingToolbar = (Toolbar) findViewById(R.id.now_playing_toolbar);
+ coverArtView = (ImageView) bottomBar.findViewById(R.id.album_art);
+ trackView = (TextView) bottomBar.findViewById(R.id.track_name);
+ artistView = (TextView) bottomBar.findViewById(R.id.artist_name);
- setSupportActionBar(mainToolbar);
+ setSupportActionBar(mainToolbar);
- if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) {
- nowPlayingFragment = new NowPlayingFragment();
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.add(R.id.now_playing_fragment_container, nowPlayingFragment, nowPlayingFragment.getTag() + "");
- trans.commit();
- }
+ if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) {
+ nowPlayingFragment = new NowPlayingFragment();
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.add(R.id.now_playing_fragment_container, nowPlayingFragment, nowPlayingFragment.getTag() + "");
+ trans.commit();
+ }
- rewindButton = (ImageButton) findViewById(R.id.download_rewind);
- rewindButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask(SubsonicFragmentActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- if (getDownloadService() == null) {
- return null;
- }
+ rewindButton = (ImageButton) findViewById(R.id.download_rewind);
+ rewindButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if (getDownloadService() == null) {
+ return null;
+ }
- getDownloadService().rewind();
- return null;
- }
- }.execute();
- }
- });
+ getDownloadService().rewind();
+ return null;
+ }
+ }.execute();
+ }
+ });
- previousButton = (ImageButton) findViewById(R.id.download_previous);
- previousButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask(SubsonicFragmentActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- if(getDownloadService() == null) {
- return null;
- }
+ previousButton = (ImageButton) findViewById(R.id.download_previous);
+ previousButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if(getDownloadService() == null) {
+ return null;
+ }
- getDownloadService().previous();
- return null;
- }
- }.execute();
- }
- });
+ getDownloadService().previous();
+ return null;
+ }
+ }.execute();
+ }
+ });
- startButton = (ImageButton) findViewById(R.id.download_start);
- startButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask(SubsonicFragmentActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- PlayerState state = getDownloadService().getPlayerState();
- if(state == PlayerState.STARTED) {
- getDownloadService().pause();
- } else {
- getDownloadService().start();
- }
+ startButton = (ImageButton) findViewById(R.id.download_start);
+ startButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ PlayerState state = getDownloadService().getPlayerState();
+ if(state == PlayerState.STARTED) {
+ getDownloadService().pause();
+ } else {
+ getDownloadService().start();
+ }
- return null;
- }
- }.execute();
- }
- });
+ return null;
+ }
+ }.execute();
+ }
+ });
- nextButton = (ImageButton) findViewById(R.id.download_next);
- nextButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask(SubsonicFragmentActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- if(getDownloadService() == null) {
- return null;
- }
+ nextButton = (ImageButton) findViewById(R.id.download_next);
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if(getDownloadService() == null) {
+ return null;
+ }
- getDownloadService().next();
- return null;
- }
- }.execute();
- }
- });
+ getDownloadService().next();
+ return null;
+ }
+ }.execute();
+ }
+ });
- fastforwardButton = (ImageButton) findViewById(R.id.download_fastforward);
- fastforwardButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask(SubsonicFragmentActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- if (getDownloadService() == null) {
- return null;
- }
+ fastforwardButton = (ImageButton) findViewById(R.id.download_fastforward);
+ fastforwardButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if (getDownloadService() == null) {
+ return null;
+ }
- getDownloadService().fastForward();
- return null;
- }
- }.execute();
- }
- });
- }
+ getDownloadService().fastForward();
+ return null;
+ }
+ }.execute();
+ }
+ });
+ }
- @Override
- protected void onPostCreate(Bundle bundle) {
- super.onPostCreate(bundle);
+ @Override
+ protected void onPostCreate(Bundle bundle) {
+ super.onPostCreate(bundle);
- showInfoDialog();
- checkUpdates();
- }
+ showInfoDialog();
+ checkUpdates();
+ }
- @Override
- public void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
- if(currentFragment != null && intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
- closeNowPlaying();
- }
+ if(currentFragment != null && intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ closeNowPlaying();
+ }
- if(currentFragment instanceof SearchFragment) {
- String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
- boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
+ if(currentFragment instanceof SearchFragment) {
+ String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
+ boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
- if (query != null) {
- ((SearchFragment)currentFragment).search(query, autoplay);
- }
- getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_QUERY);
- } else {
- setIntent(intent);
+ if (query != null) {
+ ((SearchFragment)currentFragment).search(query, autoplay);
+ }
+ getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_QUERY);
+ } else {
+ setIntent(intent);
- SearchFragment fragment = new SearchFragment();
- replaceFragment(fragment, fragment.getSupportTag());
- }
- } else if(intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, false)) {
- if(slideUpPanel.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) {
- openNowPlaying();
- }
- } else {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
- closeNowPlaying();
- }
- setIntent(intent);
- }
- if(drawer != null) {
- drawer.closeDrawers();
- }
- }
+ SearchFragment fragment = new SearchFragment();
+ replaceFragment(fragment, fragment.getSupportTag());
+ }
+ } else if(intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, false)) {
+ if(slideUpPanel.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) {
+ openNowPlaying();
+ }
+ } else {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ closeNowPlaying();
+ }
+ setIntent(intent);
+ }
+ if(drawer != null) {
+ drawer.closeDrawers();
+ }
+ }
- @Override
- public void onResume() {
- super.onResume();
+ @Override
+ public void onResume() {
+ super.onResume();
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_VIEW_ALBUM)) {
- SubsonicFragment fragment = new SelectDirectoryFragment();
- 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);
- }
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_CHILD_ID)) {
- args.putString(Constants.INTENT_EXTRA_NAME_CHILD_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_CHILD_ID));
- }
- fragment.setArguments(args);
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_VIEW_ALBUM)) {
+ SubsonicFragment fragment = new SelectDirectoryFragment();
+ 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);
+ }
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_CHILD_ID)) {
+ args.putString(Constants.INTENT_EXTRA_NAME_CHILD_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_CHILD_ID));
+ }
+ fragment.setArguments(args);
- replaceFragment(fragment, fragment.getSupportTag());
- getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
- }
+ replaceFragment(fragment, fragment.getSupportTag());
+ getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
+ }
- UserUtil.seedCurrentUser(this);
- createAccount();
- runWhenServiceAvailable(new Runnable() {
- @Override
- public void run() {
- getDownloadService().addOnSongChangedListener(SubsonicFragmentActivity.this, true);
- }
- });
- }
+ UserUtil.seedCurrentUser(this);
+ createAccount();
+ runWhenServiceAvailable(new Runnable() {
+ @Override
+ public void run() {
+ getDownloadService().addOnSongChangedListener(SubsonicFragmentActivity.this, true);
+ }
+ });
+ }
- @Override
- public void onPause() {
- super.onPause();
- DownloadService downloadService = getDownloadService();
- if(downloadService != null) {
- downloadService.removeOnSongChangeListener(this);
- }
- }
+ @Override
+ public void onPause() {
+ super.onPause();
+ DownloadService downloadService = getDownloadService();
+ if(downloadService != null) {
+ downloadService.removeOnSongChangeListener(this);
+ }
+ }
- @Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- super.onSaveInstanceState(savedInstanceState);
- savedInstanceState.putString(Constants.MAIN_NOW_PLAYING, nowPlayingFragment.getTag());
- if(secondaryFragment != null) {
- savedInstanceState.putString(Constants.MAIN_NOW_PLAYING_SECONDARY, secondaryFragment.getTag());
- }
- savedInstanceState.putInt(Constants.MAIN_SLIDE_PANEL_STATE, slideUpPanel.getPanelState().hashCode());
- }
- @Override
- public void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+ savedInstanceState.putString(Constants.MAIN_NOW_PLAYING, nowPlayingFragment.getTag());
+ if(secondaryFragment != null) {
+ savedInstanceState.putString(Constants.MAIN_NOW_PLAYING_SECONDARY, secondaryFragment.getTag());
+ }
+ savedInstanceState.putInt(Constants.MAIN_SLIDE_PANEL_STATE, slideUpPanel.getPanelState().hashCode());
+ }
+ @Override
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
- String id = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING);
- FragmentManager fm = getSupportFragmentManager();
- nowPlayingFragment = (NowPlayingFragment) fm.findFragmentByTag(id);
+ String id = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING);
+ FragmentManager fm = getSupportFragmentManager();
+ nowPlayingFragment = (NowPlayingFragment) fm.findFragmentByTag(id);
- String secondaryId = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING_SECONDARY);
- if(secondaryId != null) {
- secondaryFragment = (SubsonicFragment) fm.findFragmentByTag(secondaryId);
+ String secondaryId = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING_SECONDARY);
+ if(secondaryId != null) {
+ secondaryFragment = (SubsonicFragment) fm.findFragmentByTag(secondaryId);
- nowPlayingFragment.setPrimaryFragment(false);
- secondaryFragment.setPrimaryFragment(true);
+ nowPlayingFragment.setPrimaryFragment(false);
+ secondaryFragment.setPrimaryFragment(true);
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.hide(nowPlayingFragment);
- trans.commit();
- }
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.hide(nowPlayingFragment);
+ trans.commit();
+ }
- if(drawerToggle != null && backStack.size() > 0) {
- drawerToggle.setDrawerIndicatorEnabled(false);
- }
+ if(drawerToggle != null && backStack.size() > 0) {
+ drawerToggle.setDrawerIndicatorEnabled(false);
+ }
- if(savedInstanceState.getInt(Constants.MAIN_SLIDE_PANEL_STATE, -1) == SlidingUpPanelLayout.PanelState.EXPANDED.hashCode()) {
- panelSlideListener.onPanelStateChanged(null, null, PanelState.EXPANDED);
- }
- }
+ if(savedInstanceState.getInt(Constants.MAIN_SLIDE_PANEL_STATE, -1) == SlidingUpPanelLayout.PanelState.EXPANDED.hashCode()) {
+ panelSlideListener.onPanelStateChanged(null, null, PanelState.EXPANDED);
+ }
+ }
- @Override
- public void setContentView(int viewId) {
- super.setContentView(viewId);
- if(drawerToggle != null){
- drawerToggle.setDrawerIndicatorEnabled(true);
- }
- }
+ @Override
+ public void setContentView(int viewId) {
+ super.setContentView(viewId);
+ if(drawerToggle != null){
+ drawerToggle.setDrawerIndicatorEnabled(true);
+ }
+ }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- return super.onOptionsItemSelected(item);
- }
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return super.onOptionsItemSelected(item);
+ }
- @Override
- public void onBackPressed() {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && secondaryFragment == null) {
- slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
- } else if(onBackPressedSupport()) {
+ @Override
+ public void onBackPressed() {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && secondaryFragment == null) {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
+ } else if(onBackPressedSupport()) {
finish();
- }
- }
+ }
+ }
- @Override
- public boolean onBackPressedSupport() {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
- removeCurrent();
- return false;
- } else {
- return super.onBackPressedSupport();
- }
- }
+ @Override
+ public boolean onBackPressedSupport() {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ removeCurrent();
+ return false;
+ } else {
+ return super.onBackPressedSupport();
+ }
+ }
- @Override
- public SubsonicFragment getCurrentFragment() {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
- if(secondaryFragment == null) {
- return nowPlayingFragment;
- } else {
- return secondaryFragment;
- }
- } else {
- return super.getCurrentFragment();
- }
- }
+ @Override
+ public SubsonicFragment getCurrentFragment() {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ if(secondaryFragment == null) {
+ return nowPlayingFragment;
+ } else {
+ return secondaryFragment;
+ }
+ } else {
+ return super.getCurrentFragment();
+ }
+ }
- @Override
- public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
- if(slideUpPanel != null && slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && !isPanelClosing) {
- secondaryFragment = fragment;
- nowPlayingFragment.setPrimaryFragment(false);
- secondaryFragment.setPrimaryFragment(true);
- supportInvalidateOptionsMenu();
+ @Override
+ public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
+ if(slideUpPanel != null && slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && !isPanelClosing) {
+ secondaryFragment = fragment;
+ nowPlayingFragment.setPrimaryFragment(false);
+ secondaryFragment.setPrimaryFragment(true);
+ supportInvalidateOptionsMenu();
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
- trans.hide(nowPlayingFragment);
- trans.add(R.id.now_playing_fragment_container, secondaryFragment, tag + "");
- trans.commit();
- } else {
- super.replaceFragment(fragment, tag, replaceCurrent);
- }
- }
- @Override
- public void removeCurrent() {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && secondaryFragment != null) {
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
- trans.remove(secondaryFragment);
- trans.show(nowPlayingFragment);
- trans.commit();
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
+ trans.hide(nowPlayingFragment);
+ trans.add(R.id.now_playing_fragment_container, secondaryFragment, tag + "");
+ trans.commit();
+ } else {
+ super.replaceFragment(fragment, tag, replaceCurrent);
+ }
+ }
+ @Override
+ public void removeCurrent() {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && secondaryFragment != null) {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
+ trans.remove(secondaryFragment);
+ trans.show(nowPlayingFragment);
+ trans.commit();
- secondaryFragment = null;
- nowPlayingFragment.setPrimaryFragment(true);
- supportInvalidateOptionsMenu();
- } else {
- super.removeCurrent();
- }
- }
+ secondaryFragment = null;
+ nowPlayingFragment.setPrimaryFragment(true);
+ supportInvalidateOptionsMenu();
+ } else {
+ super.removeCurrent();
+ }
+ }
- @Override
- public void setTitle(CharSequence title) {
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
- getSupportActionBar().setTitle(title);
- } else {
- super.setTitle(title);
- }
- }
+ @Override
+ public void setTitle(CharSequence title) {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ getSupportActionBar().setTitle(title);
+ } else {
+ super.setTitle(title);
+ }
+ }
- @Override
- protected void drawerItemSelected(String fragmentType) {
- super.drawerItemSelected(fragmentType);
+ @Override
+ protected void drawerItemSelected(String fragmentType) {
+ super.drawerItemSelected(fragmentType);
- if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
- slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
- }
- }
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
+ }
+ }
- @Override
- public void startFragmentActivity(String fragmentType) {
- // Create a transaction that does all of this
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ @Override
+ public void startFragmentActivity(String fragmentType) {
+ // Create a transaction that does all of this
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- // Clear existing stack
- for(int i = backStack.size() - 1; i >= 0; i--) {
- trans.remove(backStack.get(i));
- }
- trans.remove(currentFragment);
- backStack.clear();
+ // Clear existing stack
+ for(int i = backStack.size() - 1; i >= 0; i--) {
+ trans.remove(backStack.get(i));
+ }
+ trans.remove(currentFragment);
+ backStack.clear();
- // Create new stack
- currentFragment = getNewFragment(fragmentType);
- currentFragment.setPrimaryFragment(true);
- trans.add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "");
+ // Create new stack
+ currentFragment = getNewFragment(fragmentType);
+ currentFragment.setPrimaryFragment(true);
+ trans.add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "");
- // Done, cleanup
- trans.commit();
- supportInvalidateOptionsMenu();
- recreateSpinner();
- if(drawer != null) {
- drawer.closeDrawers();
- }
+ // Done, cleanup
+ trans.commit();
+ supportInvalidateOptionsMenu();
+ recreateSpinner();
+ if(drawer != null) {
+ drawer.closeDrawers();
+ }
- if(secondaryContainer != null) {
- secondaryContainer.setVisibility(View.GONE);
- }
- if(drawerToggle != null) {
- drawerToggle.setDrawerIndicatorEnabled(true);
- }
- }
+ if(secondaryContainer != null) {
+ secondaryContainer.setVisibility(View.GONE);
+ }
+ if(drawerToggle != null) {
+ drawerToggle.setDrawerIndicatorEnabled(true);
+ }
+ }
- @Override
- public void openNowPlaying() {
- slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
- }
- @Override
- public void closeNowPlaying() {
- slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
- isPanelClosing = true;
- }
+ @Override
+ public void openNowPlaying() {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
+ }
+ @Override
+ public void closeNowPlaying() {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
+ isPanelClosing = true;
+ }
- private SubsonicFragment getNewFragment(String fragmentType) {
- if("Artist".equals(fragmentType)) {
- return new SelectArtistFragment();
- } else if("Playlist".equals(fragmentType)) {
- return new SelectPlaylistFragment();
- } else if("Download".equals(fragmentType)) {
- return new DownloadFragment();
- } else {
- return new SelectArtistFragment();
- }
- }
+ private SubsonicFragment getNewFragment(String fragmentType) {
+ if("Artist".equals(fragmentType)) {
+ return new SelectArtistFragment();
+ } else if("Playlist".equals(fragmentType)) {
+ return new SelectPlaylistFragment();
+ } else if("Download".equals(fragmentType)) {
+ return new DownloadFragment();
+ } else {
+ return new SelectArtistFragment();
+ }
+ }
- public void checkUpdates() {
- try {
- String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
- int ver = Integer.parseInt(version.replace(".", ""));
- Updater updater = new Updater(ver);
- updater.checkUpdates(this);
- }
- catch(Exception e) {
+ public void checkUpdates() {
+ try {
+ String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
+ int ver = Integer.parseInt(version.replace(".", ""));
+ Updater updater = new Updater(ver);
+ updater.checkUpdates(this);
+ }
+ catch(Exception e) {
- }
- }
+ }
+ }
- private void loadSession() {
- loadSettings();
- // If we are on Subsonic 5.2+, save play queue
- if(!Util.isOffline(this)) {
- loadRemotePlayQueue();
- }
+ private void loadSession() {
+ loadSettings();
+ // If we are on Subsonic 5.2+, save play queue
+ if(!Util.isOffline(this)) {
+ loadRemotePlayQueue();
+ }
- sessionInitialized = true;
- }
- private void loadSettings() {
- PreferenceManager.setDefaultValues(this, R.xml.settings_appearance, false);
- PreferenceManager.setDefaultValues(this, R.xml.settings_cache, false);
- PreferenceManager.setDefaultValues(this, R.xml.settings_playback, false);
+ sessionInitialized = true;
+ }
+ private void loadSettings() {
+ PreferenceManager.setDefaultValues(this, R.xml.settings_appearance, false);
+ PreferenceManager.setDefaultValues(this, R.xml.settings_cache, false);
+ PreferenceManager.setDefaultValues(this, R.xml.settings_playback, false);
- SharedPreferences prefs = Util.getPreferences(this);
- if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION) || prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null) == null) {
- resetCacheLocation(prefs);
- } else {
- String path = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
- File cacheLocation = new File(path);
- if(!FileUtil.verifyCanWrite(cacheLocation)) {
- // Only warn user if there is a difference saved
- if(resetCacheLocation(prefs)) {
- Util.info(this, R.string.common_warning, R.string.settings_cache_location_reset);
- }
- }
- }
+ SharedPreferences prefs = Util.getPreferences(this);
+ if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION) || prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null) == null) {
+ resetCacheLocation(prefs);
+ } else {
+ String path = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
+ File cacheLocation = new File(path);
+ if(!FileUtil.verifyCanWrite(cacheLocation)) {
+ // Only warn user if there is a difference saved
+ if(resetCacheLocation(prefs)) {
+ Util.info(this, R.string.common_warning, R.string.settings_cache_location_reset);
+ }
+ }
+ }
- if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) {
- SharedPreferences.Editor editor = prefs.edit();
- editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, false);
+ if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, false);
- editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + 1, "Demo Server");
- editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + 1, "http://demo.subsonic.org");
- editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest5");
- editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest");
- editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
- editor.apply();
- }
- if(!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) {
- SharedPreferences.Editor editor = prefs.edit();
- editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
- editor.apply();
- }
- }
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + 1, "Demo Server");
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + 1, "http://demo.subsonic.org");
+ editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest5");
+ editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest");
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
+ editor.apply();
+ }
+ if(!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
+ editor.apply();
+ }
+ }
- private boolean resetCacheLocation(SharedPreferences prefs) {
- String newDirectory = FileUtil.getDefaultMusicDirectory(this).getPath();
- String oldDirectory = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
- if(newDirectory == null || (oldDirectory != null && newDirectory.equals(oldDirectory))) {
- return false;
- } else {
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, newDirectory);
- editor.apply();
- return true;
- }
- }
+ private boolean resetCacheLocation(SharedPreferences prefs) {
+ String newDirectory = FileUtil.getDefaultMusicDirectory(this).getPath();
+ String oldDirectory = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
+ if(newDirectory == null || (oldDirectory != null && newDirectory.equals(oldDirectory))) {
+ return false;
+ } else {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, newDirectory);
+ editor.apply();
+ return true;
+ }
+ }
- private void loadRemotePlayQueue() {
- if(Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_RESUME_PLAY_QUEUE_NEVER, false)) {
- return;
- }
+ private void loadRemotePlayQueue() {
+ if(Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_RESUME_PLAY_QUEUE_NEVER, false)) {
+ return;
+ }
- final SubsonicActivity context = this;
- new SilentBackgroundTask(this) {
- private PlayerQueue playerQueue;
+ final SubsonicActivity context = this;
+ new SilentBackgroundTask(this) {
+ private PlayerQueue playerQueue;
- @Override
- protected Void doInBackground() throws Throwable {
- try {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- PlayerQueue remoteState = musicService.getPlayQueue(context, null);
+ @Override
+ protected Void doInBackground() throws Throwable {
+ try {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ PlayerQueue remoteState = musicService.getPlayQueue(context, null);
- // Make sure we wait until download service is ready
- DownloadService downloadService = getDownloadService();
- while(downloadService == null || !downloadService.isInitialized()) {
- Util.sleepQuietly(100L);
- downloadService = getDownloadService();
- }
+ // Make sure we wait until download service is ready
+ DownloadService downloadService = getDownloadService();
+ while(downloadService == null || !downloadService.isInitialized()) {
+ Util.sleepQuietly(100L);
+ downloadService = getDownloadService();
+ }
- // If we had a remote state and it's changed is more recent than our existing state
- if(remoteState != null && remoteState.changed != null) {
- // Check if changed + 30 seconds since some servers have slight skew
- Date remoteChange = new Date(remoteState.changed.getTime() - ALLOWED_SKEW);
- Date localChange = downloadService.getLastStateChanged();
- if(localChange == null || localChange.before(remoteChange)) {
- playerQueue = remoteState;
- }
- }
- } catch (Exception e) {
- Log.e(TAG, "Failed to get playing queue to server", e);
- }
+ // If we had a remote state and it's changed is more recent than our existing state
+ if(remoteState != null && remoteState.changed != null) {
+ // Check if changed + 30 seconds since some servers have slight skew
+ Date remoteChange = new Date(remoteState.changed.getTime() - ALLOWED_SKEW);
+ Date localChange = downloadService.getLastStateChanged();
+ if(localChange == null || localChange.before(remoteChange)) {
+ playerQueue = remoteState;
+ }
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to get playing queue to server", e);
+ }
- return null;
- }
- }.execute();
- }
+ return null;
+ }
+ }.execute();
+ }
- private void createAccount() {
- final Context context = this;
+ private void createAccount() {
+ final Context context = this;
- new SilentBackgroundTask(this) {
- @Override
- protected Void doInBackground() throws Throwable {
- AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
- Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
- accountManager.addAccountExplicitly(account, null, null);
+ new SilentBackgroundTask(this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
+ Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
+ accountManager.addAccountExplicitly(account, null, null);
- SharedPreferences prefs = Util.getPreferences(context);
- boolean syncEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_ENABLED, true);
- int syncInterval = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SYNC_INTERVAL, "60"));
+ SharedPreferences prefs = Util.getPreferences(context);
+ boolean syncEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_ENABLED, true);
+ int syncInterval = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SYNC_INTERVAL, "60"));
- // Add enabled/frequency to playlist syncing
- ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, syncEnabled);
- ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, new Bundle(), 60L * syncInterval);
+ // Add enabled/frequency to playlist syncing
+ ContentResolver.setSyncAutomatically(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, syncEnabled);
+ ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_PLAYLIST_AUTHORITY, new Bundle(), 60L * syncInterval);
- return null;
- }
+ return null;
+ }
- @Override
- protected void done(Void result) {
+ @Override
+ protected void done(Void result) {
- }
- }.execute();
- }
+ }
+ }.execute();
+ }
- private void showInfoDialog() {
- if (!infoDialogDisplayed) {
- infoDialogDisplayed = true;
- if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) {
- Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text);
- }
- }
- }
+ private void showInfoDialog() {
+ if (!infoDialogDisplayed) {
+ infoDialogDisplayed = true;
+ if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) {
+ Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text);
+ }
+ }
+ }
- public Toolbar getActiveToolbar() {
- return slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED ? nowPlayingToolbar : mainToolbar;
- }
+ public Toolbar getActiveToolbar() {
+ return slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED ? nowPlayingToolbar : mainToolbar;
+ }
- @Override
- public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex) {
- this.currentPlaying = currentPlaying;
+ @Override
+ public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex) {
+ this.currentPlaying = currentPlaying;
- MusicDirectory.Entry song = null;
- if (currentPlaying != null) {
- song = currentPlaying.getSong();
- trackView.setText(song.getTitle());
+ MusicDirectory.Entry song = null;
+ if (currentPlaying != null) {
+ song = currentPlaying.getSong();
+ trackView.setText(song.getTitle());
- if(song.getArtist() != null) {
- artistView.setVisibility(View.VISIBLE);
- artistView.setText(song.getArtist());
- } else {
- artistView.setVisibility(View.GONE);
- }
- } else {
- trackView.setText(R.string.main_title);
- artistView.setText(R.string.main_artist);
- }
+ if(song.getArtist() != null) {
+ artistView.setVisibility(View.VISIBLE);
+ artistView.setText(song.getArtist());
+ } else {
+ artistView.setVisibility(View.GONE);
+ }
+ } else {
+ trackView.setText(R.string.main_title);
+ artistView.setText(R.string.main_artist);
+ }
- if (coverArtView != null) {
- int height = coverArtView.getHeight();
- if (height <= 0) {
- int[] attrs = new int[]{R.attr.actionBarSize};
- TypedArray typedArray = this.obtainStyledAttributes(attrs);
- height = typedArray.getDimensionPixelSize(0, 0);
- typedArray.recycle();
- }
- getImageLoader().loadImage(coverArtView, song, false, height, false);
- }
+ if (coverArtView != null) {
+ int height = coverArtView.getHeight();
+ if (height <= 0) {
+ int[] attrs = new int[]{R.attr.actionBarSize};
+ TypedArray typedArray = this.obtainStyledAttributes(attrs);
+ height = typedArray.getDimensionPixelSize(0, 0);
+ typedArray.recycle();
+ }
+ getImageLoader().loadImage(coverArtView, song, false, height, false);
+ }
previousButton.setVisibility(View.VISIBLE);
nextButton.setVisibility(View.VISIBLE);
rewindButton.setVisibility(View.GONE);
fastforwardButton.setVisibility(View.GONE);
- }
+ }
- @Override
- public void onSongsChanged(List songs, DownloadFile currentPlaying, int currentPlayingIndex) {
- if(this.currentPlaying != currentPlaying || this.currentPlaying == null) {
- onSongChanged(currentPlaying, currentPlayingIndex);
- }
- }
+ @Override
+ public void onSongsChanged(List songs, DownloadFile currentPlaying, int currentPlayingIndex) {
+ if(this.currentPlaying != currentPlaying || this.currentPlaying == null) {
+ onSongChanged(currentPlaying, currentPlayingIndex);
+ }
+ }
- @Override
- public void onSongProgress(DownloadFile currentPlaying, int millisPlayed, Integer duration, boolean isSeekable) {
+ @Override
+ public void onSongProgress(DownloadFile currentPlaying, int millisPlayed, Integer duration, boolean isSeekable) {
- }
+ }
- @Override
- public void onStateUpdate(DownloadFile downloadFile, PlayerState playerState) {
- int[] attrs = new int[]{(playerState == PlayerState.STARTED) ? R.attr.actionbar_pause : R.attr.actionbar_start};
- TypedArray typedArray = this.obtainStyledAttributes(attrs);
- startButton.setImageResource(typedArray.getResourceId(0, 0));
- typedArray.recycle();
- }
+ @Override
+ public void onStateUpdate(DownloadFile downloadFile, PlayerState playerState) {
+ int[] attrs = new int[]{(playerState == PlayerState.STARTED) ? R.attr.actionbar_pause : R.attr.actionbar_start};
+ TypedArray typedArray = this.obtainStyledAttributes(attrs);
+ startButton.setImageResource(typedArray.getResourceId(0, 0));
+ typedArray.recycle();
+ }
- @Override
- public void onMetadataUpdate(MusicDirectory.Entry song, int fieldChange) {
- if(song != null && coverArtView != null && fieldChange == DownloadService.METADATA_UPDATED_COVER_ART) {
- int height = coverArtView.getHeight();
- if (height <= 0) {
- int[] attrs = new int[]{R.attr.actionBarSize};
- TypedArray typedArray = this.obtainStyledAttributes(attrs);
- height = typedArray.getDimensionPixelSize(0, 0);
- typedArray.recycle();
- }
- getImageLoader().loadImage(coverArtView, song, false, height, false);
+ @Override
+ public void onMetadataUpdate(MusicDirectory.Entry song, int fieldChange) {
+ if(song != null && coverArtView != null && fieldChange == DownloadService.METADATA_UPDATED_COVER_ART) {
+ int height = coverArtView.getHeight();
+ if (height <= 0) {
+ int[] attrs = new int[]{R.attr.actionBarSize};
+ TypedArray typedArray = this.obtainStyledAttributes(attrs);
+ height = typedArray.getDimensionPixelSize(0, 0);
+ typedArray.recycle();
+ }
+ getImageLoader().loadImage(coverArtView, song, false, height, false);
- // We need to update it immediately since it won't update if updater is not running for it
- if(nowPlayingFragment != null && slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
- nowPlayingFragment.onMetadataUpdate(song, fieldChange);
- }
- }
- }
+ // We need to update it immediately since it won't update if updater is not running for it
+ if(nowPlayingFragment != null && slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
+ nowPlayingFragment.onMetadataUpdate(song, fieldChange);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/activity/VoiceQueryReceiverActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/VoiceQueryReceiverActivity.java
index 49a199b..9aea6a1 100644
--- a/app/src/main/java/net/nullsum/audinaut/activity/VoiceQueryReceiverActivity.java
+++ b/app/src/main/java/net/nullsum/audinaut/activity/VoiceQueryReceiverActivity.java
@@ -40,7 +40,7 @@ import net.nullsum.audinaut.provider.AudinautSearchProvider;
* @author Sindre Mehus
*/
public class VoiceQueryReceiverActivity extends Activity {
- private static final String TAG = VoiceQueryReceiverActivity.class.getSimpleName();
+ private static final String TAG = VoiceQueryReceiverActivity.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -53,7 +53,7 @@ public class VoiceQueryReceiverActivity extends Activity {
intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query);
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, getIntent().getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS));
- intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Util.startActivityWithoutTransition(VoiceQueryReceiverActivity.this, intent);
}
finish();
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/AlphabeticalAlbumAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/AlphabeticalAlbumAdapter.java
index b494778..e91fdd2 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/AlphabeticalAlbumAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/AlphabeticalAlbumAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -24,21 +24,21 @@ import net.nullsum.audinaut.util.ImageLoader;
import net.nullsum.audinaut.view.FastScroller;
public class AlphabeticalAlbumAdapter extends EntryInfiniteGridAdapter implements FastScroller.BubbleTextGetter {
- public AlphabeticalAlbumAdapter(Context context, List entries, ImageLoader imageLoader, boolean largeCell) {
- super(context, entries, imageLoader, largeCell);
- }
+ public AlphabeticalAlbumAdapter(Context context, List entries, ImageLoader imageLoader, boolean largeCell) {
+ super(context, entries, imageLoader, largeCell);
+ }
- @Override
- public String getTextToShowInBubble(int position) {
- // Make sure that we are not trying to get an item for the loading placeholder
- if(position >= sections.get(0).size()) {
- if(sections.get(0).size() > 0) {
- return getTextToShowInBubble(position - 1);
- } else {
- return "*";
- }
- } else {
- return getNameIndex(getItemForPosition(position).getAlbum());
- }
- }
+ @Override
+ public String getTextToShowInBubble(int position) {
+ // Make sure that we are not trying to get an item for the loading placeholder
+ if(position >= sections.get(0).size()) {
+ if(sections.get(0).size() > 0) {
+ return getTextToShowInBubble(position - 1);
+ } else {
+ return "*";
+ }
+ } else {
+ return getNameIndex(getItemForPosition(position).getAlbum());
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/ArtistAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/ArtistAdapter.java
index e13234c..64a98ed 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/ArtistAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/ArtistAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -38,125 +38,125 @@ import net.nullsum.audinaut.view.SongView;
import net.nullsum.audinaut.view.UpdateView;
public class ArtistAdapter extends SectionAdapter implements FastScroller.BubbleTextGetter {
- public static int VIEW_TYPE_SONG = 3;
- public static int VIEW_TYPE_ARTIST = 4;
+ public static int VIEW_TYPE_SONG = 3;
+ public static int VIEW_TYPE_ARTIST = 4;
- private List musicFolders;
- private OnMusicFolderChanged onMusicFolderChanged;
+ private List musicFolders;
+ private OnMusicFolderChanged onMusicFolderChanged;
- public ArtistAdapter(Context context, List artists, OnItemClickedListener listener) {
- this(context, artists, null, listener, null);
- }
+ public ArtistAdapter(Context context, List artists, OnItemClickedListener listener) {
+ this(context, artists, null, listener, null);
+ }
- public ArtistAdapter(Context context, List artists, List musicFolders, OnItemClickedListener onItemClickedListener, OnMusicFolderChanged onMusicFolderChanged) {
- super(context, artists);
- this.musicFolders = musicFolders;
- this.onItemClickedListener = onItemClickedListener;
- this.onMusicFolderChanged = onMusicFolderChanged;
+ public ArtistAdapter(Context context, List artists, List musicFolders, OnItemClickedListener onItemClickedListener, OnMusicFolderChanged onMusicFolderChanged) {
+ super(context, artists);
+ this.musicFolders = musicFolders;
+ this.onItemClickedListener = onItemClickedListener;
+ this.onMusicFolderChanged = onMusicFolderChanged;
- if(musicFolders != null) {
- this.singleSectionHeader = true;
- }
- }
+ if(musicFolders != null) {
+ this.singleSectionHeader = true;
+ }
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
- final View header = LayoutInflater.from(context).inflate(R.layout.select_artist_header, parent, false);
- header.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- PopupMenu popup = new PopupMenu(context, header.findViewById(R.id.select_artist_folder_2));
+ @Override
+ public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
+ final View header = LayoutInflater.from(context).inflate(R.layout.select_artist_header, parent, false);
+ header.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ PopupMenu popup = new PopupMenu(context, header.findViewById(R.id.select_artist_folder_2));
- popup.getMenu().add(R.string.select_artist_all_folders);
- for (MusicFolder musicFolder : musicFolders) {
- popup.getMenu().add(musicFolder.getName());
- }
+ popup.getMenu().add(R.string.select_artist_all_folders);
+ for (MusicFolder musicFolder : musicFolders) {
+ popup.getMenu().add(musicFolder.getName());
+ }
- popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- for (MusicFolder musicFolder : musicFolders) {
- if(item.getTitle().equals(musicFolder.getName())) {
- if(onMusicFolderChanged != null) {
- onMusicFolderChanged.onMusicFolderChanged(musicFolder);
- }
- return true;
- }
- }
+ popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ for (MusicFolder musicFolder : musicFolders) {
+ if(item.getTitle().equals(musicFolder.getName())) {
+ if(onMusicFolderChanged != null) {
+ onMusicFolderChanged.onMusicFolderChanged(musicFolder);
+ }
+ return true;
+ }
+ }
- if(onMusicFolderChanged != null) {
- onMusicFolderChanged.onMusicFolderChanged(null);
- }
- return true;
- }
- });
- popup.show();
- }
- });
+ if(onMusicFolderChanged != null) {
+ onMusicFolderChanged.onMusicFolderChanged(null);
+ }
+ return true;
+ }
+ });
+ popup.show();
+ }
+ });
- return new UpdateView.UpdateViewHolder(header, false);
- }
- @Override
- public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, int sectionIndex) {
- TextView folderName = (TextView) holder.getView().findViewById(R.id.select_artist_folder_2);
+ return new UpdateView.UpdateViewHolder(header, false);
+ }
+ @Override
+ public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, int sectionIndex) {
+ TextView folderName = (TextView) holder.getView().findViewById(R.id.select_artist_folder_2);
- String musicFolderId = Util.getSelectedMusicFolderId(context);
- if(musicFolderId != null) {
- for (MusicFolder musicFolder : musicFolders) {
- if (musicFolder.getId().equals(musicFolderId)) {
- folderName.setText(musicFolder.getName());
- break;
- }
- }
- } else {
- folderName.setText(R.string.select_artist_all_folders);
- }
- }
+ String musicFolderId = Util.getSelectedMusicFolderId(context);
+ if(musicFolderId != null) {
+ for (MusicFolder musicFolder : musicFolders) {
+ if (musicFolder.getId().equals(musicFolderId)) {
+ folderName.setText(musicFolder.getName());
+ break;
+ }
+ }
+ } else {
+ folderName.setText(R.string.select_artist_all_folders);
+ }
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- UpdateView updateView = null;
- if(viewType == VIEW_TYPE_ARTIST) {
- updateView = new ArtistView(context);
- } else if(viewType == VIEW_TYPE_SONG) {
- updateView = new SongView(context);
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ UpdateView updateView = null;
+ if(viewType == VIEW_TYPE_ARTIST) {
+ updateView = new ArtistView(context);
+ } else if(viewType == VIEW_TYPE_SONG) {
+ updateView = new SongView(context);
+ }
- return new UpdateView.UpdateViewHolder(updateView);
- }
+ return new UpdateView.UpdateViewHolder(updateView);
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Serializable item, int viewType) {
- UpdateView view = holder.getUpdateView();
- if(viewType == VIEW_TYPE_ARTIST) {
- view.setObject(item);
- } else if(viewType == VIEW_TYPE_SONG) {
- SongView songView = (SongView) view;
- Entry entry = (Entry) item;
- songView.setObject(entry, checkable);
- }
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Serializable item, int viewType) {
+ UpdateView view = holder.getUpdateView();
+ if(viewType == VIEW_TYPE_ARTIST) {
+ view.setObject(item);
+ } else if(viewType == VIEW_TYPE_SONG) {
+ SongView songView = (SongView) view;
+ Entry entry = (Entry) item;
+ songView.setObject(entry, checkable);
+ }
+ }
- @Override
- public int getItemViewType(Serializable item) {
- if(item instanceof Artist) {
- return VIEW_TYPE_ARTIST;
- } else {
- return VIEW_TYPE_SONG;
- }
- }
+ @Override
+ public int getItemViewType(Serializable item) {
+ if(item instanceof Artist) {
+ return VIEW_TYPE_ARTIST;
+ } else {
+ return VIEW_TYPE_SONG;
+ }
+ }
- @Override
- public String getTextToShowInBubble(int position) {
- Object item = getItemForPosition(position);
- if(item instanceof Artist) {
- return getNameIndex(((Artist) item).getName(), true);
- } else {
- return null;
- }
- }
+ @Override
+ public String getTextToShowInBubble(int position) {
+ Object item = getItemForPosition(position);
+ if(item instanceof Artist) {
+ return getNameIndex(((Artist) item).getName(), true);
+ } else {
+ return null;
+ }
+ }
- public interface OnMusicFolderChanged {
- void onMusicFolderChanged(MusicFolder musicFolder);
- }
+ public interface OnMusicFolderChanged {
+ void onMusicFolderChanged(MusicFolder musicFolder);
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/BasicListAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/BasicListAdapter.java
index b3743f4..ae04bca 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/BasicListAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/BasicListAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -24,25 +24,25 @@ import net.nullsum.audinaut.view.BasicListView;
import net.nullsum.audinaut.view.UpdateView;
public class BasicListAdapter extends SectionAdapter {
- public static int VIEW_TYPE_LINE = 1;
+ public static int VIEW_TYPE_LINE = 1;
- public BasicListAdapter(Context context, List strings, OnItemClickedListener listener) {
- super(context, strings);
- this.onItemClickedListener = listener;
- }
+ public BasicListAdapter(Context context, List strings, OnItemClickedListener listener) {
+ super(context, strings);
+ this.onItemClickedListener = listener;
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- return new UpdateView.UpdateViewHolder(new BasicListView(context));
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ return new UpdateView.UpdateViewHolder(new BasicListView(context));
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, String item, int viewType) {
- holder.getUpdateView().setObject(item);
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, String item, int viewType) {
+ holder.getUpdateView().setObject(item);
+ }
- @Override
- public int getItemViewType(String item) {
- return VIEW_TYPE_LINE;
- }
+ @Override
+ public int getItemViewType(String item) {
+ return VIEW_TYPE_LINE;
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/DetailsAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/DetailsAdapter.java
index e1828b7..dcb03f1 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/DetailsAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/DetailsAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -30,33 +30,33 @@ import java.util.List;
import net.nullsum.audinaut.R;
public class DetailsAdapter extends ArrayAdapter {
- private List headers;
- private List details;
+ private List headers;
+ private List details;
- public DetailsAdapter(Context context, int layout, List headers, List details) {
- super(context, layout, headers);
+ public DetailsAdapter(Context context, int layout, List headers, List details) {
+ super(context, layout, headers);
- this.headers = headers;
- this.details = details;
- }
+ this.headers = headers;
+ this.details = details;
+ }
- @Override
- public View getView(int position, View convertView, ViewGroup parent){
- View view;
- if(convertView == null) {
- view = LayoutInflater.from(getContext()).inflate(R.layout.details_item, null);
- } else {
- view = convertView;
- }
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent){
+ View view;
+ if(convertView == null) {
+ view = LayoutInflater.from(getContext()).inflate(R.layout.details_item, null);
+ } else {
+ view = convertView;
+ }
- TextView nameView = (TextView) view.findViewById(R.id.detail_name);
- TextView detailsView = (TextView) view.findViewById(R.id.detail_value);
+ TextView nameView = (TextView) view.findViewById(R.id.detail_name);
+ TextView detailsView = (TextView) view.findViewById(R.id.detail_value);
- nameView.setText(headers.get(position));
+ nameView.setText(headers.get(position));
- detailsView.setText(details.get(position));
- Linkify.addLinks(detailsView, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
+ detailsView.setText(details.get(position));
+ Linkify.addLinks(detailsView, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
- return view;
- }
+ return view;
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/DownloadFileAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/DownloadFileAdapter.java
index e127ae5..6a1d1dc 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/DownloadFileAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/DownloadFileAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2014 (C) Scott Jackson
+ 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 .
+ Copyright 2014 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -33,42 +33,42 @@ import net.nullsum.audinaut.view.SongView;
import net.nullsum.audinaut.view.UpdateView;
public class DownloadFileAdapter extends SectionAdapter implements FastScroller.BubbleTextGetter {
- public static int VIEW_TYPE_DOWNLOAD_FILE = 1;
+ public static int VIEW_TYPE_DOWNLOAD_FILE = 1;
- public DownloadFileAdapter(Context context, List entries, OnItemClickedListener onItemClickedListener) {
- super(context, entries);
- this.onItemClickedListener = onItemClickedListener;
- this.checkable = true;
- }
+ public DownloadFileAdapter(Context context, List entries, OnItemClickedListener onItemClickedListener) {
+ super(context, entries);
+ this.onItemClickedListener = onItemClickedListener;
+ this.checkable = true;
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- return new UpdateView.UpdateViewHolder(new SongView(context));
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ return new UpdateView.UpdateViewHolder(new SongView(context));
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, DownloadFile item, int viewType) {
- SongView songView = (SongView) holder.getUpdateView();
- songView.setObject(item.getSong(), Util.isBatchMode(context));
- songView.setDownloadFile(item);
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, DownloadFile item, int viewType) {
+ SongView songView = (SongView) holder.getUpdateView();
+ songView.setObject(item.getSong(), Util.isBatchMode(context));
+ songView.setDownloadFile(item);
+ }
- @Override
- public int getItemViewType(DownloadFile item) {
- return VIEW_TYPE_DOWNLOAD_FILE;
- }
+ @Override
+ public int getItemViewType(DownloadFile item) {
+ return VIEW_TYPE_DOWNLOAD_FILE;
+ }
- @Override
- public String getTextToShowInBubble(int position) {
- return null;
- }
+ @Override
+ public String getTextToShowInBubble(int position) {
+ return null;
+ }
- @Override
- public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
- if(Util.isOffline(context)) {
- menuInflater.inflate(R.menu.multiselect_nowplaying_offline, menu);
- } else {
- menuInflater.inflate(R.menu.multiselect_nowplaying, menu);
- }
- }
+ @Override
+ public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
+ if(Util.isOffline(context)) {
+ menuInflater.inflate(R.menu.multiselect_nowplaying_offline, menu);
+ } else {
+ menuInflater.inflate(R.menu.multiselect_nowplaying, menu);
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/EntryGridAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/EntryGridAdapter.java
index b301666..017dfa0 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/EntryGridAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/EntryGridAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -35,122 +35,122 @@ import net.nullsum.audinaut.view.UpdateView;
import net.nullsum.audinaut.view.UpdateView.UpdateViewHolder;
public class EntryGridAdapter extends SectionAdapter {
- private static String TAG = EntryGridAdapter.class.getSimpleName();
+ private static String TAG = EntryGridAdapter.class.getSimpleName();
- public static int VIEW_TYPE_ALBUM_CELL = 1;
- public static int VIEW_TYPE_ALBUM_LINE = 2;
- public static int VIEW_TYPE_SONG = 3;
+ public static int VIEW_TYPE_ALBUM_CELL = 1;
+ public static int VIEW_TYPE_ALBUM_LINE = 2;
+ public static int VIEW_TYPE_SONG = 3;
- private ImageLoader imageLoader;
- private boolean largeAlbums;
- private boolean showArtist = false;
- private boolean showAlbum = false;
- private boolean removeFromPlaylist = false;
- private View header;
+ private ImageLoader imageLoader;
+ private boolean largeAlbums;
+ private boolean showArtist = false;
+ private boolean showAlbum = false;
+ private boolean removeFromPlaylist = false;
+ private View header;
- public EntryGridAdapter(Context context, List entries, ImageLoader imageLoader, boolean largeCell) {
- super(context, entries);
- this.imageLoader = imageLoader;
- this.largeAlbums = largeCell;
+ public EntryGridAdapter(Context context, List entries, ImageLoader imageLoader, boolean largeCell) {
+ super(context, entries);
+ this.imageLoader = imageLoader;
+ this.largeAlbums = largeCell;
- // Always show artist if they aren't all the same
- String artist = null;
- for(MusicDirectory.Entry entry: entries) {
- if(artist == null) {
- artist = entry.getArtist();
- }
+ // Always show artist if they aren't all the same
+ String artist = null;
+ for(MusicDirectory.Entry entry: entries) {
+ if(artist == null) {
+ artist = entry.getArtist();
+ }
- if(artist != null && !artist.equals(entry.getArtist())) {
- showArtist = true;
- }
- }
- checkable = true;
- }
+ if(artist != null && !artist.equals(entry.getArtist())) {
+ showArtist = true;
+ }
+ }
+ checkable = true;
+ }
- @Override
- public UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- UpdateView updateView = null;
- if(viewType == VIEW_TYPE_ALBUM_LINE || viewType == VIEW_TYPE_ALBUM_CELL) {
- updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL);
- } else if(viewType == VIEW_TYPE_SONG) {
- updateView = new SongView(context);
- }
+ @Override
+ public UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ UpdateView updateView = null;
+ if(viewType == VIEW_TYPE_ALBUM_LINE || viewType == VIEW_TYPE_ALBUM_CELL) {
+ updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL);
+ } else if(viewType == VIEW_TYPE_SONG) {
+ updateView = new SongView(context);
+ }
- return new UpdateViewHolder(updateView);
- }
+ return new UpdateViewHolder(updateView);
+ }
- @Override
- public void onBindViewHolder(UpdateViewHolder holder, Entry entry, int viewType) {
- UpdateView view = holder.getUpdateView();
- if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
- AlbumView albumView = (AlbumView) view;
- albumView.setShowArtist(showArtist);
- albumView.setObject(entry, imageLoader);
- } else if(viewType == VIEW_TYPE_SONG) {
- SongView songView = (SongView) view;
- songView.setShowAlbum(showAlbum);
- songView.setObject(entry, checkable);
- }
- }
+ @Override
+ public void onBindViewHolder(UpdateViewHolder holder, Entry entry, int viewType) {
+ UpdateView view = holder.getUpdateView();
+ if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
+ AlbumView albumView = (AlbumView) view;
+ albumView.setShowArtist(showArtist);
+ albumView.setObject(entry, imageLoader);
+ } else if(viewType == VIEW_TYPE_SONG) {
+ SongView songView = (SongView) view;
+ songView.setShowAlbum(showAlbum);
+ songView.setObject(entry, checkable);
+ }
+ }
- public UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
- return new UpdateViewHolder(header, false);
- }
- public void onBindHeaderHolder(UpdateViewHolder holder, String header, int sectionIndex) {
+ public UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
+ return new UpdateViewHolder(header, false);
+ }
+ public void onBindHeaderHolder(UpdateViewHolder holder, String header, int sectionIndex) {
- }
+ }
- @Override
- public int getItemViewType(Entry entry) {
- if(entry.isDirectory()) {
- if (largeAlbums) {
- return VIEW_TYPE_ALBUM_CELL;
- } else {
- return VIEW_TYPE_ALBUM_LINE;
- }
- } else {
- return VIEW_TYPE_SONG;
- }
- }
+ @Override
+ public int getItemViewType(Entry entry) {
+ if(entry.isDirectory()) {
+ if (largeAlbums) {
+ return VIEW_TYPE_ALBUM_CELL;
+ } else {
+ return VIEW_TYPE_ALBUM_LINE;
+ }
+ } else {
+ return VIEW_TYPE_SONG;
+ }
+ }
- public void setHeader(View header) {
- this.header = header;
- this.singleSectionHeader = true;
- }
- public View getHeader() {
- return header;
- }
+ public void setHeader(View header) {
+ this.header = header;
+ this.singleSectionHeader = true;
+ }
+ public View getHeader() {
+ return header;
+ }
- public void setShowArtist(boolean showArtist) {
- this.showArtist = showArtist;
- }
+ public void setShowArtist(boolean showArtist) {
+ this.showArtist = showArtist;
+ }
- public void setShowAlbum(boolean showAlbum) {
- this.showAlbum = showAlbum;
- }
+ public void setShowAlbum(boolean showAlbum) {
+ this.showAlbum = showAlbum;
+ }
- public void removeAt(int index) {
- sections.get(0).remove(index);
- if(header != null) {
- index++;
- }
- notifyItemRemoved(index);
- }
+ public void removeAt(int index) {
+ sections.get(0).remove(index);
+ if(header != null) {
+ index++;
+ }
+ notifyItemRemoved(index);
+ }
- public void setRemoveFromPlaylist(boolean removeFromPlaylist) {
- this.removeFromPlaylist = removeFromPlaylist;
- }
+ public void setRemoveFromPlaylist(boolean removeFromPlaylist) {
+ this.removeFromPlaylist = removeFromPlaylist;
+ }
- @Override
- public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
- if(Util.isOffline(context)) {
- menuInflater.inflate(R.menu.multiselect_media_offline, menu);
- } else {
- menuInflater.inflate(R.menu.multiselect_media, menu);
- }
+ @Override
+ public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
+ if(Util.isOffline(context)) {
+ menuInflater.inflate(R.menu.multiselect_media_offline, menu);
+ } else {
+ menuInflater.inflate(R.menu.multiselect_media, menu);
+ }
- if(!removeFromPlaylist) {
- menu.removeItem(R.id.menu_remove_playlist);
- }
- }
+ if(!removeFromPlaylist) {
+ menu.removeItem(R.id.menu_remove_playlist);
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/EntryInfiniteGridAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/EntryInfiniteGridAdapter.java
index 978458c..5af5066 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/EntryInfiniteGridAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/EntryInfiniteGridAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -33,120 +33,120 @@ import net.nullsum.audinaut.util.SilentBackgroundTask;
import net.nullsum.audinaut.view.UpdateView;
public class EntryInfiniteGridAdapter extends EntryGridAdapter {
- public static int VIEW_TYPE_LOADING = 4;
+ public static int VIEW_TYPE_LOADING = 4;
- private String type;
- private String extra;
- private int size;
+ private String type;
+ private String extra;
+ private int size;
- private boolean loading = false;
- private boolean allLoaded = false;
+ private boolean loading = false;
+ private boolean allLoaded = false;
- public EntryInfiniteGridAdapter(Context context, List entries, ImageLoader imageLoader, boolean largeCell) {
- super(context, entries, imageLoader, largeCell);
- }
+ public EntryInfiniteGridAdapter(Context context, List entries, ImageLoader imageLoader, boolean largeCell) {
+ super(context, entries, imageLoader, largeCell);
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- if(viewType == VIEW_TYPE_LOADING) {
- View progress = LayoutInflater.from(context).inflate(R.layout.tab_progress, null);
- progress.setVisibility(View.VISIBLE);
- return new UpdateView.UpdateViewHolder(progress, false);
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ if(viewType == VIEW_TYPE_LOADING) {
+ View progress = LayoutInflater.from(context).inflate(R.layout.tab_progress, null);
+ progress.setVisibility(View.VISIBLE);
+ return new UpdateView.UpdateViewHolder(progress, false);
+ }
- return super.onCreateViewHolder(parent, viewType);
- }
+ return super.onCreateViewHolder(parent, viewType);
+ }
- @Override
- public int getItemViewType(int position) {
- if(isLoadingView(position)) {
- return VIEW_TYPE_LOADING;
- }
+ @Override
+ public int getItemViewType(int position) {
+ if(isLoadingView(position)) {
+ return VIEW_TYPE_LOADING;
+ }
- return super.getItemViewType(position);
- }
+ return super.getItemViewType(position);
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, int position) {
- if(!isLoadingView(position)) {
- super.onBindViewHolder(holder, position);
- }
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, int position) {
+ if(!isLoadingView(position)) {
+ super.onBindViewHolder(holder, position);
+ }
+ }
- @Override
- public int getItemCount() {
- int size = super.getItemCount();
+ @Override
+ public int getItemCount() {
+ int size = super.getItemCount();
- if(!allLoaded) {
- size++;
- }
+ if(!allLoaded) {
+ size++;
+ }
- return size;
- }
+ return size;
+ }
- public void setData(String type, String extra, int size) {
- this.type = type;
- this.extra = extra;
- this.size = size;
+ public void setData(String type, String extra, int size) {
+ this.type = type;
+ this.extra = extra;
+ this.size = size;
- if(super.getItemCount() < size) {
- allLoaded = true;
- }
- }
+ if(super.getItemCount() < size) {
+ allLoaded = true;
+ }
+ }
- public void loadMore() {
- if(loading || allLoaded) {
- return;
- }
- loading = true;
+ public void loadMore() {
+ if(loading || allLoaded) {
+ return;
+ }
+ loading = true;
- new SilentBackgroundTask(context) {
- private List newData;
+ new SilentBackgroundTask(context) {
+ private List newData;
- @Override
- protected Void doInBackground() throws Throwable {
- newData = cacheInBackground();
- return null;
- }
+ @Override
+ protected Void doInBackground() throws Throwable {
+ newData = cacheInBackground();
+ return null;
+ }
- @Override
- protected void done(Void result) {
- appendCachedData(newData);
- loading = false;
+ @Override
+ protected void done(Void result) {
+ appendCachedData(newData);
+ loading = false;
- if(newData.size() < size) {
- allLoaded = true;
- notifyDataSetChanged();
- }
- }
- }.execute();
- }
+ if(newData.size() < size) {
+ allLoaded = true;
+ notifyDataSetChanged();
+ }
+ }
+ }.execute();
+ }
- protected List cacheInBackground() throws Exception {
- MusicService service = MusicServiceFactory.getMusicService(context);
- MusicDirectory result;
- int offset = sections.get(0).size();
- if("genres".equals(type) || "years".equals(type)) {
- result = service.getAlbumList(type, extra, size, offset, false, context, null);
- } else if("genres".equals(type) || "genres-songs".equals(type)) {
- result = service.getSongsByGenre(extra, size, offset, context, null);
- }else if(type.indexOf(MainFragment.SONGS_LIST_PREFIX) != -1) {
- result = service.getSongList(type, size, offset, context, null);
- } else {
- result = service.getAlbumList(type, size, offset, false, context, null);
- }
- return result.getChildren();
- }
+ protected List cacheInBackground() throws Exception {
+ MusicService service = MusicServiceFactory.getMusicService(context);
+ MusicDirectory result;
+ int offset = sections.get(0).size();
+ if("genres".equals(type) || "years".equals(type)) {
+ result = service.getAlbumList(type, extra, size, offset, false, context, null);
+ } else if("genres".equals(type) || "genres-songs".equals(type)) {
+ result = service.getSongsByGenre(extra, size, offset, context, null);
+ }else if(type.indexOf(MainFragment.SONGS_LIST_PREFIX) != -1) {
+ result = service.getSongList(type, size, offset, context, null);
+ } else {
+ result = service.getAlbumList(type, size, offset, false, context, null);
+ }
+ return result.getChildren();
+ }
- protected void appendCachedData(List newData) {
- if(newData.size() > 0) {
- int start = sections.get(0).size();
- sections.get(0).addAll(newData);
- this.notifyItemRangeInserted(start, newData.size());
- }
- }
+ protected void appendCachedData(List newData) {
+ if(newData.size() > 0) {
+ int start = sections.get(0).size();
+ sections.get(0).addAll(newData);
+ this.notifyItemRangeInserted(start, newData.size());
+ }
+ }
- protected boolean isLoadingView(int position) {
- return !allLoaded && position >= sections.get(0).size();
- }
+ protected boolean isLoadingView(int position) {
+ return !allLoaded && position >= sections.get(0).size();
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/ExpandableSectionAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/ExpandableSectionAdapter.java
index 1b44cb1..7212496 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/ExpandableSectionAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/ExpandableSectionAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -31,120 +31,120 @@ import net.nullsum.audinaut.view.BasicHeaderView;
import net.nullsum.audinaut.view.UpdateView;
public abstract class ExpandableSectionAdapter extends SectionAdapter {
- private static final String TAG = ExpandableSectionAdapter.class.getSimpleName();
- private static final int DEFAULT_VISIBLE = 4;
- private static final int EXPAND_TOGGLE = R.attr.select_server;
- private static final int COLLAPSE_TOGGLE = R.attr.select_tabs;
+ private static final String TAG = ExpandableSectionAdapter.class.getSimpleName();
+ private static final int DEFAULT_VISIBLE = 4;
+ private static final int EXPAND_TOGGLE = R.attr.select_server;
+ private static final int COLLAPSE_TOGGLE = R.attr.select_tabs;
- protected List sectionsDefaultVisible;
- protected List> sectionsExtras;
- protected int expandToggleRes;
- protected int collapseToggleRes;
+ protected List sectionsDefaultVisible;
+ protected List> sectionsExtras;
+ protected int expandToggleRes;
+ protected int collapseToggleRes;
- protected ExpandableSectionAdapter() {}
- public ExpandableSectionAdapter(Context context, List section) {
- List> sections = new ArrayList<>();
- sections.add(section);
+ protected ExpandableSectionAdapter() {}
+ public ExpandableSectionAdapter(Context context, List section) {
+ List> sections = new ArrayList<>();
+ sections.add(section);
- init(context, Arrays.asList("Section"), sections, Arrays.asList((Integer) null));
- }
- public ExpandableSectionAdapter(Context context, List headers, List> sections) {
- init(context, headers, sections, null);
- }
- public ExpandableSectionAdapter(Context context, List headers, List> sections, List sectionsDefaultVisible) {
- init(context, headers, sections, sectionsDefaultVisible);
- }
- protected void init(Context context, List headers, List> fullSections, List sectionsDefaultVisible) {
- this.context = context;
- this.headers = headers;
- this.sectionsDefaultVisible = sectionsDefaultVisible;
- if(sectionsDefaultVisible == null) {
- sectionsDefaultVisible = new ArrayList<>(fullSections.size());
- for(int i = 0; i < fullSections.size(); i++) {
- sectionsDefaultVisible.add(DEFAULT_VISIBLE);
- }
- }
+ init(context, Arrays.asList("Section"), sections, Arrays.asList((Integer) null));
+ }
+ public ExpandableSectionAdapter(Context context, List headers, List> sections) {
+ init(context, headers, sections, null);
+ }
+ public ExpandableSectionAdapter(Context context, List headers, List> sections, List sectionsDefaultVisible) {
+ init(context, headers, sections, sectionsDefaultVisible);
+ }
+ protected void init(Context context, List headers, List> fullSections, List sectionsDefaultVisible) {
+ this.context = context;
+ this.headers = headers;
+ this.sectionsDefaultVisible = sectionsDefaultVisible;
+ if(sectionsDefaultVisible == null) {
+ sectionsDefaultVisible = new ArrayList<>(fullSections.size());
+ for(int i = 0; i < fullSections.size(); i++) {
+ sectionsDefaultVisible.add(DEFAULT_VISIBLE);
+ }
+ }
- this.sections = new ArrayList<>();
- this.sectionsExtras = new ArrayList<>();
- int i = 0;
- for(List fullSection: fullSections) {
- List visibleSection = new ArrayList<>();
+ this.sections = new ArrayList<>();
+ this.sectionsExtras = new ArrayList<>();
+ int i = 0;
+ for(List fullSection: fullSections) {
+ List visibleSection = new ArrayList<>();
- Integer defaultVisible = sectionsDefaultVisible.get(i);
- if(defaultVisible == null || defaultVisible >= fullSection.size()) {
- visibleSection.addAll(fullSection);
- this.sectionsExtras.add(null);
- } else {
- visibleSection.addAll(fullSection.subList(0, defaultVisible));
- this.sectionsExtras.add(fullSection.subList(defaultVisible, fullSection.size()));
- }
- this.sections.add(visibleSection);
+ Integer defaultVisible = sectionsDefaultVisible.get(i);
+ if(defaultVisible == null || defaultVisible >= fullSection.size()) {
+ visibleSection.addAll(fullSection);
+ this.sectionsExtras.add(null);
+ } else {
+ visibleSection.addAll(fullSection.subList(0, defaultVisible));
+ this.sectionsExtras.add(fullSection.subList(defaultVisible, fullSection.size()));
+ }
+ this.sections.add(visibleSection);
- i++;
- }
+ i++;
+ }
- expandToggleRes = DrawableTint.getDrawableRes(context, EXPAND_TOGGLE);
- collapseToggleRes = DrawableTint.getDrawableRes(context, COLLAPSE_TOGGLE);
- }
+ expandToggleRes = DrawableTint.getDrawableRes(context, EXPAND_TOGGLE);
+ collapseToggleRes = DrawableTint.getDrawableRes(context, COLLAPSE_TOGGLE);
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
- return new UpdateView.UpdateViewHolder(new BasicHeaderView(context, R.layout.expandable_header));
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
+ return new UpdateView.UpdateViewHolder(new BasicHeaderView(context, R.layout.expandable_header));
+ }
- @Override
- public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, final int sectionIndex) {
- UpdateView view = holder.getUpdateView();
- ImageView toggleSelectionView = (ImageView) view.findViewById(R.id.item_select);
+ @Override
+ public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, final int sectionIndex) {
+ UpdateView view = holder.getUpdateView();
+ ImageView toggleSelectionView = (ImageView) view.findViewById(R.id.item_select);
- List visibleSelection = sections.get(sectionIndex);
- List sectionExtras = sectionsExtras.get(sectionIndex);
+ List visibleSelection = sections.get(sectionIndex);
+ List sectionExtras = sectionsExtras.get(sectionIndex);
- if(sectionExtras != null && !sectionExtras.isEmpty()) {
- toggleSelectionView.setVisibility(View.VISIBLE);
- toggleSelectionView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- List visibleSelection = sections.get(sectionIndex);
- List sectionExtras = sectionsExtras.get(sectionIndex);
+ if(sectionExtras != null && !sectionExtras.isEmpty()) {
+ toggleSelectionView.setVisibility(View.VISIBLE);
+ toggleSelectionView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ List visibleSelection = sections.get(sectionIndex);
+ List sectionExtras = sectionsExtras.get(sectionIndex);
- // Update icon
- int selectToggleAttr;
- if (!visibleSelection.contains(sectionExtras.get(0))) {
- selectToggleAttr = COLLAPSE_TOGGLE;
+ // Update icon
+ int selectToggleAttr;
+ if (!visibleSelection.contains(sectionExtras.get(0))) {
+ selectToggleAttr = COLLAPSE_TOGGLE;
- // Update how many are displayed
- int lastIndex = getItemPosition(visibleSelection.get(visibleSelection.size() - 1));
- visibleSelection.addAll(sectionExtras);
- notifyItemRangeInserted(lastIndex, sectionExtras.size());
- } else {
- selectToggleAttr = EXPAND_TOGGLE;
+ // Update how many are displayed
+ int lastIndex = getItemPosition(visibleSelection.get(visibleSelection.size() - 1));
+ visibleSelection.addAll(sectionExtras);
+ notifyItemRangeInserted(lastIndex, sectionExtras.size());
+ } else {
+ selectToggleAttr = EXPAND_TOGGLE;
- // Update how many are displayed
- visibleSelection.removeAll(sectionExtras);
- int lastIndex = getItemPosition(visibleSelection.get(visibleSelection.size() - 1));
- notifyItemRangeRemoved(lastIndex, sectionExtras.size());
- }
+ // Update how many are displayed
+ visibleSelection.removeAll(sectionExtras);
+ int lastIndex = getItemPosition(visibleSelection.get(visibleSelection.size() - 1));
+ notifyItemRangeRemoved(lastIndex, sectionExtras.size());
+ }
- ((ImageView) v).setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr));
- }
- });
+ ((ImageView) v).setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr));
+ }
+ });
- int selectToggleAttr;
- if (!visibleSelection.contains(sectionExtras.get(0))) {
- selectToggleAttr = EXPAND_TOGGLE;
- } else {
- selectToggleAttr = COLLAPSE_TOGGLE;
- }
+ int selectToggleAttr;
+ if (!visibleSelection.contains(sectionExtras.get(0))) {
+ selectToggleAttr = EXPAND_TOGGLE;
+ } else {
+ selectToggleAttr = COLLAPSE_TOGGLE;
+ }
- toggleSelectionView.setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr));
- } else {
- toggleSelectionView.setVisibility(View.GONE);
- }
+ toggleSelectionView.setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr));
+ } else {
+ toggleSelectionView.setVisibility(View.GONE);
+ }
- if(view != null) {
- view.setObject(header);
- }
- }
+ if(view != null) {
+ view.setObject(header);
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/GenreAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/GenreAdapter.java
index d5158b6..eb9fab0 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/GenreAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/GenreAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -25,30 +25,30 @@ import net.nullsum.audinaut.view.UpdateView;
import java.util.List;
public class GenreAdapter extends SectionAdapter implements FastScroller.BubbleTextGetter{
- public static int VIEW_TYPE_GENRE = 1;
+ public static int VIEW_TYPE_GENRE = 1;
- public GenreAdapter(Context context, List genres, OnItemClickedListener listener) {
+ public GenreAdapter(Context context, List genres, OnItemClickedListener listener) {
super(context, genres);
- this.onItemClickedListener = listener;
+ this.onItemClickedListener = listener;
}
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- return new UpdateView.UpdateViewHolder(new GenreView(context));
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ return new UpdateView.UpdateViewHolder(new GenreView(context));
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Genre item, int viewType) {
- holder.getUpdateView().setObject(item);
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Genre item, int viewType) {
+ holder.getUpdateView().setObject(item);
+ }
- @Override
- public int getItemViewType(Genre item) {
- return VIEW_TYPE_GENRE;
- }
+ @Override
+ public int getItemViewType(Genre item) {
+ return VIEW_TYPE_GENRE;
+ }
- @Override
- public String getTextToShowInBubble(int position) {
- return getNameIndex(getItemForPosition(position).getName());
- }
+ @Override
+ public String getTextToShowInBubble(int position) {
+ return getNameIndex(getItemForPosition(position).getName());
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/MainAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/MainAdapter.java
index f185971..b44cdd4 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/MainAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/MainAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -30,55 +30,55 @@ import net.nullsum.audinaut.view.BasicListView;
import net.nullsum.audinaut.view.UpdateView;
public class MainAdapter extends SectionAdapter {
- public static final int VIEW_TYPE_ALBUM_LIST = 1;
+ public static final int VIEW_TYPE_ALBUM_LIST = 1;
- public MainAdapter(Context context, List headers, List> sections, OnItemClickedListener onItemClickedListener) {
- super(context, headers, sections);
- this.onItemClickedListener = onItemClickedListener;
- }
+ public MainAdapter(Context context, List headers, List> sections, OnItemClickedListener onItemClickedListener) {
+ super(context, headers, sections);
+ this.onItemClickedListener = onItemClickedListener;
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- UpdateView updateView = new BasicListView(context);
- return new UpdateView.UpdateViewHolder(updateView);
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ UpdateView updateView = new BasicListView(context);
+ return new UpdateView.UpdateViewHolder(updateView);
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Integer item, int viewType) {
- UpdateView updateView = holder.getUpdateView();
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Integer item, int viewType) {
+ UpdateView updateView = holder.getUpdateView();
- if(viewType == VIEW_TYPE_ALBUM_LIST) {
- updateView.setObject(context.getResources().getString(item));
- } else {
- updateView.setObject(item);
- }
- }
+ if(viewType == VIEW_TYPE_ALBUM_LIST) {
+ updateView.setObject(context.getResources().getString(item));
+ } else {
+ updateView.setObject(item);
+ }
+ }
- @Override
- public int getItemViewType(Integer item) {
- return VIEW_TYPE_ALBUM_LIST;
- }
+ @Override
+ public int getItemViewType(Integer item) {
+ return VIEW_TYPE_ALBUM_LIST;
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
- return new UpdateView.UpdateViewHolder(new BasicHeaderView(context, R.layout.album_list_header));
- }
- @Override
- public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, int sectionIndex) {
- UpdateView view = holder.getUpdateView();
- CheckBox checkBox = (CheckBox) view.findViewById(R.id.item_checkbox);
+ @Override
+ public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
+ return new UpdateView.UpdateViewHolder(new BasicHeaderView(context, R.layout.album_list_header));
+ }
+ @Override
+ public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, int sectionIndex) {
+ UpdateView view = holder.getUpdateView();
+ CheckBox checkBox = (CheckBox) view.findViewById(R.id.item_checkbox);
- String display;
- if("songs".equals(header)) {
- display = context.getResources().getString(R.string.search_songs);
- checkBox.setVisibility(View.GONE);
- } else {
- display = header;
- checkBox.setVisibility(View.GONE);
- }
+ String display;
+ if("songs".equals(header)) {
+ display = context.getResources().getString(R.string.search_songs);
+ checkBox.setVisibility(View.GONE);
+ } else {
+ display = header;
+ checkBox.setVisibility(View.GONE);
+ }
- if(view != null) {
- view.setObject(display);
- }
- }
+ if(view != null) {
+ view.setObject(display);
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java
index 961c439..94a48a4 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -26,47 +26,47 @@ import net.nullsum.audinaut.view.PlaylistView;
import net.nullsum.audinaut.view.UpdateView;
public class PlaylistAdapter extends SectionAdapter implements FastScroller.BubbleTextGetter {
- public static int VIEW_TYPE_PLAYLIST = 1;
+ public static int VIEW_TYPE_PLAYLIST = 1;
- private ImageLoader imageLoader;
- private boolean largeCell;
+ private ImageLoader imageLoader;
+ private boolean largeCell;
- public PlaylistAdapter(Context context, List playlists, ImageLoader imageLoader, boolean largeCell, OnItemClickedListener listener) {
- super(context, playlists);
- this.imageLoader = imageLoader;
- this.largeCell = largeCell;
- this.onItemClickedListener = listener;
- }
- public PlaylistAdapter(Context context, List headers, List> sections, ImageLoader imageLoader, boolean largeCell, OnItemClickedListener listener) {
- super(context, headers, sections);
- this.imageLoader = imageLoader;
- this.largeCell = largeCell;
- this.onItemClickedListener = listener;
- }
+ public PlaylistAdapter(Context context, List playlists, ImageLoader imageLoader, boolean largeCell, OnItemClickedListener listener) {
+ super(context, playlists);
+ this.imageLoader = imageLoader;
+ this.largeCell = largeCell;
+ this.onItemClickedListener = listener;
+ }
+ public PlaylistAdapter(Context context, List headers, List> sections, ImageLoader imageLoader, boolean largeCell, OnItemClickedListener listener) {
+ super(context, headers, sections);
+ this.imageLoader = imageLoader;
+ this.largeCell = largeCell;
+ this.onItemClickedListener = listener;
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- return new UpdateView.UpdateViewHolder(new PlaylistView(context, imageLoader, largeCell));
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ return new UpdateView.UpdateViewHolder(new PlaylistView(context, imageLoader, largeCell));
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Playlist playlist, int viewType) {
- holder.getUpdateView().setObject(playlist);
- holder.setItem(playlist);
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Playlist playlist, int viewType) {
+ holder.getUpdateView().setObject(playlist);
+ holder.setItem(playlist);
+ }
- @Override
- public int getItemViewType(Playlist playlist) {
- return VIEW_TYPE_PLAYLIST;
- }
+ @Override
+ public int getItemViewType(Playlist playlist) {
+ return VIEW_TYPE_PLAYLIST;
+ }
- @Override
- public String getTextToShowInBubble(int position) {
- Object item = getItemForPosition(position);
- if(item instanceof Playlist) {
- return getNameIndex(((Playlist) item).getName());
- } else {
- return null;
- }
- }
+ @Override
+ public String getTextToShowInBubble(int position) {
+ Object item = getItemForPosition(position);
+ if(item instanceof Playlist) {
+ return getNameIndex(((Playlist) item).getName());
+ } else {
+ return null;
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/SearchAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/SearchAdapter.java
index d5858c0..b76ffa2 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/SearchAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/SearchAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -45,96 +45,96 @@ import static net.nullsum.audinaut.adapter.EntryGridAdapter.VIEW_TYPE_ALBUM_LINE
import static net.nullsum.audinaut.adapter.EntryGridAdapter.VIEW_TYPE_SONG;
public class SearchAdapter extends ExpandableSectionAdapter {
- private ImageLoader imageLoader;
- private boolean largeAlbums;
+ private ImageLoader imageLoader;
+ private boolean largeAlbums;
- private static final int MAX_ARTISTS = 10;
- private static final int MAX_ALBUMS = 4;
- private static final int MAX_SONGS = 10;
+ private static final int MAX_ARTISTS = 10;
+ private static final int MAX_ALBUMS = 4;
+ private static final int MAX_SONGS = 10;
- public SearchAdapter(Context context, SearchResult searchResult, ImageLoader imageLoader, boolean largeAlbums, OnItemClickedListener listener) {
- this.imageLoader = imageLoader;
- this.largeAlbums = largeAlbums;
+ public SearchAdapter(Context context, SearchResult searchResult, ImageLoader imageLoader, boolean largeAlbums, OnItemClickedListener listener) {
+ this.imageLoader = imageLoader;
+ this.largeAlbums = largeAlbums;
- List> sections = new ArrayList<>();
- List headers = new ArrayList<>();
- List defaultVisible = new ArrayList<>();
- Resources res = context.getResources();
- if(!searchResult.getArtists().isEmpty()) {
- sections.add((List) (List>) searchResult.getArtists());
- headers.add(res.getString(R.string.search_artists));
- defaultVisible.add(MAX_ARTISTS);
- }
- if(!searchResult.getAlbums().isEmpty()) {
- sections.add((List) (List>) searchResult.getAlbums());
- headers.add(res.getString(R.string.search_albums));
- defaultVisible.add(MAX_ALBUMS);
- }
- if(!searchResult.getSongs().isEmpty()) {
- sections.add((List) (List>) searchResult.getSongs());
- headers.add(res.getString(R.string.search_songs));
- defaultVisible.add(MAX_SONGS);
- }
- init(context, headers, sections, defaultVisible);
+ List> sections = new ArrayList<>();
+ List headers = new ArrayList<>();
+ List defaultVisible = new ArrayList<>();
+ Resources res = context.getResources();
+ if(!searchResult.getArtists().isEmpty()) {
+ sections.add((List) (List>) searchResult.getArtists());
+ headers.add(res.getString(R.string.search_artists));
+ defaultVisible.add(MAX_ARTISTS);
+ }
+ if(!searchResult.getAlbums().isEmpty()) {
+ sections.add((List) (List>) searchResult.getAlbums());
+ headers.add(res.getString(R.string.search_albums));
+ defaultVisible.add(MAX_ALBUMS);
+ }
+ if(!searchResult.getSongs().isEmpty()) {
+ sections.add((List) (List>) searchResult.getSongs());
+ headers.add(res.getString(R.string.search_songs));
+ defaultVisible.add(MAX_SONGS);
+ }
+ init(context, headers, sections, defaultVisible);
- this.onItemClickedListener = listener;
- checkable = true;
- }
+ this.onItemClickedListener = listener;
+ checkable = true;
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- UpdateView updateView = null;
- if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
- updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL);
- } else if(viewType == VIEW_TYPE_SONG) {
- updateView = new SongView(context);
- } else if(viewType == VIEW_TYPE_ARTIST) {
- updateView = new ArtistView(context);
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ UpdateView updateView = null;
+ if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
+ updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL);
+ } else if(viewType == VIEW_TYPE_SONG) {
+ updateView = new SongView(context);
+ } else if(viewType == VIEW_TYPE_ARTIST) {
+ updateView = new ArtistView(context);
+ }
- return new UpdateView.UpdateViewHolder(updateView);
- }
+ return new UpdateView.UpdateViewHolder(updateView);
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Serializable item, int viewType) {
- UpdateView view = holder.getUpdateView();
- if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
- AlbumView albumView = (AlbumView) view;
- albumView.setObject((Entry) item, imageLoader);
- } else if(viewType == VIEW_TYPE_SONG) {
- SongView songView = (SongView) view;
- songView.setObject((Entry) item, true);
- } else if(viewType == VIEW_TYPE_ARTIST) {
- view.setObject(item);
- }
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Serializable item, int viewType) {
+ UpdateView view = holder.getUpdateView();
+ if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) {
+ AlbumView albumView = (AlbumView) view;
+ albumView.setObject((Entry) item, imageLoader);
+ } else if(viewType == VIEW_TYPE_SONG) {
+ SongView songView = (SongView) view;
+ songView.setObject((Entry) item, true);
+ } else if(viewType == VIEW_TYPE_ARTIST) {
+ view.setObject(item);
+ }
+ }
- @Override
- public int getItemViewType(Serializable item) {
- if(item instanceof Entry) {
- Entry entry = (Entry) item;
- if (entry.isDirectory()) {
- if (largeAlbums) {
- return VIEW_TYPE_ALBUM_CELL;
- } else {
- return VIEW_TYPE_ALBUM_LINE;
- }
- } else {
- return VIEW_TYPE_SONG;
- }
- } else {
- return VIEW_TYPE_ARTIST;
- }
- }
+ @Override
+ public int getItemViewType(Serializable item) {
+ if(item instanceof Entry) {
+ Entry entry = (Entry) item;
+ if (entry.isDirectory()) {
+ if (largeAlbums) {
+ return VIEW_TYPE_ALBUM_CELL;
+ } else {
+ return VIEW_TYPE_ALBUM_LINE;
+ }
+ } else {
+ return VIEW_TYPE_SONG;
+ }
+ } else {
+ return VIEW_TYPE_ARTIST;
+ }
+ }
- @Override
- public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
- if(Util.isOffline(context)) {
- menuInflater.inflate(R.menu.multiselect_media_offline, menu);
- } else {
- menuInflater.inflate(R.menu.multiselect_media, menu);
- }
+ @Override
+ public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
+ if(Util.isOffline(context)) {
+ menuInflater.inflate(R.menu.multiselect_media_offline, menu);
+ } else {
+ menuInflater.inflate(R.menu.multiselect_media, menu);
+ }
- menu.removeItem(R.id.menu_remove_playlist);
- }
+ menu.removeItem(R.id.menu_remove_playlist);
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/SectionAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/SectionAdapter.java
index 2a99425..1a310b1 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/SectionAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/SectionAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2015 (C) Scott Jackson
+ 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 .
+ Copyright 2015 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -46,471 +46,471 @@ import net.nullsum.audinaut.view.UpdateView;
import net.nullsum.audinaut.view.UpdateView.UpdateViewHolder;
public abstract class SectionAdapter extends RecyclerView.Adapter> {
- private static String TAG = SectionAdapter.class.getSimpleName();
- public static int VIEW_TYPE_HEADER = 0;
- public static String[] ignoredArticles;
+ private static String TAG = SectionAdapter.class.getSimpleName();
+ public static int VIEW_TYPE_HEADER = 0;
+ public static String[] ignoredArticles;
- protected Context context;
- protected List headers;
- protected List> sections;
- protected boolean singleSectionHeader;
- protected OnItemClickedListener onItemClickedListener;
- protected List selected = new ArrayList<>();
- protected List selectedViews = new ArrayList<>();
- protected ActionMode currentActionMode;
- protected boolean checkable = false;
+ protected Context context;
+ protected List headers;
+ protected List> sections;
+ protected boolean singleSectionHeader;
+ protected OnItemClickedListener onItemClickedListener;
+ protected List selected = new ArrayList<>();
+ protected List selectedViews = new ArrayList<>();
+ protected ActionMode currentActionMode;
+ protected boolean checkable = false;
- protected SectionAdapter() {}
- public SectionAdapter(Context context, List section) {
- this(context, section, false);
- }
- public SectionAdapter(Context context, List section, boolean singleSectionHeader) {
- this.context = context;
- this.headers = Arrays.asList("Section");
- this.sections = new ArrayList<>();
- this.sections.add(section);
- this.singleSectionHeader = singleSectionHeader;
- }
- public SectionAdapter(Context context, List headers, List> sections) {
- this(context, headers, sections, true);
- }
- public SectionAdapter(Context context, List headers, List> sections, boolean singleSectionHeader){
- this.context = context;
- this.headers = headers;
- this.sections = sections;
- this.singleSectionHeader = singleSectionHeader;
- }
+ protected SectionAdapter() {}
+ public SectionAdapter(Context context, List section) {
+ this(context, section, false);
+ }
+ public SectionAdapter(Context context, List section, boolean singleSectionHeader) {
+ this.context = context;
+ this.headers = Arrays.asList("Section");
+ this.sections = new ArrayList<>();
+ this.sections.add(section);
+ this.singleSectionHeader = singleSectionHeader;
+ }
+ public SectionAdapter(Context context, List headers, List> sections) {
+ this(context, headers, sections, true);
+ }
+ public SectionAdapter(Context context, List headers, List> sections, boolean singleSectionHeader){
+ this.context = context;
+ this.headers = headers;
+ this.sections = sections;
+ this.singleSectionHeader = singleSectionHeader;
+ }
- public void replaceExistingData(List section) {
- this.sections = new ArrayList<>();
- this.sections.add(section);
- notifyDataSetChanged();
- }
- public void replaceExistingData(List headers, List> sections) {
- this.headers = headers;
- this.sections = sections;
- notifyDataSetChanged();
- }
+ public void replaceExistingData(List section) {
+ this.sections = new ArrayList<>();
+ this.sections.add(section);
+ notifyDataSetChanged();
+ }
+ public void replaceExistingData(List headers, List> sections) {
+ this.headers = headers;
+ this.sections = sections;
+ notifyDataSetChanged();
+ }
- @Override
- public UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- if(viewType == VIEW_TYPE_HEADER) {
- return onCreateHeaderHolder(parent);
- } else {
- final UpdateViewHolder holder = onCreateSectionViewHolder(parent, viewType);
- final UpdateView updateView = holder.getUpdateView();
+ @Override
+ public UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ if(viewType == VIEW_TYPE_HEADER) {
+ return onCreateHeaderHolder(parent);
+ } else {
+ final UpdateViewHolder holder = onCreateSectionViewHolder(parent, viewType);
+ final UpdateView updateView = holder.getUpdateView();
- if(updateView != null) {
- updateView.getChildAt(0).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- T item = holder.getItem();
- updateView.onClick();
- if (currentActionMode != null) {
- if(updateView.isCheckable()) {
- if (selected.contains(item)) {
- selected.remove(item);
- selectedViews.remove(updateView);
- setChecked(updateView, false);
- } else {
- selected.add(item);
- selectedViews.add(updateView);
- setChecked(updateView, true);
- }
+ if(updateView != null) {
+ updateView.getChildAt(0).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ T item = holder.getItem();
+ updateView.onClick();
+ if (currentActionMode != null) {
+ if(updateView.isCheckable()) {
+ if (selected.contains(item)) {
+ selected.remove(item);
+ selectedViews.remove(updateView);
+ setChecked(updateView, false);
+ } else {
+ selected.add(item);
+ selectedViews.add(updateView);
+ setChecked(updateView, true);
+ }
- if (selected.isEmpty()) {
- currentActionMode.finish();
- } else {
- currentActionMode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
- }
- }
- } else if (onItemClickedListener != null) {
- onItemClickedListener.onItemClicked(updateView, item);
- }
- }
- });
+ if (selected.isEmpty()) {
+ currentActionMode.finish();
+ } else {
+ currentActionMode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
+ }
+ }
+ } else if (onItemClickedListener != null) {
+ onItemClickedListener.onItemClicked(updateView, item);
+ }
+ }
+ });
- View moreButton = updateView.findViewById(R.id.item_more);
- if (moreButton != null) {
- moreButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- final T item = holder.getItem();
- if (onItemClickedListener != null) {
- PopupMenu popup = new PopupMenu(context, v);
- onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item);
+ View moreButton = updateView.findViewById(R.id.item_more);
+ if (moreButton != null) {
+ moreButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ final T item = holder.getItem();
+ if (onItemClickedListener != null) {
+ PopupMenu popup = new PopupMenu(context, v);
+ onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item);
- popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem menuItem) {
- return onItemClickedListener.onContextItemSelected(menuItem, updateView, item);
- }
- });
- popup.show();
- }
- } catch(Exception e) {
- Log.w(TAG, "Failed to show popup", e);
- }
- }
- });
+ popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem menuItem) {
+ return onItemClickedListener.onContextItemSelected(menuItem, updateView, item);
+ }
+ });
+ popup.show();
+ }
+ } catch(Exception e) {
+ Log.w(TAG, "Failed to show popup", e);
+ }
+ }
+ });
- if(checkable) {
- updateView.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- if(updateView.isCheckable()) {
- if (currentActionMode == null) {
- startActionMode(holder);
- } else {
- updateView.getChildAt(0).performClick();
- }
- }
- return true;
- }
- });
- }
- }
- }
+ if(checkable) {
+ updateView.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ if(updateView.isCheckable()) {
+ if (currentActionMode == null) {
+ startActionMode(holder);
+ } else {
+ updateView.getChildAt(0).performClick();
+ }
+ }
+ return true;
+ }
+ });
+ }
+ }
+ }
- return holder;
- }
- }
+ return holder;
+ }
+ }
- @Override
- public void onBindViewHolder(UpdateViewHolder holder, int position) {
- UpdateView updateView = holder.getUpdateView();
+ @Override
+ public void onBindViewHolder(UpdateViewHolder holder, int position) {
+ UpdateView updateView = holder.getUpdateView();
- if(sections.size() == 1 && !singleSectionHeader) {
- T item = sections.get(0).get(position);
- onBindViewHolder(holder, item, getItemViewType(position));
- postBindView(updateView, item);
- holder.setItem(item);
- return;
- }
+ if(sections.size() == 1 && !singleSectionHeader) {
+ T item = sections.get(0).get(position);
+ onBindViewHolder(holder, item, getItemViewType(position));
+ postBindView(updateView, item);
+ holder.setItem(item);
+ return;
+ }
- int subPosition = 0;
- int subHeader = 0;
- for(List section: sections) {
- boolean validHeader = headers.get(subHeader) != null;
- if(position == subPosition && validHeader) {
- onBindHeaderHolder(holder, headers.get(subHeader), subHeader);
- return;
- }
+ int subPosition = 0;
+ int subHeader = 0;
+ for(List section: sections) {
+ boolean validHeader = headers.get(subHeader) != null;
+ if(position == subPosition && validHeader) {
+ onBindHeaderHolder(holder, headers.get(subHeader), subHeader);
+ return;
+ }
- int headerOffset = validHeader ? 1 : 0;
- if(position < (subPosition + section.size() + headerOffset)) {
- T item = section.get(position - subPosition - headerOffset);
- onBindViewHolder(holder, item, getItemViewType(item));
+ int headerOffset = validHeader ? 1 : 0;
+ if(position < (subPosition + section.size() + headerOffset)) {
+ T item = section.get(position - subPosition - headerOffset);
+ onBindViewHolder(holder, item, getItemViewType(item));
- postBindView(updateView, item);
- holder.setItem(item);
- return;
- }
+ postBindView(updateView, item);
+ holder.setItem(item);
+ return;
+ }
- subPosition += section.size();
- if(validHeader) {
- subPosition += 1;
- }
- subHeader++;
- }
- }
+ subPosition += section.size();
+ if(validHeader) {
+ subPosition += 1;
+ }
+ subHeader++;
+ }
+ }
- private void postBindView(UpdateView updateView, T item) {
- if(updateView.isCheckable()) {
- setChecked(updateView, selected.contains(item));
- }
+ private void postBindView(UpdateView updateView, T item) {
+ if(updateView.isCheckable()) {
+ setChecked(updateView, selected.contains(item));
+ }
- View moreButton = updateView.findViewById(R.id.item_more);
- if(moreButton != null) {
- if(onItemClickedListener != null) {
- PopupMenu popup = new PopupMenu(context, moreButton);
- Menu menu = popup.getMenu();
- onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item);
- if (menu.size() == 0) {
- moreButton.setVisibility(View.GONE);
- } else {
- moreButton.setVisibility(View.VISIBLE);
- }
- } else {
- moreButton.setVisibility(View.VISIBLE);
- }
- }
- }
+ View moreButton = updateView.findViewById(R.id.item_more);
+ if(moreButton != null) {
+ if(onItemClickedListener != null) {
+ PopupMenu popup = new PopupMenu(context, moreButton);
+ Menu menu = popup.getMenu();
+ onItemClickedListener.onCreateContextMenu(popup.getMenu(), popup.getMenuInflater(), updateView, item);
+ if (menu.size() == 0) {
+ moreButton.setVisibility(View.GONE);
+ } else {
+ moreButton.setVisibility(View.VISIBLE);
+ }
+ } else {
+ moreButton.setVisibility(View.VISIBLE);
+ }
+ }
+ }
- @Override
- public int getItemCount() {
- if(sections.size() == 1 && !singleSectionHeader) {
- return sections.get(0).size();
- }
+ @Override
+ public int getItemCount() {
+ if(sections.size() == 1 && !singleSectionHeader) {
+ return sections.get(0).size();
+ }
- int count = 0;
- for(String header: headers) {
- if(header != null) {
- count++;
- }
- }
- for(List section: sections) {
- count += section.size();
- }
+ int count = 0;
+ for(String header: headers) {
+ if(header != null) {
+ count++;
+ }
+ }
+ for(List section: sections) {
+ count += section.size();
+ }
- return count;
- }
+ return count;
+ }
- @Override
- public int getItemViewType(int position) {
- if(sections.size() == 1 && !singleSectionHeader) {
- return getItemViewType(sections.get(0).get(position));
- }
+ @Override
+ public int getItemViewType(int position) {
+ if(sections.size() == 1 && !singleSectionHeader) {
+ return getItemViewType(sections.get(0).get(position));
+ }
- int subPosition = 0;
- int subHeader = 0;
- for(List section: sections) {
- boolean validHeader = headers.get(subHeader) != null;
- if(position == subPosition && validHeader) {
- return VIEW_TYPE_HEADER;
- }
+ int subPosition = 0;
+ int subHeader = 0;
+ for(List section: sections) {
+ boolean validHeader = headers.get(subHeader) != null;
+ if(position == subPosition && validHeader) {
+ return VIEW_TYPE_HEADER;
+ }
- int headerOffset = validHeader ? 1 : 0;
- if(position < (subPosition + section.size() + headerOffset)) {
- return getItemViewType(section.get(position - subPosition - headerOffset));
- }
+ int headerOffset = validHeader ? 1 : 0;
+ if(position < (subPosition + section.size() + headerOffset)) {
+ return getItemViewType(section.get(position - subPosition - headerOffset));
+ }
- subPosition += section.size();
- if(validHeader) {
- subPosition += 1;
- }
- subHeader++;
- }
+ subPosition += section.size();
+ if(validHeader) {
+ subPosition += 1;
+ }
+ subHeader++;
+ }
- return -1;
- }
+ return -1;
+ }
- public UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
- return new UpdateViewHolder(new BasicHeaderView(context));
- }
- public void onBindHeaderHolder(UpdateViewHolder holder, String header, int sectionIndex) {
- UpdateView view = holder.getUpdateView();
- if(view != null) {
- view.setObject(header);
- }
- }
+ public UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) {
+ return new UpdateViewHolder(new BasicHeaderView(context));
+ }
+ public void onBindHeaderHolder(UpdateViewHolder holder, String header, int sectionIndex) {
+ UpdateView view = holder.getUpdateView();
+ if(view != null) {
+ view.setObject(header);
+ }
+ }
- public T getItemForPosition(int position) {
- if(sections.size() == 1 && !singleSectionHeader) {
- return sections.get(0).get(position);
- }
+ public T getItemForPosition(int position) {
+ if(sections.size() == 1 && !singleSectionHeader) {
+ return sections.get(0).get(position);
+ }
- int subPosition = 0;
- for(List section: sections) {
- if(position == subPosition) {
- return null;
- }
+ int subPosition = 0;
+ for(List section: sections) {
+ if(position == subPosition) {
+ return null;
+ }
- if(position <= (subPosition + section.size())) {
- return section.get(position - subPosition - 1);
- }
+ if(position <= (subPosition + section.size())) {
+ return section.get(position - subPosition - 1);
+ }
- subPosition += section.size() + 1;
- }
+ subPosition += section.size() + 1;
+ }
- return null;
- }
- public int getItemPosition(T item) {
- if(sections.size() == 1 && !singleSectionHeader) {
- return sections.get(0).indexOf(item);
- }
+ return null;
+ }
+ public int getItemPosition(T item) {
+ if(sections.size() == 1 && !singleSectionHeader) {
+ return sections.get(0).indexOf(item);
+ }
- int subPosition = 0;
- for(List section: sections) {
- subPosition += section.size() + 1;
+ int subPosition = 0;
+ for(List section: sections) {
+ subPosition += section.size() + 1;
- int position = section.indexOf(item);
- if(position != -1) {
- return position + subPosition;
- }
- }
+ int position = section.indexOf(item);
+ if(position != -1) {
+ return position + subPosition;
+ }
+ }
- return -1;
- }
+ return -1;
+ }
- public void setOnItemClickedListener(OnItemClickedListener onItemClickedListener) {
- this.onItemClickedListener = onItemClickedListener;
- }
+ public void setOnItemClickedListener(OnItemClickedListener onItemClickedListener) {
+ this.onItemClickedListener = onItemClickedListener;
+ }
- public void addSelected(T item) {
- selected.add(item);
- }
- public List getSelected() {
- List selected = new ArrayList<>();
- selected.addAll(this.selected);
- return selected;
- }
+ public void addSelected(T item) {
+ selected.add(item);
+ }
+ public List getSelected() {
+ List selected = new ArrayList<>();
+ selected.addAll(this.selected);
+ return selected;
+ }
- public void clearSelected() {
- // TODO: This needs to work with multiple sections
- for(T item: selected) {
- int index = sections.get(0).indexOf(item);
+ public void clearSelected() {
+ // TODO: This needs to work with multiple sections
+ for(T item: selected) {
+ int index = sections.get(0).indexOf(item);
- if(singleSectionHeader) {
- index++;
- }
- }
- selected.clear();
+ if(singleSectionHeader) {
+ index++;
+ }
+ }
+ selected.clear();
- for(UpdateView updateView: selectedViews) {
- updateView.setChecked(false);
- }
- }
+ for(UpdateView updateView: selectedViews) {
+ updateView.setChecked(false);
+ }
+ }
- public void moveItem(int from, int to) {
- List section = sections.get(0);
- int max = section.size();
- if(to >= max) {
- to = max - 1;
- } else if(to < 0) {
- to = 0;
- }
+ public void moveItem(int from, int to) {
+ List section = sections.get(0);
+ int max = section.size();
+ if(to >= max) {
+ to = max - 1;
+ } else if(to < 0) {
+ to = 0;
+ }
- T moved = section.remove(from);
- section.add(to, moved);
+ T moved = section.remove(from);
+ section.add(to, moved);
- notifyItemMoved(from, to);
- }
- public void removeItem(T item) {
- int subPosition = 0;
- for(List section: sections) {
- if(sections.size() > 1 || singleSectionHeader) {
- subPosition++;
- }
+ notifyItemMoved(from, to);
+ }
+ public void removeItem(T item) {
+ int subPosition = 0;
+ for(List section: sections) {
+ if(sections.size() > 1 || singleSectionHeader) {
+ subPosition++;
+ }
- int index = section.indexOf(item);
- if (index != -1) {
- section.remove(item);
- notifyItemRemoved(subPosition + index);
- break;
- }
+ int index = section.indexOf(item);
+ if (index != -1) {
+ section.remove(item);
+ notifyItemRemoved(subPosition + index);
+ break;
+ }
- subPosition += section.size();
- }
- }
+ subPosition += section.size();
+ }
+ }
- public abstract UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType);
- public abstract void onBindViewHolder(UpdateViewHolder holder, T item, int viewType);
- public abstract int getItemViewType(T item);
- public void setCheckable(boolean checkable) {
- this.checkable = checkable;
- }
- public void setChecked(UpdateView updateView, boolean checked) {
- updateView.setChecked(checked);
- }
- public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {}
+ public abstract UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType);
+ public abstract void onBindViewHolder(UpdateViewHolder holder, T item, int viewType);
+ public abstract int getItemViewType(T item);
+ public void setCheckable(boolean checkable) {
+ this.checkable = checkable;
+ }
+ public void setChecked(UpdateView updateView, boolean checked) {
+ updateView.setChecked(checked);
+ }
+ public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {}
- private void startActionMode(final UpdateView.UpdateViewHolder holder) {
- final UpdateView updateView = holder.getUpdateView();
- if (context instanceof SubsonicFragmentActivity && currentActionMode == null) {
- final SubsonicFragmentActivity fragmentActivity = (SubsonicFragmentActivity) context;
- fragmentActivity.startSupportActionMode(new ActionMode.Callback() {
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- currentActionMode = mode;
+ private void startActionMode(final UpdateView.UpdateViewHolder holder) {
+ final UpdateView updateView = holder.getUpdateView();
+ if (context instanceof SubsonicFragmentActivity && currentActionMode == null) {
+ final SubsonicFragmentActivity fragmentActivity = (SubsonicFragmentActivity) context;
+ fragmentActivity.startSupportActionMode(new ActionMode.Callback() {
+ @Override
+ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ currentActionMode = mode;
- T item = holder.getItem();
- selected.add(item);
- selectedViews.add(updateView);
- setChecked(updateView, true);
+ T item = holder.getItem();
+ selected.add(item);
+ selectedViews.add(updateView);
+ setChecked(updateView, true);
- onCreateActionModeMenu(menu, mode.getMenuInflater());
- MenuUtil.hideMenuItems(context, menu, updateView);
+ onCreateActionModeMenu(menu, mode.getMenuInflater());
+ MenuUtil.hideMenuItems(context, menu, updateView);
- mode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
- TypedValue typedValue = new TypedValue();
- Resources.Theme theme = context.getTheme();
- theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
- int colorPrimaryDark = typedValue.data;
+ mode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
+ TypedValue typedValue = new TypedValue();
+ Resources.Theme theme = context.getTheme();
+ theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
+ int colorPrimaryDark = typedValue.data;
- Window window = ((SubsonicFragmentActivity) context).getWindow();
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- window.setStatusBarColor(colorPrimaryDark);
- }
- return true;
- }
+ Window window = ((SubsonicFragmentActivity) context).getWindow();
+ window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ window.setStatusBarColor(colorPrimaryDark);
+ }
+ return true;
+ }
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return false;
- }
+ @Override
+ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+ return false;
+ }
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- if (fragmentActivity.onOptionsItemSelected(item)) {
- currentActionMode.finish();
- return true;
- } else {
- return false;
- }
- }
+ @Override
+ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+ if (fragmentActivity.onOptionsItemSelected(item)) {
+ currentActionMode.finish();
+ return true;
+ } else {
+ return false;
+ }
+ }
- @Override
- public void onDestroyActionMode(ActionMode mode) {
- currentActionMode = null;
- selected.clear();
- for (UpdateView updateView : selectedViews) {
- updateView.setChecked(false);
- }
- selectedViews.clear();
+ @Override
+ public void onDestroyActionMode(ActionMode mode) {
+ currentActionMode = null;
+ selected.clear();
+ for (UpdateView updateView : selectedViews) {
+ updateView.setChecked(false);
+ }
+ selectedViews.clear();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
- Window window = ((SubsonicFragmentActivity) context).getWindow();
- window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- }
- }
- });
- }
- }
- public void stopActionMode() {
- if(currentActionMode != null) {
- currentActionMode.finish();
- }
- }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
+ Window window = ((SubsonicFragmentActivity) context).getWindow();
+ window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ }
+ }
+ });
+ }
+ }
+ public void stopActionMode() {
+ if(currentActionMode != null) {
+ currentActionMode.finish();
+ }
+ }
- public String getNameIndex(String name) {
- return getNameIndex(name, false);
- }
- public String getNameIndex(String name, boolean removeIgnoredArticles) {
- if(name == null) {
- return "*";
- }
+ public String getNameIndex(String name) {
+ return getNameIndex(name, false);
+ }
+ public String getNameIndex(String name, boolean removeIgnoredArticles) {
+ if(name == null) {
+ return "*";
+ }
- if(removeIgnoredArticles) {
- if (ignoredArticles == null) {
- SharedPreferences prefs = Util.getPreferences(context);
- String ignoredArticlesString = prefs.getString(Constants.CACHE_KEY_IGNORE, "The El La Los Las Le Les");
- ignoredArticles = ignoredArticlesString.split(" ");
- }
+ if(removeIgnoredArticles) {
+ if (ignoredArticles == null) {
+ SharedPreferences prefs = Util.getPreferences(context);
+ String ignoredArticlesString = prefs.getString(Constants.CACHE_KEY_IGNORE, "The El La Los Las Le Les");
+ ignoredArticles = ignoredArticlesString.split(" ");
+ }
- name = name.toLowerCase();
- for (String article : ignoredArticles) {
- int index = name.indexOf(article.toLowerCase() + " ");
- if (index == 0) {
- name = name.substring(article.length() + 1);
- }
- }
- }
+ name = name.toLowerCase();
+ for (String article : ignoredArticles) {
+ int index = name.indexOf(article.toLowerCase() + " ");
+ if (index == 0) {
+ name = name.substring(article.length() + 1);
+ }
+ }
+ }
- String index = name.substring(0, 1).toUpperCase();
- if (!Character.isLetter(index.charAt(0))) {
- index = "#";
- }
+ String index = name.substring(0, 1).toUpperCase();
+ if (!Character.isLetter(index.charAt(0))) {
+ index = "#";
+ }
- return index;
- }
+ return index;
+ }
- public interface OnItemClickedListener {
- void onItemClicked(UpdateView updateView, T item);
- void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView updateView, T item);
- boolean onContextItemSelected(MenuItem menuItem, UpdateView updateView, T item);
- }
+ public interface OnItemClickedListener {
+ void onItemClicked(UpdateView updateView, T item);
+ void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView updateView, T item);
+ boolean onContextItemSelected(MenuItem menuItem, UpdateView updateView, T item);
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/SettingsAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/SettingsAdapter.java
index 5d0764e..4cf06cf 100644
--- a/app/src/main/java/net/nullsum/audinaut/adapter/SettingsAdapter.java
+++ b/app/src/main/java/net/nullsum/audinaut/adapter/SettingsAdapter.java
@@ -1,16 +1,16 @@
/*
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 .
- Copyright 2014 (C) Scott Jackson
+ 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 .
+ Copyright 2014 (C) Scott Jackson
*/
package net.nullsum.audinaut.adapter;
@@ -36,86 +36,86 @@ import net.nullsum.audinaut.view.UpdateView;
import static net.nullsum.audinaut.domain.User.Setting;
public class SettingsAdapter extends SectionAdapter {
- private static final String TAG = SettingsAdapter.class.getSimpleName();
- public final int VIEW_TYPE_SETTING = 1;
- public final int VIEW_TYPE_SETTING_HEADER = 2;
+ private static final String TAG = SettingsAdapter.class.getSimpleName();
+ public final int VIEW_TYPE_SETTING = 1;
+ public final int VIEW_TYPE_SETTING_HEADER = 2;
- private final User user;
- private final boolean editable;
- private final ImageLoader imageLoader;
+ private final User user;
+ private final boolean editable;
+ private final ImageLoader imageLoader;
- public SettingsAdapter(Context context, User user, List headers, List> settingSections, ImageLoader imageLoader, boolean editable, OnItemClickedListener onItemClickedListener) {
- super(context, headers, settingSections, imageLoader != null);
- this.user = user;
- this.imageLoader = imageLoader;
- this.editable = editable;
- this.onItemClickedListener = onItemClickedListener;
+ public SettingsAdapter(Context context, User user, List headers, List> settingSections, ImageLoader imageLoader, boolean editable, OnItemClickedListener onItemClickedListener) {
+ super(context, headers, settingSections, imageLoader != null);
+ this.user = user;
+ this.imageLoader = imageLoader;
+ this.editable = editable;
+ this.onItemClickedListener = onItemClickedListener;
- for(List settings: sections) {
- for (Setting setting : settings) {
- if (setting.getValue()) {
- addSelected(setting);
- }
- }
- }
- }
+ for(List settings: sections) {
+ for (Setting setting : settings) {
+ if (setting.getValue()) {
+ addSelected(setting);
+ }
+ }
+ }
+ }
- @Override
- public int getItemViewType(int position) {
- int viewType = super.getItemViewType(position);
- if(viewType == SectionAdapter.VIEW_TYPE_HEADER) {
- if(position == 0 && imageLoader != null) {
- return VIEW_TYPE_HEADER;
- } else {
- return VIEW_TYPE_SETTING_HEADER;
- }
- } else {
- return viewType;
- }
- }
+ @Override
+ public int getItemViewType(int position) {
+ int viewType = super.getItemViewType(position);
+ if(viewType == SectionAdapter.VIEW_TYPE_HEADER) {
+ if(position == 0 && imageLoader != null) {
+ return VIEW_TYPE_HEADER;
+ } else {
+ return VIEW_TYPE_SETTING_HEADER;
+ }
+ } else {
+ return viewType;
+ }
+ }
- public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String description, int sectionIndex) {
- View header = holder.getView();
- }
+ public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String description, int sectionIndex) {
+ View header = holder.getView();
+ }
- @Override
- public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
- if(viewType == VIEW_TYPE_SETTING_HEADER) {
- return new UpdateView.UpdateViewHolder(new BasicHeaderView(context));
- } else {
- return new UpdateView.UpdateViewHolder(new SettingView(context));
- }
- }
+ @Override
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ if(viewType == VIEW_TYPE_SETTING_HEADER) {
+ return new UpdateView.UpdateViewHolder(new BasicHeaderView(context));
+ } else {
+ return new UpdateView.UpdateViewHolder(new SettingView(context));
+ }
+ }
- @Override
- public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Setting item, int viewType) {
- holder.getUpdateView().setObject(item, editable);
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Setting item, int viewType) {
+ holder.getUpdateView().setObject(item, editable);
+ }
- @Override
- public int getItemViewType(Setting item) {
- return VIEW_TYPE_SETTING;
- }
+ @Override
+ public int getItemViewType(Setting item) {
+ return VIEW_TYPE_SETTING;
+ }
- @Override
- public void setChecked(UpdateView updateView, boolean checked) {
- if(updateView instanceof SettingView) {
- updateView.setChecked(checked);
- }
- }
+ @Override
+ public void setChecked(UpdateView updateView, boolean checked) {
+ if(updateView instanceof SettingView) {
+ updateView.setChecked(checked);
+ }
+ }
- public static SettingsAdapter getSettingsAdapter(Context context, User user, ImageLoader imageLoader, OnItemClickedListener onItemClickedListener) {
- return getSettingsAdapter(context, user, imageLoader, true, onItemClickedListener);
- }
- public static SettingsAdapter getSettingsAdapter(Context context, User user, ImageLoader imageLoader, boolean isEditable, OnItemClickedListener onItemClickedListener) {
- List headers = new ArrayList<>();
- List> settingsSections = new ArrayList<>();
- settingsSections.add(user.getSettings());
+ public static SettingsAdapter getSettingsAdapter(Context context, User user, ImageLoader imageLoader, OnItemClickedListener onItemClickedListener) {
+ return getSettingsAdapter(context, user, imageLoader, true, onItemClickedListener);
+ }
+ public static SettingsAdapter getSettingsAdapter(Context context, User user, ImageLoader imageLoader, boolean isEditable, OnItemClickedListener onItemClickedListener) {
+ List headers = new ArrayList<>();
+ List> settingsSections = new ArrayList<>();
+ settingsSections.add(user.getSettings());
- if(user.getMusicFolderSettings() != null) {
- settingsSections.add(user.getMusicFolderSettings());
- }
+ if(user.getMusicFolderSettings() != null) {
+ settingsSections.add(user.getMusicFolderSettings());
+ }
- return new SettingsAdapter(context, user, headers, settingsSections, imageLoader, isEditable, onItemClickedListener);
- }
+ return new SettingsAdapter(context, user, headers, settingsSections, imageLoader, isEditable, onItemClickedListener);
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/audiofx/AudioEffectsController.java b/app/src/main/java/net/nullsum/audinaut/audiofx/AudioEffectsController.java
index a63eed7..6549538 100644
--- a/app/src/main/java/net/nullsum/audinaut/audiofx/AudioEffectsController.java
+++ b/app/src/main/java/net/nullsum/audinaut/audiofx/AudioEffectsController.java
@@ -29,27 +29,27 @@ public class AudioEffectsController {
private static final String TAG = AudioEffectsController.class.getSimpleName();
private final Context context;
- private int audioSessionId = 0;
+ private int audioSessionId = 0;
- private EqualizerController equalizerController;
+ private EqualizerController equalizerController;
public AudioEffectsController(Context context, int audioSessionId) {
this.context = context;
- this.audioSessionId = audioSessionId;
+ this.audioSessionId = audioSessionId;
}
- public void release() {
- if(equalizerController != null) {
- equalizerController.release();
- }
- }
+ public void release() {
+ if(equalizerController != null) {
+ equalizerController.release();
+ }
+ }
- public EqualizerController getEqualizerController() {
- if (equalizerController == null) {
- equalizerController = new EqualizerController(context, audioSessionId);
+ public EqualizerController getEqualizerController() {
+ if (equalizerController == null) {
+ equalizerController = new EqualizerController(context, audioSessionId);
equalizerController.loadSettings();
- }
- return equalizerController;
- }
+ }
+ return equalizerController;
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/audiofx/LoudnessEnhancerController.java b/app/src/main/java/net/nullsum/audinaut/audiofx/LoudnessEnhancerController.java
index c0b299c..3e67334 100644
--- a/app/src/main/java/net/nullsum/audinaut/audiofx/LoudnessEnhancerController.java
+++ b/app/src/main/java/net/nullsum/audinaut/audiofx/LoudnessEnhancerController.java
@@ -1,20 +1,20 @@
/*
- This file is part of Subsonic.
+ 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 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.
+ 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 .
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see .
- Copyright 2014 (C) Scott Jackson
+ Copyright 2014 (C) Scott Jackson
*/
package net.nullsum.audinaut.audiofx;
@@ -23,55 +23,55 @@ import android.media.audiofx.LoudnessEnhancer;
import android.util.Log;
public class LoudnessEnhancerController {
- private static final String TAG = LoudnessEnhancerController.class.getSimpleName();
+ private static final String TAG = LoudnessEnhancerController.class.getSimpleName();
- private final Context context;
- private LoudnessEnhancer enhancer;
- private boolean released = false;
- private int audioSessionId = 0;
+ private final Context context;
+ private LoudnessEnhancer enhancer;
+ private boolean released = false;
+ private int audioSessionId = 0;
- public LoudnessEnhancerController(Context context, int audioSessionId) {
- this.context = context;
- try {
- this.audioSessionId = audioSessionId;
- enhancer = new LoudnessEnhancer(audioSessionId);
- } catch (Throwable x) {
- Log.w(TAG, "Failed to create enhancer", x);
- }
- }
+ public LoudnessEnhancerController(Context context, int audioSessionId) {
+ this.context = context;
+ try {
+ this.audioSessionId = audioSessionId;
+ enhancer = new LoudnessEnhancer(audioSessionId);
+ } catch (Throwable x) {
+ Log.w(TAG, "Failed to create enhancer", x);
+ }
+ }
- public boolean isAvailable() {
- return enhancer != null;
- }
+ public boolean isAvailable() {
+ return enhancer != null;
+ }
- public boolean isEnabled() {
- try {
- return isAvailable() && enhancer.getEnabled();
- } catch(Exception e) {
- return false;
- }
- }
+ public boolean isEnabled() {
+ try {
+ return isAvailable() && enhancer.getEnabled();
+ } catch(Exception e) {
+ return false;
+ }
+ }
- public void enable() {
- enhancer.setEnabled(true);
- }
- public void disable() {
- enhancer.setEnabled(false);
- }
+ public void enable() {
+ enhancer.setEnabled(true);
+ }
+ public void disable() {
+ enhancer.setEnabled(false);
+ }
- public float getGain() {
- return enhancer.getTargetGain();
- }
- public void setGain(int gain) {
- enhancer.setTargetGain(gain);
- }
+ public float getGain() {
+ return enhancer.getTargetGain();
+ }
+ public void setGain(int gain) {
+ enhancer.setTargetGain(gain);
+ }
- public void release() {
- if (isAvailable()) {
- enhancer.release();
- released = true;
- }
- }
+ public void release() {
+ if (isAvailable()) {
+ enhancer.release();
+ released = true;
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/domain/MusicDirectory.java b/app/src/main/java/net/nullsum/audinaut/domain/MusicDirectory.java
index acc4adc..61d9512 100644
--- a/app/src/main/java/net/nullsum/audinaut/domain/MusicDirectory.java
+++ b/app/src/main/java/net/nullsum/audinaut/domain/MusicDirectory.java
@@ -43,19 +43,19 @@ import net.nullsum.audinaut.util.Util;
* @author Sindre Mehus
*/
public class MusicDirectory implements Serializable {
- private static final String TAG = MusicDirectory.class.getSimpleName();
+ private static final String TAG = MusicDirectory.class.getSimpleName();
private String name;
- private String id;
- private String parent;
+ private String id;
+ private String parent;
private List children;
- public MusicDirectory() {
- children = new ArrayList();
- }
- public MusicDirectory(List children) {
- this.children = children;
- }
+ public MusicDirectory() {
+ children = new ArrayList();
+ }
+ public MusicDirectory(List children) {
+ this.children = children;
+ }
public String getName() {
return name;
@@ -64,35 +64,35 @@ public class MusicDirectory implements Serializable {
public void setName(String name) {
this.name = name;
}
-
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
-
- public String getParent() {
- return parent;
- }
+ public String getId() {
+ return id;
+ }
- public void setParent(String parent) {
- this.parent = parent;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public void addChild(Entry child) {
- if(child != null) {
- children.add(child);
- }
- }
- public void addChildren(List children) {
- this.children.addAll(children);
- }
-
- public void replaceChildren(List children) {
- this.children = children;
- }
+ public String getParent() {
+ return parent;
+ }
+
+ public void setParent(String parent) {
+ this.parent = parent;
+ }
+
+ public void addChild(Entry child) {
+ if(child != null) {
+ children.add(child);
+ }
+ }
+ public void addChildren(List children) {
+ this.children.addAll(children);
+ }
+
+ public void replaceChildren(List children) {
+ this.children = children;
+ }
public synchronized List getChildren() {
return getChildren(true, true);
@@ -111,209 +111,209 @@ public class MusicDirectory implements Serializable {
}
return result;
}
- public synchronized List getSongs() {
- List result = new ArrayList();
- for (Entry child : children) {
- if (child != null && !child.isDirectory()) {
- result.add(child);
- }
- }
- return result;
- }
-
- public synchronized int getChildrenSize() {
- return children.size();
- }
+ public synchronized List getSongs() {
+ List result = new ArrayList();
+ for (Entry child : children) {
+ if (child != null && !child.isDirectory()) {
+ result.add(child);
+ }
+ }
+ return result;
+ }
- public void shuffleChildren() {
- Collections.shuffle(this.children);
- }
-
- public void sortChildren(Context context, int instance) {
+ public synchronized int getChildrenSize() {
+ return children.size();
+ }
+
+ public void shuffleChildren() {
+ Collections.shuffle(this.children);
+ }
+
+ public void sortChildren(Context context, int instance) {
sortChildren(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true));
- }
- public void sortChildren(boolean byYear) {
- EntryComparator.sort(children, byYear);
- }
+ }
+ public void sortChildren(boolean byYear) {
+ EntryComparator.sort(children, byYear);
+ }
- public synchronized boolean updateMetadata(MusicDirectory refreshedDirectory) {
- boolean metadataUpdated = false;
- Iterator it = children.iterator();
- while(it.hasNext()) {
- Entry entry = it.next();
- int index = refreshedDirectory.children.indexOf(entry);
- if(index != -1) {
- final Entry refreshed = refreshedDirectory.children.get(index);
+ public synchronized boolean updateMetadata(MusicDirectory refreshedDirectory) {
+ boolean metadataUpdated = false;
+ Iterator it = children.iterator();
+ while(it.hasNext()) {
+ Entry entry = it.next();
+ int index = refreshedDirectory.children.indexOf(entry);
+ if(index != -1) {
+ final Entry refreshed = refreshedDirectory.children.get(index);
- entry.setTitle(refreshed.getTitle());
- entry.setAlbum(refreshed.getAlbum());
- entry.setArtist(refreshed.getArtist());
- entry.setTrack(refreshed.getTrack());
- entry.setYear(refreshed.getYear());
- entry.setGenre(refreshed.getGenre());
- entry.setTranscodedContentType(refreshed.getTranscodedContentType());
- entry.setTranscodedSuffix(refreshed.getTranscodedSuffix());
- entry.setDiscNumber(refreshed.getDiscNumber());
- entry.setType(refreshed.getType());
- if(!Util.equals(entry.getCoverArt(), refreshed.getCoverArt())) {
- metadataUpdated = true;
- entry.setCoverArt(refreshed.getCoverArt());
- }
+ entry.setTitle(refreshed.getTitle());
+ entry.setAlbum(refreshed.getAlbum());
+ entry.setArtist(refreshed.getArtist());
+ entry.setTrack(refreshed.getTrack());
+ entry.setYear(refreshed.getYear());
+ entry.setGenre(refreshed.getGenre());
+ entry.setTranscodedContentType(refreshed.getTranscodedContentType());
+ entry.setTranscodedSuffix(refreshed.getTranscodedSuffix());
+ entry.setDiscNumber(refreshed.getDiscNumber());
+ entry.setType(refreshed.getType());
+ if(!Util.equals(entry.getCoverArt(), refreshed.getCoverArt())) {
+ metadataUpdated = true;
+ entry.setCoverArt(refreshed.getCoverArt());
+ }
- new UpdateHelper.EntryInstanceUpdater(entry) {
- @Override
- public void update(Entry found) {
- found.setTitle(refreshed.getTitle());
- found.setAlbum(refreshed.getAlbum());
- found.setArtist(refreshed.getArtist());
- found.setTrack(refreshed.getTrack());
- found.setYear(refreshed.getYear());
- found.setGenre(refreshed.getGenre());
- found.setTranscodedContentType(refreshed.getTranscodedContentType());
- found.setTranscodedSuffix(refreshed.getTranscodedSuffix());
- found.setDiscNumber(refreshed.getDiscNumber());
- found.setType(refreshed.getType());
- if(!Util.equals(found.getCoverArt(), refreshed.getCoverArt())) {
- found.setCoverArt(refreshed.getCoverArt());
- metadataUpdate = DownloadService.METADATA_UPDATED_COVER_ART;
- }
- }
- }.execute();
- }
- }
+ new UpdateHelper.EntryInstanceUpdater(entry) {
+ @Override
+ public void update(Entry found) {
+ found.setTitle(refreshed.getTitle());
+ found.setAlbum(refreshed.getAlbum());
+ found.setArtist(refreshed.getArtist());
+ found.setTrack(refreshed.getTrack());
+ found.setYear(refreshed.getYear());
+ found.setGenre(refreshed.getGenre());
+ found.setTranscodedContentType(refreshed.getTranscodedContentType());
+ found.setTranscodedSuffix(refreshed.getTranscodedSuffix());
+ found.setDiscNumber(refreshed.getDiscNumber());
+ found.setType(refreshed.getType());
+ if(!Util.equals(found.getCoverArt(), refreshed.getCoverArt())) {
+ found.setCoverArt(refreshed.getCoverArt());
+ metadataUpdate = DownloadService.METADATA_UPDATED_COVER_ART;
+ }
+ }
+ }.execute();
+ }
+ }
- return metadataUpdated;
- }
- public synchronized boolean updateEntriesList(Context context, int instance, MusicDirectory refreshedDirectory) {
- boolean changed = false;
- Iterator it = children.iterator();
- while(it.hasNext()) {
- Entry entry = it.next();
- // No longer exists in here
- if(refreshedDirectory.children.indexOf(entry) == -1) {
- it.remove();
- changed = true;
- }
- }
+ return metadataUpdated;
+ }
+ public synchronized boolean updateEntriesList(Context context, int instance, MusicDirectory refreshedDirectory) {
+ boolean changed = false;
+ Iterator it = children.iterator();
+ while(it.hasNext()) {
+ Entry entry = it.next();
+ // No longer exists in here
+ if(refreshedDirectory.children.indexOf(entry) == -1) {
+ it.remove();
+ changed = true;
+ }
+ }
- // Make sure we contain all children from refreshed set
- boolean resort = false;
- for(Entry refreshed: refreshedDirectory.children) {
- if(!this.children.contains(refreshed)) {
- this.children.add(refreshed);
- resort = true;
- changed = true;
- }
- }
+ // Make sure we contain all children from refreshed set
+ boolean resort = false;
+ for(Entry refreshed: refreshedDirectory.children) {
+ if(!this.children.contains(refreshed)) {
+ this.children.add(refreshed);
+ resort = true;
+ changed = true;
+ }
+ }
- if(resort) {
- this.sortChildren(context, instance);
- }
+ if(resort) {
+ this.sortChildren(context, instance);
+ }
- return changed;
- }
+ return changed;
+ }
public static class Entry implements Serializable {
- public static final int TYPE_SONG = 0;
+ public static final int TYPE_SONG = 0;
- private String id;
- private String parent;
- private String grandParent;
- private String albumId;
- private String artistId;
- private boolean directory;
- private String title;
- private String album;
- private String artist;
- private Integer track;
- private Integer year;
- private String genre;
- private String contentType;
- private String suffix;
- private String transcodedContentType;
- private String transcodedSuffix;
- private String coverArt;
- private Long size;
- private Integer duration;
- private Integer bitRate;
- private String path;
- private Integer discNumber;
- private int type = 0;
- private int closeness;
- private transient Artist linkedArtist;
+ private String id;
+ private String parent;
+ private String grandParent;
+ private String albumId;
+ private String artistId;
+ private boolean directory;
+ private String title;
+ private String album;
+ private String artist;
+ private Integer track;
+ private Integer year;
+ private String genre;
+ private String contentType;
+ private String suffix;
+ private String transcodedContentType;
+ private String transcodedSuffix;
+ private String coverArt;
+ private Long size;
+ private Integer duration;
+ private Integer bitRate;
+ private String path;
+ private Integer discNumber;
+ private int type = 0;
+ private int closeness;
+ private transient Artist linkedArtist;
- public Entry() {
+ public Entry() {
- }
- public Entry(String id) {
- this.id = id;
- }
- public Entry(Artist artist) {
- this.id = artist.getId();
- this.title = artist.getName();
- this.directory = true;
- this.linkedArtist = artist;
- }
-
- public void loadMetadata(File file) {
- try {
- MediaMetadataRetriever metadata = new MediaMetadataRetriever();
- metadata.setDataSource(file.getAbsolutePath());
- String discNumber = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER);
- if(discNumber == null) {
- discNumber = "1/1";
- }
- int slashIndex = discNumber.indexOf("/");
- if(slashIndex > 0) {
- discNumber = discNumber.substring(0, slashIndex);
- }
- try {
- setDiscNumber(Integer.parseInt(discNumber));
- } catch(Exception e) {
- Log.w(TAG, "Non numbers in disc field!");
- }
- String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
- setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000);
- String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
- setDuration(Integer.parseInt(length) / 1000);
- String artist = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
- if(artist != null) {
- setArtist(artist);
- }
- String album = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
- if(album != null) {
- setAlbum(album);
- }
- metadata.release();
- } catch(Exception e) {
- Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver", e);
- }
- }
- public void rebaseTitleOffPath() {
- try {
- String filename = getPath();
- if(filename == null) {
- return;
- }
+ }
+ public Entry(String id) {
+ this.id = id;
+ }
+ public Entry(Artist artist) {
+ this.id = artist.getId();
+ this.title = artist.getName();
+ this.directory = true;
+ this.linkedArtist = artist;
+ }
- int index = filename.lastIndexOf('/');
- if (index != -1) {
- filename = filename.substring(index + 1);
- if (getTrack() != null) {
- filename = filename.replace(String.format("%02d ", getTrack()), "");
- }
+ public void loadMetadata(File file) {
+ try {
+ MediaMetadataRetriever metadata = new MediaMetadataRetriever();
+ metadata.setDataSource(file.getAbsolutePath());
+ String discNumber = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER);
+ if(discNumber == null) {
+ discNumber = "1/1";
+ }
+ int slashIndex = discNumber.indexOf("/");
+ if(slashIndex > 0) {
+ discNumber = discNumber.substring(0, slashIndex);
+ }
+ try {
+ setDiscNumber(Integer.parseInt(discNumber));
+ } catch(Exception e) {
+ Log.w(TAG, "Non numbers in disc field!");
+ }
+ String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
+ setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000);
+ String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
+ setDuration(Integer.parseInt(length) / 1000);
+ String artist = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
+ if(artist != null) {
+ setArtist(artist);
+ }
+ String album = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
+ if(album != null) {
+ setAlbum(album);
+ }
+ metadata.release();
+ } catch(Exception e) {
+ Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver", e);
+ }
+ }
+ public void rebaseTitleOffPath() {
+ try {
+ String filename = getPath();
+ if(filename == null) {
+ return;
+ }
- index = filename.lastIndexOf('.');
- if(index != -1) {
- filename = filename.substring(0, index);
- }
+ int index = filename.lastIndexOf('/');
+ if (index != -1) {
+ filename = filename.substring(index + 1);
+ if (getTrack() != null) {
+ filename = filename.replace(String.format("%02d ", getTrack()), "");
+ }
- setTitle(filename);
- }
- } catch(Exception e) {
- Log.w(TAG, "Failed to update title based off of path", e);
- }
- }
+ index = filename.lastIndexOf('.');
+ if(index != -1) {
+ filename = filename.substring(0, index);
+ }
+
+ setTitle(filename);
+ }
+ } catch(Exception e) {
+ Log.w(TAG, "Failed to update title based off of path", e);
+ }
+ }
public String getId() {
return id;
@@ -330,8 +330,8 @@ public class MusicDirectory implements Serializable {
public void setParent(String parent) {
this.parent = parent;
}
-
- public String getGrandParent() {
+
+ public String getGrandParent() {
return grandParent;
}
@@ -339,21 +339,21 @@ public class MusicDirectory implements Serializable {
this.grandParent = grandParent;
}
- public String getAlbumId() {
- return albumId;
- }
+ public String getAlbumId() {
+ return albumId;
+ }
- public void setAlbumId(String albumId) {
- this.albumId = albumId;
- }
+ public void setAlbumId(String albumId) {
+ this.albumId = albumId;
+ }
- public String getArtistId() {
- return artistId;
- }
+ public String getArtistId() {
+ return artistId;
+ }
- public void setArtistId(String artistId) {
- this.artistId = artistId;
- }
+ public void setArtistId(String artistId) {
+ this.artistId = artistId;
+ }
public boolean isDirectory() {
return directory;
@@ -375,17 +375,17 @@ public class MusicDirectory implements Serializable {
return album;
}
- public boolean isAlbum() {
- return getParent() != null || getArtist() != null;
- }
+ public boolean isAlbum() {
+ return getParent() != null || getArtist() != null;
+ }
- public String getAlbumDisplay() {
- if(album != null && title.startsWith("Disc ")) {
- return album;
- } else {
- return title;
- }
- }
+ public String getAlbumDisplay() {
+ if(album != null && title.startsWith("Disc ")) {
+ return album;
+ } else {
+ return title;
+ }
+ }
public void setAlbum(String album) {
this.album = album;
@@ -495,43 +495,43 @@ public class MusicDirectory implements Serializable {
this.path = path;
}
- public Integer getDiscNumber() {
- return discNumber;
- }
-
- public void setDiscNumber(Integer discNumber) {
- this.discNumber = discNumber;
- }
-
- public int getType() {
- return type;
- }
- public void setType(int type) {
- this.type = type;
- }
- public boolean isSong() {
- return type == TYPE_SONG;
- }
+ public Integer getDiscNumber() {
+ return discNumber;
+ }
- public int getCloseness() {
- return closeness;
- }
+ public void setDiscNumber(Integer discNumber) {
+ this.discNumber = discNumber;
+ }
- public void setCloseness(int closeness) {
- this.closeness = closeness;
- }
+ public int getType() {
+ return type;
+ }
+ public void setType(int type) {
+ this.type = type;
+ }
+ public boolean isSong() {
+ return type == TYPE_SONG;
+ }
- public boolean isOnlineId(Context context) {
- try {
- String cacheLocation = Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
- return cacheLocation == null || id == null || id.indexOf(cacheLocation) == -1;
- } catch(Exception e) {
- Log.w(TAG, "Failed to check online id validity");
+ public int getCloseness() {
+ return closeness;
+ }
- // Err on the side of default functionality
- return true;
- }
- }
+ public void setCloseness(int closeness) {
+ this.closeness = closeness;
+ }
+
+ public boolean isOnlineId(Context context) {
+ try {
+ String cacheLocation = Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
+ return cacheLocation == null || id == null || id.indexOf(cacheLocation) == -1;
+ } catch(Exception e) {
+ Log.w(TAG, "Failed to check online id validity");
+
+ // Err on the side of default functionality
+ return true;
+ }
+ }
@Override
public boolean equals(Object o) {
@@ -555,72 +555,72 @@ public class MusicDirectory implements Serializable {
public String toString() {
return title;
}
- }
-
- public static class EntryComparator implements Comparator {
- private boolean byYear;
- private Collator collator;
-
- public EntryComparator(boolean byYear) {
- this.byYear = byYear;
- this.collator = Collator.getInstance(Locale.US);
- this.collator.setStrength(Collator.PRIMARY);
- }
-
- public int compare(Entry lhs, Entry rhs) {
- if(lhs.isDirectory() && !rhs.isDirectory()) {
- return -1;
- } else if(!lhs.isDirectory() && rhs.isDirectory()) {
- return 1;
- } else if(lhs.isDirectory() && rhs.isDirectory()) {
- if(byYear) {
- Integer lhsYear = lhs.getYear();
- Integer rhsYear = rhs.getYear();
- if(lhsYear != null && rhsYear != null) {
- return lhsYear.compareTo(rhsYear);
- } else if(lhsYear != null) {
- return -1;
- } else if(rhsYear != null) {
- return 1;
- }
- }
+ }
- return collator.compare(lhs.getAlbumDisplay(), rhs.getAlbumDisplay());
- }
-
- Integer lhsDisc = lhs.getDiscNumber();
- Integer rhsDisc = rhs.getDiscNumber();
-
- if(lhsDisc != null && rhsDisc != null) {
- if(lhsDisc < rhsDisc) {
- return -1;
- } else if(lhsDisc > rhsDisc) {
- return 1;
- }
- }
-
- Integer lhsTrack = lhs.getTrack();
- Integer rhsTrack = rhs.getTrack();
- if(lhsTrack != null && rhsTrack != null && lhsTrack != rhsTrack) {
- return lhsTrack.compareTo(rhsTrack);
- } else if(lhsTrack != null) {
- return -1;
- } else if(rhsTrack != null) {
- return 1;
- }
+ public static class EntryComparator implements Comparator {
+ private boolean byYear;
+ private Collator collator;
- return collator.compare(lhs.getTitle(), rhs.getTitle());
- }
-
- public static void sort(List entries) {
- sort(entries, true);
- }
- public static void sort(List entries, boolean byYear) {
- try {
- Collections.sort(entries, new EntryComparator(byYear));
- } catch (Exception e) {
- Log.w(TAG, "Failed to sort MusicDirectory");
- }
- }
- }
+ public EntryComparator(boolean byYear) {
+ this.byYear = byYear;
+ this.collator = Collator.getInstance(Locale.US);
+ this.collator.setStrength(Collator.PRIMARY);
+ }
+
+ public int compare(Entry lhs, Entry rhs) {
+ if(lhs.isDirectory() && !rhs.isDirectory()) {
+ return -1;
+ } else if(!lhs.isDirectory() && rhs.isDirectory()) {
+ return 1;
+ } else if(lhs.isDirectory() && rhs.isDirectory()) {
+ if(byYear) {
+ Integer lhsYear = lhs.getYear();
+ Integer rhsYear = rhs.getYear();
+ if(lhsYear != null && rhsYear != null) {
+ return lhsYear.compareTo(rhsYear);
+ } else if(lhsYear != null) {
+ return -1;
+ } else if(rhsYear != null) {
+ return 1;
+ }
+ }
+
+ return collator.compare(lhs.getAlbumDisplay(), rhs.getAlbumDisplay());
+ }
+
+ Integer lhsDisc = lhs.getDiscNumber();
+ Integer rhsDisc = rhs.getDiscNumber();
+
+ if(lhsDisc != null && rhsDisc != null) {
+ if(lhsDisc < rhsDisc) {
+ return -1;
+ } else if(lhsDisc > rhsDisc) {
+ return 1;
+ }
+ }
+
+ Integer lhsTrack = lhs.getTrack();
+ Integer rhsTrack = rhs.getTrack();
+ if(lhsTrack != null && rhsTrack != null && lhsTrack != rhsTrack) {
+ return lhsTrack.compareTo(rhsTrack);
+ } else if(lhsTrack != null) {
+ return -1;
+ } else if(rhsTrack != null) {
+ return 1;
+ }
+
+ return collator.compare(lhs.getTitle(), rhs.getTitle());
+ }
+
+ public static void sort(List entries) {
+ sort(entries, true);
+ }
+ public static void sort(List entries, boolean byYear) {
+ try {
+ Collections.sort(entries, new EntryComparator(byYear));
+ } catch (Exception e) {
+ Log.w(TAG, "Failed to sort MusicDirectory");
+ }
+ }
+ }
}
diff --git a/app/src/main/java/net/nullsum/audinaut/domain/MusicFolder.java b/app/src/main/java/net/nullsum/audinaut/domain/MusicFolder.java
index 8bc2a5f..0524b6e 100644
--- a/app/src/main/java/net/nullsum/audinaut/domain/MusicFolder.java
+++ b/app/src/main/java/net/nullsum/audinaut/domain/MusicFolder.java
@@ -32,49 +32,49 @@ import java.util.List;
* @version $Id$
*/
public class MusicFolder implements Serializable {
- private static final String TAG = MusicFolder.class.getSimpleName();
- private String id;
- private String name;
- private boolean enabled;
+ private static final String TAG = MusicFolder.class.getSimpleName();
+ private String id;
+ private String name;
+ private boolean enabled;
- public MusicFolder() {
+ public MusicFolder() {
- }
- public MusicFolder(String id, String name) {
- this.id = id;
- this.name = name;
- }
+ }
+ public MusicFolder(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
- public String getId() {
- return id;
- }
+ public String getId() {
+ return id;
+ }
- public String getName() {
- return name;
- }
+ public String getName() {
+ return name;
+ }
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
- public boolean getEnabled() {
- return enabled;
- }
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ public boolean getEnabled() {
+ return enabled;
+ }
- public static class MusicFolderComparator implements Comparator