use of net.dean.jraw.models.Submission in project Slide by ccrama.
the class StackRemoteViewsFactory method getViewAt.
public RemoteViews getViewAt(int position) {
final RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.submission_widget);
if (position <= getCount()) {
final Submission submission = submissions.get(position);
String url = "";
ContentType.Type type = ContentType.getContentType(submission);
if (type == ContentType.Type.IMAGE) {
url = submission.getUrl();
} else if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && submission.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt() > 200) {
url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
} else if (submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
url = submission.getThumbnail();
}
try {
// todo rv.setImageViewBitmap(R.id.thumbnail, Glide.with(mContext).load(url).asBitmap().);
rv.setTextViewText(R.id.title, Html.fromHtml(submission.getTitle()));
} catch (Exception e) {
Log.v(LogUtil.getTag(), e.toString());
}
rv.setTextViewText(R.id.title, Html.fromHtml(submission.getTitle()));
rv.setTextViewText(R.id.subreddit, submission.getSubredditName());
rv.setTextViewText(R.id.info, submission.getAuthor() + " " + TimeUtils.getTimeAgo(submission.getCreated().getTime(), mContext));
Bundle extras = new Bundle();
extras.putString("url", submission.getUrl());
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.card, fillInIntent);
}
return rv;
}
use of net.dean.jraw.models.Submission in project Slide by ccrama.
the class HasSeen method setHasSeenContrib.
public static void setHasSeenContrib(List<Contribution> submissions) {
if (hasSeen == null) {
hasSeen = new ArrayList<>();
seenTimes = new HashMap<>();
}
KVManger m = KVStore.getInstance();
for (Contribution s : submissions) {
if (s instanceof Submission) {
String fullname = s.getFullName();
if (fullname.contains("t3_")) {
fullname = fullname.substring(3, fullname.length());
}
if (!m.getByContains(fullname).isEmpty() && m.get(fullname) != null) {
hasSeen.add(fullname);
try {
seenTimes.put(fullname, Long.valueOf(m.get(fullname)));
} catch (Exception e) {
}
}
}
}
}
use of net.dean.jraw.models.Submission in project Slide by ccrama.
the class CommentCacheAsync method doInBackground.
@Override
public Void doInBackground(Object[] params) {
if (Authentication.isLoggedIn && Authentication.me == null || Authentication.reddit == null) {
if (Authentication.reddit == null) {
new Authentication(context);
}
if (Authentication.reddit != null) {
try {
Authentication.me = Authentication.reddit.me();
Authentication.mod = Authentication.me.isMod();
Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
final String name = Authentication.me.getFullName();
Authentication.name = name;
LogUtil.v("AUTHENTICATED");
if (Authentication.reddit.isAuthenticated()) {
final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
if (accounts.contains(name)) {
// convert to new system
accounts.remove(name);
accounts.add(name + ":" + Authentication.refresh);
// force commit
Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
}
Authentication.isLoggedIn = true;
Reddit.notFirst = true;
}
} catch (Exception e) {
new Authentication(context);
}
}
}
Map<String, String> multiNameToSubsMap = UserSubscriptions.getMultiNameToSubs(true);
if (Authentication.reddit == null)
Reddit.authentication = new Authentication(context);
ArrayList<String> success = new ArrayList<>();
ArrayList<String> error = new ArrayList<>();
for (final String fSub : subs) {
final String sub;
final String name = fSub;
CommentSort sortType = SettingValues.getCommentSorting(name);
if (multiNameToSubsMap.containsKey(fSub)) {
sub = multiNameToSubsMap.get(fSub);
} else {
sub = fSub;
}
if (!sub.isEmpty()) {
if (!sub.equals(SAVED_SUBMISSIONS)) {
mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(context);
mBuilder.setOngoing(true);
mBuilder.setChannelId(Reddit.CHANNEL_COMMENT_CACHE);
mBuilder.setContentTitle(context.getString(R.string.offline_caching_title, sub.equalsIgnoreCase("frontpage") ? name : (name.contains("/m/") ? name : "/r/" + name))).setSmallIcon(R.drawable.save_png);
}
List<Submission> submissions = new ArrayList<>();
ArrayList<String> newFullnames = new ArrayList<>();
int count = 0;
if (alreadyReceived != null) {
submissions.addAll(alreadyReceived);
} else {
SubredditPaginator p;
if (name.equalsIgnoreCase("frontpage")) {
p = new SubredditPaginator(Authentication.reddit);
} else {
p = new SubredditPaginator(Authentication.reddit, sub);
}
p.setLimit(Constants.PAGINATOR_POST_LIMIT);
try {
submissions.addAll(p.next());
} catch (Exception e) {
e.printStackTrace();
}
}
int commentDepth = Integer.valueOf(SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "5"));
int commentCount = Integer.valueOf(SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "50"));
Log.v("CommentCacheAsync", "comment count " + commentCount);
int random = (int) (Math.random() * 100);
for (final Submission s : submissions) {
try {
JsonNode n = getSubmission(new SubmissionRequest.Builder(s.getId()).limit(commentCount).depth(commentDepth).sort(sortType).build());
Submission s2 = SubmissionSerializer.withComments(n, CommentSort.CONFIDENCE);
OfflineSubreddit.writeSubmission(n, s2, context);
newFullnames.add(s2.getFullName());
if (!SettingValues.noImages)
loadPhotos(s, context);
switch(ContentType.getContentType(s)) {
case GIF:
if (otherChoices[0]) {
if (context instanceof Activity) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
ExecutorService service = Executors.newSingleThreadExecutor();
new GifUtils.AsyncLoadGif().executeOnExecutor(service, s.getUrl());
}
});
}
}
break;
case ALBUM:
if (otherChoices[1]) // todo this AlbumUtils.saveAlbumToCache(context, s.getUrl());
{
break;
}
}
} catch (Exception ignored) {
}
count = count + 1;
if (mBuilder != null) {
mBuilder.setProgress(submissions.size(), count, false);
mNotifyManager.notify(random, mBuilder.build());
}
}
OfflineSubreddit.newSubreddit(sub).writeToMemory(newFullnames);
if (mBuilder != null) {
mNotifyManager.cancel(random);
}
if (!submissions.isEmpty())
success.add(sub);
}
}
if (mBuilder != null) {
mBuilder.setContentText(context.getString(R.string.offline_caching_complete)).setSubText(success.size() + " subreddits cached").setProgress(0, 0, false);
mBuilder.setOngoing(false);
mNotifyManager.notify(2001, mBuilder.build());
}
return null;
}
use of net.dean.jraw.models.Submission in project Slide by ccrama.
the class SubredditPostsRealm method loadPhotos.
public void loadPhotos(List<Submission> submissions) {
for (Submission submission : submissions) {
String url;
ContentType.Type type = ContentType.getContentType(submission);
if (submission.getThumbnails() != null) {
if (type == ContentType.Type.IMAGE || type == ContentType.Type.SELF || (submission.getThumbnailType() == Submission.ThumbnailType.URL)) {
if (type == ContentType.Type.IMAGE) {
if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile) || SettingValues.lowResAlways) && submission.getThumbnails() != null && submission.getThumbnails().getVariations() != null && submission.getThumbnails().getVariations().length > 0) {
int length = submission.getThumbnails().getVariations().length;
if (SettingValues.lqLow && length >= 3) {
url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
} else if (SettingValues.lqMid && length >= 4) {
url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
} else if (length >= 5) {
url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
} else {
url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
}
} else {
if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
// Load the preview image which has probably already been cached in memory instead of the direct link
url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
} else {
url = submission.getUrl();
}
}
((Reddit) c.getApplicationContext()).getImageLoader().loadImage(url, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
} else if (submission.getThumbnails() != null) {
if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile) || SettingValues.lowResAlways) && submission.getThumbnails().getVariations().length != 0) {
int length = submission.getThumbnails().getVariations().length;
if (SettingValues.lqLow && length >= 3) {
url = Html.fromHtml(submission.getThumbnails().getVariations()[2].getUrl()).toString();
} else if (SettingValues.lqMid && length >= 4) {
url = Html.fromHtml(submission.getThumbnails().getVariations()[3].getUrl()).toString();
} else if (length >= 5) {
url = Html.fromHtml(submission.getThumbnails().getVariations()[length - 1].getUrl()).toString();
} else {
url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
}
} else {
url = Html.fromHtml(submission.getThumbnails().getSource().getUrl()).toString();
}
((Reddit) c.getApplicationContext()).getImageLoader().loadImage(url, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
} else if (submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
((Reddit) c.getApplicationContext()).getImageLoader().loadImage(submission.getUrl(), new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
}
}
}
}
}
use of net.dean.jraw.models.Submission in project Slide by ccrama.
the class OfflineSubreddit method writeToMemoryNoStorage.
public void writeToMemoryNoStorage() {
if (cache == null)
cache = new HashMap<>();
if (subreddit != null) {
String title = subreddit.toLowerCase(Locale.ENGLISH) + "," + (base ? 0 : time);
String fullNames = "";
for (Submission sub : submissions) {
fullNames += sub.getFullName() + ",";
}
if (fullNames.length() > 0) {
Reddit.cachedData.edit().putString(title, fullNames.substring(0, fullNames.length() - 1)).apply();
}
cache.put(title, this);
}
}
Aggregations