aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-05-07 14:25:38 -0700
committerScott Jackson <daneren2005@gmail.com>2015-05-07 14:25:38 -0700
commit40706126b2588d3ae75ba875855d786dc772b054 (patch)
tree1f3f89cfd2c5e9dc7b7dda58e76cc4c22ce2243a /app/src/main/java
parent2a4817a915659cd57255f52b682244c4a458a14f (diff)
downloaddsub-40706126b2588d3ae75ba875855d786dc772b054.tar.gz
dsub-40706126b2588d3ae75ba875855d786dc772b054.tar.bz2
dsub-40706126b2588d3ae75ba875855d786dc772b054.zip
#493 Start of adding header to drawer
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java45
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java21
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java4
3 files changed, 45 insertions, 25 deletions
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);
}
}
}