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/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
-rw-r--r--app/src/main/res/layout/drawer_header.xml42
-rw-r--r--app/src/main/res/layout/drawer_list_item.xml5
-rw-r--r--app/src/main/res/values-v16/themes.xml2
6 files changed, 91 insertions, 28 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);
}
}
}
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">