package com.gh4a.loader;

import java.io.InputStream;

import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.ContentService;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;

import com.gh4a.Constants;
import com.gh4a.DefaultClient;
import com.gh4a.Gh4Application;
import com.gh4a.utils.StringUtils;

public class ReadmeLoader extends AsyncTaskLoader<String> {

    private String mRepoOwner;
    private String mRepoName;
    
    public ReadmeLoader(Context context, String repoOwner, String repoName) {
        super(context);
        mRepoOwner = repoOwner;
        mRepoName = repoName;
    }
    
    @Override
    public String loadInBackground() {
        GitHubClient client = new DefaultClient("application/vnd.github.beta.html");
        try {
            ContentService contentService = new ContentService(client);
            InputStream is = contentService.getHtmlReadme(new RepositoryId(mRepoOwner, mRepoName));
            if (is != null) {
                return StringUtils.convertStreamToString(is);
            }
            else {
                return null;
            }
        } catch (Exception e) {
            Log.e(Constants.LOG_TAG, e.getMessage(), e);
            return null;
        }
    }
}

@@ -802,24 +802,108 @@
 kground() %7B%0A
+        Gh4Application app = (Gh4Application) getContext().getApplicationContext();%0A
         GitH
@@ -975,16 +975,67 @@
 html%22);%0A
+        client.setOAuth2Token(app.getAuthToken());%0A
         

Fix README not showing in private repo