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;
}
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();
}
}
Aggregations