mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-23 21:23:56 +01:00
Fixed infinite loading duplicate posts when there is no more posts to load. Minor bugs fixed. Minor layout tweaks.
This commit is contained in:
parent
91e6174aa5
commit
f7a192dcbe
@ -87,7 +87,6 @@ class ParsePost {
|
||||
int previewWidth = -1;
|
||||
int previewHeight = -1;
|
||||
if(data.has(JSONUtils.PREVIEW_KEY)) {
|
||||
Log.i("haspreview", Integer.toString(i));
|
||||
previewUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
|
||||
.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
|
||||
previewWidth = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
|
||||
@ -95,7 +94,6 @@ class ParsePost {
|
||||
previewHeight = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
|
||||
.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY);
|
||||
}
|
||||
|
||||
if(data.has(JSONUtils.CROSSPOST_PARENT_LIST)) {
|
||||
//Cross post
|
||||
data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0);
|
||||
@ -160,129 +158,136 @@ class ParsePost {
|
||||
}
|
||||
bestPostData.add(linkPost);
|
||||
}
|
||||
} else if(isVideo) {
|
||||
//Video post
|
||||
Log.i("video", Integer.toString(i));
|
||||
JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
|
||||
int postType = Post.VIDEO_TYPE;
|
||||
String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY);
|
||||
} else {
|
||||
if(previewUrl.equals("")) {
|
||||
previewUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
|
||||
.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
|
||||
}
|
||||
|
||||
Post videoPost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, previewUrl, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost, true);
|
||||
if(isVideo) {
|
||||
//Video post
|
||||
Log.i("video", Integer.toString(i));
|
||||
JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
|
||||
int postType = Post.VIDEO_TYPE;
|
||||
String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY);
|
||||
|
||||
videoPost.setPreviewWidth(previewWidth);
|
||||
videoPost.setPreviewHeight(previewHeight);
|
||||
videoPost.setVideoUrl(videoUrl);
|
||||
videoPost.setDownloadableGifOrVideo(false);
|
||||
|
||||
bestPostData.add(videoPost);
|
||||
} else if(data.has(JSONUtils.PREVIEW_KEY)){
|
||||
JSONObject variations = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0);
|
||||
if (variations.has(JSONUtils.VARIANTS_KEY) && variations.getJSONObject(JSONUtils.VARIANTS_KEY).has(JSONUtils.MP4_KEY)) {
|
||||
//Gif video post (MP4)
|
||||
Log.i("gif video mp4", Integer.toString(i));
|
||||
int postType = Post.GIF_VIDEO_TYPE;
|
||||
String videoUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
|
||||
String gifDownloadUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
|
||||
Post post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
|
||||
previewUrl, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost, false);
|
||||
|
||||
post.setPreviewWidth(previewWidth);
|
||||
post.setPreviewHeight(previewHeight);
|
||||
post.setVideoUrl(videoUrl);
|
||||
post.setDownloadableGifOrVideo(true);
|
||||
post.setGifOrVideoDownloadUrl(gifDownloadUrl);
|
||||
|
||||
bestPostData.add(post);
|
||||
} else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) {
|
||||
//Gif video post (Dash)
|
||||
Log.i("gif video dash", Integer.toString(i));
|
||||
int postType = Post.GIF_VIDEO_TYPE;
|
||||
String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY)
|
||||
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY);
|
||||
|
||||
Post post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
|
||||
previewUrl, permalink, score, postType, voteType,
|
||||
Post videoPost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, previewUrl, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost, true);
|
||||
|
||||
post.setPreviewWidth(previewWidth);
|
||||
post.setPreviewHeight(previewHeight);
|
||||
post.setVideoUrl(videoUrl);
|
||||
post.setDownloadableGifOrVideo(false);
|
||||
videoPost.setPreviewWidth(previewWidth);
|
||||
videoPost.setPreviewHeight(previewHeight);
|
||||
videoPost.setVideoUrl(videoUrl);
|
||||
videoPost.setDownloadableGifOrVideo(false);
|
||||
|
||||
bestPostData.add(post);
|
||||
bestPostData.add(videoPost);
|
||||
} else if(data.has(JSONUtils.PREVIEW_KEY)){
|
||||
JSONObject variations = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0);
|
||||
if (variations.has(JSONUtils.VARIANTS_KEY) && variations.getJSONObject(JSONUtils.VARIANTS_KEY).has(JSONUtils.MP4_KEY)) {
|
||||
//Gif video post (MP4)
|
||||
Log.i("gif video mp4", Integer.toString(i));
|
||||
int postType = Post.GIF_VIDEO_TYPE;
|
||||
String videoUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
|
||||
String gifDownloadUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
|
||||
Post post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
|
||||
previewUrl, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost, false);
|
||||
|
||||
post.setPreviewWidth(previewWidth);
|
||||
post.setPreviewHeight(previewHeight);
|
||||
post.setVideoUrl(videoUrl);
|
||||
post.setDownloadableGifOrVideo(true);
|
||||
post.setGifOrVideoDownloadUrl(gifDownloadUrl);
|
||||
|
||||
bestPostData.add(post);
|
||||
} else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) {
|
||||
//Gif video post (Dash)
|
||||
Log.i("gif video dash", Integer.toString(i));
|
||||
int postType = Post.GIF_VIDEO_TYPE;
|
||||
String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY)
|
||||
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY);
|
||||
|
||||
Post post = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
|
||||
previewUrl, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost, true);
|
||||
|
||||
post.setPreviewWidth(previewWidth);
|
||||
post.setPreviewHeight(previewHeight);
|
||||
post.setVideoUrl(videoUrl);
|
||||
post.setDownloadableGifOrVideo(false);
|
||||
|
||||
bestPostData.add(post);
|
||||
} else {
|
||||
if (url.endsWith("jpg") || url.endsWith("png")) {
|
||||
//Image post
|
||||
Log.i("image", Integer.toString(i));
|
||||
int postType = Post.IMAGE_TYPE;
|
||||
|
||||
Post imagePost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, url, url, permalink, score, postType,
|
||||
voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
|
||||
imagePost.setPreviewWidth(previewWidth);
|
||||
imagePost.setPreviewHeight(previewHeight);
|
||||
|
||||
bestPostData.add(imagePost);
|
||||
} else {
|
||||
if (url.contains(permalink)) {
|
||||
//Text post but with a preview
|
||||
Log.i("text with image", Integer.toString(i));
|
||||
int postType = Post.TEXT_TYPE;
|
||||
Post textWithImagePost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, permalink, score, postType, voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
|
||||
textWithImagePost.setPreviewWidth(previewWidth);
|
||||
textWithImagePost.setPreviewHeight(previewHeight);
|
||||
|
||||
if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
|
||||
textWithImagePost.setSelfText("");
|
||||
} else {
|
||||
textWithImagePost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
|
||||
}
|
||||
bestPostData.add(textWithImagePost);
|
||||
} else {
|
||||
//Link post
|
||||
Log.i("link", Integer.toString(i));
|
||||
int postType = Post.LINK_TYPE;
|
||||
Post linkPost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, previewUrl, url, permalink, score,
|
||||
postType, voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
|
||||
linkPost.setSelfText("");
|
||||
} else {
|
||||
linkPost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
|
||||
}
|
||||
|
||||
linkPost.setPreviewWidth(previewWidth);
|
||||
linkPost.setPreviewHeight(previewHeight);
|
||||
|
||||
bestPostData.add(linkPost);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (url.endsWith("jpg") || url.endsWith("png")) {
|
||||
//Image post
|
||||
Log.i("image", Integer.toString(i));
|
||||
Log.i("CP image", Integer.toString(i));
|
||||
int postType = Post.IMAGE_TYPE;
|
||||
|
||||
Post imagePost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, url, url, permalink, score, postType,
|
||||
Post linkPost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, previewUrl, url, permalink, score, postType,
|
||||
voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
|
||||
imagePost.setPreviewWidth(previewWidth);
|
||||
imagePost.setPreviewHeight(previewHeight);
|
||||
|
||||
bestPostData.add(imagePost);
|
||||
linkPost.setPreviewWidth(previewWidth);
|
||||
linkPost.setPreviewHeight(previewHeight);
|
||||
bestPostData.add(linkPost);
|
||||
} else {
|
||||
if (url.contains(permalink)) {
|
||||
//Text post but with a preview
|
||||
Log.i("text with image", Integer.toString(i));
|
||||
int postType = Post.TEXT_TYPE;
|
||||
Post textWithImagePost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, permalink, score, postType, voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
|
||||
textWithImagePost.setPreviewWidth(previewWidth);
|
||||
textWithImagePost.setPreviewHeight(previewHeight);
|
||||
|
||||
if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
|
||||
textWithImagePost.setSelfText("");
|
||||
} else {
|
||||
textWithImagePost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
|
||||
}
|
||||
bestPostData.add(textWithImagePost);
|
||||
} else {
|
||||
//Link post
|
||||
Log.i("link", Integer.toString(i));
|
||||
int postType = Post.LINK_TYPE;
|
||||
Post linkPost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, previewUrl, url, permalink, score,
|
||||
postType, voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
|
||||
linkPost.setSelfText("");
|
||||
} else {
|
||||
linkPost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
|
||||
}
|
||||
|
||||
linkPost.setPreviewWidth(previewWidth);
|
||||
linkPost.setPreviewHeight(previewHeight);
|
||||
|
||||
bestPostData.add(linkPost);
|
||||
}
|
||||
//CP No Preview Link post
|
||||
Log.i("CP no preview link", Integer.toString(i));
|
||||
int postType = Post.NO_PREVIEW_LINK_TYPE;
|
||||
bestPostData.add(new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
|
||||
url, url, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (url.endsWith("jpg") || url.endsWith("png")) {
|
||||
//Image post
|
||||
Log.i("CP image", Integer.toString(i));
|
||||
int postType = Post.IMAGE_TYPE;
|
||||
Post linkPost = new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime,
|
||||
title, previewUrl, url, permalink, score, postType,
|
||||
voteType, gilded, nsfw, stickied, isCrosspost);
|
||||
linkPost.setPreviewWidth(previewWidth);
|
||||
linkPost.setPreviewHeight(previewHeight);
|
||||
bestPostData.add(linkPost);
|
||||
} else {
|
||||
//CP No Preview Link post
|
||||
Log.i("CP no preview link", Integer.toString(i));
|
||||
int postType = Post.NO_PREVIEW_LINK_TYPE;
|
||||
bestPostData.add(new Post(id, fullName, subredditNamePrefixed, author, formattedPostTime, title,
|
||||
url, url, permalink, score, postType, voteType,
|
||||
gilded, nsfw, stickied, isCrosspost));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
static final int TYPE_FRONT_PAGE = 0;
|
||||
static final int TYPE_SUBREDDIT = 1;
|
||||
static final int TYPE_USER = 2;
|
||||
|
||||
private Retrofit retrofit;
|
||||
private String accessToken;
|
||||
private Locale locale;
|
||||
@ -86,6 +87,10 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
this.params = params;
|
||||
this.callback = callback;
|
||||
|
||||
if(params.key.equals("null")) {
|
||||
return;
|
||||
}
|
||||
|
||||
paginationNetworkStateLiveData.postValue(NetworkState.LOADING);
|
||||
|
||||
switch (postType) {
|
||||
|
@ -82,6 +82,7 @@
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_centerVertical="true"
|
||||
app:chipBackgroundColor="@color/colorPrimaryDark"/>
|
||||
|
||||
<ImageView
|
||||
@ -90,6 +91,7 @@
|
||||
android:layout_height="24dp"
|
||||
android:layout_toEndOf="@id/type_text_view_item_best_post"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
@ -102,7 +104,8 @@
|
||||
android:layout_toEndOf="@id/gilded_image_view_item_best_post"
|
||||
android:visibility="gone"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/gold"/>
|
||||
android:textColor="@color/gold"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/crosspost_image_view_item_best_post"
|
||||
@ -115,6 +118,7 @@
|
||||
android:layout_toEndOf="@id/gilded_number_text_view_item_best_post"
|
||||
android:src="@drawable/crosspost"
|
||||
android:tint="@color/colorAccent"
|
||||
android:layout_centerVertical="true"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<android.support.design.chip.Chip
|
||||
@ -128,6 +132,7 @@
|
||||
android:textSize="12sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:visibility="gone"
|
||||
android:layout_centerVertical="true"
|
||||
app:chipBackgroundColor="@color/colorAccent"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user