diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-06-09 06:21:04 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-06-09 06:21:04 -0700 |
commit | b573caa53594995e5587d62e1f4d999452e23a41 (patch) | |
tree | 5f2693c01c5d30b83a7151cda143bc8722b17908 | |
parent | c6b392e681e1eabc88f0b8875c46b2400f9ca9ab (diff) | |
download | dsub-b573caa53594995e5587d62e1f4d999452e23a41.tar.gz dsub-b573caa53594995e5587d62e1f4d999452e23a41.tar.bz2 dsub-b573caa53594995e5587d62e1f4d999452e23a41.zip |
#171 Add more stubs to Admin tab
-rw-r--r-- | res/menu/admin_context.xml | 16 | ||||
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/fragments/AdminFragment.java | 41 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/CachedMusicService.java | 29 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/MusicService.java | 10 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/OfflineMusicService.java | 25 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/RESTMusicService.java | 45 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Util.java | 5 |
8 files changed, 172 insertions, 3 deletions
diff --git a/res/menu/admin_context.xml b/res/menu/admin_context.xml new file mode 100644 index 00000000..e4948acd --- /dev/null +++ b/res/menu/admin_context.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:compat="http://schemas.android.com/apk/res-auto">
+
+ <item
+ android:id="@+id/admin_update_permissions"
+ android:title="@string/admin.update_permissions"/>
+
+ <item
+ android:id="@+id/admin_change_password"
+ android:title="@string/admin.change_password"/>
+
+ <item
+ android:id="@+id/admin_delete_user"
+ android:title="@string/admin.delete_user"/>
+</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml index 0e385186..8fb6f164 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -447,6 +447,10 @@ <string name="share.via">Share via</string>
<string name="share.delete">Delete Share</string>
+ <string name="admin.update_permissions">Update Permissions</string>
+ <string name="admin.change_password">Change Password</string>
+ <string name="admin.delete_user">Delete User</string>
+
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
<string name="background_task.wait">Please wait...</string>
diff --git a/src/github/daneren2005/dsub/fragments/AdminFragment.java b/src/github/daneren2005/dsub/fragments/AdminFragment.java index c43da8d4..716279cb 100644 --- a/src/github/daneren2005/dsub/fragments/AdminFragment.java +++ b/src/github/daneren2005/dsub/fragments/AdminFragment.java @@ -15,10 +15,15 @@ package github.daneren2005.dsub.fragments;
+import android.util.Log;
+import android.view.ContextMenu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -27,9 +32,37 @@ import github.daneren2005.dsub.domain.User; import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.parser.SubsonicRESTException;
import github.daneren2005.dsub.util.ProgressListener;
+import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.UserAdapter;
public class AdminFragment extends SelectListFragment<User> {
+ private static String TAG = AdminFragment.class.getSimpleName();
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+
+ MenuInflater inflater = context.getMenuInflater();
+ inflater.inflate(R.menu.admin_context, menu);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ User user = objects.get(info.position);
+
+ switch(menuItem.getItemId()) {
+ case R.id.admin_update_permissions:
+ break;
+ case R.id.admin_change_password:
+ break;
+ case R.id.admin_delete_user:
+ break;
+ }
+
+ return true;
+ }
+
@Override
public int getOptionsMenu() {
return R.menu.admin;
@@ -46,8 +79,14 @@ public class AdminFragment extends SelectListFragment<User> { // Will only work if user is admin
return musicService.getUsers(refresh, context, listener);
} catch(SubsonicRESTException e) {
+ // Delete cached users if not allowed to get them
+ String s = Util.getRestUrl(context, null, false);
+ String cache = "users-" + s.hashCode() + ".ser";
+ File file = new File(context.getCacheDir(), cache);
+ file.delete();
+
List<User> users = new ArrayList<User>();
- users.add(musicService.getUser(refresh, "scott", context, listener));
+ users.add(musicService.getUser(refresh, Util.getCurrentUsername(context), context, listener));
return users;
}
}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 7dd5120a..e14b4d84 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -512,12 +512,12 @@ public class CachedMusicService implements MusicService { User result = null; if(!refresh) { - result = FileUtil.deserialize(context, getCacheName(context, "user"), User.class); + result = FileUtil.deserialize(context, getCacheName(context, "user-" + username), User.class); } if(result == null) { result = musicService.getUser(refresh, username, context, progressListener); - FileUtil.serialize(context, result, getCacheName(context, "user")); + FileUtil.serialize(context, result, getCacheName(context, "user-" + username)); } return result; @@ -540,6 +540,31 @@ public class CachedMusicService implements MusicService { } @Override + public void createUser(User user, Context context, ProgressListener progressListener) throws Exception { + musicService.createUser(user, context, progressListener); + } + + @Override + public void updateUser(User user, Context context, ProgressListener progressListener) throws Exception { + musicService.updateUser(user, context, progressListener); + } + + @Override + public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception { + musicService.deleteUser(username, context, progressListener); + } + + @Override + public void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception { + musicService.changePassword(username, password, context, progressListener); + } + + @Override + public Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception { + return musicService.getAvatar(username, context, progressListener); + } + + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ return musicService.processOfflineSyncs(context, progressListener); } diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index 1164886d..6f58603c 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -165,6 +165,16 @@ public interface MusicService { User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception; List<User> getUsers(boolean refresh, Context context, ProgressListener progressListener) throws Exception; + + void createUser(User user, Context context, ProgressListener progressListener) throws Exception; + + void updateUser(User user, Context context, ProgressListener progressListener) throws Exception; + + void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception; + + void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception; + + Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception; int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception; diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index a809f0d1..9e2b9e13 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -701,6 +701,31 @@ public class OfflineMusicService extends RESTMusicService { } @Override + public void createUser(User user, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Creating users not available in offline mode"); + } + + @Override + public void updateUser(User user, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Updating users not available in offline mode"); + } + + @Override + public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Deleting users not available in offline mode"); + } + + @Override + public void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Changing passwords not available in offline mode"); + } + + @Override + public Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception { + return null; + } + + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ throw new OfflineException("Offline scrobble cached can not be processes while in offline mode"); } diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 10647d99..20328d54 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -1219,6 +1219,51 @@ public class RESTMusicService implements MusicService { } @Override + public void createUser(User user, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "createUser", null); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void updateUser(User user, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "createUser", null); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "deleteUser", null, Arrays.asList("username"), Arrays.<Object>asList(username)); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "changePassword", null, Arrays.asList("username", "password"), Arrays.<Object>asList(username, password)); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception { + return null; + } + + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ return processOfflineScrobbles(context, progressListener) + processOfflineStars(context, progressListener); } diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index b62b3382..dad557e3 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -169,6 +169,11 @@ public final class Util { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false) ? 0 : prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); } + + public static String getCurrentUsername(Context context) { + SharedPreferences prefs = getPreferences(context); + return prefs.getString(Constants.PREFERENCES_KEY_USERNAME + getActiveServer(context), null); + } public static boolean checkServerVersion(Context context, String requiredVersion) { Version version = Util.getServerRestVersion(context); |