From e62cbdae5a41909a03652ae4a967a4e72fe96748 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 5 Jun 2015 17:39:57 -0700 Subject: #493 Switch from ListView to NavigationView + move server selection logic into drawer --- app/build.gradle | 9 +- .../dsub/activity/SettingsActivity.java | 1 + .../dsub/activity/SubsonicActivity.java | 294 ++++++++++++--------- .../dsub/activity/SubsonicFragmentActivity.java | 67 +++-- .../daneren2005/dsub/adapter/DrawerAdapter.java | 126 --------- .../daneren2005/dsub/fragments/MainFragment.java | 42 +-- .../github/daneren2005/dsub/util/ImageLoader.java | 5 + .../daneren2005/dsub/util/Notifications.java | 3 +- app/src/main/res/layout/abstract_activity.xml | 15 +- app/src/main/res/layout/drawer_header.xml | 52 ++-- app/src/main/res/layout/drawer_list_item.xml | 27 -- app/src/main/res/menu/drawer_navigation.xml | 51 ++++ app/src/main/res/values/arrays.xml | 39 --- app/src/main/res/values/attrs.xml | 10 + app/src/main/res/values/themes.xml | 26 +- 15 files changed, 357 insertions(+), 410 deletions(-) delete mode 100644 app/src/main/java/github/daneren2005/dsub/adapter/DrawerAdapter.java delete mode 100644 app/src/main/res/layout/drawer_list_item.xml create mode 100644 app/src/main/res/menu/drawer_navigation.xml (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index 1e2a6fe1..be66c701 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,10 +29,11 @@ dependencies { compile project(':DragSort ListView') compile project(':Server Proxy') compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:support-v4:22.1.1' - compile 'com.android.support:appcompat-v7:22.1.1' - compile 'com.android.support:mediarouter-v7:22.1.1' - compile 'com.android.support:recyclerview-v7:22.1.1' + compile 'com.android.support:support-v4:22.2.+' + compile 'com.android.support:appcompat-v7:22.2.+' + compile 'com.android.support:mediarouter-v7:22.2.+' + compile 'com.android.support:recyclerview-v7:22.2.+' + compile 'com.android.support:design:22.2.+' compile 'com.google.android.gms:play-services-cast:7.0.0' compile 'com.sothree.slidinguppanel:library:3.0.0' compile 'de.hdodenhof:circleimageview:1.2.1' 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 backStack = new ArrayList(); @@ -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 @@ -197,19 +222,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte Util.disablePendingTransition(this); } - @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()) { @@ -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 drawerItemsList = new ArrayList(Arrays.asList(drawerItems)); - List drawerItemsIconsList = new ArrayList(); - List drawerItemsVisibleList = new ArrayList(); - - 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 f3d62999..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,19 +603,22 @@ public class SubsonicFragmentActivity extends SubsonicActivity { artistView.setText(R.string.main_artist); } - SilentBackgroundTask task = getImageLoader().loadImage(coverArtView, song, false, coverArtView.getHeight(), false); - if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { - if(task == null) { - getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); - } else { - task.setOnCompletionListener(new Runnable() { - @Override - public void run() { - getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); - } - }); + 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) { + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); + } else { + task.setOnCompletionListener(new Runnable() { + @Override + public void run() { + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); + } + }); + } } } + int[] attrs = new int[] {(state == PlayerState.STARTED) ? R.attr.media_button_pause : R.attr.media_button_start}; TypedArray typedArray = this.obtainStyledAttributes(attrs); startButton.setImageResource(typedArray.getResourceId(0, 0)); diff --git a/app/src/main/java/github/daneren2005/dsub/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 . - - 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 { - private static String TAG = DrawerAdapter.class.getSimpleName(); - private Context context; - private List items; - private List icons; - private List visible; - private int selectedPosition = -1; - - public DrawerAdapter(Context context, List items, List icons, List 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 @@ -115,35 +115,6 @@ public class MainFragment extends SubsonicFragment { return false; } - @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 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 @@ @@ -9,13 +10,11 @@ android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"/> + - + 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"> - + android:layout_height="wrap_content"> + + + + + + + - + android:paddingRight="20dp"/> - - - - - - 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 @@ + + + + + + + + + + + + + + + + + + + \ 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 @@ - - @string/button_bar.home - @string/button_bar.browse - @string/button_bar.playlists - @string/button_bar.podcasts - @string/button_bar.bookmarks - @string/button_bar.shares - @string/button_bar.chat - @string/button_bar.admin - @string/button_bar.downloading - @string/menu.settings - - Home Artist @@ -46,32 +33,6 @@ Chat - - @drawable/main_offline_light - @drawable/ic_menu_library_light - @drawable/ic_menu_playlist_light - @drawable/ic_menu_podcast_light - @drawable/ic_menu_bookmark_light - @drawable/ic_menu_share_light - @drawable/ic_menu_chat_light - @drawable/ic_menu_admin_light - @drawable/ic_menu_download_light - @drawable/ic_menu_settings_light - - - - @drawable/main_offline_dark - @drawable/ic_menu_library_dark - @drawable/ic_menu_playlist_dark - @drawable/ic_menu_podcast_dark - @drawable/ic_menu_bookmark_dark - @drawable/ic_menu_share_dark - @drawable/ic_menu_chat_dark - @drawable/ic_menu_admin_dark - @drawable/ic_menu_download_dark - @drawable/ic_menu_settings_dark - - light dark 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 @@ + + + + + + + + + + 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 @@ @drawable/ic_action_rating_bad_light @drawable/ic_action_rating_good_light @drawable/ic_menu_radio_light - @array/drawerItemIconsLight + @drawable/main_offline_light + @drawable/ic_menu_library_light + @drawable/ic_menu_playlist_light + @drawable/ic_menu_podcast_light + @drawable/ic_menu_bookmark_light + @drawable/ic_menu_share_light + @drawable/ic_menu_chat_light + @drawable/ic_menu_admin_light + @drawable/ic_menu_download_light + @drawable/ic_menu_settings_light @style/DSub.TextViewStyle @style/DSub.ButtonStyle.Light @style/DSub.DrawerArrow + @color/cyan + @color/cyan @color/cyan