Search in sources :

Example 1 with RedditClient

use of net.dean.jraw.RedditClient in project Slide by ccrama.

the class CommentAdapter method getAuthenticatedClient.

private RedditClient getAuthenticatedClient(String profileName) {
    String token;
    RedditClient reddit = new RedditClient(UserAgent.of("android:me.ccrama.RedditSlide:v" + BuildConfig.VERSION_NAME));
    final HashMap<String, String> accounts = new HashMap<>();
    for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
        if (s.contains(":")) {
            accounts.put(s.split(":")[0], s.split(":")[1]);
        } else {
            accounts.put(s, "");
        }
    }
    final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
    if (accounts.containsKey(profileName) && !accounts.get(profileName).isEmpty()) {
        token = accounts.get(profileName);
    } else {
        ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
        int index = keys.indexOf(profileName);
        if (keys.indexOf(profileName) > tokens.size()) {
            index -= 1;
        }
        token = tokens.get(index);
    }
    Authentication.doVerify(token, reddit, true, mContext);
    return reddit;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RedditClient(net.dean.jraw.RedditClient) HashSet(java.util.HashSet)

Example 2 with RedditClient

use of net.dean.jraw.RedditClient in project Slide by ccrama.

the class Authentication method updateToken.

public void updateToken(Context c) {
    if (BuildConfig.DEBUG)
        LogUtil.v("Executing update token");
    if (reddit == null) {
        hasDone = true;
        isLoggedIn = false;
        reddit = new RedditClient(UserAgent.of("android:me.ccrama.RedditSlide:v" + BuildConfig.VERSION_NAME));
        reddit.setLoggingMode(LoggingMode.ALWAYS);
        didOnline = true;
        new VerifyCredentials(c).execute();
    } else {
        new UpdateToken(c).execute();
    }
}
Also used : RedditClient(net.dean.jraw.RedditClient)

Aggregations

RedditClient (net.dean.jraw.RedditClient)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1