aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-04-27 18:09:40 -0700
committerScott Jackson <daneren2005@gmail.com>2015-04-27 18:09:40 -0700
commit366b3d35ae8d3a410678e90f3382e457c7d9445e (patch)
tree9cebc000b2fe77925e5db29c36621c3f613e0de2 /app/src/main/java/github
parent28a8dba5682a953570c04013b4acbd7b5dcab685 (diff)
downloaddsub-366b3d35ae8d3a410678e90f3382e457c7d9445e.tar.gz
dsub-366b3d35ae8d3a410678e90f3382e457c7d9445e.tar.bz2
dsub-366b3d35ae8d3a410678e90f3382e457c7d9445e.zip
Merge work for #259 after project structure change
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/DownloadActivity.java62
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java81
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java137
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java181
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java254
-rw-r--r--app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Util.java27
9 files changed, 402 insertions, 353 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/DownloadActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/DownloadActivity.java
deleted file mode 100644
index e13a8b8c..00000000
--- a/app/src/main/java/github/daneren2005/dsub/activity/DownloadActivity.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- This file is part of Subsonic.
-
- Subsonic is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Subsonic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2009 (C) Sindre Mehus
- */
-package github.daneren2005.dsub.activity;
-
-import github.daneren2005.dsub.R;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import github.daneren2005.dsub.fragments.NowPlayingFragment;
-
-import android.widget.EditText;
-
-import github.daneren2005.dsub.util.Constants;
-
-public class DownloadActivity extends SubsonicActivity {
- private static final String TAG = DownloadActivity.class.getSimpleName();
- private EditText playlistNameView;
-
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.download_activity);
-
- if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) {
- currentFragment = new NowPlayingFragment();
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
- Bundle args = new Bundle();
- args.putBoolean(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true);
- currentFragment.setArguments(args);
- }
- currentFragment.setPrimaryFragment(true);
- getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit();
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent me) {
- if(currentFragment != null && currentFragment.getGestureDetector() != null) {
- return currentFragment.getGestureDetector().onTouchEvent(me);
- } else {
- return false;
- }
- }
-}
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 4651eb0b..17f22586 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -118,7 +118,16 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
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);
+ }
+ }
+
+ @Override
+ 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);
@@ -130,14 +139,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
- if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
- lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
- }
- }
-
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
if(drawerToggle != null) {
drawerToggle.syncState();
@@ -160,7 +161,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
restart();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
-
+
populateDrawer();
UpdateView.addActiveActivity();
}
@@ -210,7 +211,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
LayoutInflater layoutInflater = getLayoutInflater();
layoutInflater.inflate(viewId, rootView);
}
-
+
drawerList = (ListView) findViewById(R.id.left_drawer);
drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
@@ -299,7 +300,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
primaryContainer = findViewById(R.id.fragment_container);
}
}
-
+
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
@@ -370,10 +371,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
-
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
+ SubsonicFragment currentFragment = getCurrentFragment();
if(drawerOpen) {
menuInflater.inflate(R.menu.drawer_menu, menu);
} else if(currentFragment != null) {
@@ -399,7 +401,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
return true;
}
- return currentFragment.onOptionsItemSelected(item);
+ return getCurrentFragment().onOptionsItemSelected(item);
}
@Override
@@ -415,7 +417,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
return super.onKeyDown(keyCode, event);
}
-
+
@Override
public void setTitle(CharSequence title) {
if(title != null && !title.equals(getSupportActionBar().getTitle())) {
@@ -426,7 +428,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
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;
@@ -439,9 +441,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
@Override
public void onNothingSelected(AdapterView<?> parent) {
-
+
}
-
+
private void populateDrawer() {
SharedPreferences prefs = Util.getPreferences(this);
boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true);
@@ -449,7 +451,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this);
boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true) && !Util.isOffline(this);
boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true) && !Util.isOffline(this);
-
+
if(drawerItems == null || !enabledItems[0] == podcastsEnabled || !enabledItems[1] == bookmarksEnabled || !enabledItems[2] == sharedEnabled || !enabledItems[3] == chatEnabled || !enabledItems[4] == adminEnabled) {
drawerItems = getResources().getStringArray(R.array.drawerItems);
drawerItemsDescriptions = getResources().getStringArray(R.array.drawerItemsDescriptions);
@@ -488,7 +490,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(!getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
drawerItemsVisibleList.set(8, false);
}
-
+
drawerList.setAdapter(drawerAdapter = new DrawerAdapter(this, drawerItemsList, drawerItemsIconsList, drawerItemsVisibleList));
enabledItems[0] = podcastsEnabled;
enabledItems[1] = bookmarksEnabled;
@@ -517,15 +519,15 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
}
}
-
+
private void drawerItemSelected(int position, View view) {
startFragmentActivity(drawerItemsDescriptions[position]);
-
+
if(lastSelectedView != view) {
if(lastSelectedView != null) {
lastSelectedView.setTextAppearance(this, R.style.DSub_TextViewStyle);
}
-
+
lastSelectedView = (TextView) view.findViewById(R.id.drawer_name);
lastSelectedView.setTextAppearance(this, R.style.DSub_TextViewStyle_Bold);
lastSelectedPosition = position;
@@ -575,6 +577,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
}
+ protected SubsonicFragment getCurrentFragment() {
+ return this.currentFragment;
+ }
+
public void replaceFragment(SubsonicFragment fragment, int tag) {
replaceFragment(fragment, tag, false);
}
@@ -628,11 +634,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
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 + "");
-
+
// Commit it all
trans.commit();
}
@@ -656,7 +662,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
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(oldFrag);
@@ -682,7 +688,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right));
secondaryContainer.setVisibility(View.GONE);
}
-
+
trans.commit();
}
recreateSpinner();
@@ -697,10 +703,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
currentFragment.invalidate();
populateDrawer();
}
-
+
supportInvalidateOptionsMenu();
}
-
+
protected void recreateSpinner() {
if(currentFragment == null || currentFragment.getTitle() == null) {
return;
@@ -745,7 +751,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
theme = theme.substring(0, theme.indexOf("_fullscreen"));
Util.setTheme(this, theme);
}
-
+
Util.applyTheme(this, theme);
}
private void applyFullscreen() {
@@ -754,8 +760,8 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
// Hide additional elements on higher Android versions
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_FULLSCREEN |
- View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ View.SYSTEM_UI_FLAG_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(flags);
} else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
@@ -786,7 +792,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
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();
@@ -799,7 +805,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
return DownloadService.getInstance();
}
-
+
public static String getThemeName() {
return theme;
}
@@ -811,6 +817,13 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
return touchscreen;
}
+ public void openNowPlaying() {
+
+ }
+ public void closeNowPlaying() {
+
+ }
+
private void setUncaughtExceptionHandler() {
Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
if (!(handler instanceof SubsonicActivity.SubsonicUncaughtExceptionHandler)) {
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 6614e09d..b534adc5 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -31,14 +31,16 @@ import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
+import com.sothree.slidinguppanel.SlidingUpPanelLayout;
+
import java.io.File;
-import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -53,6 +55,7 @@ import github.daneren2005.dsub.fragments.AdminFragment;
import github.daneren2005.dsub.fragments.ChatFragment;
import github.daneren2005.dsub.fragments.DownloadFragment;
import github.daneren2005.dsub.fragments.MainFragment;
+import github.daneren2005.dsub.fragments.NowPlayingFragment;
import github.daneren2005.dsub.fragments.SearchFragment;
import github.daneren2005.dsub.fragments.SelectArtistFragment;
import github.daneren2005.dsub.fragments.SelectBookmarkFragment;
@@ -66,7 +69,6 @@ import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.updates.Updater;
-import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.SilentBackgroundTask;
@@ -83,6 +85,12 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
private static boolean sessionInitialized = false;
private static long ALLOWED_SKEW = 30000L;
+ private Handler handler = new Handler();
+ private SlidingUpPanelLayout slideUpPanel;
+ private NowPlayingFragment nowPlayingFragment;
+ private Toolbar mainToolbar;
+ private Toolbar nowPlayingToolbar;
+
private ScheduledExecutorService executorService;
private View bottomBar;
private View coverArtView;
@@ -105,14 +113,6 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
if(drawerAdapter != null) {
drawerAdapter.setDownloadVisible(true);
}
- } else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) {
- DownloadService service = getDownloadService();
- if((service != null && service.getCurrentPlaying() != null)) {
- getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD);
- Intent intent = new Intent();
- intent.setClass(this, DownloadActivity.class);
- startActivity(intent);
- }
}
setContentView(R.layout.abstract_fragment_activity);
@@ -128,49 +128,99 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
}
}
currentFragment = getNewFragment(fragmentType);
-
+
if("".equals(fragmentType) || fragmentType == null || firstRun) {
// Initial startup stuff
if(!sessionInitialized) {
loadSession();
}
}
-
+
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 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);
-
+
fragment.setArguments(args);
replaceFragment(fragment, fragment.getSupportTag());
}
}
- bottomBar = findViewById(R.id.bottom_bar);
- bottomBar.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Intent intent = new Intent();
- intent.setClass(v.getContext(), DownloadActivity.class);
- startActivity(intent);
+ slideUpPanel = (SlidingUpPanelLayout) findViewById(R.id.slide_up_panel);
+ slideUpPanel.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
+ @Override
+ public void onPanelSlide(View panel, float slideOffset) {
+
+ }
+
+ @Override
+ public void onPanelCollapsed(View panel) {
+ bottomBar.setVisibility(View.VISIBLE);
+ nowPlayingToolbar.setVisibility(View.GONE);
+ nowPlayingFragment.setPrimaryFragment(false);
+ setSupportActionBar(mainToolbar);
+ }
+
+ @Override
+ public void onPanelExpanded(View panel) {
+ bottomBar.setVisibility(View.GONE);
+ nowPlayingToolbar.setVisibility(View.VISIBLE);
+ setSupportActionBar(nowPlayingToolbar);
+ nowPlayingFragment.setPrimaryFragment(true);
+
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setHomeButtonEnabled(true);
+ drawerToggle.setDrawerIndicatorEnabled(true);
+ }
+
+ @Override
+ public void onPanelAnchored(View panel) {
+
+ }
+
+ @Override
+ public void onPanelHidden(View panel) {
+
}
});
+
+ 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);
+ }
+
+ 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);
trackView = (TextView) bottomBar.findViewById(R.id.track_name);
artistView = (TextView) bottomBar.findViewById(R.id.artist_name);
+ setSupportActionBar(mainToolbar);
+
+ nowPlayingFragment = new NowPlayingFragment();
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.add(R.id.now_playing_fragment_container, nowPlayingFragment, nowPlayingFragment.getTag() + "");
+ trans.commit();
+
ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous);
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -262,7 +312,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
}
}
}
-
+
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@@ -300,7 +350,6 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
public void onResume() {
super.onResume();
- final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
@@ -369,7 +418,9 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
@Override
public void onBackPressed() {
- if(onBackPressedSupport()) {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
+ } else if(onBackPressedSupport()) {
if(!Util.disableExitPrompt(this) && lastBackPressTime < (System.currentTimeMillis() - 4000)) {
lastBackPressTime = System.currentTimeMillis();
Util.toast(this, R.string.main_back_confirm);
@@ -380,6 +431,15 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
}
@Override
+ protected SubsonicFragment getCurrentFragment() {
+ if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
+ return nowPlayingFragment;
+ } else {
+ return super.getCurrentFragment();
+ }
+ }
+
+ @Override
public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
super.replaceFragment(fragment, tag, replaceCurrent);
if(drawerToggle != null) {
@@ -393,24 +453,24 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
drawerToggle.setDrawerIndicatorEnabled(true);
}
}
-
+
@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();
-
+
// Create new stack
currentFragment = getNewFragment(fragmentType);
currentFragment.setPrimaryFragment(true);
trans.add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "");
-
+
// Done, cleanup
trans.commit();
supportInvalidateOptionsMenu();
@@ -426,7 +486,16 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
drawerToggle.setDrawerIndicatorEnabled(true);
}
}
-
+
+ @Override
+ public void openNowPlaying() {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
+ }
+ @Override
+ public void closeNowPlaying() {
+ slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
+ }
+
private SubsonicFragment getNewFragment(String fragmentType) {
if("Artist".equals(fragmentType)) {
return new SelectArtistFragment();
@@ -447,7 +516,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
} else {
return new MainFragment();
}
- }
+ }
private void update() {
DownloadService downloadService = getDownloadService();
@@ -502,7 +571,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
if(ServerInfo.canSavePlayQueue(this) && !Util.isOffline(this)) {
loadRemotePlayQueue();
}
-
+
sessionInitialized = true;
}
private void loadSettings() {
@@ -551,7 +620,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
return true;
}
}
-
+
private void loadBookmarks() {
final Context context = this;
new SilentBackgroundTask<Void>(context) {
@@ -562,7 +631,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
return null;
}
-
+
@Override
public void error(Throwable error) {
Log.e(TAG, "Failed to get bookmarks", error);
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index fa7e3404..953b429a 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -20,6 +20,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
@@ -141,6 +142,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
startFlipped = true;
}
}
+ primaryFragment = false;
}
@Override
@@ -153,11 +155,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
rootView = inflater.inflate(R.layout.download, container, false);
setTitle(R.string.button_bar_now_playing);
-
+
mainLayout = rootView.findViewById(R.id.download_layout);
- if(!primaryFragment) {
- mainLayout.setVisibility(View.GONE);
- }
WindowManager w = context.getWindowManager();
Display d = w.getDefaultDisplay();
@@ -397,7 +396,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
} else {
// Immediately skip to the next song
downloadService.next(true);
-
+
// Otherwise set rating to 1
setRating(entry, 1);
rateBadButton.setImageResource(R.drawable.ic_action_rating_bad_selected);
@@ -470,35 +469,35 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
});
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onStopTrackingTouch(final SeekBar seekBar) {
- new SilentBackgroundTask<Void>(context) {
- @Override
- protected Void doInBackground() throws Throwable {
- getDownloadService().seekTo(progressBar.getProgress());
- return null;
- }
-
- @Override
- protected void done(Void result) {
- seekInProgress = false;
- NowPlayingFragment.this.onProgressChanged();
- }
- }.execute();
- }
-
- @Override
- public void onStartTrackingTouch(final SeekBar seekBar) {
+ @Override
+ public void onStopTrackingTouch(final SeekBar seekBar) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ getDownloadService().seekTo(progressBar.getProgress());
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ seekInProgress = false;
+ NowPlayingFragment.this.onProgressChanged();
+ }
+ }.execute();
+ }
+
+ @Override
+ public void onStartTrackingTouch(final SeekBar seekBar) {
seekInProgress = true;
- }
+ }
- @Override
- public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) {
+ @Override
+ public void onProgressChanged(final SeekBar seekBar, final int position, final boolean fromUser) {
if (fromUser) {
Util.toast(context, Util.formatDuration(position / 1000), true);
setControlsVisible(true);
}
- }
+ }
});
playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
@@ -543,13 +542,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
registerForContextMenu(playlistView);
- DownloadService downloadService = getDownloadService();
- if (downloadService != null && context.getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
- context.getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE);
- warnIfStorageUnavailable();
- downloadService.setShufflePlayEnabled(true);
- }
-
if(Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) {
View slider = rootView.findViewById(R.id.download_slider);
slider.setPadding(0, 0, 0, 0);
@@ -603,7 +595,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if(menuItemSelected(menuItem.getItemId(), null)) {
return true;
}
-
+
return super.onOptionsItemSelected(menuItem);
}
@@ -640,7 +632,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if(!primaryFragment) {
return false;
}
-
+
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem);
@@ -840,7 +832,9 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
@Override
public void onResume() {
super.onResume();
-
+ onResumeHandlers();
+ }
+ private void onResumeHandlers() {
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
@@ -897,25 +891,43 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
@Override
public void onPause() {
super.onPause();
+ onPauseHandlers();
+ }
+ private void onPauseHandlers() {
executorService.shutdown();
if(getDownloadService() != null) {
getDownloadService().stopRemoteScan();
}
+ playlistFlipper.setDisplayedChild(0);
}
-
+
@Override
public void setPrimaryFragment(boolean primary) {
super.setPrimaryFragment(primary);
if(rootView != null) {
if(primary) {
- mainLayout.setVisibility(View.VISIBLE);
- updateButtons();
+ onResumeHandlers();
} else {
- mainLayout.setVisibility(View.GONE);
+ onPauseHandlers();
}
}
}
+ @Override
+ public void setTitle(int title) {
+ this.title = context.getResources().getString(title);
+ if(this.primaryFragment) {
+ context.setTitle(this.title);
+ }
+ }
+ @Override
+ public void setSubtitle(CharSequence title) {
+ this.subtitle = title;
+ if(this.primaryFragment) {
+ context.setSubtitle(title);
+ }
+ }
+
private void scheduleHideControls() {
if (hideControlsFuture != null) {
hideControlsFuture.cancel(false);
@@ -953,7 +965,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if(context == null) {
return;
}
-
+
if(Util.isOffline(context)) {
bookmarkButton.setVisibility(View.GONE);
rateBadButton.setVisibility(View.GONE);
@@ -970,6 +982,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
// Scroll to current playing/downloading.
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void scrollToCurrent() {
if (getDownloadService() == null || songListAdapter == null) {
scrollWhenLoaded = true;
@@ -1042,26 +1055,26 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
- lengthBar.setProgress(length - 1);
+ lengthBar.setProgress(length - 1);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.menu_set_timer)
- .setView(dialogView)
- .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- int length = getMinutes(lengthBar.getProgress());
+ .setView(dialogView)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ int length = getMinutes(lengthBar.getProgress());
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, Integer.toString(length));
- editor.commit();
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, Integer.toString(length));
+ editor.commit();
- getDownloadService().setSleepTimerDuration(length);
- getDownloadService().startSleepTimer();
- context.supportInvalidateOptionsMenu();
- }
- })
- .setNegativeButton(R.string.common_cancel, null);
+ getDownloadService().setSleepTimerDuration(length);
+ getDownloadService().startSleepTimer();
+ context.supportInvalidateOptionsMenu();
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null);
AlertDialog dialog = builder.create();
dialog.show();
}
@@ -1086,7 +1099,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_up_in));
playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.push_up_out));
playlistFlipper.setDisplayedChild(1);
-
+
UpdateView.triggerUpdate();
}
}
@@ -1124,7 +1137,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
protected Void doInBackground() throws Throwable {
currentPlayingIndex = downloadService.getCurrentPlayingIndex() + 1;
size = downloadService.size();
-
+
return null;
}
@@ -1132,14 +1145,14 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
protected void done(Void result) {
List<DownloadFile> list;
list = downloadService.getSongs();
-
+
if(downloadService.isShufflePlayEnabled()) {
emptyTextView.setText(R.string.download_shuffle_loading);
}
else {
emptyTextView.setText(R.string.download_empty);
}
-
+
if(songListAdapter == null || refresh) {
songList = new ArrayList<DownloadFile>();
songList.addAll(list);
@@ -1149,7 +1162,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
songList.addAll(list);
songListAdapter.notifyDataSetChanged();
}
-
+
emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
currentRevision = downloadService.getDownloadListUpdateRevision();
@@ -1170,7 +1183,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
default:
break;
}
-
+
if(scrollWhenLoaded) {
scrollToCurrent();
scrollWhenLoaded = false;
@@ -1193,7 +1206,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if (downloadService == null || onCurrentChangedTask != null) {
return;
}
-
+
onCurrentChangedTask = new SilentBackgroundTask<Void>(context) {
int currentPlayingIndex;
int currentPlayingSize;
@@ -1254,7 +1267,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
}
};
-
+
if(onDownloadListChangedTask == null) {
onCurrentChangedTask.execute();
}
@@ -1390,33 +1403,33 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
}.execute();
}
-
+
private void createBookmark() {
DownloadService downloadService = getDownloadService();
if(downloadService == null) {
return;
}
-
+
final DownloadFile currentDownload = downloadService.getCurrentPlaying();
if(currentDownload == null) {
return;
}
-
+
View dialogView = context.getLayoutInflater().inflate(R.layout.create_bookmark, null);
final EditText commentBox = (EditText)dialogView.findViewById(R.id.comment_text);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.download_save_bookmark_title)
- .setView(dialogView)
- .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- String comment = commentBox.getText().toString();
+ .setView(dialogView)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ String comment = commentBox.getText().toString();
- createBookmark(currentDownload, comment);
- }
- })
- .setNegativeButton(R.string.common_cancel, null);
+ createBookmark(currentDownload, comment);
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null);
AlertDialog dialog = builder.create();
dialog.show();
}
@@ -1425,13 +1438,13 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if(downloadService == null) {
return;
}
-
+
final Entry currentSong = currentDownload.getSong();
final int position = downloadService.getPlayerPosition();
final Bookmark oldBookmark = currentSong.getBookmark();
currentSong.setBookmark(new Bookmark(position));
bookmarkButton.setImageResource(R.drawable.ic_menu_bookmark_selected);
-
+
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
@@ -1453,12 +1466,12 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
Util.toast(context, R.string.download_save_bookmark);
setControlsVisible(true);
}
-
+
@Override
protected void error(Throwable error) {
Log.w(TAG, "Failed to create bookmark", error);
currentSong.setBookmark(oldBookmark);
-
+
// If no bookmark at start, then return to no bookmark
if(oldBookmark == null) {
int bookmark;
@@ -1469,14 +1482,14 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
bookmarkButton.setImageResource(bookmark);
}
-
+
String msg;
if(error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
} else {
msg = context.getResources().getString(R.string.download_save_bookmark_failed) + getErrorMessage(error);
}
-
+
Util.toast(context, msg, false);
}
}.execute();
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
index c71d99f6..830e2957 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java
@@ -25,7 +25,6 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.DownloadService;
@@ -110,7 +109,7 @@ public class SelectBookmarkFragment extends SelectListFragment<MusicDirectory.En
@Override
protected void done(Void result) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ context.openNowPlaying();
}
}.execute();
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 841a6369..9e7cd053 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -46,7 +46,6 @@ import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
-import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
@@ -993,7 +992,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
@Override
protected void done(Void result) {
if (autoplay) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ context.openNowPlaying();
} else if (save) {
Util.toast(context,
context.getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size()));
@@ -1335,7 +1334,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
@Override
protected void done(Void result) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ context.openNowPlaying();
}
}.execute();
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 109983ba..fcae3a5c 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -18,6 +18,7 @@
*/
package github.daneren2005.dsub.fragments;
+import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
@@ -28,6 +29,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v4.app.Fragment;
@@ -49,7 +51,6 @@ import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;
import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.activity.SubsonicActivity;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.Artist;
@@ -101,7 +102,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
private static final String TAG = SubsonicFragment.class.getSimpleName();
private static int TAG_INC = 10;
private int tag;
-
+
protected SubsonicActivity context;
protected CharSequence title = null;
protected CharSequence subtitle = null;
@@ -116,7 +117,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
protected boolean artistOverride = false;
protected SwipeRefreshLayout refreshLayout;
protected boolean firstRun;
-
+
public SubsonicFragment() {
super();
tag = TAG_INC++;
@@ -187,7 +188,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
return false;
}
-
+
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo, Object selected) {
MenuInflater inflater = context.getMenuInflater();
@@ -199,7 +200,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
else {
inflater.inflate(R.menu.select_podcast_episode_context, menu);
-
+
if(entry.getBookmark() == null) {
menu.removeItem(R.id.bookmark_menu_delete);
}
@@ -223,7 +224,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
else {
inflater.inflate(R.menu.select_song_context, menu);
-
+
if(entry.getBookmark() == null) {
menu.removeItem(R.id.bookmark_menu_delete);
}
@@ -286,7 +287,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(info.targetView instanceof SongView) {
SongView songView = (SongView) info.targetView;
DownloadFile downloadFile = songView.getDownloadFile();
-
+
try {
if(downloadFile != null) {
if(downloadFile.isWorkDone()) {
@@ -294,7 +295,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(downloadFile.isSaved()) {
menu.removeItem(R.id.song_menu_pin);
}
-
+
// Remove cache option no matter what if already downloaded
menu.removeItem(R.id.song_menu_download);
} else {
@@ -324,7 +325,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
folder = ((ArtistEntryView) info.targetView).getFile();
id = R.id.artist_menu_delete;
}
-
+
try {
if(folder != null && !folder.exists()) {
menu.removeItem(id);
@@ -475,7 +476,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
return true;
}
-
+
public void replaceFragment(SubsonicFragment fragment) {
replaceFragment(fragment, true);
}
@@ -492,7 +493,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
public int getSupportTag() {
return tag;
}
-
+
public void setPrimaryFragment(boolean primary) {
primaryFragment = primary;
if(primary) {
@@ -650,9 +651,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
protected void onShuffleRequested() {
if(Util.isOffline(context)) {
- Intent intent = new Intent(context, DownloadActivity.class);
- intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
- Util.startActivityWithoutTransition(context, intent);
+ DownloadService downloadService = getDownloadService();
+ if(downloadService == null) {
+ return;
+ }
+ downloadService.setShufflePlayEnabled(true);
+ context.openNowPlaying();
return;
}
@@ -691,21 +695,21 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
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 == 0) {
- genreCombo.setText("");
- } else {
- genreCombo.setText(finalNames.get(which));
- }
- }
- });
+ .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if(which == 0) {
+ genreCombo.setText("");
+ } else {
+ genreCombo.setText(finalNames.get(which));
+ }
+ }
+ });
AlertDialog dialog = builder.create();
dialog.show();
}
@Override
- protected void error(Throwable error) {
+ protected void error(Throwable error) {
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
@@ -731,31 +735,34 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.shuffle_title)
- .setView(dialogView)
- .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- Intent intent = new Intent(context, DownloadActivity.class);
- intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
- String genre;
- if(useCombo) {
- genre = genreCombo.getText().toString();
- } else {
- genre = genreBox.getText().toString();
+ .setView(dialogView)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ String genre;
+ if (useCombo) {
+ genre = genreCombo.getText().toString();
+ } else {
+ genre = genreBox.getText().toString();
+ }
+ String startYear = startYearBox.getText().toString();
+ String endYear = endYearBox.getText().toString();
+
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear);
+ editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear);
+ editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
+ editor.commit();
+
+ DownloadService downloadService = getDownloadService();
+ if (downloadService == null) {
+ return;
+ }
+ downloadService.setShufflePlayEnabled(true);
+ context.openNowPlaying();
}
- String startYear = startYearBox.getText().toString();
- String endYear = endYearBox.getText().toString();
-
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear);
- editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear);
- editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
- editor.commit();
-
- Util.startActivityWithoutTransition(context, intent);
- }
- })
- .setNegativeButton(R.string.common_cancel, null);
+ })
+ .setNegativeButton(R.string.common_cancel, null);
AlertDialog dialog = builder.create();
dialog.show();
}
@@ -906,7 +913,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
playNowOverride = true;
return false;
}
-
+
if (!append && !background) {
downloadService.clear();
}
@@ -994,7 +1001,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
MusicService musicService = MusicServiceFactory.getMusicService(context);
List<Playlist> playlists = new ArrayList<Playlist>();
playlists.addAll(musicService.getPlaylists(false, context, this));
-
+
// Iterate through and remove all non owned public playlists
Iterator<Playlist> it = playlists.iterator();
while(it.hasNext()) {
@@ -1003,7 +1010,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
it.remove();
}
}
-
+
return playlists;
}
@@ -1016,7 +1023,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Playlist playlist = getItem(position);
-
+
// Create new if not getting a convert view to use
PlaylistSongView view;
if(convertView instanceof PlaylistSongView) {
@@ -1033,21 +1040,21 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.playlist_add_to)
- .setAdapter(playlistAdapter, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (which > 0) {
- addToPlaylist(playlists.get(which), songs);
- } else {
- createNewPlaylist(songs, false);
+ .setAdapter(playlistAdapter, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if (which > 0) {
+ addToPlaylist(playlists.get(which), songs);
+ } else {
+ createNewPlaylist(songs, false);
+ }
}
- }
- });
+ });
AlertDialog dialog = builder.create();
dialog.show();
}
@Override
- protected void error(Throwable error) {
+ protected void error(Throwable error) {
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
@@ -1075,7 +1082,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
@Override
- protected void error(Throwable error) {
+ protected void error(Throwable error) {
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
@@ -1087,7 +1094,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
}.execute();
}
-
+
protected void createNewPlaylist(final List<Entry> songs, final boolean getSuggestion) {
View layout = context.getLayoutInflater().inflate(R.layout.save_playlist, null);
final EditText playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name);
@@ -1115,34 +1122,34 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.download_playlist_title)
- .setMessage(R.string.download_playlist_name)
- .setView(layout)
- .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- String playlistName = String.valueOf(playlistNameView.getText());
- if(overwriteCheckBox.isChecked()) {
- overwritePlaylist(songs, playlistName, getDownloadService().getSuggestedPlaylistId());
- } else {
- createNewPlaylist(songs, playlistName);
-
- if(getSuggestion) {
- DownloadService downloadService = getDownloadService();
- if(downloadService != null) {
- downloadService.setSuggestedPlaylistName(playlistName, null);
+ .setMessage(R.string.download_playlist_name)
+ .setView(layout)
+ .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ String playlistName = String.valueOf(playlistNameView.getText());
+ if(overwriteCheckBox.isChecked()) {
+ overwritePlaylist(songs, playlistName, getDownloadService().getSuggestedPlaylistId());
+ } else {
+ createNewPlaylist(songs, playlistName);
+
+ if(getSuggestion) {
+ DownloadService downloadService = getDownloadService();
+ if(downloadService != null) {
+ downloadService.setSuggestedPlaylistName(playlistName, null);
+ }
}
}
}
- }
- })
- .setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- })
- .setCancelable(true);
-
+ })
+ .setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ })
+ .setCancelable(true);
+
AlertDialog dialog = builder.create();
dialog.show();
}
@@ -1184,7 +1191,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
@Override
- protected void error(Throwable error) {
+ protected void error(Throwable error) {
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
@@ -1197,6 +1204,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}.execute();
}
+ @TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
public void displaySongInfo(final Entry song) {
Integer duration = null;
Integer bitrate = null;
@@ -1209,12 +1217,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(file.exists()) {
MediaMetadataRetriever metadata = new MediaMetadataRetriever();
metadata.setDataSource(file.getAbsolutePath());
-
+
String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
duration = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
format = FileUtil.getExtension(file.getName());
size = file.length();
-
+
// If no duration try to read bitrate tag
if(duration == null) {
tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
@@ -1224,7 +1232,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
// Divide by 1000 so in kbps
bitrate = (int) (size / duration) / 1000 * 8;
}
-
+
if(Util.isOffline(context)) {
song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
@@ -1286,7 +1294,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
Util.info(context, song.getTitle(), msg);
}
-
+
protected void playVideo(Entry entry) {
if(entryExists(entry)) {
playExternalPlayer(entry);
@@ -1315,7 +1323,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
intent.putExtra(Intent.EXTRA_TITLE, entry.getTitle());
List<ResolveInfo> intents = context.getPackageManager()
- .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(intents != null && intents.size() > 0) {
startActivity(intent);
}else {
@@ -1373,7 +1381,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
public void deleteRecursively(Artist artist) {
deleteRecursively(FileUtil.getArtistDirectory(context, artist));
}
-
+
public void deleteRecursively(Entry album) {
deleteRecursively(FileUtil.getAlbumDirectory(context, album));
@@ -1490,7 +1498,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
intent.putExtra(Intent.EXTRA_TEXT, share.getUrl());
context.startActivity(Intent.createChooser(intent, context.getResources().getString(R.string.share_via)));
}
-
+
public GestureDetector getGestureDetector() {
return gestureScanner;
}
@@ -1515,7 +1523,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
public void onClick(DialogInterface dialog, int id) {
final Bookmark oldBookmark = song.getBookmark();
song.setBookmark(null);
-
+
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
@@ -1528,7 +1536,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
@Override
protected void error(Throwable error) {
song.setBookmark(oldBookmark);
-
+
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
@@ -1546,7 +1554,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
AlertDialog dialog = builder.create();
dialog.show();
}
-
+
protected void playNow(List<Entry> entries) {
playNow(entries, null, null);
}
@@ -1558,7 +1566,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
break;
}
}
-
+
// If no bookmark found, just play from start
if(bookmark == null) {
playNow(entries, 0, playlistName, playlistId);
@@ -1585,17 +1593,17 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(downloadService == null) {
return null;
}
-
+
downloadService.clear();
downloadService.download(entries, false, true, true, false, entries.indexOf(song), position);
downloadService.setSuggestedPlaylistName(playlistName, playlistId);
return null;
}
-
+
@Override
protected void done(Void result) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ context.openNowPlaying();
}
}.execute();
}
@@ -1657,19 +1665,19 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
View layout = context.getLayoutInflater().inflate(R.layout.rating, null);
final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.rating_bar);
ratingBar.setRating((float) entry.getRating());
-
+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getResources().getString(R.string.rating_title, entry.getTitle()))
- .setView(layout)
- .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- int rating = (int) ratingBar.getRating();
- setRating(entry, rating, onRatingChange);
- }
- })
- .setNegativeButton(R.string.common_cancel, null);
-
+ .setView(layout)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ int rating = (int) ratingBar.getRating();
+ setRating(entry, rating, onRatingChange);
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null);
+
AlertDialog dialog = builder.create();
dialog.show();
}
@@ -1684,7 +1692,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(onRatingChange != null) {
onRatingChange.ratingChange(rating);
}
-
+
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
@@ -1711,7 +1719,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if(onRatingChange != null) {
onRatingChange.ratingChange(oldRating);
}
-
+
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
@@ -1723,16 +1731,16 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
}.execute();
}
-
+
protected abstract class EntryInstanceUpdater {
private Entry entry;
-
+
public EntryInstanceUpdater(Entry entry) {
this.entry = entry;
}
-
+
public abstract void update(Entry found);
-
+
public void execute() {
DownloadService downloadService = getDownloadService();
if(downloadService != null && !entry.isDirectory()) {
@@ -1745,12 +1753,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
serializeChanges = true;
}
}
-
+
if(serializeChanges) {
downloadService.serializeQueue();
}
}
-
+
Entry find = UpdateView.findEntry(entry);
if(find != null) {
update(find);
@@ -1810,7 +1818,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
if(result) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ context.openNowPlaying();
}
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java
index 444b6cff..7cb3ce8b 100644
--- a/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java
+++ b/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java
@@ -39,7 +39,6 @@ import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.activity.SubsonicActivity;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -270,9 +269,7 @@ public class DSubWidgetProvider extends AppWidgetProvider {
/**
* Link up various button actions using {@link PendingIntent}.
*
- * @param playerActive True if player is active in background, which means
- * widget click will launch {@link DownloadActivity},
- * otherwise we launch {@link github.daneren2005.dsub.activity.SubsonicFragmentActivity}.
+ * @param playerActive @param playerActive True if player is active in background. Launch {@link github.daneren2005.dsub.activity.SubsonicFragmentActivity}.
*/
private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
Intent intent = new Intent(context, SubsonicFragmentActivity.class);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java
index 75d8d5dd..876dc648 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Util.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java
@@ -48,6 +48,7 @@ import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.RepeatMode;
@@ -256,14 +257,26 @@ public final class Util {
}
public static void applyTheme(Context context, String theme) {
- if ("dark".equals(theme)) {
- context.setTheme(R.style.Theme_DSub_Dark);
- } else if ("black".equals(theme)) {
- context.setTheme(R.style.Theme_DSub_Black);
- } else if ("holo".equals(theme)) {
- context.setTheme(R.style.Theme_DSub_Holo);
+ if(context instanceof SubsonicFragmentActivity) {
+ if ("dark".equals(theme)) {
+ context.setTheme(R.style.Theme_DSub_Dark_No_Actionbar);
+ } else if ("black".equals(theme)) {
+ context.setTheme(R.style.Theme_DSub_Black_No_Actionbar);
+ } else if ("holo".equals(theme)) {
+ context.setTheme(R.style.Theme_DSub_Holo_No_Actionbar);
+ } else {
+ context.setTheme(R.style.Theme_DSub_Light_No_Actionbar);
+ }
} else {
- context.setTheme(R.style.Theme_DSub_Light);
+ if ("dark".equals(theme)) {
+ context.setTheme(R.style.Theme_DSub_Dark);
+ } else if ("black".equals(theme)) {
+ context.setTheme(R.style.Theme_DSub_Black);
+ } else if ("holo".equals(theme)) {
+ context.setTheme(R.style.Theme_DSub_Holo);
+ } else {
+ context.setTheme(R.style.Theme_DSub_Light);
+ }
}
SharedPreferences prefs = Util.getPreferences(context);