aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-10-14 21:59:17 -0700
committerScott Jackson <daneren2005@gmail.com>2013-10-14 21:59:17 -0700
commitb2341df451aaa360e9a9c07d215e2931aef855a6 (patch)
tree913ee402066ddaed9ebac84c1863b490dcc99c9c /src
parente1cf77e0ee66701dc979f4c3f5e38ce0508f5645 (diff)
downloaddsub-b2341df451aaa360e9a9c07d215e2931aef855a6.tar.gz
dsub-b2341df451aaa360e9a9c07d215e2931aef855a6.tar.bz2
dsub-b2341df451aaa360e9a9c07d215e2931aef855a6.zip
#162 Start of convert to pull out drawer
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/DownloadActivity.java3
-rw-r--r--src/github/daneren2005/dsub/activity/MainActivity.java9
-rw-r--r--src/github/daneren2005/dsub/activity/SearchActivity.java3
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java135
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java73
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java1
6 files changed, 209 insertions, 15 deletions
diff --git a/src/github/daneren2005/dsub/activity/DownloadActivity.java b/src/github/daneren2005/dsub/activity/DownloadActivity.java
index d8ebb98a..262beffe 100644
--- a/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -66,9 +66,6 @@ public class DownloadActivity extends SubsonicActivity {
currentFragment.setPrimaryFragment(true);
getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit();
}
-
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
diff --git a/src/github/daneren2005/dsub/activity/MainActivity.java b/src/github/daneren2005/dsub/activity/MainActivity.java
index 9dbc2b5e..fca1b1e9 100644
--- a/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -159,14 +159,7 @@ public class MainActivity extends SubsonicActivity {
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);
- addTab(R.string.button_bar_podcasts, SelectPodcastsFragment.class, null);
- SharedPreferences prefs = Util.getPreferences(this);
- if(prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true)) {
- addTab(R.string.button_bar_chat, ChatFragment.class, null);
- }
-
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- getSupportActionBar().setHomeButtonEnabled(false);
+
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
diff --git a/src/github/daneren2005/dsub/activity/SearchActivity.java b/src/github/daneren2005/dsub/activity/SearchActivity.java
index 1dfe4790..4e93afb6 100644
--- a/src/github/daneren2005/dsub/activity/SearchActivity.java
+++ b/src/github/daneren2005/dsub/activity/SearchActivity.java
@@ -41,9 +41,6 @@ public class SearchActivity extends SubsonicActivity {
currentFragment.setPrimaryFragment(true);
getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit();
}
-
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index bae3273c..98698d87 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -1,3 +1,21 @@
+/*
+ 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 android.content.Context;
@@ -7,22 +25,27 @@ import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
+import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
+import android.widget.ListView;
import android.widget.Spinner;
import github.daneren2005.dsub.R;
@@ -48,6 +71,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
protected SubsonicFragment currentFragment;
Spinner actionBarSpinner;
ArrayAdapter<CharSequence> spinnerAdapter;
+ ViewGroup rootView;
+ DrawerLayout drawer;
+ ActionBarDrawerToggle drawerToggle;
+ ListView drawerList;
@Override
protected void onCreate(Bundle bundle) {
@@ -65,6 +92,15 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
actionBarSpinner.setAdapter(spinnerAdapter);
getSupportActionBar().setCustomView(actionbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setHomeButtonEnabled(true);
+ }
+
+ @Override
+ protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ // Sync the toggle state after onRestoreInstanceState has occurred.
+ drawerToggle.syncState();
}
@Override
@@ -90,6 +126,67 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
super.finish();
Util.disablePendingTransition(this);
}
+
+ @Override
+ public void setContentView(int viewId) {
+ super.setContentView(R.layout.abstract_activity);
+ rootView = (ViewGroup) findViewById(R.id.content_frame);
+ LayoutInflater layoutInflater = getLayoutInflater();
+ layoutInflater.inflate(viewId, rootView);
+
+ String[] drawerListItems = getResources().getStringArray(R.array.drawerItems);
+ drawerList = (ListView) findViewById(R.id.left_drawer);
+ drawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, drawerListItems));
+
+ 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);
+ break;
+ case 1:
+ startFragmentActivity("Podcast");
+ break;
+ case 2:
+ startFragmentActivity("Chat");
+ break;
+ case 3:
+ startActivity(DownloadActivity.class);
+ break;
+ case 4:
+ startActivity(SettingsActivity.class);
+ break;
+ case 5:
+ exit();
+ break;
+ }
+ }
+ });
+
+ drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
+ drawerToggle = new ActionBarDrawerToggle(this, drawer, R.drawable.ic_drawer, R.string.common_appname, R.string.common_appname) {
+ @Override
+ public void onDrawerClosed(View view) {
+ /*if(pagerAdapter != null) {
+
+ } else {
+ getActionBar().setTitle(currentFragment.getTitle());
+ }*/
+ }
+
+ @Override
+ public void onDrawerOpened(View view) {
+ // getActionBar().setTitle(R.string.common_appname);
+ }
+ };
+ drawer.setDrawerListener(drawerToggle);
+ if(this.getClass() != MainActivity.class) {
+ drawerToggle.setDrawerIndicatorEnabled(false);
+ }
+ }
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
@@ -141,6 +238,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ if(drawerToggle.onOptionsItemSelected(item)) {
+ return true;
+ }
+
if(pagerAdapter != null) {
return pagerAdapter.onOptionsItemSelected(item);
} else if(currentFragment != null) {
@@ -194,7 +295,39 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
public void onNothingSelected(AdapterView<?> parent) {
}
-
+
+ public void startActivity(Class t) {
+ Intent intent = new Intent();
+ intent.setClass(SubsonicActivity.this, t);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ if(this.getClass() != MainActivity.class) {
+ finish();
+ }
+ }
+ public void startFragmentActivity(String fragmentType) {
+ Intent intent = new Intent();
+ intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
+ startActivity(intent);
+ if(this.getClass() != MainActivity.class) {
+ finish();
+ }
+ }
+
+ protected void exit() {
+ if(this.getClass() != MainActivity.class) {
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true);
+ Util.startActivityWithoutTransition(this, intent);
+ } else {
+ this.stopService(new Intent(this, DownloadServiceImpl.class));
+ this.finish();
+ }
+ }
+
public boolean onBackPressedSupport() {
if(pagerAdapter != null) {
return pagerAdapter.onBackPressed();
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
new file mode 100644
index 00000000..4d85e9d4
--- /dev/null
+++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -0,0 +1,73 @@
+/*
+ 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 android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.MenuItem;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.fragments.ChatFragment;
+import github.daneren2005.dsub.fragments.SelectPodcastsFragment;
+import github.daneren2005.dsub.util.Constants;
+
+/**
+ * Created by Scott on 10/14/13.
+ */
+public class SubsonicFragmentActivity extends SubsonicActivity {
+ private static String TAG = SubsonicFragmentActivity.class.getSimpleName();
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.download_activity);
+
+ if (findViewById(R.id.download_container) != null && savedInstanceState == null) {
+ String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
+ if("Chat".equals(fragmentType)) {
+ currentFragment = new ChatFragment();
+ } else if("Podcast".equals(fragmentType)) {
+ currentFragment = new SelectPodcastsFragment();
+ } else {
+ finish();
+ return;
+ }
+ currentFragment.setPrimaryFragment(true);
+ getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit();
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(item.getItemId() == android.R.id.home) {
+ startActivity(MainActivity.class);
+ return true;
+ } else {
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if(onBackPressedSupport()) {
+ super.onBackPressed();
+ }
+ }
+}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index edc919ae..36ea928c 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -59,6 +59,7 @@ public final class Constants {
public static final String INTENT_EXTRA_NAME_PODCAST_ID = "subsonic.podcast.id";
public static final String INTENT_EXTRA_NAME_PODCAST_NAME = "subsonic.podcast.name";
public static final String INTENT_EXTRA_NAME_PODCAST_DESCRIPTION = "subsonic.podcast.description";
+ public static final String INTENT_EXTRA_FRAGMENT_TYPE = "fragmentType";
// Notification IDs.
public static final int NOTIFICATION_ID_PLAYING = 100;