aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout/change_password.xml28
-rw-r--r--res/values/strings.xml6
-rw-r--r--src/github/daneren2005/dsub/fragments/AdminFragment.java105
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectListFragment.java6
-rw-r--r--src/github/daneren2005/dsub/fragments/UserFragment.java61
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java4
-rw-r--r--src/github/daneren2005/dsub/view/UserAdapter.java1
7 files changed, 208 insertions, 3 deletions
diff --git a/res/layout/change_password.xml b/res/layout/change_password.xml
new file mode 100644
index 00000000..ad3e9cd8
--- /dev/null
+++ b/res/layout/change_password.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/new_password_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/admin.change_password_label" />
+ <EditText
+ android:id="@+id/new_password"
+ android:inputType="textPassword"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginLeft="4dp" />
+ </LinearLayout>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8fb6f164..3148ae99 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -449,7 +449,13 @@
<string name="admin.update_permissions">Update Permissions</string>
<string name="admin.change_password">Change Password</string>
+ <string name="admin.change_password_success">Successfully changed password for %1$s</string>
+ <string name="admin.change_password_error">Failed to change password for %1$s</string>
+ <string name="admin.change_password_label">New Password:</string>
+ <string name="admin.change_password_invalid">Enter a valid password</string>
<string name="admin.delete_user">Delete User</string>
+ <string name="admin.delete_user_success">Successfully deleted %1$s</string>
+ <string name="admin.delete_user_error">Failed to delete %1$s</string>
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
diff --git a/src/github/daneren2005/dsub/fragments/AdminFragment.java b/src/github/daneren2005/dsub/fragments/AdminFragment.java
index 716279cb..f6e8e153 100644
--- a/src/github/daneren2005/dsub/fragments/AdminFragment.java
+++ b/src/github/daneren2005/dsub/fragments/AdminFragment.java
@@ -15,6 +15,9 @@
package github.daneren2005.dsub.fragments;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
@@ -22,6 +25,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
@@ -30,8 +34,13 @@ import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.service.OfflineException;
+import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.service.parser.SubsonicRESTException;
+import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ProgressListener;
+import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.UserAdapter;
@@ -55,8 +64,10 @@ public class AdminFragment extends SelectListFragment<User> {
case R.id.admin_update_permissions:
break;
case R.id.admin_change_password:
+ changePassword(user);
break;
case R.id.admin_delete_user:
+ deleteUser(user);
break;
}
@@ -98,6 +109,100 @@ public class AdminFragment extends SelectListFragment<User> {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ User user = (User) parent.getItemAtPosition(position);
+ SubsonicFragment fragment = new UserFragment();
+ Bundle args = new Bundle();
+ args.putSerializable(Constants.INTENT_EXTRA_NAME_ID, user);
+ fragment.setArguments(args);
+
+ replaceFragment(fragment);
+ }
+
+ private void changePassword(final User user) {
+ View layout = context.getLayoutInflater().inflate(R.layout.change_password, null);
+ final TextView passwordView = (TextView) layout.findViewById(R.id.new_password);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.admin_change_password)
+ .setView(layout)
+ .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ final String password = passwordView.getText().toString();
+ // Don't allow blank passwords
+ if ("".equals(password)) {
+ Util.toast(context, R.string.admin_change_password_invalid);
+ return;
+ }
+
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.changePassword(user.getUsername(), password, context, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void v) {
+ Util.toast(context, context.getResources().getString(R.string.admin_change_password_success, user.getUsername()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_change_password_error, user.getUsername());
+ }
+
+ Util.toast(context, msg);
+ }
+ }.execute();
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null)
+ .setCancelable(true);
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+
+ private void deleteUser(final User user) {
+ Util.confirmDialog(context, R.string.common_delete, user.getUsername(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.deleteUser(user.getUsername(), context, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void v) {
+ adapter.remove(user);
+ adapter.notifyDataSetChanged();
+
+ Util.toast(context, context.getResources().getString(R.string.admin_delete_user_success, user.getUsername()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_delete_user_error, user.getUsername());
+ }
+
+ Util.toast(context, msg);
+ }
+ }.execute();
+ }
+ });
}
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectListFragment.java b/src/github/daneren2005/dsub/fragments/SelectListFragment.java
index 4938fb3b..1c77ad68 100644
--- a/src/github/daneren2005/dsub/fragments/SelectListFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectListFragment.java
@@ -107,12 +107,14 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
-
}
@Override
protected void refresh(final boolean refresh) {
- setTitle(getTitleResource());
+ int titleRes = getTitleResource();
+ if(titleRes != 0) {
+ setTitle(getTitleResource());
+ }
listView.setVisibility(View.INVISIBLE);
emptyView.setVisibility(View.GONE);
diff --git a/src/github/daneren2005/dsub/fragments/UserFragment.java b/src/github/daneren2005/dsub/fragments/UserFragment.java
new file mode 100644
index 00000000..3a85c6bb
--- /dev/null
+++ b/src/github/daneren2005/dsub/fragments/UserFragment.java
@@ -0,0 +1,61 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.fragments;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.User;
+import github.daneren2005.dsub.util.Constants;
+
+public class UserFragment extends SubsonicFragment{
+ private ListView listView;
+ private LayoutInflater inflater;
+ private User user;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
+ this.inflater = inflater;
+ rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
+
+ Bundle args = getArguments();
+ user = (User) args.getSerializable(Constants.INTENT_EXTRA_NAME_ID);
+ setTitle(user.getUsername());
+
+ return rootView;
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
+ if(!primaryFragment) {
+ return;
+ }
+
+ menuInflater.inflate(R.menu.empty, menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index e14b4d84..1f1715c4 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -552,6 +552,10 @@ public class CachedMusicService implements MusicService {
@Override
public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception {
musicService.deleteUser(username, context, progressListener);
+
+ // Delete cached users if any have been removed from list
+ File file = new File(context.getCacheDir(), getCacheName(context, "users"));
+ file.delete();
}
@Override
diff --git a/src/github/daneren2005/dsub/view/UserAdapter.java b/src/github/daneren2005/dsub/view/UserAdapter.java
index 8aaa261c..937e2e92 100644
--- a/src/github/daneren2005/dsub/view/UserAdapter.java
+++ b/src/github/daneren2005/dsub/view/UserAdapter.java
@@ -26,7 +26,6 @@ import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.User;
public class UserAdapter extends ArrayAdapter<User> {
-
private final Context activity;
public UserAdapter(Context activity, List<User> users) {