aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SettingsActivity.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java294
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java44
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/DrawerAdapter.java126
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java42
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Notifications.java3
-rw-r--r--app/src/main/res/layout/abstract_activity.xml15
-rw-r--r--app/src/main/res/layout/drawer_header.xml52
-rw-r--r--app/src/main/res/layout/drawer_list_item.xml27
-rw-r--r--app/src/main/res/menu/drawer_navigation.xml51
-rw-r--r--app/src/main/res/values/arrays.xml39
-rw-r--r--app/src/main/res/values/attrs.xml10
-rw-r--r--app/src/main/res/values/themes.xml26
14 files changed, 339 insertions, 396 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SettingsActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SettingsActivity.java
index d5ac60d3..babc9d48 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -73,6 +73,7 @@ public class SettingsActivity extends SubsonicActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ lastSelectedPosition = R.id.drawer_settings;
setContentView(R.layout.download_activity);
if (savedInstanceState == null) {
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 cb09728c..d730b412 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -25,11 +25,11 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
-import android.content.res.TypedArray;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.support.design.widget.NavigationView;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@@ -52,14 +52,12 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
-import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import github.daneren2005.dsub.R;
@@ -71,7 +69,6 @@ import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Util;
-import github.daneren2005.dsub.adapter.DrawerAdapter;
import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.dsub.util.UserUtil;
@@ -80,10 +77,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
private static ImageLoader IMAGE_LOADER;
protected static String theme;
protected static boolean fullScreen;
- private String[] drawerItemsDescriptions;
- private String[] drawerItems;
+ private static final int MENU_GROUP_SERVER = 10;
+ private static final int MENU_ITEM_SERVER_BASE = 100;
+
private boolean drawerIdle = true;
- private boolean[] enabledItems = {true, true, true, true, true};
private boolean destroyed = false;
private boolean finished = false;
protected List<SubsonicFragment> backStack = new ArrayList<SubsonicFragment>();
@@ -97,15 +94,15 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
ViewGroup rootView;
DrawerLayout drawer;
ActionBarDrawerToggle drawerToggle;
- DrawerAdapter drawerAdapter;
- ListView drawerList;
+ NavigationView drawerList;
View drawerHeader;
ImageView drawerUserAvatar;
TextView drawerServerName;
TextView drawerUserName;
- TextView lastSelectedView = null;
int lastSelectedPosition = 0;
+ boolean showingTabs = true;
boolean drawerOpen = false;
+ SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
@Override
protected void onCreate(Bundle bundle) {
@@ -128,6 +125,33 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
}
+
+ if(preferencesListener == null) {
+ preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ // When changing drawer settings change visibility
+ switch(key) {
+ case Constants.PREFERENCES_KEY_PODCASTS_ENABLED:
+ setDrawerItemVisible(R.id.drawer_podcasts, false);
+ break;
+ case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED:
+ setDrawerItemVisible(R.id.drawer_bookmarks, false);
+ break;
+ case Constants.PREFERENCES_KEY_SHARED_ENABLED:
+ setDrawerItemVisible(R.id.drawer_shares, false);
+ break;
+ case Constants.PREFERENCES_KEY_CHAT_ENABLED:
+ setDrawerItemVisible(R.id.drawer_chat, false);
+ break;
+ case Constants.PREFERENCES_KEY_ADMIN_ENABLED:
+ setDrawerItemVisible(R.id.drawer_admin, false);
+ break;
+ }
+ }
+ };
+ Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
+ }
}
@Override
@@ -174,7 +198,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
- populateDrawer();
+ populateTabs();
UpdateView.addActiveActivity();
}
@@ -189,6 +213,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
protected void onDestroy() {
super.onDestroy();
destroyed = true;
+ Util.getPreferences(this).unregisterOnSharedPreferenceChangeListener(preferencesListener);
}
@Override
@@ -198,19 +223,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
@Override
- public void startActivity(Intent intent) {
- if(intent.getComponent() != null) {
- String name = intent.getComponent().getClassName();
- if(name != null && name.indexOf("DownloadActivity") != -1) {
- intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
- } else if(name != null && name.indexOf("SettingsActivity") != -1) {
- intent.putExtra(Constants.FRAGMENT_POSITION, drawerItems.length - 1);
- }
- }
- super.startActivity(intent);
- }
-
- @Override
public void setContentView(int viewId) {
if(isTv()) {
super.setContentView(R.layout.static_drawer_activity);
@@ -224,34 +236,88 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
layoutInflater.inflate(viewId, rootView);
}
- drawerList = (ListView) findViewById(R.id.left_drawer);
- drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
+ drawerList = (NavigationView) findViewById(R.id.left_drawer);
+ drawerList.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
- public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {
- final int actualPosition = drawerAdapter.getActualPosition(position - 1);
- if("Settings".equals(drawerItemsDescriptions[actualPosition])) {
- startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class));
- drawer.closeDrawers();
- } else if("Admin".equals(drawerItemsDescriptions[actualPosition]) && UserUtil.isCurrentAdmin()) {
- UserUtil.confirmCredentials(SubsonicActivity.this, new Runnable() {
- @Override
- public void run() {
- drawerItemSelected(actualPosition, view);
- }
- });
+ public boolean onNavigationItemSelected(MenuItem menuItem) {
+ if(showingTabs) {
+ // Settings are on a different selectable track
+ if (menuItem.getItemId() != R.id.drawer_settings) {
+ menuItem.setChecked(true);
+ }
+ lastSelectedPosition = menuItem.getItemId();
+
+ switch (menuItem.getItemId()) {
+ case R.id.drawer_home:
+ drawerItemSelected("Home");
+ return true;
+ case R.id.drawer_library:
+ drawerItemSelected("Artist");
+ return true;
+ case R.id.drawer_playlists:
+ drawerItemSelected("Playlist");
+ return true;
+ case R.id.drawer_podcasts:
+ drawerItemSelected("Podcast");
+ return true;
+ case R.id.drawer_bookmarks:
+ drawerItemSelected("Bookmark");
+ return true;
+ case R.id.drawer_shares:
+ drawerItemSelected("Share");
+ return true;
+ case R.id.drawer_chat:
+ drawerItemSelected("Chat");
+ return true;
+ case R.id.drawer_admin:
+ if (UserUtil.isCurrentAdmin()) {
+ UserUtil.confirmCredentials(SubsonicActivity.this, new Runnable() {
+ @Override
+ public void run() {
+ drawerItemSelected("Admin");
+ }
+ });
+ } else {
+ drawerItemSelected("Admin");
+ }
+ return true;
+ case R.id.drawer_downloading:
+ drawerItemSelected("Download");
+ return true;
+ case R.id.drawer_settings:
+ startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class));
+ drawer.closeDrawers();
+ return true;
+ }
} else {
- drawerItemSelected(actualPosition, view);
+ int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE;
+ SubsonicActivity.this.setActiveServer(activeServer);
+ populateTabs();
+ return true;
+ }
+
+ return false;
+ }
+ });
+ populateTabs();
+
+ drawerHeader = drawerList.inflateHeaderView(R.layout.drawer_header);
+ drawerHeader.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(showingTabs) {
+ populateServers();
+ } else {
+ populateTabs();
}
}
});
- drawerHeader = getLayoutInflater().inflate(R.layout.drawer_header, drawerList, false);
drawerServerName = (TextView) drawerHeader.findViewById(R.id.header_server_name);
drawerUserName = (TextView) drawerHeader.findViewById(R.id.header_user_name);
drawerUserAvatar = (ImageView) drawerHeader.findViewById(R.id.header_user_avatar);
updateDrawerHeader();
- drawerList.addHeaderView(drawerHeader, null, false);
if(!isTv()) {
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
@@ -265,23 +331,19 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
drawerOpen = false;
supportInvalidateOptionsMenu();
+ if(!showingTabs) {
+ populateTabs();
+ }
}
@Override
public void onDrawerOpened(View view) {
DownloadService downloadService = getDownloadService();
- if (downloadService == null || downloadService.getBackgroundDownloads().isEmpty()) {
- drawerAdapter.setDownloadVisible(false);
- } else {
- drawerAdapter.setDownloadVisible(true);
- }
-
- if (lastSelectedView == null && drawerList.getCount() > lastSelectedPosition) {
- lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition + 1).findViewById(R.id.drawer_name);
- if (lastSelectedView != null) {
- lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold);
- }
+ boolean downloadingVisible = downloadService != null && !downloadService.getBackgroundDownloads().isEmpty();
+ if(lastSelectedPosition == R.id.drawer_downloading) {
+ downloadingVisible = true;
}
+ setDrawerItemVisible(R.id.drawer_downloading, downloadingVisible);
getSupportActionBar().setTitle(R.string.common_appname);
getSupportActionBar().setDisplayShowCustomEnabled(false);
@@ -382,6 +444,12 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
+ if(lastSelectedPosition != 0) {
+ MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
+ if(item != null) {
+ item.setChecked(true);
+ }
+ }
recreateSpinner();
}
@@ -462,7 +530,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
- private void populateDrawer() {
+ private void populateTabs() {
+ drawerList.getMenu().clear();
+ drawerList.inflateMenu(R.menu.drawer_navigation);
+
SharedPreferences prefs = Util.getPreferences(this);
boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true);
boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true) && !Util.isOffline(this) && ServerInfo.canBookmark(this);
@@ -470,88 +541,56 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
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);
-
- List<String> drawerItemsList = new ArrayList<String>(Arrays.asList(drawerItems));
- List<Integer> drawerItemsIconsList = new ArrayList<Integer>();
- List<Boolean> drawerItemsVisibleList = new ArrayList<Boolean>();
-
- int[] arrayAttr = {R.attr.drawerItemsIcons};
- TypedArray arrayType = obtainStyledAttributes(arrayAttr);
- int arrayId = arrayType.getResourceId(0, 0);
- TypedArray iconType = getResources().obtainTypedArray(arrayId);
- for(int i = 0; i < drawerItemsList.size(); i++) {
- drawerItemsIconsList.add(iconType.getResourceId(i, 0));
- drawerItemsVisibleList.add(true);
- }
- iconType.recycle();
- arrayType.recycle();
-
- // Hide listings user doesn't want to see
- if(!podcastsEnabled) {
- drawerItemsVisibleList.set(3, false);
- }
- if(!bookmarksEnabled) {
- drawerItemsVisibleList.set(4, false);
- }
- if(!sharedEnabled) {
- drawerItemsVisibleList.set(5, false);
- }
- if(!chatEnabled) {
- drawerItemsVisibleList.set(6, false);
- }
- if(!adminEnabled) {
- drawerItemsVisibleList.set(7, false);
- }
- 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;
- enabledItems[2] = sharedEnabled;
- enabledItems[3] = chatEnabled;
- enabledItems[4] = adminEnabled;
-
- String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
- if(fragmentType != null && lastSelectedPosition == 0) {
- for(int i = 0; i < drawerItemsDescriptions.length; i++) {
- if(fragmentType.equals(drawerItemsDescriptions[i])) {
- lastSelectedPosition = drawerAdapter.getAdapterPosition(i);
- break;
- }
- }
- }
+ if(!podcastsEnabled) {
+ setDrawerItemVisible(R.id.drawer_podcasts, false);
+ }
+ if(!bookmarksEnabled) {
+ setDrawerItemVisible(R.id.drawer_bookmarks, false);
+ }
+ if(!sharedEnabled) {
+ setDrawerItemVisible(R.id.drawer_shares, false);
+ }
+ if(!chatEnabled) {
+ setDrawerItemVisible(R.id.drawer_chat, false);
+ }
+ if(!adminEnabled) {
+ setDrawerItemVisible(R.id.drawer_admin, false);
+ }
- if(drawerList.getChildAt(lastSelectedPosition + 1) == null) {
- lastSelectedView = null;
- drawerAdapter.setSelectedPosition(lastSelectedPosition);
- } else {
- lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition + 1).findViewById(R.id.drawer_name);
- if(lastSelectedView != null) {
- lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold);
- }
+ if(lastSelectedPosition != 0) {
+ MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
+ if(item != null) {
+ item.setChecked(true);
}
}
+ showingTabs = true;
}
+ private void populateServers() {
+ drawerList.getMenu().clear();
- protected void drawerItemSelected(int position, View view) {
- startFragmentActivity(drawerItemsDescriptions[position]);
-
- if(lastSelectedView != view) {
- if(lastSelectedView != null) {
- lastSelectedView.setTextAppearance(this, R.style.DSub_TextViewStyle);
+ int serverCount = Util.getServerCount(this);
+ int activeServer = Util.getActiveServer(this);
+ for(int i = 1; i <= serverCount; i++) {
+ MenuItem item = drawerList.getMenu().add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_BASE + i, MENU_ITEM_SERVER_BASE + i, Util.getServerName(this, i));
+ if(activeServer == i) {
+ item.setChecked(true);
}
+ }
+ drawerList.getMenu().setGroupCheckable(MENU_GROUP_SERVER, true, true);
- lastSelectedView = (TextView) view.findViewById(R.id.drawer_name);
- lastSelectedView.setTextAppearance(this, R.style.DSub_TextViewStyle_Bold);
- lastSelectedPosition = position;
+ showingTabs = false;
+ }
+ private void setDrawerItemVisible(int id, boolean visible) {
+ MenuItem item = drawerList.getMenu().findItem(id);
+ if(item != null) {
+ item.setVisible(visible);
}
}
+ protected void drawerItemSelected(String fragmentType) {
+ startFragmentActivity(fragmentType);
+ }
+
public void startFragmentActivity(String fragmentType) {
Intent intent = new Intent();
intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class);
@@ -559,6 +598,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(!"".equals(fragmentType)) {
intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
}
+ if(lastSelectedPosition != 0) {
+ intent.putExtra(Constants.FRAGMENT_POSITION, lastSelectedPosition);
+ }
startActivity(intent);
finish();
}
@@ -719,7 +761,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
}
currentFragment.invalidate();
- populateDrawer();
+ populateTabs();
}
supportInvalidateOptionsMenu();
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 c5391a88..08930ae7 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -112,9 +112,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
getImageLoader().clearCache();
} else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, "Download");
- if(drawerAdapter != null) {
- drawerAdapter.setDownloadVisible(true);
- }
+ lastSelectedPosition = R.id.drawer_downloading;
}
setContentView(R.layout.abstract_fragment_activity);
@@ -127,6 +125,37 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
if(fragmentType != null) {
getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType);
firstRun = true;
+
+ switch(fragmentType) {
+ case "Home":
+ lastSelectedPosition = R.id.drawer_home;
+ break;
+ case "Artist":
+ lastSelectedPosition = R.id.drawer_library;
+ break;
+ case "Playlist":
+ lastSelectedPosition = R.id.drawer_playlists;
+ break;
+ case "Podcast":
+ lastSelectedPosition = R.id.drawer_podcasts;
+ break;
+ case "Bookmark":
+ lastSelectedPosition = R.id.drawer_bookmarks;
+ break;
+ case "Share":
+ lastSelectedPosition = R.id.drawer_shares;
+ break;
+ case "Chat":
+ lastSelectedPosition = R.id.drawer_chat;
+ break;
+ }
+ } else {
+ lastSelectedPosition = R.id.drawer_home;
+ }
+
+ MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
+ if(item != null) {
+ item.setChecked(true);
}
}
currentFragment = getNewFragment(fragmentType);
@@ -394,9 +423,6 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
replaceFragment(fragment, fragment.getSupportTag());
getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
- if("Artist".equals(getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE))) {
- lastSelectedPosition = 1;
- }
}
createAccount();
@@ -480,8 +506,8 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
}
@Override
- protected void drawerItemSelected(int position, View view) {
- super.drawerItemSelected(position, view);
+ protected void drawerItemSelected(String fragmentType) {
+ super.drawerItemSelected(fragmentType);
if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
slideUpPanel.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
@@ -577,7 +603,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
artistView.setText(R.string.main_artist);
}
- if(coverArtView.getHeight() > 0 ) {
+ if(coverArtView != null && coverArtView.getHeight() != 0) {
SilentBackgroundTask task = getImageLoader().loadImage(coverArtView, song, false, coverArtView.getHeight(), false);
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
if (task == null) {
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/DrawerAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/DrawerAdapter.java
deleted file mode 100644
index b0a4a33d..00000000
--- a/app/src/main/java/github/daneren2005/dsub/adapter/DrawerAdapter.java
+++ /dev/null
@@ -1,126 +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.adapter;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import java.util.List;
-
-import github.daneren2005.dsub.R;
-
-/**
- * Created by Scott on 11/8/13.
- */
-public class DrawerAdapter extends ArrayAdapter<String> {
- private static String TAG = DrawerAdapter.class.getSimpleName();
- private Context context;
- private List<String> items;
- private List<Integer> icons;
- private List<Boolean> visible;
- private int selectedPosition = -1;
-
- public DrawerAdapter(Context context, List<String> items, List<Integer> icons, List<Boolean> visible) {
- super(context, R.layout.drawer_list_item, items);
-
- this.context = context;
- this.items = items;
- this.icons = icons;
- this.visible = visible;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- position = getActualPosition(position);
- String item = items.get(position);
- Integer icon = icons.get(position);
-
- if(convertView == null) {
- convertView = LayoutInflater.from(context).inflate(R.layout.drawer_list_item, null);
- }
-
- TextView textView = (TextView) convertView.findViewById(R.id.drawer_name);
- textView.setText(item);
-
- if(selectedPosition == position) {
- textView.setTextAppearance(context, R.style.DSub_TextViewStyle_Bold);
- selectedPosition = -1;
- }
-
- ImageView iconView = (ImageView) convertView.findViewById(R.id.drawer_icon);
- iconView.setImageResource(icon);
-
- return convertView;
- }
-
- @Override
- public int getCount() {
- int count = 0;
- for(int i = 0; i < visible.size(); i++) {
- if(visible.get(i)) {
- count++;
- }
- }
-
- return count;
- }
-
- public int getActualPosition(int position) {
- for(int i = 0; i <= position; i++) {
- if(!visible.get(i)) {
- position++;
- }
- }
-
- return position;
- }
- public int getAdapterPosition(int position) {
- if(!visible.get(position)) {
- visible.set(position, true);
- notifyDataSetChanged();
- }
-
- for(int i = position; i >= 0; i--) {
- if(!visible.get(i)) {
- position--;
- }
- }
-
- return position;
- }
-
- public void setItemVisible(int position, boolean visible) {
- if(this.visible.get(position) != visible) {
- this.visible.set(position, visible);
- notifyDataSetInvalidated();
- }
- }
- public void setDownloadVisible(boolean visible) {
- setItemVisible(items.size() - 2, visible);
- }
-
- public void setSelectedPosition(int position) {
- selectedPosition = position;
- }
-}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java
index 71c135aa..0c33ef8c 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java
@@ -116,35 +116,6 @@ public class MainFragment extends SubsonicFragment {
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
- super.onCreateContextMenu(menu, view, menuInfo);
-
- int serverCount = Util.getServerCount(context);
- int activeServer = Util.getActiveServer(context);
- for(int i = 1; i <= serverCount; i++) {
- android.view.MenuItem menuItem = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_BASE + i, MENU_ITEM_SERVER_BASE + i, Util.getServerName(context, i));
- if(i == activeServer) {
- menuItem.setChecked(true);
- }
- }
- menu.setGroupCheckable(MENU_GROUP_SERVER, true, true);
- menu.setHeaderTitle(R.string.main_select_server);
-
- recreateContextMenu(menu);
- }
-
- @Override
- public boolean onContextItemSelected(android.view.MenuItem menuItem) {
- if(menuItem.getGroupId() != getSupportTag()) {
- return false;
- }
-
- int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE;
- context.setActiveServer(activeServer);
- return true;
- }
-
- @Override
protected void refresh(boolean refresh) {
createLayout();
}
@@ -152,8 +123,6 @@ public class MainFragment extends SubsonicFragment {
private void createLayout() {
View buttons = inflater.inflate(R.layout.main_buttons, null);
- final View serverButton = buttons.findViewById(R.id.main_select_server);
- final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2);
final TextView offlineButton = (TextView) buttons.findViewById(R.id.main_offline);
offlineButton.setText(Util.isOffline(context) ? R.string.main_online : R.string.main_offline);
@@ -171,8 +140,6 @@ public class MainFragment extends SubsonicFragment {
final View albumsAlphabeticalButton = buttons.findViewById(R.id.main_albums_alphabetical);
final View videosButton = buttons.findViewById(R.id.main_videos);
- final View dummyView = rootView.findViewById(R.id.main_dummy);
-
final CheckBox albumsPerFolderCheckbox = (CheckBox) buttons.findViewById(R.id.main_albums_per_folder);
if(!Util.isOffline(context) && ServerInfo.canAlbumListPerFolder(context)) {
albumsPerFolderCheckbox.setChecked(Util.getAlbumListsPerFolder(context));
@@ -188,14 +155,10 @@ public class MainFragment extends SubsonicFragment {
int instance = Util.getActiveServer(context);
String name = Util.getServerName(context, instance);
- serverTextView.setText(name);
ListView list = (ListView) rootView.findViewById(R.id.main_list);
MergeAdapter adapter = new MergeAdapter();
- if (!Util.isOffline(context)) {
- adapter.addViews(Arrays.asList(serverButton), true);
- }
adapter.addView(offlineButton, true);
if (!Util.isOffline(context)) {
adapter.addView(albumsTitle, false);
@@ -213,14 +176,11 @@ public class MainFragment extends SubsonicFragment {
}
}
list.setAdapter(adapter);
- registerForContextMenu(dummyView);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- if (view == serverButton) {
- dummyView.showContextMenu();
- } else if (view == offlineButton) {
+ if (view == offlineButton) {
toggleOffline();
} else if (view == albumsNewestButton) {
showAlbumList("newest");
diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
index c3d86d4b..a770fbb1 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
@@ -277,6 +277,11 @@ public class ImageLoader {
}
public SilentBackgroundTask<Void> loadAvatar(Context context, ImageView view, String username) {
+ if(username == null) {
+ view.setImageResource(R.drawable.ic_social_person);
+ return null;
+ }
+
Bitmap bitmap = cache.get(username);
if (bitmap != null && !bitmap.isRecycled()) {
Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
index d078d77e..c7b6986e 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
@@ -260,10 +260,9 @@ public final class Notifications {
cancelPI);
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);
- builder.setContentIntent(PendingIntent.getActivity(context, 1, notificationIntent, 0));
+ builder.setContentIntent(PendingIntent.getActivity(context, 2, notificationIntent, 0));
final Notification notification = builder.build();
downloadShowing = true;
diff --git a/app/src/main/res/layout/abstract_activity.xml b/app/src/main/res/layout/abstract_activity.xml
index be65e437..f012f484 100644
--- a/app/src/main/res/layout/abstract_activity.xml
+++ b/app/src/main/res/layout/abstract_activity.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -9,13 +10,11 @@
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
+
<!-- The navigation drawer -->
- <ListView android:id="@+id/left_drawer"
- android:layout_width="240dp"
- android:layout_height="match_parent"
- android:layout_gravity="start"
- android:choiceMode="singleChoice"
- android:divider="@android:color/transparent"
- android:dividerHeight="0dp"
- android:background="?android:windowBackground"/>
+ <android.support.design.widget.NavigationView
+ android:id="@+id/left_drawer"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
diff --git a/app/src/main/res/layout/drawer_header.xml b/app/src/main/res/layout/drawer_header.xml
index 00441b73..fe0a9f2d 100644
--- a/app/src/main/res/layout/drawer_header.xml
+++ b/app/src/main/res/layout/drawer_header.xml
@@ -3,34 +3,54 @@
android:layout_width="match_parent"
android:layout_height="178dp"
android:orientation="vertical"
- android:weightSum="1">
+ android:weightSum="1"
+ android:background="?attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
- android:orientation="vertical"
+ android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
- <TextView
- android:id="@+id/header_server_name"
+ <LinearLayout
+ android:orientation="vertical"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:textColor="?android:textColorPrimary"
- android:textSize="14sp"
- android:textStyle="bold"/>
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/header_server_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="16dp"
+ android:textColor="?android:textColorPrimary"
+ android:textSize="14sp"
+ android:textStyle="bold"/>
+
+ <TextView
+ android:id="@+id/header_user_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="16dp"
+ android:layout_marginTop="5dp"
+ android:textColor="?android:textColorSecondary"
+ android:textSize="14sp"
+ android:textStyle="normal"/>
+ </LinearLayout>
+
+ <View
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_weight="1"/>
- <TextView
- android:id="@+id/header_user_name"
+ <ImageView
+ android:id="@+id/header_select_image"
+ android:src="?attr/select_server"
+ android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="5dp"
- android:textColor="?android:textColorSecondary"
- android:textSize="14sp"
- android:textStyle="normal"/>
+ android:paddingRight="20dp"/>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
diff --git a/app/src/main/res/layout/drawer_list_item.xml b/app/src/main/res/layout/drawer_list_item.xml
deleted file mode 100644
index 607b3658..00000000
--- a/app/src/main/res/layout/drawer_list_item.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dip"
- android:paddingBottom="9dip">
-
- <ImageView
- android:id="@+id/drawer_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="left|center_vertical"
- android:paddingTop="1dip"
- android:paddingBottom="1dip"
- android:paddingRight="8dip"
- android:paddingLeft="10dip"/>
-
- <TextView
- android:id="@+id/drawer_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textColor="?android:textColorPrimary"
- android:textAppearance="?android:attr/textAppearanceLarge"
- style="DSub.TextViewStyle"/>
-</LinearLayout>
diff --git a/app/src/main/res/menu/drawer_navigation.xml b/app/src/main/res/menu/drawer_navigation.xml
new file mode 100644
index 00000000..88ecd920
--- /dev/null
+++ b/app/src/main/res/menu/drawer_navigation.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <group android:checkableBehavior="single">
+ <item
+ android:id="@+id/drawer_home"
+ android:icon="?attr/drawerHome"
+ android:title="@string/button_bar.home"/>
+ <item
+ android:id="@+id/drawer_library"
+ android:icon="?attr/drawerLibrary"
+ android:title="@string/button_bar.browse"/>
+ <item
+ android:id="@+id/drawer_playlists"
+ android:icon="?attr/drawerPlaylists"
+ android:title="@string/button_bar.playlists"/>
+ <item
+ android:id="@+id/drawer_podcasts"
+ android:icon="?attr/drawerPodcasts"
+ android:title="@string/button_bar.podcasts"/>
+ <item
+ android:id="@+id/drawer_bookmarks"
+ android:icon="?attr/drawerBookmarks"
+ android:title="@string/button_bar.bookmarks"/>
+ <item
+ android:id="@+id/drawer_shares"
+ android:icon="?attr/drawerShares"
+ android:title="@string/button_bar.shares"/>
+ <item
+ android:id="@+id/drawer_chat"
+ android:icon="?attr/drawerChat"
+ android:title="@string/button_bar.chat"/>
+ <item
+ android:id="@+id/drawer_admin"
+ android:icon="?attr/drawerAdmin"
+ android:title="@string/button_bar.admin"/>
+ <item
+ android:id="@+id/drawer_downloading"
+ android:icon="?attr/drawerDownloading"
+ android:title="@string/button_bar.downloading"
+ android:visible="false"/>
+ </group>
+
+ <group
+ android:id="@+id/drawer_bottom"
+ android:checkableBehavior="single">
+
+ <item
+ android:id="@+id/drawer_settings"
+ android:title="@string/menu.settings"/>
+ </group>
+</menu> \ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 37b15d12..d876ecdb 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -1,18 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string-array name="drawerItems">
- <item>@string/button_bar.home</item>
- <item>@string/button_bar.browse</item>
- <item>@string/button_bar.playlists</item>
- <item>@string/button_bar.podcasts</item>
- <item>@string/button_bar.bookmarks</item>
- <item>@string/button_bar.shares</item>
- <item>@string/button_bar.chat</item>
- <item>@string/button_bar.admin</item>
- <item>@string/button_bar.downloading</item>
- <item>@string/menu.settings</item>
- </string-array>
-
<string-array name="drawerItemsDescriptions">
<item>Home</item>
<item>Artist</item>
@@ -46,32 +33,6 @@
<item>Chat</item>
</string-array>
- <array name="drawerItemIconsLight">
- <item>@drawable/main_offline_light</item>
- <item>@drawable/ic_menu_library_light</item>
- <item>@drawable/ic_menu_playlist_light</item>
- <item>@drawable/ic_menu_podcast_light</item>
- <item>@drawable/ic_menu_bookmark_light</item>
- <item>@drawable/ic_menu_share_light</item>
- <item>@drawable/ic_menu_chat_light</item>
- <item>@drawable/ic_menu_admin_light</item>
- <item>@drawable/ic_menu_download_light</item>
- <item>@drawable/ic_menu_settings_light</item>
- </array>
-
- <array name="drawerItemIconsDark">
- <item>@drawable/main_offline_dark</item>
- <item>@drawable/ic_menu_library_dark</item>
- <item>@drawable/ic_menu_playlist_dark</item>
- <item>@drawable/ic_menu_podcast_dark</item>
- <item>@drawable/ic_menu_bookmark_dark</item>
- <item>@drawable/ic_menu_share_dark</item>
- <item>@drawable/ic_menu_chat_dark</item>
- <item>@drawable/ic_menu_admin_dark</item>
- <item>@drawable/ic_menu_download_dark</item>
- <item>@drawable/ic_menu_settings_dark</item>
- </array>
-
<string-array name="themeValues">
<item>light</item>
<item>dark</item>
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index 9667117c..3db670e6 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -27,6 +27,16 @@
<attr name="rating_good" format="reference"/>
<attr name="radio" format="reference"/>
<attr name="drawerItemsIcons" format="reference"/>
+ <attr name="drawerHome" format="reference"/>
+ <attr name="drawerLibrary" format="reference"/>
+ <attr name="drawerPlaylists" format="reference"/>
+ <attr name="drawerPodcasts" format="reference"/>
+ <attr name="drawerBookmarks" format="reference"/>
+ <attr name="drawerShares" format="reference"/>
+ <attr name="drawerChat" format="reference"/>
+ <attr name="drawerAdmin" format="reference"/>
+ <attr name="drawerDownloading" format="reference"/>
+ <attr name="drawerSettings" format="reference"/>
<declare-styleable name="SeekBarPreference">
<attr name="min" format="integer"/>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 50d2d171..27082530 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -29,10 +29,21 @@
<item name="rating_bad">@drawable/ic_action_rating_bad_light</item>
<item name="rating_good">@drawable/ic_action_rating_good_light</item>
<item name="radio">@drawable/ic_menu_radio_light</item>
- <item name="drawerItemsIcons">@array/drawerItemIconsLight</item>
+ <item name="drawerHome">@drawable/main_offline_light</item>
+ <item name="drawerLibrary">@drawable/ic_menu_library_light</item>
+ <item name="drawerPlaylists">@drawable/ic_menu_playlist_light</item>
+ <item name="drawerPodcasts">@drawable/ic_menu_podcast_light</item>
+ <item name="drawerBookmarks">@drawable/ic_menu_bookmark_light</item>
+ <item name="drawerShares">@drawable/ic_menu_share_light</item>
+ <item name="drawerChat">@drawable/ic_menu_chat_light</item>
+ <item name="drawerAdmin">@drawable/ic_menu_admin_light</item>
+ <item name="drawerDownloading">@drawable/ic_menu_download_light</item>
+ <item name="drawerSettings">@drawable/ic_menu_settings_light</item>
<item name="android:textViewStyle">@style/DSub.TextViewStyle</item>
<item name="android:buttonStyle">@style/DSub.ButtonStyle.Light</item>
<item name="drawerArrowStyle">@style/DSub.DrawerArrow</item>
+ <item name="colorPrimary">@color/cyan</item>
+ <item name="colorPrimaryDark">@color/cyan</item>
<item name="colorAccent">@color/cyan</item>
</style>
<style name="Theme.DSub.Dark" parent="@style/Theme.AppCompat">
@@ -64,10 +75,21 @@
<item name="rating_bad">@drawable/ic_action_rating_bad_dark</item>
<item name="rating_good">@drawable/ic_action_rating_good_dark</item>
<item name="radio">@drawable/ic_menu_radio_dark</item>
- <item name="drawerItemsIcons">@array/drawerItemIconsDark</item>
+ <item name="drawerHome">@drawable/main_offline_dark</item>
+ <item name="drawerLibrary">@drawable/ic_menu_library_dark</item>
+ <item name="drawerPlaylists">@drawable/ic_menu_playlist_dark</item>
+ <item name="drawerPodcasts">@drawable/ic_menu_podcast_dark</item>
+ <item name="drawerBookmarks">@drawable/ic_menu_bookmark_dark</item>
+ <item name="drawerShares">@drawable/ic_menu_share_dark</item>
+ <item name="drawerChat">@drawable/ic_menu_chat_dark</item>
+ <item name="drawerAdmin">@drawable/ic_menu_admin_dark</item>
+ <item name="drawerDownloading">@drawable/ic_menu_download_dark</item>
+ <item name="drawerSettings">@drawable/ic_menu_settings_dark</item>
<item name="android:textViewStyle">@style/DSub.TextViewStyle</item>
<item name="android:buttonStyle">@style/DSub.ButtonStyle.Dark</item>
<item name="drawerArrowStyle">@style/DSub.DrawerArrow</item>
+ <item name="colorPrimary">@color/cyan</item>
+ <item name="colorPrimaryDark">@color/cyan</item>
<item name="colorAccent">@color/cyan</item>
</style>
<style name="Theme.DSub.Black" parent="Theme.DSub.Dark">