Fix posts out of order, and posts staying with a trashcan.

captchafix
Florens Douwes 11 years ago
parent 24c4abe9a6
commit 49cfa2a20c
  1. 12
      Clover/app/src/main/java/org/floens/chan/core/model/Post.java
  2. 16
      Clover/app/src/main/java/org/floens/chan/core/net/ChanReaderRequest.java
  3. 6
      Clover/app/src/main/java/org/floens/chan/ui/fragment/ImageViewFragment.java

@ -39,7 +39,7 @@ public class Post {
public String name = "";
public CharSequence comment = "";
public String subject = "";
public String tim;
public long tim = -1;
public String ext;
public String filename;
public int replies = -1;
@ -55,7 +55,7 @@ public class Post {
public String capcode = "";
public String country = "";
public String countryName = "";
public long time = 0;
public long time = -1;
public String email = "";
public boolean isSavedReply = false;
public String title = "";
@ -108,7 +108,7 @@ public class Post {
if (board == null)
return false;
if (no < 0 || resto < 0 || date == null)
if (no < 0 || resto < 0 || date == null || time < 0)
return false;
isOP = resto == 0;
@ -121,11 +121,11 @@ public class Post {
}
if (hasImage) {
if (filename == null || tim == null || ext == null || imageWidth <= 0 || imageHeight <= 0)
if (filename == null || ext == null || imageWidth <= 0 || imageHeight <= 0 || tim < 0)
return false;
thumbnailUrl = ChanUrls.getThumbnailUrl(board, tim);
imageUrl = ChanUrls.getImageUrl(board, tim, ext);
thumbnailUrl = ChanUrls.getThumbnailUrl(board, Long.toString(tim));
imageUrl = ChanUrls.getImageUrl(board, Long.toString(tim), ext);
filename = Parser.unescapeEntities(filename, false);
}

@ -31,6 +31,8 @@ import org.floens.chan.core.model.Post;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -107,8 +109,7 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
}
}
if (!serverHas)
cache.deleted = true;
cache.deleted = !serverHas;
}
// If there's a post in the list from the server, that's not in the cached list, add it.
@ -128,6 +129,15 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
totalList.add(post);
}
}
// Sort if it got out of order due to posts disappearing/reappearing
Collections.sort(totalList, new Comparator<Post>() {
@Override
public int compare(Post lhs, Post rhs) {
return lhs.time == rhs.time ? 0 : (lhs.time < rhs.time ? -1 : 1);
}
});
} else {
totalList.addAll(serverList);
}
@ -300,7 +310,7 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
post.rawComment = reader.nextString();
break;
case "tim":
post.tim = reader.nextString();
post.tim = reader.nextLong();
break;
case "time":
post.time = reader.nextLong();

@ -231,10 +231,10 @@ public class ImageViewFragment extends Fragment implements ThumbnailImageViewCal
Utils.openLink(context, post.imageUrl);
break;
case R.id.action_image_save:
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, false);
break;
case R.id.action_share:
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, true);
ImageSaver.saveImage(context, post.imageUrl,
ChanPreferences.getImageSaveOriginalFilename() ? Long.toString(post.tim) : post.filename, post.ext,
item.getItemId() == R.id.action_share);
break;
default:
// Search if it was an ImageSearch item

Loading…
Cancel
Save