Permalink
Browse files

[android] Implemented authentication and requesting API with auth token.

  • Loading branch information...
1 parent 2307479 commit b46092dade8cc7b0dc35c89563e67ba8221d25e6 @yatsu committed Nov 4, 2012
@@ -73,6 +73,7 @@ public void onFinish(Token token) {
AuthManager.getInstance().setToken(activity, token.getToken());
Intent intent = new Intent();
+ intent.putExtra("authenticated", true);
setResult(Activity.RESULT_OK, intent);
finish();
}
@@ -168,6 +168,14 @@ private void login() {
private void logout() {
AuthManager.getInstance().clearToken(this);
invalidateOptionsMenu();
+
+ FragmentManager fm = getFragmentManager();
+ mPrivatePostsFragment.setListShown(false);
+ PrivatePostsResponderFragment responder =
+ (PrivatePostsResponderFragment)fm.findFragmentByTag("PrivatePostsResponder");
+ if (responder != null) {
+ responder.reload();
+ }
}
private void refresh() {
@@ -47,6 +47,8 @@ public void onFailure(int code, String response) {
//Toast.makeText(getActivity(), "Failed to load data. Check your internet settings.", Toast.LENGTH_SHORT).show();
//setListShown(true);
+ mPosts = null;
+
if (getActivity() != null) {
if (code == 401) {
setEmptyText("Login Required");
@@ -60,7 +62,6 @@ public void onFailure(int code, String response) {
}
private void setPostsAdapter() {
- Log.d(TAG, "setPostsAdapter");
if (mPostsAdapter == null) {
mPostsAdapter = new ArrayAdapter<String>(getActivity(), R.layout.post);
setListAdapter(mPostsAdapter);
@@ -29,6 +29,8 @@
import android.os.ResultReceiver;
import android.util.Log;
+import com.valleyport.bestmix.auth.AuthManager;
+
public class RESTService extends IntentService {
private static final String TAG = RESTService.class.getName();
@@ -122,6 +124,12 @@ protected void onHandleIntent(Intent intent) {
}
if (request != null) {
+ String token = AuthManager.getInstance().getToken(this);
+ Log.d(TAG, "token: " + token);
+ if (token != null) {
+ request.setHeader("Authorization", "Bearer " + token);
+ }
+
HttpClient client = new DefaultHttpClient();
// Let's send some useful debug information so we can monitor things

0 comments on commit b46092d

Please sign in to comment.