aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2014-06-23 14:41:51 -0700
committerdaneren2005 <daneren2005@gmail.com>2014-06-23 14:41:51 -0700
commit17edb005b613d0f9bf58489014254909080689f1 (patch)
tree3b134953d010f17130195617ae3de7509edf9567
parent109132de514923ae57574ba40642133d425b0344 (diff)
downloaddsub-17edb005b613d0f9bf58489014254909080689f1.tar.gz
dsub-17edb005b613d0f9bf58489014254909080689f1.tar.bz2
dsub-17edb005b613d0f9bf58489014254909080689f1.zip
Only seed user once, added quick permission lookups
-rw-r--r--src/github/daneren2005/dsub/util/UserUtil.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/github/daneren2005/dsub/util/UserUtil.java b/src/github/daneren2005/dsub/util/UserUtil.java
index b5cead77..ccda1070 100644
--- a/src/github/daneren2005/dsub/util/UserUtil.java
+++ b/src/github/daneren2005/dsub/util/UserUtil.java
@@ -40,6 +40,7 @@ import github.daneren2005.dsub.view.SettingsAdapter;
public final class UserUtil {
private static final String TAG = UserUtil.class.getSimpleName();
+ private static int instance = -1;
private static User currentUser;
public static void seedCurrentUser(final Context context) {
@@ -47,11 +48,18 @@ public final class UserUtil {
if(Util.isOffline(context)) {
return;
}
+
+ final int instance = Util.getActiveServer(context);
+ if(this.instance == instance && currentUser != null) {
+ return;
+ } else {
+ this.instance = instance;
+ }
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
- currentUser = MusicServiceFactory.getMusicService(context).getUser(false, getCurrentUsername(context), context, null);
+ currentUser = MusicServiceFactory.getMusicService(context).getUser(false, getCurrentUsername(context, instance), context, null);
return null;
}
@@ -77,11 +85,17 @@ public final class UserUtil {
}
public static boolean isCurrentAdmin() {
- if(currentUser == null) {
- return false;
- } else {
- return isCurrentRole("adminRole");
- }
+ return isCurrentRole("adminRole");
+ }
+
+ public static boolean canPodcast() {
+ return isCurrentRole("podcastRole");
+ }
+ public static boolean canShare() {
+ return isCurrentRole("shareRole");
+ }
+ public static boolean canJukebox() {
+ return isCurrentRole("jukeboxRole");
}
public static boolean isCurrentRole(String role) {