1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2024-12-25 07:52:58 +01:00

fixed crashes when reading incompatible status cache

fixed NPEs
This commit is contained in:
Mariotaku Lee 2015-09-02 10:45:18 +08:00
parent 5d61948d08
commit 78e5a43985
3 changed files with 34 additions and 23 deletions

View File

@ -30,6 +30,7 @@ import android.text.TextUtils;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.bluelinelabs.logansquare.annotation.OnJsonParseComplete;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
@ -449,6 +450,16 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
return date != null ? date.getTime() : 0;
}
public static ParcelableStatus[] fromStatuses(Status[] statuses, long accountId) {
if (statuses == null) return null;
int size = statuses.length;
final ParcelableStatus[] result = new ParcelableStatus[size];
for (int i = 0; i < size; i++) {
result[i] = new ParcelableStatus(statuses[i], accountId, false);
}
return result;
}
@Override
public int compareTo(@NonNull final ParcelableStatus another) {
final long diff = another.id - id;
@ -543,14 +554,10 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
ParcelableStatusParcelablePlease.writeToParcel(this, out, flags);
}
public static ParcelableStatus[] fromStatuses(Status[] statuses, long accountId) {
if (statuses == null) return null;
int size = statuses.length;
final ParcelableStatus[] result = new ParcelableStatus[size];
for (int i = 0; i < size; i++) {
result[i] = new ParcelableStatus(statuses[i], accountId, false);
}
return result;
@OnJsonParseComplete
void onParseComplete() throws IOException {
if (is_quote && TextUtils.isEmpty(quoted_text_html))
throw new IOException("Incompatible model");
}
public static final class CursorIndices extends ObjectCursor.CursorIndices<ParcelableStatus> {

View File

@ -24,6 +24,7 @@ import android.content.SharedPreferences;
import android.util.Log;
import android.util.Pair;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.restfu.annotation.method.POST;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.restfu.http.RestHttpRequest;
@ -85,9 +86,11 @@ public class UploadLogsTask implements Runnable {
return !filename.equalsIgnoreCase(todayDir);
}
};
for (File dayLogsDir : logsDir.listFiles(filter)) {
for (Object dayLogsDirObj : ArrayUtils.nullToEmpty(logsDir.listFiles(filter))) {
final File dayLogsDir = (File) dayLogsDirObj;
boolean succeeded = true;
for (File logFile : dayLogsDir.listFiles()) {
for (Object logFileObj : ArrayUtils.nullToEmpty(dayLogsDir.listFiles())) {
File logFile = (File) logFileObj;
FileTypedData body = null;
RestHttpResponse response = null;
try {

View File

@ -171,15 +171,16 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
quotedNameView.setName(manager.getUserNickname(status.quoted_user_id, status.quoted_user_name, false));
quotedNameView.setScreenName("@" + status.quoted_user_screen_name);
if (adapter.getLinkHighlightingStyle() == VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
final String text = status.quoted_text_unescaped;
quotedTextView.setText(text);
} else {
if (adapter.getLinkHighlightingStyle() != VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE
&& !TextUtils.isEmpty(status.quoted_text_html)) {
final Spanned text = Html.fromHtml(status.quoted_text_html);
quotedTextView.setText(text);
linkify.applyAllLinks(quotedTextView, status.account_id, getLayoutPosition(),
status.is_possibly_sensitive, adapter.getLinkHighlightingStyle());
quotedTextView.setMovementMethod(null);
} else {
final String text = status.quoted_text_unescaped;
quotedTextView.setText(text);
}
quoteIndicator.setColor(manager.getUserColor(status.user_id, false));
@ -530,6 +531,11 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
return false;
}
@Override
public void setLoadMoreIndicatorVisible(boolean enabled) {
}
@Override
public boolean isLoadMoreSupported() {
return false;
@ -540,11 +546,6 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
}
@Override
public void setLoadMoreIndicatorVisible(boolean enabled) {
}
@Override
public ParcelableStatus getStatus(int position) {
return null;
@ -570,6 +571,10 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
return displayMediaPreview;
}
public void setMediaPreviewEnabled(boolean enabled) {
displayMediaPreview = enabled;
}
@Override
public int getLinkHighlightingStyle() {
return linkHighlightStyle;
@ -600,10 +605,6 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
return false;
}
public void setMediaPreviewEnabled(boolean enabled) {
displayMediaPreview = enabled;
}
@Override
public boolean isGapItem(int position) {
return false;