From a72e12ae06fafe1885aa763ffa04faa84afb9523 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 28 Apr 2015 17:31:59 -0700 Subject: #259 Bunch of fixes/improvements to swipe up bar --- .../dsub/activity/SubsonicActivity.java | 28 +++++++++---- .../dsub/activity/SubsonicFragmentActivity.java | 49 ++++++++++++++++++---- .../github/daneren2005/dsub/util/ImageLoader.java | 5 ++- 3 files changed, 65 insertions(+), 17 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java index 17f22586..814598c5 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -128,14 +128,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); - View actionbar = getLayoutInflater().inflate(R.layout.actionbar_spinner, null); - actionBarSpinner = (Spinner)actionbar.findViewById(R.id.spinner); - 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(actionbar); + if(spinnerAdapter == null) { + createCustomActionBarView(); + } getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); @@ -151,6 +146,17 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } } + protected void createCustomActionBarView() { + View customActionbar = getLayoutInflater().inflate(R.layout.actionbar_spinner, null); + actionBarSpinner = (Spinner)customActionbar.findViewById(R.id.spinner); + 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(customActionbar); + } + @Override protected void onResume() { super.onResume(); @@ -520,7 +526,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } } - private void drawerItemSelected(int position, View view) { + protected void drawerItemSelected(int position, View view) { startFragmentActivity(drawerItemsDescriptions[position]); if(lastSelectedView != view) { @@ -711,6 +717,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(currentFragment == null || currentFragment.getTitle() == null) { return; } + if(spinnerAdapter == null) { + createCustomActionBarView(); + } if(backStack.size() > 0) { spinnerAdapter.clear(); @@ -733,6 +742,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte getSupportActionBar().setDisplayShowCustomEnabled(true); } } else if(!isTv()) { + getSupportActionBar().setTitle(currentFragment.getTitle()); getSupportActionBar().setDisplayShowCustomEnabled(false); } } diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index b534adc5..83d5bce8 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -36,6 +36,7 @@ import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import com.sothree.slidinguppanel.SlidingUpPanelLayout; @@ -93,7 +94,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { private ScheduledExecutorService executorService; private View bottomBar; - private View coverArtView; + private ImageView coverArtView; private TextView trackView; private TextView artistView; private ImageButton startButton; @@ -172,18 +173,31 @@ public class SubsonicFragmentActivity extends SubsonicActivity { nowPlayingToolbar.setVisibility(View.GONE); nowPlayingFragment.setPrimaryFragment(false); setSupportActionBar(mainToolbar); + + if(getSupportActionBar().getCustomView() == null) { + createCustomActionBarView(); + } + recreateSpinner(); + if(drawerToggle != null && backStack.size() > 0) { + drawerToggle.setDrawerIndicatorEnabled(false); + } else { + drawerToggle.setDrawerIndicatorEnabled(true); + } } @Override public void onPanelExpanded(View panel) { + // Disable custom view before switching + getSupportActionBar().setDisplayShowCustomEnabled(false); + bottomBar.setVisibility(View.GONE); nowPlayingToolbar.setVisibility(View.VISIBLE); setSupportActionBar(nowPlayingToolbar); nowPlayingFragment.setPrimaryFragment(true); + drawerToggle.setDrawerIndicatorEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); - drawerToggle.setDrawerIndicatorEnabled(true); + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); } @Override @@ -210,7 +224,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { bottomBar = findViewById(R.id.bottom_bar); mainToolbar = (Toolbar) findViewById(R.id.main_toolbar); nowPlayingToolbar = (Toolbar) findViewById(R.id.now_playing_toolbar); - coverArtView = bottomBar.findViewById(R.id.album_art); + coverArtView = (ImageView) bottomBar.findViewById(R.id.album_art); trackView = (TextView) bottomBar.findViewById(R.id.track_name); artistView = (TextView) bottomBar.findViewById(R.id.artist_name); @@ -454,6 +468,15 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } } + @Override + protected void drawerItemSelected(int position, View view) { + super.drawerItemSelected(position, view); + + 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 @@ -539,11 +562,23 @@ public class SubsonicFragmentActivity extends SubsonicActivity { trackView.setText(song.getTitle()); artistView.setText(song.getArtist()); } else { - trackView.setText("Title"); - artistView.setText("Artist"); + trackView.setText(R.string.main_title); + artistView.setText(R.string.main_artist); } - getImageLoader().loadImage(coverArtView, song, false, false); + SilentBackgroundTask task = getImageLoader().loadImage(coverArtView, song, false, coverArtView.getHeight(), false); + if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { + if(task == null) { + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); + } else { + task.setOnCompletionListener(new Runnable() { + @Override + public void run() { + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); + } + }); + } + } int[] attrs = new int[] {(state == PlayerState.STARTED) ? R.attr.media_button_pause : R.attr.media_button_start}; TypedArray typedArray = this.obtainStyledAttributes(attrs); startButton.setImageResource(typedArray.getResourceId(0, 0)); diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java index 1a0e8242..65ef46fe 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java +++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java @@ -192,8 +192,11 @@ public class ImageLoader { } public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) { - // TODO: If we know this a artist, try to load artist info instead int size = large ? imageSizeLarge : imageSizeDefault; + return loadImage(view, entry, large, size, crossfade); + } + public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, int size, boolean crossfade) { + // TODO: If we know this a artist, try to load artist info instead if(entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11") && !Util.isOffline(context)) { SilentBackgroundTask task = new ArtistImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade); task.execute(); -- cgit v1.2.3