/*
 * Copyright (C) 2012 Brian Muramatsu
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.btmura.android.reddit.accounts;

import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.accounts.NetworkErrorException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.btmura.android.reddit.R;

public class AccountAuthenticator extends AbstractAccountAuthenticator {

    public static final String TAG = "AccountAuthenticator";

    public static final String AUTH_TOKEN_COOKIE = "cookie";
    public static final String AUTH_TOKEN_MODHASH = "modhash";

    private final Context context;

    public static String getAccountType(Context context) {
        return context.getString(R.string.account_type);
    }

    public AccountAuthenticator(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
            String authTokenType, String[] requiredFeatures, Bundle options)
            throws NetworkErrorException {
        Log.d(TAG, "addAccount");

        Intent intent = new Intent(context, AccountAuthenticatorActivity.class);
        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

        Bundle result = new Bundle(1);
        result.putParcelable(AccountManager.KEY_INTENT, intent);
        return result;
    }

    @Override
    public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account,
            Bundle options) throws NetworkErrorException {
        Log.d(TAG, "confirmCredentials");
        return null;
    }

    @Override
    public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
        Log.d(TAG, "editProperties");
        return null;
    }

    @Override
    public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
            String authTokenType, Bundle options) throws NetworkErrorException {
        Log.d(TAG, "getAuthToken");
        return null;
    }

    @Override
    public String getAuthTokenLabel(String authTokenType) {
        Log.d(TAG, "getAuthTokenLabel");
        return null;
    }

    @Override
    public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account,
            String[] features) throws NetworkErrorException {
        Log.d(TAG, "hasFeatures");
        return null;
    }

    @Override
    public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account,
            String authTokenType, Bundle options) throws NetworkErrorException {
        Log.d(TAG, "updateCredentials");
        return null;
    }
}

@@ -986,16 +986,56 @@
 l.Log;%0A%0A
+import com.btmura.android.reddit.Debug;%0A
 import c
@@ -1062,16 +1062,16 @@
 ddit.R;%0A
-
 %0Apublic 
@@ -1197,16 +1197,69 @@
 icator%22;
+%0A    public static final boolean DEBUG = Debug.DEBUG;
 %0A%0A    pu
@@ -1864,32 +1864,57 @@
 rrorException %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -1930,16 +1930,26 @@
 count%22);
+%0A        %7D
 %0A%0A      
@@ -2402,32 +2402,57 @@
 rrorException %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -2469,32 +2469,42 @@
 mCredentials%22);%0A
+        %7D%0A
         return n
@@ -2615,32 +2615,57 @@
  accountType) %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -2682,24 +2682,34 @@
 operties%22);%0A
+        %7D%0A
         retu
@@ -2898,32 +2898,57 @@
 rrorException %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -2963,24 +2963,34 @@
 uthToken%22);%0A
+        %7D%0A
         retu
@@ -3071,32 +3071,57 @@
 uthTokenType) %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -3141,24 +3141,34 @@
 kenLabel%22);%0A
+        %7D%0A
         retu
@@ -3337,32 +3337,57 @@
 rrorException %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -3401,24 +3401,34 @@
 Features%22);%0A
+        %7D%0A
         retu
@@ -3622,32 +3622,57 @@
 rrorException %7B%0A
+        if (DEBUG) %7B%0A    
         Log.d(TA
@@ -3688,32 +3688,42 @@
 eCredentials%22);%0A
+        %7D%0A
         return n

Clean up log statements in AccountAuthenticator