Show login as menu item for staff users. Open dialog for entering username.

This commit is contained in:
Mark Anderson 2014-12-08 23:29:16 +00:00
parent 23bc4f2c69
commit 64e5a79adf
7 changed files with 89 additions and 1 deletions

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<EditText
android:id="@+id/username_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:singleLine="false"
android:inputType="textCapSentences|textMultiLine" />
</RelativeLayout>

View file

@ -22,6 +22,11 @@
<item android:id="@+id/menu_feedback"
android:title="@string/menu_feedback"
android:showAsAction="never" />
<item android:id="@+id/menu_loginas"
android:title="@string/menu_loginas"
android:showAsAction="never"
android:visible="false"/>
<item android:id="@+id/menu_logout"
android:title="@string/menu_logout"

View file

@ -139,6 +139,9 @@
<string name="menu_mark_all_as_read">Mark all as read</string>
<string name="menu_logout">Log out</string>
<string name="menu_feedback">Send app feedback</string>
<string name="menu_loginas">Login as...</string>
<string name="loginas_title">Login As User</string>
<string name="empty_list_view_loading">Loading…</string>
<string name="empty_list_view_no_stories">No stories to read</string>

View file

@ -20,6 +20,7 @@ import android.widget.TextView;
import com.newsblur.R;
import com.newsblur.fragment.FeedIntelligenceSelectorFragment;
import com.newsblur.fragment.FolderListFragment;
import com.newsblur.fragment.LoginAsDialogFragment;
import com.newsblur.fragment.LogoutDialogFragment;
import com.newsblur.service.BootReceiver;
import com.newsblur.service.NBSyncService;
@ -85,7 +86,16 @@ public class Main extends NbActivity implements StateChangedListener, SwipeRefre
}
}
@Override
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem loginAsItem = menu.findItem(R.id.menu_loginas);
if (NBSyncService.isStaff == Boolean.TRUE) {
loginAsItem.setVisible(true);
}
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
@ -131,6 +141,9 @@ public class Main extends NbActivity implements StateChangedListener, SwipeRefre
Log.wtf(this.getClass().getName(), "device cannot even open URLs to report feedback");
}
return true;
} else if (item.getItemId() == R.id.menu_loginas) {
DialogFragment newFragment = new LoginAsDialogFragment();
newFragment.show(getFragmentManager(), "dialog");
}
return super.onOptionsItemSelected(item);
}

View file

@ -0,0 +1,46 @@
package com.newsblur.fragment;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import com.newsblur.R;
/**
* Created by mark on 08/12/2014.
*/
public class LoginAsDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.loginas_title);
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View usernameView = layoutInflater.inflate(R.layout.loginas_dialog, null);
builder.setView(usernameView);
final EditText username = (EditText) usernameView.findViewById(R.id.username_field);
builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// TODO
LoginAsDialogFragment.this.dismiss();
}
});
builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
LoginAsDialogFragment.this.dismiss();
}
});
return builder.create();
}
}

View file

@ -36,6 +36,7 @@ public class FeedFolderResponse {
public boolean isAuthenticated;
public boolean isPremium;
public boolean isStaff;
public FeedFolderResponse(String json, Gson gson) {
@ -44,6 +45,7 @@ public class FeedFolderResponse {
JsonObject asJsonObject = parser.parse(json).getAsJsonObject();
this.isAuthenticated = asJsonObject.get("authenticated").getAsBoolean();
this.isStaff = asJsonObject.get("is_staff").getAsBoolean();
JsonElement userProfile = asJsonObject.get("user_profile");
if (userProfile != null) {

View file

@ -80,6 +80,7 @@ public class NBSyncService extends Service {
private volatile static boolean isMemoryLow = false;
private volatile static boolean HaltNow = false;
public volatile static Boolean isPremium = null;
public volatile static Boolean isStaff = null;
private static long lastFeedCount = 0L;
private static long lastFFWriteMillis = 0L;
@ -327,6 +328,7 @@ public class NBSyncService extends Service {
long startTime = System.currentTimeMillis();
isPremium = feedResponse.isPremium;
isStaff = feedResponse.isStaff;
// clean out the feed / folder tables
dbHelper.cleanupFeedsFolders();