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 ++- .../abstract_fragment_container.xml | 4 +- .../main/res/layout/abstract_fragment_activity.xml | 24 +++++++---- .../res/layout/abstract_fragment_container.xml | 6 +++ app/src/main/res/values-large/dimens.xml | 2 + app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/strings.xml | 2 + 9 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/layout/abstract_fragment_container.xml 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(); diff --git a/app/src/main/res/layout-large-land/abstract_fragment_container.xml b/app/src/main/res/layout-large-land/abstract_fragment_container.xml index 5e3b1561..3901710f 100644 --- a/app/src/main/res/layout-large-land/abstract_fragment_container.xml +++ b/app/src/main/res/layout-large-land/abstract_fragment_container.xml @@ -2,8 +2,8 @@ + android:layout_height="match_parent" + android:layout_marginTop="?attr/actionBarSize"> - + + android:textSize="@dimen/BottomBar.Text.Major" + android:text="@string/main.title" + android:ellipsize="marquee" + android:marqueeRepeatLimit="marquee_forever" + android:scrollHorizontally="true" + android:focusable="true" + android:focusableInTouchMode="true"> + + + + android:textSize="@dimen/BottomBar.Text.Minor" + android:text="@string/main.artist"/> diff --git a/app/src/main/res/layout/abstract_fragment_container.xml b/app/src/main/res/layout/abstract_fragment_container.xml new file mode 100644 index 00000000..f13356c4 --- /dev/null +++ b/app/src/main/res/layout/abstract_fragment_container.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values-large/dimens.xml b/app/src/main/res/values-large/dimens.xml index b08dda86..fe8f1a6c 100644 --- a/app/src/main/res/values-large/dimens.xml +++ b/app/src/main/res/values-large/dimens.xml @@ -4,4 +4,6 @@ 54dip 96dip 210dip + 18sp + 16sp \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index be3e843d..9759e1c2 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,4 +4,6 @@ 46dip 78dip 120dip + 13sp + 12sp \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b897cad6..8e7ae537 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,6 +79,8 @@ @string/main.albums_genres Press back again to exit Completed scan of Server + Artist + Title Search Shuffle -- cgit v1.2.3