aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/DownloadActivity.java21
-rw-r--r--src/github/daneren2005/dsub/activity/MainActivity.java315
-rw-r--r--src/github/daneren2005/dsub/activity/SearchActivity.java3
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java419
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java300
-rw-r--r--src/github/daneren2005/dsub/fragments/DownloadFragment.java5
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java2
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java6
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidgetProvider.java8
-rw-r--r--src/github/daneren2005/dsub/util/Util.java6
-rw-r--r--src/github/daneren2005/dsub/view/ErrorDialog.java5
11 files changed, 364 insertions, 726 deletions
diff --git a/src/github/daneren2005/dsub/activity/DownloadActivity.java b/src/github/daneren2005/dsub/activity/DownloadActivity.java
index 262beffe..44a7a0ff 100644
--- a/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -23,26 +23,11 @@ import android.os.Bundle;
import android.view.MenuItem;
import android.view.MotionEvent;
import github.daneren2005.dsub.fragments.DownloadFragment;
-import android.app.Dialog;
-import android.view.LayoutInflater;
+
import android.widget.EditText;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
import android.content.Intent;
-import android.util.Log;
-import android.view.View;
-import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.service.DownloadFile;
-import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
+
import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.SilentBackgroundTask;
-import github.daneren2005.dsub.util.Util;
-import java.util.LinkedList;
-import java.util.List;
public class DownloadActivity extends SubsonicActivity {
private static final String TAG = DownloadActivity.class.getSimpleName();
@@ -72,7 +57,7 @@ public class DownloadActivity extends SubsonicActivity {
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == android.R.id.home) {
Intent i = new Intent();
- i.setClass(this, MainActivity.class);
+ i.setClass(this, SubsonicFragmentActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
return true;
diff --git a/src/github/daneren2005/dsub/activity/MainActivity.java b/src/github/daneren2005/dsub/activity/MainActivity.java
deleted file mode 100644
index fca1b1e9..00000000
--- a/src/github/daneren2005/dsub/activity/MainActivity.java
+++ /dev/null
@@ -1,315 +0,0 @@
-package github.daneren2005.dsub.activity;
-
-import android.app.AlertDialog;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.os.Handler;
-import android.preference.PreferenceManager;
-import android.support.v4.view.ViewPager;
-import android.support.v7.app.ActionBar;
-import android.util.Log;
-import android.view.View;
-import android.widget.ImageButton;
-import android.widget.TextView;
-import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.domain.PlayerState;
-import github.daneren2005.dsub.fragments.ChatFragment;
-import github.daneren2005.dsub.fragments.MainFragment;
-import github.daneren2005.dsub.fragments.SelectArtistFragment;
-import github.daneren2005.dsub.fragments.SelectDirectoryFragment;
-import github.daneren2005.dsub.fragments.SelectPlaylistFragment;
-import github.daneren2005.dsub.fragments.SelectPodcastsFragment;
-import github.daneren2005.dsub.fragments.SubsonicFragment;
-import github.daneren2005.dsub.service.DownloadFile;
-import github.daneren2005.dsub.service.DownloadServiceImpl;
-import github.daneren2005.dsub.updates.Updater;
-import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.FileUtil;
-import github.daneren2005.dsub.util.SilentBackgroundTask;
-import github.daneren2005.dsub.util.Util;
-import github.daneren2005.dsub.view.ChangeLog;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-public class MainActivity extends SubsonicActivity {
- private static final String TAG = MainActivity.class.getSimpleName();
- private static boolean infoDialogDisplayed;
- private ScheduledExecutorService executorService;
- private View bottomBar;
- private View coverArtView;
- private TextView trackView;
- private TextView artistView;
- private ImageButton startButton;
- private long lastBackPressTime = 0;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
- stopService(new Intent(this, DownloadServiceImpl.class));
- finish();
- } else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) {
- getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD);
- Intent intent = new Intent();
- intent.setClass(this, DownloadActivity.class);
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
- intent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true);
- }
- startActivity(intent);
- }
- setContentView(R.layout.main);
- loadSettings();
-
- 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);
- }
- });
- coverArtView = bottomBar.findViewById(R.id.album_art);
- trackView = (TextView) bottomBar.findViewById(R.id.track_name);
- artistView = (TextView) bottomBar.findViewById(R.id.artist_name);
-
- ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous);
- previousButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask<Void>(MainActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- if(getDownloadService() == null) {
- return null;
- }
-
- getDownloadService().previous();
- return null;
- }
-
- @Override
- protected void done(Void result) {
- update();
- }
- }.execute();
- }
- });
-
- startButton = (ImageButton) findViewById(R.id.download_start);
- startButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask<Void>(MainActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- PlayerState state = getDownloadService().getPlayerState();
- if(state == PlayerState.STARTED) {
- getDownloadService().pause();
- } else {
- getDownloadService().start();
- }
-
- return null;
- }
-
- @Override
- protected void done(Void result) {
- update();
- }
- }.execute();
- }
- });
-
- ImageButton nextButton = (ImageButton) findViewById(R.id.download_next);
- nextButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new SilentBackgroundTask<Void>(MainActivity.this) {
- @Override
- protected Void doInBackground() throws Throwable {
- if(getDownloadService() == null) {
- return null;
- }
-
- if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
- getDownloadService().next();
- }
- return null;
- }
-
- @Override
- protected void done(Void result) {
- update();
- }
- }.execute();
- }
- });
-
- viewPager = (ViewPager) findViewById(R.id.pager);
- viewPager.setOffscreenPageLimit(4);
- pagerAdapter = new TabPagerAdapter(this, viewPager);
- viewPager.setAdapter(pagerAdapter);
- viewPager.setOnPageChangeListener(pagerAdapter);
-
- addTab(R.string.button_bar_home, MainFragment.class, null);
- addTab(R.string.button_bar_browse, SelectArtistFragment.class, null);
- addTab(R.string.button_bar_playlists, SelectPlaylistFragment.class, null);
-
- getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- }
-
- @Override
- protected void onPostCreate(Bundle bundle) {
- super.onPostCreate(bundle);
-
- showInfoDialog();
- checkUpdates();
-
- ChangeLog changeLog = new ChangeLog(this, Util.getPreferences(this));
- if(changeLog.isFirstRun()) {
- changeLog.getLogDialog().show();
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- final Handler handler = new Handler();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- handler.post(new Runnable() {
- @Override
- public void run() {
- update();
- }
- });
- }
- };
-
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_VIEW_ALBUM)) {
- viewPager.setCurrentItem(1);
-
- int fragmentID = R.id.select_artist_layout;
- if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID)) {
- SubsonicFragment fragment = new SelectDirectoryFragment();
- Bundle args = new Bundle();
- args.putString(Constants.INTENT_EXTRA_NAME_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID));
- args.putString(Constants.INTENT_EXTRA_NAME_NAME, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PARENT_NAME));
- fragment.setArguments(args);
-
- pagerAdapter.queueFragment(fragment, R.id.select_artist_layout);
- fragmentID = fragment.getRootId();
- }
-
- 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));
- fragment.setArguments(args);
-
- pagerAdapter.queueFragment(fragment, fragmentID);
- getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
- }
-
- executorService = Executors.newSingleThreadScheduledExecutor();
- executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS);
- }
-
- @Override
- public void onPause() {
- super.onPause();
- executorService.shutdown();
- }
-
- @Override
- public void onBackPressed() {
- if(onBackPressedSupport()) {
- if(lastBackPressTime < (System.currentTimeMillis() - 4000)) {
- lastBackPressTime = System.currentTimeMillis();
- Util.toast(this, R.string.main_back_confirm);
- } else {
- finish();
- }
- }
- }
-
- private void update() {
- if (getDownloadService() == null) {
- return;
- }
-
- DownloadFile current = getDownloadService().getCurrentPlaying();
- if(current == null) {
- trackView.setText("Title");
- artistView.setText("Artist");
- getImageLoader().loadImage(coverArtView, null, false, false);
- return;
- }
-
- MusicDirectory.Entry song = current.getSong();
- trackView.setText(song.getTitle());
- artistView.setText(song.getArtist());
- getImageLoader().loadImage(coverArtView, song, false, false);
- int[] attrs = new int[] {(getDownloadService().getPlayerState() == PlayerState.STARTED) ? R.attr.media_button_pause : R.attr.media_button_start};
- TypedArray typedArray = this.obtainStyledAttributes(attrs);
- Drawable drawable = typedArray.getDrawable(0);
- startButton.setImageDrawable(drawable);
- typedArray.recycle();
- }
-
- 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 loadSettings() {
- PreferenceManager.setDefaultValues(this, R.xml.settings, false);
- SharedPreferences prefs = Util.getPreferences(this);
- if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) {
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath());
- editor.commit();
- }
-
- 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, "android-guest");
- editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest");
- editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
- editor.commit();
- }
- if(!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) {
- SharedPreferences.Editor editor = prefs.edit();
- editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 3);
- editor.commit();
- }
- }
-
- private void showInfoDialog() {
- if (!infoDialogDisplayed) {
- infoDialogDisplayed = true;
- Log.i(TAG, Util.getRestUrl(this, null));
- if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) {
- Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text);
- }
- }
- }
-}
diff --git a/src/github/daneren2005/dsub/activity/SearchActivity.java b/src/github/daneren2005/dsub/activity/SearchActivity.java
index 4e93afb6..7e558b20 100644
--- a/src/github/daneren2005/dsub/activity/SearchActivity.java
+++ b/src/github/daneren2005/dsub/activity/SearchActivity.java
@@ -22,7 +22,6 @@ package github.daneren2005.dsub.activity;
import github.daneren2005.dsub.R;
import android.content.Intent;
import android.os.Bundle;
-import android.util.Log;
import android.view.MenuItem;
import github.daneren2005.dsub.fragments.SearchFragment;
@@ -67,7 +66,7 @@ public class SearchActivity extends SubsonicActivity {
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == android.R.id.home) {
Intent i = new Intent();
- i.setClass(this, MainActivity.class);
+ i.setClass(this, SubsonicFragmentActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
return true;
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 83f11ecd..a0effd6b 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -65,8 +65,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
private static ImageLoader IMAGE_LOADER;
protected static String theme;
private boolean destroyed = false;
- protected TabPagerAdapter pagerAdapter;
- protected ViewPager viewPager;
protected List<SubsonicFragment> backStack = new ArrayList<SubsonicFragment>();
protected SubsonicFragment currentFragment;
Spinner actionBarSpinner;
@@ -141,25 +139,29 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Intent intent;
-
switch(position) {
case 0:
- startActivity(MainActivity.class);
+ startActivity(SubsonicFragmentActivity.class);
break;
case 1:
- startFragmentActivity("Podcast");
+ startFragmentActivity("Artist");
break;
case 2:
- startFragmentActivity("Chat");
+ startFragmentActivity("Playlist");
break;
case 3:
- startActivity(DownloadActivity.class);
+ startFragmentActivity("Podcast");
break;
case 4:
- startActivity(SettingsActivity.class);
+ startFragmentActivity("Chat");
break;
case 5:
+ startActivity(DownloadActivity.class);
+ break;
+ case 6:
+ startActivity(SettingsActivity.class);
+ break;
+ case 7:
exit();
break;
}
@@ -183,7 +185,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
};
drawer.setDrawerListener(drawerToggle);
- if(this.getClass() != MainActivity.class) {
+ if(this.getClass() != SubsonicFragmentActivity.class) {
drawerToggle.setDrawerIndicatorEnabled(false);
}
}
@@ -191,49 +193,36 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
- if(viewPager == null) {
- 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);
- } else {
- pagerAdapter.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);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
- if(viewPager == null) {
- 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);
- supportInvalidateOptionsMenu();
- for(int i = 1; i < size; i++) {
- SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i]);
- backStack.add(frag);
- }
- recreateSpinner();
- } else {
- pagerAdapter.onRestoreInstanceState(savedInstanceState);
- super.onRestoreInstanceState(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);
+ supportInvalidateOptionsMenu();
+ for(int i = 1; i < size; i++) {
+ SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i]);
+ backStack.add(frag);
}
+ recreateSpinner();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
- if(pagerAdapter != null) {
- pagerAdapter.onCreateOptionsMenu(menu, menuInflater);
- } else if(currentFragment != null) {
- currentFragment.onCreateOptionsMenu(menu, menuInflater);
- }
+ currentFragment.onCreateOptionsMenu(menu, menuInflater);
return true;
}
@Override
@@ -242,12 +231,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
return true;
}
- if(pagerAdapter != null) {
- return pagerAdapter.onOptionsItemSelected(item);
- } else if(currentFragment != null) {
- return currentFragment.onOptionsItemSelected(item);
- }
- return true;
+ return currentFragment.onOptionsItemSelected(item);
}
@Override
@@ -267,11 +251,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
@Override
public void setTitle(CharSequence title) {
super.setTitle(title);
- if(pagerAdapter != null) {
- pagerAdapter.recreateSpinner();
- } else {
- recreateSpinner();
- }
+ recreateSpinner();
}
public void setSubtitle(CharSequence title) {
getSupportActionBar().setSubtitle(title);
@@ -282,11 +262,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
int top = spinnerAdapter.getCount() - 1;
if(position < top) {
for(int i = top; i > position; i--) {
- if(pagerAdapter != null) {
- pagerAdapter.removeCurrent();
- } else {
- removeCurrent();
- }
+ removeCurrent();
}
}
}
@@ -301,7 +277,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
intent.setClass(SubsonicActivity.this, t);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
- if(this.getClass() != MainActivity.class) {
+ if(this.getClass() != SubsonicFragmentActivity.class) {
finish();
}
}
@@ -311,14 +287,12 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
startActivity(intent);
- if(this.getClass() != MainActivity.class) {
- finish();
- }
+ finish();
}
protected void exit() {
- if(this.getClass() != MainActivity.class) {
- Intent intent = new Intent(this, MainActivity.class);
+ if(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);
@@ -329,36 +303,28 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
public boolean onBackPressedSupport() {
- if(pagerAdapter != null) {
- return pagerAdapter.onBackPressed();
+ if(backStack.size() > 0) {
+ removeCurrent();
+ return false;
} else {
- if(backStack.size() > 0) {
- removeCurrent();
- return false;
- } else {
- return true;
- }
+ return true;
}
}
public void replaceFragment(SubsonicFragment fragment, int id, int tag) {
- if(pagerAdapter != null) {
- pagerAdapter.replaceCurrent(fragment, id, tag);
- } else {
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
- }
- backStack.add(currentFragment);
-
- currentFragment = fragment;
- currentFragment.setPrimaryFragment(true);
- supportInvalidateOptionsMenu();
-
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.add(id, fragment, tag + "");
- trans.commit();
- recreateSpinner();
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false);
}
+ backStack.add(currentFragment);
+
+ currentFragment = fragment;
+ currentFragment.setPrimaryFragment(true);
+ supportInvalidateOptionsMenu();
+
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.add(id, fragment, tag + "");
+ trans.commit();
+ recreateSpinner();
}
private void removeCurrent() {
if(currentFragment != null) {
@@ -390,13 +356,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
getSupportActionBar().setDisplayShowCustomEnabled(false);
}
}
-
- protected void addTab(int titleRes, Class fragmentClass, Bundle args) {
- pagerAdapter.addTab(getString(titleRes), fragmentClass, args);
- }
- protected void addTab(CharSequence title, Class fragmentClass, Bundle args) {
- pagerAdapter.addTab(title, fragmentClass, args);
- }
protected void restart() {
Intent intent = new Intent(this, this.getClass());
@@ -459,13 +418,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
return DownloadServiceImpl.getInstance();
}
- public ViewPager getViewPager() {
- return viewPager;
- }
- public TabPagerAdapter getPagerAdapter() {
- return pagerAdapter;
- }
-
public static String getThemeName() {
return theme;
}
@@ -516,265 +468,4 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
}
}
-
- public class TabPagerAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
- private ActionBarActivity activity;
- private ViewPager pager;
- private ActionBar actionBar;
- private SubsonicFragment currentFragment;
- private List<TabInfo> tabs = new ArrayList<TabInfo>();
- private List<List<SubsonicFragment>> frags = new ArrayList<List<SubsonicFragment>>();
- private List<QueuedFragment> queue = new ArrayList<QueuedFragment>();
- private int currentPosition;
- private boolean dontRecreate = false;
-
- public TabPagerAdapter(ActionBarActivity activity, ViewPager pager) {
- super(activity.getSupportFragmentManager());
- this.activity = activity;
- this.actionBar = activity.getSupportActionBar();
- this.pager = pager;
- this.currentPosition = 0;
- }
-
- @Override
- public Fragment getItem(int i) {
- final TabInfo tabInfo = tabs.get(i);
- SubsonicFragment frag = (SubsonicFragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args);
- List<SubsonicFragment> fragStack = new ArrayList<SubsonicFragment>();
- fragStack.add(frag);
- while(i > frags.size()) {
- frags.add(null);
- }
- if(i == frags.size()) {
- frags.add(i, fragStack);
- } else {
- frags.set(i, fragStack);
- }
- if(currentFragment == null || currentPosition == i) {
- currentFragment = frag;
- currentFragment.setPrimaryFragment(true);
- }
- return frag;
- }
-
- @Override
- public int getCount() {
- return tabs.size();
- }
-
- public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
- if(currentFragment != null && !dontRecreate) {
- for(QueuedFragment addFragment: queue) {
- // Let Pager know not to try to create options menu in replaceFragment
- dontRecreate = true;
- replaceFragment(addFragment.fragment, addFragment.id, currentFragment.getSupportTag());
- currentFragment = addFragment.fragment;
- }
- dontRecreate = false;
- queue.clear();
-
- currentFragment.setPrimaryFragment(true);
- currentFragment.onCreateOptionsMenu(menu, menuInflater);
- }
- }
- public boolean onOptionsItemSelected(MenuItem item) {
- if(currentFragment != null) {
- return currentFragment.onOptionsItemSelected(item);
- } else {
- return false;
- }
- }
-
- public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
- TabInfo tabInfo = (TabInfo) tab.getTag();
- for (int i = 0; i < tabs.size(); i++) {
- if ( tabs.get(i) == tabInfo ) {
- pager.setCurrentItem(i);
- break;
- }
- }
- }
-
- public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {}
-
- public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {}
-
- public void onPageScrollStateChanged(int arg0) {}
-
- public void onPageScrolled(int arg0, float arg1, int arg2) {}
-
- public void onPageSelected(int position) {
- currentPosition = position;
- actionBar.setSelectedNavigationItem(position);
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
- }
- if(position <= frags.size()) {
- List<SubsonicFragment> fragStack = frags.get(position);
- currentFragment = fragStack.get(fragStack.size() - 1);
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(true);
- }
- activity.supportInvalidateOptionsMenu();
- recreateSpinner();
- }
- }
-
- public void addTab(CharSequence title, Class fragmentClass, Bundle args) {
- final TabInfo tabInfo = new TabInfo(fragmentClass, args);
-
- ActionBar.Tab tab = actionBar.newTab();
- tab.setText(title);
- tab.setTabListener(this);
- tab.setTag(tabInfo);
-
- tabs.add(tabInfo);
-
- actionBar.addTab(tab);
- notifyDataSetChanged();
- }
- public void queueFragment(SubsonicFragment fragment, int id) {
- QueuedFragment frag = new QueuedFragment();
- frag.fragment = fragment;
- frag.id = id;
- queue.add(frag);
- }
- public void replaceCurrent(SubsonicFragment fragment, int id, int tag) {
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
- }
- List<SubsonicFragment> fragStack = frags.get(currentPosition);
- fragStack.add(fragment);
-
- currentFragment = fragment;
- currentFragment.setPrimaryFragment(true);
- activity.supportInvalidateOptionsMenu();
-
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.add(id, fragment, tag + "");
- trans.commit();
- recreateSpinner();
- }
-
- public void removeCurrent() {
- if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
- }
- List<SubsonicFragment> fragStack = frags.get(currentPosition);
- Fragment oldFrag = (Fragment)fragStack.remove(fragStack.size() - 1);
-
- currentFragment = fragStack.get(fragStack.size() - 1);
- currentFragment.setPrimaryFragment(true);
- activity.supportInvalidateOptionsMenu();
-
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.remove(oldFrag);
- trans.commit();
- }
-
- public boolean onBackPressed() {
- List<SubsonicFragment> fragStack = frags.get(currentPosition);
- if(fragStack.size() > 1) {
- removeCurrent();
- recreateSpinner();
- return false;
- } else {
- if(currentPosition == 0) {
- return true;
- } else {
- viewPager.setCurrentItem(0);
- return false;
- }
- }
- }
-
- private void recreateSpinner() {
- if(frags.isEmpty()) {
- return;
- }
-
- List<SubsonicFragment> fragStack = frags.get(currentPosition);
- if(fragStack.size() > 1) {
- spinnerAdapter.clear();
- for(int i = 0; i < fragStack.size(); i++) {
- SubsonicFragment frag = fragStack.get(i);
- spinnerAdapter.add(frag.getTitle());
- }
- spinnerAdapter.notifyDataSetChanged();
- actionBarSpinner.setSelection(spinnerAdapter.getCount() - 1);
- actionBar.setDisplayShowCustomEnabled(true);
- } else {
- actionBar.setDisplayShowCustomEnabled(false);
- }
- }
-
- public void invalidate() {
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- for (int i = 0; i < frags.size(); i++) {
- List<SubsonicFragment> fragStack = frags.get(i);
-
- for(int j = fragStack.size() - 1; j > 0; j--) {
- SubsonicFragment oldFrag = fragStack.remove(j);
- trans.remove((Fragment)oldFrag);
- }
-
- SubsonicFragment frag = (SubsonicFragment)fragStack.get(0);
- frag.invalidate();
- }
- trans.commit();
- }
-
- public void onSaveInstanceState(Bundle savedInstanceState) {
- for(int i = 0; i < frags.size(); i++) {
- List<SubsonicFragment> fragStack = frags.get(i);
- String[] ids = new String[fragStack.size()];
-
- for(int j = 0; j < fragStack.size(); j++) {
- ids[j] = fragStack.get(j).getTag();
- }
- savedInstanceState.putStringArray(Constants.MAIN_BACK_STACK + i, ids);
- savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE + i, fragStack.size());
- }
- savedInstanceState.putInt(Constants.MAIN_BACK_STACK_TABS, frags.size());
- savedInstanceState.putInt(Constants.MAIN_BACK_STACK_POSITION, currentPosition);
- }
-
- public void onRestoreInstanceState(Bundle savedInstanceState) {
- int tabCount = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_TABS);
- FragmentManager fm = activity.getSupportFragmentManager();
- for(int i = 0; i < tabCount; i++) {
- int stackSize = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE + i);
- String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK + i);
- List<SubsonicFragment> fragStack = new ArrayList<SubsonicFragment>();
-
- for(int j = 0; j < stackSize; j++) {
- SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[j]);
- fragStack.add(frag);
- }
-
- frags.add(i, fragStack);
- }
-
- if(tabCount > 0) {
- currentPosition = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_POSITION);
- List<SubsonicFragment> fragStack = frags.get(currentPosition);
- currentFragment = fragStack.get(fragStack.size() - 1);
- currentFragment.setPrimaryFragment(true);
- activity.supportInvalidateOptionsMenu();
- }
- }
-
- private class TabInfo {
- public final Class fragmentClass;
- public final Bundle args;
- public TabInfo(Class fragmentClass, Bundle args) {
- this.fragmentClass = fragmentClass;
- this.args = args;
- }
- }
- private class QueuedFragment {
- public SubsonicFragment fragment;
- public int id;
- }
- }
}
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index 4d85e9d4..c8d43f31 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -19,55 +19,335 @@
package github.daneren2005.dsub.activity;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.os.Handler;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.TextView;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.fragments.ChatFragment;
+import github.daneren2005.dsub.fragments.MainFragment;
+import github.daneren2005.dsub.fragments.SelectArtistFragment;
+import github.daneren2005.dsub.fragments.SelectDirectoryFragment;
+import github.daneren2005.dsub.fragments.SelectPlaylistFragment;
import github.daneren2005.dsub.fragments.SelectPodcastsFragment;
+import github.daneren2005.dsub.fragments.SubsonicFragment;
+import github.daneren2005.dsub.service.DownloadFile;
+import github.daneren2005.dsub.service.DownloadServiceImpl;
+import github.daneren2005.dsub.updates.Updater;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.SilentBackgroundTask;
+import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.ChangeLog;
/**
* Created by Scott on 10/14/13.
*/
public class SubsonicFragmentActivity extends SubsonicActivity {
private static String TAG = SubsonicFragmentActivity.class.getSimpleName();
+ private static boolean infoDialogDisplayed;
+ private ScheduledExecutorService executorService;
+ private View bottomBar;
+ private View coverArtView;
+ private TextView trackView;
+ private TextView artistView;
+ private ImageButton startButton;
+ private long lastBackPressTime = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.download_activity);
+ if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
+ stopService(new Intent(this, DownloadServiceImpl.class));
+ finish();
+ } else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) {
+ getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD);
+ Intent intent = new Intent();
+ intent.setClass(this, DownloadActivity.class);
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true);
+ }
+ startActivity(intent);
+ }
+ setContentView(R.layout.abstract_fragment_activity);
- if (findViewById(R.id.download_container) != null && savedInstanceState == null) {
+ if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) {
String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
- if("Chat".equals(fragmentType)) {
+ if("Artist".equals(fragmentType)) {
+ currentFragment = new SelectArtistFragment();
+ } else if("Playlist".equals(fragmentType)) {
+ currentFragment = new SelectPlaylistFragment();
+ } else if("Chat".equals(fragmentType)) {
currentFragment = new ChatFragment();
} else if("Podcast".equals(fragmentType)) {
currentFragment = new SelectPodcastsFragment();
} else {
- finish();
- return;
+ currentFragment = new MainFragment();
+
+ // Initial startup stuff
+ loadSettings();
}
currentFragment.setPrimaryFragment(true);
- getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit();
+ getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, currentFragment, currentFragment.getSupportTag() + "").commit();
+ }
+
+ 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);
+ }
+ });
+ coverArtView = bottomBar.findViewById(R.id.album_art);
+ trackView = (TextView) bottomBar.findViewById(R.id.track_name);
+ artistView = (TextView) bottomBar.findViewById(R.id.artist_name);
+
+ ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous);
+ previousButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if(getDownloadService() == null) {
+ return null;
+ }
+
+ getDownloadService().previous();
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ update();
+ }
+ }.execute();
+ }
+ });
+
+ startButton = (ImageButton) findViewById(R.id.download_start);
+ startButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ PlayerState state = getDownloadService().getPlayerState();
+ if(state == PlayerState.STARTED) {
+ getDownloadService().pause();
+ } else {
+ getDownloadService().start();
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ update();
+ }
+ }.execute();
+ }
+ });
+
+ ImageButton nextButton = (ImageButton) findViewById(R.id.download_next);
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if(getDownloadService() == null) {
+ return null;
+ }
+
+ if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
+ getDownloadService().next();
+ }
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ update();
+ }
+ }.execute();
+ }
+ });
+ }
+
+ @Override
+ protected void onPostCreate(Bundle bundle) {
+ super.onPostCreate(bundle);
+
+ showInfoDialog();
+ checkUpdates();
+
+ ChangeLog changeLog = new ChangeLog(this, Util.getPreferences(this));
+ if(changeLog.isFirstRun()) {
+ changeLog.getLogDialog().show();
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ final Handler handler = new Handler();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ update();
+ }
+ });
+ }
+ };
+
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_VIEW_ALBUM)) {
+ int fragmentID = R.id.select_artist_layout;
+ if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID)) {
+ SubsonicFragment fragment = new SelectDirectoryFragment();
+ Bundle args = new Bundle();
+ args.putString(Constants.INTENT_EXTRA_NAME_ID, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID));
+ args.putString(Constants.INTENT_EXTRA_NAME_NAME, getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PARENT_NAME));
+ fragment.setArguments(args);
+
+ replaceFragment(fragment, R.id.select_artist_layout, currentFragment.getSupportTag());
+ fragmentID = fragment.getRootId();
+ }
+
+ 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));
+ fragment.setArguments(args);
+
+ replaceFragment(fragment, fragmentID, currentFragment.getSupportTag());
+ getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
}
+
+ executorService = Executors.newSingleThreadScheduledExecutor();
+ executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ executorService.shutdown();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if(item.getItemId() == android.R.id.home) {
- startActivity(MainActivity.class);
+ if(super.onOptionsItemSelected(item)) {
+ return true;
+ } else if(item.getItemId() == android.R.id.home) {
+ startActivity(SubsonicFragmentActivity.class);
return true;
} else {
- return super.onOptionsItemSelected(item);
+ return false;
}
}
@Override
public void onBackPressed() {
if(onBackPressedSupport()) {
- super.onBackPressed();
+ if(lastBackPressTime < (System.currentTimeMillis() - 4000)) {
+ lastBackPressTime = System.currentTimeMillis();
+ Util.toast(this, R.string.main_back_confirm);
+ } else {
+ finish();
+ }
+ }
+ }
+
+ private void update() {
+ if (getDownloadService() == null) {
+ return;
+ }
+
+ DownloadFile current = getDownloadService().getCurrentPlaying();
+ if(current == null) {
+ trackView.setText("Title");
+ artistView.setText("Artist");
+ getImageLoader().loadImage(coverArtView, null, false, false);
+ return;
+ }
+
+ MusicDirectory.Entry song = current.getSong();
+ trackView.setText(song.getTitle());
+ artistView.setText(song.getArtist());
+ getImageLoader().loadImage(coverArtView, song, false, false);
+ int[] attrs = new int[] {(getDownloadService().getPlayerState() == PlayerState.STARTED) ? R.attr.media_button_pause : R.attr.media_button_start};
+ TypedArray typedArray = this.obtainStyledAttributes(attrs);
+ Drawable drawable = typedArray.getDrawable(0);
+ startButton.setImageDrawable(drawable);
+ typedArray.recycle();
+ }
+
+ 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 loadSettings() {
+ PreferenceManager.setDefaultValues(this, R.xml.settings, false);
+ SharedPreferences prefs = Util.getPreferences(this);
+ if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath());
+ editor.commit();
+ }
+
+ 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, "android-guest");
+ editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest");
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
+ editor.commit();
+ }
+ if(!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 3);
+ editor.commit();
+ }
+ }
+
+ private void showInfoDialog() {
+ if (!infoDialogDisplayed) {
+ infoDialogDisplayed = true;
+ Log.i(TAG, Util.getRestUrl(this, null));
+ if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) {
+ Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text);
+ }
}
}
}
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
index 7bd162f1..8d30c523 100644
--- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java
+++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
@@ -40,6 +40,7 @@ import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ViewFlipper;
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.RemoteControlState;
@@ -60,7 +61,6 @@ import java.util.ArrayList;
import java.util.concurrent.ScheduledFuture;
import com.mobeta.android.dslv.*;
import github.daneren2005.dsub.activity.EqualizerActivity;
-import github.daneren2005.dsub.activity.MainActivity;
import github.daneren2005.dsub.activity.SubsonicActivity;
public class DownloadFragment extends SubsonicFragment implements OnGestureListener {
@@ -554,10 +554,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
case R.id.menu_show_album:
MusicDirectory.Entry entry = song.getSong();
- Intent intent = new Intent(context, MainActivity.class);
+ Intent intent = new Intent(context, SubsonicFragmentActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_VIEW_ALBUM, true);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getParent());
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getAlbum());
+ intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, "Artist");
if(entry.getGrandParent() != null) {
intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.getGrandParent());
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index 05726483..e1bd8db6 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -116,7 +116,6 @@ public class MainFragment extends SubsonicFragment {
int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE;
setActiveServer(activeServer);
- context.getPagerAdapter().invalidate();
return true;
}
@@ -201,7 +200,6 @@ public class MainFragment extends SubsonicFragment {
private void toggleOffline() {
boolean isOffline = Util.isOffline(context);
Util.setOffline(context, !isOffline);
- context.getPagerAdapter().invalidate();
if(isOffline) {
int scrobblesCount = Util.offlineScrobblesCount(context);
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 5af3feb7..e9f246fa 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -42,10 +42,10 @@ import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.activity.HelpActivity;
-import github.daneren2005.dsub.activity.MainActivity;
import github.daneren2005.dsub.activity.SearchActivity;
import github.daneren2005.dsub.activity.SettingsActivity;
import github.daneren2005.dsub.activity.SubsonicActivity;
+import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -335,8 +335,8 @@ public class SubsonicFragment extends Fragment {
}
protected void exit() {
- if(context.getClass() != MainActivity.class) {
- Intent intent = new Intent(context, MainActivity.class);
+ if(context.getClass() != SubsonicFragmentActivity.class) {
+ Intent intent = new Intent(context, SubsonicFragmentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true);
Util.startActivityWithoutTransition(context, intent);
diff --git a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
index f0c7f9fb..3b4e545f 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
@@ -41,7 +41,7 @@ import android.view.View;
import android.widget.RemoteViews;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.DownloadActivity;
-import github.daneren2005.dsub.activity.MainActivity;
+import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.DownloadServiceImpl;
@@ -49,8 +49,6 @@ import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
-import java.util.HashMap;
-
/**
* Simple widget to show currently playing album art along
* with play/pause and next track buttons.
@@ -257,10 +255,10 @@ public class DSubWidgetProvider extends AppWidgetProvider {
*
* @param playerActive True if player is active in background, which means
* widget click will launch {@link DownloadActivity},
- * otherwise we launch {@link MainActivity}.
+ * otherwise we launch {@link github.daneren2005.dsub.activity.SubsonicFragmentActivity}.
*/
private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
- Intent intent = new Intent(context, MainActivity.class);
+ Intent intent = new Intent(context, SubsonicFragmentActivity.class);
if(playerActive) {
intent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 606b4b0d..f8a0af79 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -54,7 +54,7 @@ import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.Toast;
import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.activity.MainActivity;
+import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.RepeatMode;
@@ -836,7 +836,7 @@ public final class Util {
setupViews(smallContentView, context, song, playing);
notification.contentView = smallContentView;
- Intent notificationIntent = new Intent(context, MainActivity.class);
+ Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -943,7 +943,7 @@ public final class Util {
.setProgress(10, 5, true)
.setOngoing(true);
- Intent notificationIntent = new Intent(context, MainActivity.class);
+ Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/src/github/daneren2005/dsub/view/ErrorDialog.java b/src/github/daneren2005/dsub/view/ErrorDialog.java
index 55f230a4..246b3756 100644
--- a/src/github/daneren2005/dsub/view/ErrorDialog.java
+++ b/src/github/daneren2005/dsub/view/ErrorDialog.java
@@ -22,8 +22,9 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
-import github.daneren2005.dsub.activity.MainActivity;
+
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.util.Util;
/**
@@ -67,7 +68,7 @@ public class ErrorDialog {
}
private void restart(Activity context) {
- Intent intent = new Intent(context, MainActivity.class);
+ Intent intent = new Intent(context, SubsonicFragmentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Util.startActivityWithoutTransition(context, intent);
}