Android Open Source - GitHubContributionsApp Git Hub Profile Details Downloader Base






From Project

Back to project page GitHubContributionsApp.

License

The source code is released under:

GNU General Public License

If you think the Android project GitHubContributionsApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.githubcardandroidapp.app.GitHubContributionsIO;
// www .j a  va  2  s. c  om
import android.util.Log;

import com.githubcardandroidapp.app.BusinessObjects.GitHubProfileDetails;
import com.githubcardandroidapp.app.BusinessObjects.GitHubProfileDetailsImpl;

import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public abstract class GitHubProfileDetailsDownloaderBase implements GitHubProfileDetailsDownloader {

    protected final String UriText = "https://api.github.com/users/";

    @Override
    public GitHubProfileDetails downloadProfileDetails(String login) throws IOException, JSONException {

        String result = downloadProfileDetailsCore(getUriForProfileDetails(login));
        GitHubProfileDetails profileDetails = ParseJSONToProfileDetails(result);
        return profileDetails;
    }

    @Override
    public List<String> downloadUserRepositories(String login) throws IOException, JSONException {

        String repositoriesUri = getUriForUserRepositories(login);
        return downloadUserRepositoriesCore(repositoriesUri);
    }

    protected abstract List<String> downloadUserRepositoriesCore(String repositoriesUri) throws IOException, JSONException;

    protected abstract String downloadProfileDetailsCore(String login) throws IOException, JSONException;

    protected static GitHubProfileDetails ParseJSONToProfileDetails(String result) throws JSONException
    {
        GitHubProfileDetails profileDetails = null;

        try {
            JSONObject json = new JSONObject(result);
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");

            String name = json.getString("name");
            String blog = json.getString("blog");
            String login = json.getString("login");
            Date createdAt = formatter.parse(json.getString("created_at"));
            int numFollowers = json.getInt("followers");

            String avatarUrlText = json.getString("avatar_url");

            profileDetails =
                    new GitHubProfileDetailsImpl(login, name, avatarUrlText, blog, createdAt, numFollowers );
        }
        catch (ParseException exception) {
            Log.i("JSON Exception", "Parsing exception");
        }

        return profileDetails;
    }

    protected String getUriForProfileDetails(String login)
    {
        return String.format("%s%s", UriText, login);
    }

    protected String getUriForUserRepositories(String login)
    {
        return String.format("%s/repos", getUriForProfileDetails(login));
    }
}




Java Source Code List

com.githubcardandroidapp.app.GitHubCardActivity.java
com.githubcardandroidapp.app.SettingsActivity.java
com.githubcardandroidapp.app.BusinessObjects.GitHubProfileDetailsImpl.java
com.githubcardandroidapp.app.BusinessObjects.GitHubProfileDetails.java
com.githubcardandroidapp.app.BusinessObjects.GitHubUserRepositoriesImpl.java
com.githubcardandroidapp.app.BusinessObjects.GitHubUserRepositories.java
com.githubcardandroidapp.app.GitHubContributionsIO.GitHubProfileDetailsDownloaderBase.java
com.githubcardandroidapp.app.GitHubContributionsIO.GitHubProfileDetailsDownloader.java
com.githubcardandroidapp.app.GitHubContributionsIO.HttpClientProfileDetailsDownloader.java
com.githubcardandroidapp.app.GitHubContributionsIO.HttpUrlConnectionProfileDetailsDownloader.java
com.githubcardandroidapp.app.GitHubContributionsIO.Profile.GitHubActivityInternalStorageAsyncTask.java
com.githubcardandroidapp.app.GitHubContributionsIO.Profile.GitHubActivityOnlineUserProfileAsyncTask.java
com.githubcardandroidapp.app.GitHubContributionsIO.Profile.GitHubProfileAsyncTask.java
com.githubcardandroidapp.app.GitHubContributionsIO.Repositories.GitHubActivityOnlineUserRepositoriesAsyncTask.java
com.githubcardandroidapp.app.GitHubContributionsIO.Repositories.GitHubInternalStorageUserRepositoriesAsyncTask.java
com.githubcardandroidapp.app.GitHubContributionsIO.Repositories.GitHubUserRepositoriesAsyncTask.java
com.githubcardandroidapp.app.GitHubContributionsIO.Services.DeviceStartupReceiver.java
com.githubcardandroidapp.app.GitHubContributionsIO.Services.GitHubCardActivityReceiver.java
com.githubcardandroidapp.app.GitHubContributionsIO.Services.GitHubSyncService.java
com.githubcardandroidapp.app.Network.ConnectivityChecker.java
com.githubcardandroidapp.app.Network.ConnectivityReceiver.java
com.githubcardandroidapp.app.Serialization.PersistenceHandlerImpl.java
com.githubcardandroidapp.app.Serialization.PersistenceHandler.java
com.githubcardandroidapp.app.Serialization.UserNamePicker.java