diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-05-07 14:25:38 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-05-07 14:25:38 -0700 |
commit | 40706126b2588d3ae75ba875855d786dc772b054 (patch) | |
tree | 1f3f89cfd2c5e9dc7b7dda58e76cc4c22ce2243a | |
parent | 2a4817a915659cd57255f52b682244c4a458a14f (diff) | |
download | dsub-40706126b2588d3ae75ba875855d786dc772b054.tar.gz dsub-40706126b2588d3ae75ba875855d786dc772b054.tar.bz2 dsub-40706126b2588d3ae75ba875855d786dc772b054.zip |
#493 Start of adding header to drawer
-rw-r--r-- | app/app.iml | 2 | ||||
-rw-r--r-- | app/build.gradle | 1 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java | 45 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java | 21 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java | 4 | ||||
-rw-r--r-- | app/src/main/res/layout/drawer_header.xml | 42 | ||||
-rw-r--r-- | app/src/main/res/layout/drawer_list_item.xml | 5 | ||||
-rw-r--r-- | app/src/main/res/values-v16/themes.xml | 2 |
8 files changed, 94 insertions, 28 deletions
diff --git a/app/app.iml b/app/app.iml index 6e923bd8..da1edd11 100644 --- a/app/app.iml +++ b/app/app.iml @@ -75,6 +75,7 @@ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.0.0/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-cast/7.0.0/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.sothree.slidinguppanel/library/3.0.0/jars" /> + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/de.hdodenhof/circleimageview/1.2.1/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" /> @@ -113,6 +114,7 @@ <orderEntry type="library" exported="" name="cling-support-2.0.1" level="project" /> <orderEntry type="library" exported="" name="jetty-io-8.1.16.v20140903" level="project" /> <orderEntry type="library" exported="" name="CWAC-EndlessAdapter" level="project" /> + <orderEntry type="library" exported="" name="circleimageview-1.2.1" level="project" /> <orderEntry type="library" exported="" name="jetty-security-8.1.16.v20140903" level="project" /> <orderEntry type="library" exported="" name="jetty-servlet-8.1.16.v20140903" level="project" /> <orderEntry type="library" exported="" name="CWAC-AdapterWrapper" level="project" /> diff --git a/app/build.gradle b/app/build.gradle index e17e8256..56da71aa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,7 @@ dependencies { compile 'com.android.support:mediarouter-v7:22.1.1' 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' compile group: 'org.fourthline.cling', name: 'cling-core', version:'2.0.1' compile group: 'org.fourthline.cling', name: 'cling-support', version:'2.0.1' compile group: 'org.eclipse.jetty', name: 'jetty-server', version:'8.1.16.v20140903' 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 814598c5..cb09728c 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -51,6 +51,7 @@ import android.view.animation.AnimationUtils; 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; @@ -68,6 +69,7 @@ import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.HeadphoneListenerService; 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; @@ -97,6 +99,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte ActionBarDrawerToggle drawerToggle; DrawerAdapter drawerAdapter; ListView drawerList; + View drawerHeader; + ImageView drawerUserAvatar; + TextView drawerServerName; + TextView drawerUserName; TextView lastSelectedView = null; int lastSelectedPosition = 0; boolean drawerOpen = false; @@ -222,7 +228,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte drawerList.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) { - final int actualPosition = drawerAdapter.getActualPosition(position); + final int actualPosition = drawerAdapter.getActualPosition(position - 1); if("Settings".equals(drawerItemsDescriptions[actualPosition])) { startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class)); drawer.closeDrawers(); @@ -239,7 +245,13 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } }); + 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,7 +277,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } if (lastSelectedView == null && drawerList.getCount() > lastSelectedPosition) { - lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition).findViewById(R.id.drawer_name); + lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition + 1).findViewById(R.id.drawer_name); if (lastSelectedView != null) { lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold); } @@ -514,11 +526,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } } - if(drawerList.getChildAt(lastSelectedPosition) == null) { + if(drawerList.getChildAt(lastSelectedPosition + 1) == null) { lastSelectedView = null; drawerAdapter.setSelectedPosition(lastSelectedPosition); } else { - lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition).findViewById(R.id.drawer_name); + lastSelectedView = (TextView) drawerList.getChildAt(lastSelectedPosition + 1).findViewById(R.id.drawer_name); if(lastSelectedView != null) { lastSelectedView.setTextAppearance(SubsonicActivity.this, R.style.DSub_TextViewStyle_Bold); } @@ -834,6 +846,31 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } + public void setActiveServer(int instance) { + if (Util.getActiveServer(this) != instance) { + final DownloadService service = getDownloadService(); + if (service != null) { + new SilentBackgroundTask<Void>(this) { + @Override + protected Void doInBackground() throws Throwable { + service.clearIncomplete(); + return null; + } + }.execute(); + + } + Util.setActiveServer(this, instance); + invalidate(); + UserUtil.refreshCurrentUser(this, false, true); + updateDrawerHeader(); + } + } + private void updateDrawerHeader() { + drawerServerName.setText(Util.getServerName(this)); + drawerUserName.setText(UserUtil.getCurrentUsername(this)); + getImageLoader().loadAvatar(this, drawerUserAvatar, UserUtil.getCurrentUsername(this)); + } + private void setUncaughtExceptionHandler() { Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); if (!(handler instanceof SubsonicActivity.SubsonicUncaughtExceptionHandler)) { 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 ae38534a..71c135aa 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java @@ -140,7 +140,7 @@ public class MainFragment extends SubsonicFragment { } int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE; - setActiveServer(activeServer); + context.setActiveServer(activeServer); return true; } @@ -252,25 +252,6 @@ public class MainFragment extends SubsonicFragment { } } - private void setActiveServer(int instance) { - if (Util.getActiveServer(context) != instance) { - final DownloadService service = getDownloadService(); - if (service != null) { - new SilentBackgroundTask<Void>(context) { - @Override - protected Void doInBackground() throws Throwable { - service.clearIncomplete(); - return null; - } - }.execute(); - - } - Util.setActiveServer(context, instance); - context.invalidate(); - UserUtil.refreshCurrentUser(context, false, true); - } - } - private void toggleOffline() { boolean isOffline = Util.isOffline(context); Util.setOffline(context, !isOffline); 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 65ef46fe..54b4085d 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java +++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java @@ -285,6 +285,7 @@ public class ImageLoader { view.setImageDrawable(drawable); return null; } + view.setImageDrawable(null); SilentBackgroundTask<Void> task = new AvatarTask(context, view, username); task.execute(); @@ -587,7 +588,6 @@ public class ImageLoader { } } catch (Throwable x) { Log.e(TAG, "Failed to download album art.", x); - cancelled.set(true); } return null; @@ -597,6 +597,8 @@ public class ImageLoader { protected void done(Void result) { if(mDrawable != null) { mView.setImageDrawable(mDrawable); + } else { + mView.setImageResource(R.drawable.ic_social_person); } } } diff --git a/app/src/main/res/layout/drawer_header.xml b/app/src/main/res/layout/drawer_header.xml new file mode 100644 index 00000000..00441b73 --- /dev/null +++ b/app/src/main/res/layout/drawer_header.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="178dp" + android:orientation="vertical" + android:weightSum="1"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="56dp" + android:orientation="vertical" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true"> + + <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> + + <de.hdodenhof.circleimageview.CircleImageView + android:id="@+id/header_user_avatar" + android:layout_width="70dp" + android:layout_height="70dp" + android:layout_marginLeft="16dp" + android:layout_marginTop="38dp"/> +</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/drawer_list_item.xml b/app/src/main/res/layout/drawer_list_item.xml index 5f17c9e9..607b3658 100644 --- a/app/src/main/res/layout/drawer_list_item.xml +++ b/app/src/main/res/layout/drawer_list_item.xml @@ -20,7 +20,8 @@ android:id="@+id/drawer_name" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textSize="26sp" android:singleLine="true" - android:textColor="?android:textColorPrimary"/> + android:textColor="?android:textColorPrimary" + android:textAppearance="?android:attr/textAppearanceLarge" + style="DSub.TextViewStyle"/> </LinearLayout> diff --git a/app/src/main/res/values-v16/themes.xml b/app/src/main/res/values-v16/themes.xml index 013ac0aa..a14b6a1b 100644 --- a/app/src/main/res/values-v16/themes.xml +++ b/app/src/main/res/values-v16/themes.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <style name="DSub.TextViewStyle" parent="android:Widget.TextView"> - <item name="android:fontFamily">sans-serif-light</item> + <item name="android:fontFamily">sans-serif</item> </style> <style name="DSub.TextViewStyle.Bold" parent="android:Widget.TextView"> |