diff options
Diffstat (limited to 'src/github/daneren2005')
6 files changed, 152 insertions, 3 deletions
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); |