aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-11-09 12:40:15 -0800
committerScott Jackson <daneren2005@gmail.com>2013-11-09 12:40:15 -0800
commitf018b56985ff12a63b21cefe302421bb5f0c2209 (patch)
treed6837ac2f85dd2426a50b430797a9fa91b6245d3 /src
parent37aa807311067eb7fc6e6ded74e640411ab1b920 (diff)
downloaddsub-f018b56985ff12a63b21cefe302421bb5f0c2209.tar.gz
dsub-f018b56985ff12a63b21cefe302421bb5f0c2209.tar.bz2
dsub-f018b56985ff12a63b21cefe302421bb5f0c2209.zip
Added icons to the drawer
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java26
-rw-r--r--src/github/daneren2005/dsub/view/DrawerAdapter.java68
2 files changed, 83 insertions, 11 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 71b2b790..3c884683 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
+import android.content.res.TypedArray;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
@@ -58,10 +59,14 @@ import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.DrawerAdapter;
+
import java.io.File;
import java.io.PrintWriter;
+import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
public class SubsonicActivity extends ActionBarActivity implements OnItemSelectedListener {
@@ -376,11 +381,18 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
int alreadyRemoved = 0;
List<String> drawerItemsList = new ArrayList<String>(Arrays.asList(drawerItems));
List<String> drawerItemsDescriptionsList = new ArrayList<String>(Arrays.asList(drawerItemsDescriptions));
+ List<Integer> drawerItemsIconsList = new ArrayList<Integer>();
+
+ TypedArray typedArray = getResources().obtainTypedArray(R.array.drawerItemIcons);
+ for(int i = 0; i < drawerItemsList.size(); i++) {
+ drawerItemsIconsList.add(typedArray.getResourceId(i, 0));
+ }
// Selectively remove podcast listing [3]
if(!podcastsEnabled) {
drawerItemsList.remove(3 - alreadyRemoved);
drawerItemsDescriptionsList.remove(3 - alreadyRemoved);
+ drawerItemsIconsList.remove(3 - alreadyRemoved);
alreadyRemoved++;
}
@@ -388,6 +400,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(!bookmarksEnabled) {
drawerItemsList.remove(4 - alreadyRemoved);
drawerItemsDescriptionsList.remove(4 - alreadyRemoved);
+ drawerItemsIconsList.remove(4 - alreadyRemoved);
alreadyRemoved++;
}
@@ -395,6 +408,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(!chatEnabled) {
drawerItemsList.remove(5 - alreadyRemoved);
drawerItemsDescriptionsList.remove(5 - alreadyRemoved);
+ drawerItemsIconsList.remove(5 - alreadyRemoved);
alreadyRemoved++;
}
@@ -404,23 +418,13 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
drawerItemsDescriptions = drawerItemsDescriptionsList.toArray(new String[0]);
}
- drawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, drawerItems));
+ drawerList.setAdapter(new DrawerAdapter(this, drawerItemsList, drawerItemsIconsList));
enabledItems[0] = podcastsEnabled;
enabledItems[1] = bookmarksEnabled;
enabledItems[2] = chatEnabled;
}
}
- public void startActivity(Class t) {
- Intent intent = new Intent();
- intent.setClass(SubsonicActivity.this, t);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- if(this.getClass() != SubsonicFragmentActivity.class) {
- finish();
- }
- drawer.closeDrawers();
- }
public void startFragmentActivity(String fragmentType) {
Intent intent = new Intent();
intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class);
diff --git a/src/github/daneren2005/dsub/view/DrawerAdapter.java b/src/github/daneren2005/dsub/view/DrawerAdapter.java
new file mode 100644
index 00000000..d3639373
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/DrawerAdapter.java
@@ -0,0 +1,68 @@
+/*
+ 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.view;
+
+import android.content.Context;
+import android.util.Log;
+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;
+
+ public DrawerAdapter(Context context, List<String> items, List<Integer> icons) {
+ super(context, R.layout.drawer_list_item, items);
+
+ this.context = context;
+ this.items = items;
+ this.icons = icons;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ 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);
+ ImageView iconView = (ImageView) convertView.findViewById(R.id.drawer_icon);
+ Log.d(TAG, "icon: " + icon);
+ iconView.setImageResource(icon);
+
+ return convertView;
+ }
+}