aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-15 17:49:13 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-15 17:49:13 -0700
commitf851f1421a9fbeec065df4ee06042e7513eb30b8 (patch)
treef9d85048220498fac49109d8011a369ec7cc01df
parentd04a5041c3467e5a289f6af3b07fbcb20a6ea078 (diff)
downloaddsub-f851f1421a9fbeec065df4ee06042e7513eb30b8.tar.gz
dsub-f851f1421a9fbeec065df4ee06042e7513eb30b8.tar.bz2
dsub-f851f1421a9fbeec065df4ee06042e7513eb30b8.zip
#368 Finish up requiring password for admin tab
-rw-r--r--res/layout/confirm_password.xml28
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java16
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java2
-rw-r--r--src/github/daneren2005/dsub/util/UserUtil.java17
5 files changed, 51 insertions, 14 deletions
diff --git a/res/layout/confirm_password.xml b/res/layout/confirm_password.xml
new file mode 100644
index 00000000..97cbcac3
--- /dev/null
+++ b/res/layout/confirm_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/password_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/admin.add_user_password" />
+ <EditText
+ android:id="@+id/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 77f18ea9..537e4649 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -464,6 +464,8 @@
<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="admin.confirm_password">Confirm Password</string>
+ <string name="admin.confirm_password_bad">Entered password is wrong</string>
<string name="admin.scrobblingEnabled">Scrobbling allowed</string>
<string name="admin.role.admin">Administrator</string>
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index a2f8ab22..514dea25 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -181,19 +181,19 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {
- position = drawerAdapter.getActualPosition(position);
- if("Settings".equals(drawerItemsDescriptions[position])) {
+ final int actualPosition = drawerAdapter.getActualPosition(position);
+ if("Settings".equals(drawerItemsDescriptions[actualPosition])) {
startActivity(new Intent(SubsonicActivity.this, SettingsActivity.class));
drawer.closeDrawers();
- } else if("Admin".equals(drawerItemsDescriptions[position]) && UserUtil.isCurrentAdmin()) {
- UserUtil.confirmCredentials(context, new Runnable() {
+ } else if("Admin".equals(drawerItemsDescriptions[actualPosition]) && UserUtil.isCurrentAdmin()) {
+ UserUtil.confirmCredentials(SubsonicActivity.this, new Runnable() {
@Override
public void run() {
- drawerItemSelected(position, view);
+ drawerItemSelected(actualPosition, view);
}
});
} else {
- drawerItemSelected(position, view);
+ drawerItemSelected(actualPosition, view);
}
}
});
@@ -472,11 +472,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(lastSelectedView != view) {
if(lastSelectedView != null) {
- lastSelectedView.setTextAppearance(this, R.style.Dsub_TextViewStyle);
+ lastSelectedView.setTextAppearance(this, R.style.DSub_TextViewStyle);
}
lastSelectedView = (TextView) view.findViewById(R.id.drawer_name);
- lastSelectedView.setTextAppearance(this, R.style.Dsub_TextViewStyle_Bold);
+ lastSelectedView.setTextAppearance(this, R.style.DSub_TextViewStyle_Bold);
lastSelectedPosition = position;
}
}
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index fc86ad36..561e32c4 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -209,7 +209,7 @@ public class MainFragment extends SubsonicFragment {
}
Util.setActiveServer(context, instance);
context.invalidate();
- UserUtil.refreshCurrentUser(context, false);
+ UserUtil.refreshCurrentUser(context, false, true);
}
}
diff --git a/src/github/daneren2005/dsub/util/UserUtil.java b/src/github/daneren2005/dsub/util/UserUtil.java
index 50ee2b7c..77e07f6b 100644
--- a/src/github/daneren2005/dsub/util/UserUtil.java
+++ b/src/github/daneren2005/dsub/util/UserUtil.java
@@ -49,8 +49,15 @@ public final class UserUtil {
private static User currentUser;
private static long lastVerifiedTime = 0;
+
public static void refreshCurrentUser(Context context, boolean forceRefresh) {
+ refreshCurrentUser(context, forceRefresh, false);
+ }
+ public static void refreshCurrentUser(Context context, boolean forceRefresh, boolean unAuth) {
currentUser = null;
+ if(unAuth) {
+ lastVerifiedTime = 0;
+ }
seedCurrentUser(context, forceRefresh);
}
@@ -141,13 +148,13 @@ public final class UserUtil {
return false;
}
- public static void confirmCredentials(final Context context, final Runnable onSuccess) {
+ public static void confirmCredentials(final Activity context, final Runnable onSuccess) {
final long currentTime = System.currentTimeMillis();
// If already ran this check within last x time, just go ahead and auth
- if((currentTime - lastVerified) < MIN_VERIFY_DURATION) {
+ if((currentTime - lastVerifiedTime) < MIN_VERIFY_DURATION) {
onSuccess.run();
} else {
- View layout = context.getLayoutInflater().inflate(R.layout.verify_password, null);
+ View layout = context.getLayoutInflater().inflate(R.layout.confirm_password, null);
final TextView passwordView = (TextView) layout.findViewById(R.id.password);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
@@ -162,7 +169,7 @@ public final class UserUtil {
String correctPassword = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + Util.getActiveServer(context), null);
if(password != null && password.equals(correctPassword)) {
- lastVerified = currentTime;
+ lastVerifiedTime = currentTime;
onSuccess.run();
} else {
Util.toast(context, R.string.admin_confirm_password_bad);
@@ -170,7 +177,7 @@ public final class UserUtil {
}
})
.setNegativeButton(R.string.common_cancel, null)
- .setCancellable(true);
+ .setCancelable(true);
AlertDialog dialog = builder.create();
dialog.show();