Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Jan 14, 2016
1 parent ac76444 commit 94ad1a6
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
@JsonObject
public class MediaUploadResponse extends TwitterResponseObject implements TwitterResponse {

@JsonField(name = "media_id")
long mediaId;
@JsonField(name = "size")
long size;
@JsonField(name = "image")
Image image;
@JsonField(name = "video")
Video video;

public long getId() {
return mediaId;
}
Expand All @@ -40,13 +49,19 @@ public long getSize() {
return size;
}

@JsonField(name = "media_id")
long mediaId;
@JsonField(name = "size")
long size;
@JsonField(name = "image")
Image image;
public Video getVideo() {
return video;
}

@JsonObject
public static class Video {
@JsonField(name = "video_type")
String videoType;

public String getVideoType() {
return videoType;
}
}

@JsonObject
public static class Image {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.mariotaku.restfu.http.RestHttpRequest;
import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.restfu.http.mime.FileTypedData;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.util.BugReporter;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.Utils;
Expand All @@ -40,6 +41,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import edu.tsinghua.hotmobi.model.UploadLogEvent;

Expand Down Expand Up @@ -103,13 +105,16 @@ public boolean accept(File dir, String filename) {
headers.add(Pair.create("X-HotMobi-UUID", uuid));
headers.add(Pair.create("X-HotMobi-Date", dayLogsDir.getName()));
headers.add(Pair.create("X-HotMobi-FileName", logFile.getName()));
headers.add(Pair.create("User-Agent", String.format(Locale.ROOT,
"HotMobi (Twidere %s %d)", BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE)));
builder.headers(headers);
body = new FileTypedData(logFile);
builder.body(body);
final UploadLogEvent uploadLogEvent = UploadLogEvent.create(context, logFile);
response = client.execute(builder.build());
if (response.isSuccessful()) {
uploadLogEvent.markEnd();
uploadLogEvent.finish(response);
if (!uploadLogEvent.shouldSkip()) {
HotMobiLogger.getInstance(context).log(uploadLogEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@

import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.ParcelBagger;
import com.hannesdorfmann.parcelableplease.annotation.Bagger;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.mariotaku.restfu.Pair;
import org.mariotaku.restfu.http.RestHttpResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
* Created by mariotaku on 16/1/2.
Expand All @@ -33,11 +42,13 @@ public UploadLogEvent[] newArray(int size) {
String fileName;
@ParcelableThisPlease
@JsonField(name = "file_length")

long fileLength;
@ParcelableThisPlease
@Bagger(StringMapBagger.class)
@JsonField(name = "extra_headers")
Map<String, String> extraHeaders;

public long getFileLength() {

return fileLength;
}

Expand All @@ -53,6 +64,14 @@ public void setFileName(String fileName) {
this.fileName = fileName;
}

public Map<String, String> getExtraHeaders() {
return extraHeaders;
}

public void setExtraHeaders(Map<String, String> extraHeaders) {
this.extraHeaders = extraHeaders;
}

@Override
public int describeContents() {
return 0;
Expand All @@ -63,6 +82,17 @@ public void writeToParcel(Parcel dest, int flags) {
UploadLogEventParcelablePlease.writeToParcel(this, dest, flags);
}

public void finish(RestHttpResponse response) {
HashMap<String, String> extraHeaders = new HashMap<>();
for (Pair<String, String> pair : response.getHeaders()) {
if (StringUtils.startsWithIgnoreCase(pair.first, "X-Dnext")) {
extraHeaders.put(pair.first, pair.second);
}
}
setExtraHeaders(extraHeaders);
markEnd();
}

public static UploadLogEvent create(Context context, File file) {
UploadLogEvent event = new UploadLogEvent();
event.markStart(context);
Expand All @@ -71,7 +101,44 @@ public static UploadLogEvent create(Context context, File file) {
return event;
}

@Override
public String toString() {
return new ToStringBuilder(this)
.append("fileName", fileName)
.append("fileLength", fileLength)
.append("extraHeaders", extraHeaders)
.toString();
}

public boolean shouldSkip() {
return fileName.contains("upload_log");
}

public static class StringMapBagger implements ParcelBagger<Map<String, String>> {
@Override
public void write(Map<String, String> value, Parcel out, int flags) {
if (value == null) {
out.writeInt(-1);
} else {
out.writeInt(value.size());
for (Map.Entry<String, String> entry : value.entrySet()) {
out.writeString(entry.getKey());
out.writeString(entry.getValue());
}
}
}

@Override
public Map<String, String> read(Parcel in) {
final int size = in.readInt();
if (size < 0) return null;
final Map<String, String> map = new HashMap<>();
for (int i = 0; i < size; i++) {
final String key = in.readString();
final String value = in.readString();
map.put(key, value);
}
return map;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ private static class StatusAdapter extends BaseRecyclerViewAdapter<ViewHolder> i
private List<ParcelableStatus> mData;
private CharSequence mReplyError, mConversationError;
private boolean mRepliesLoading, mConversationsLoading;
private int mReplyStart;

public StatusAdapter(StatusFragment fragment, boolean compact) {
super(fragment.getContext());
Expand Down Expand Up @@ -1474,11 +1475,16 @@ public int getMediaPreviewStyle() {
public ParcelableStatus getStatus(int position) {
final int itemType = getItemType(position);
switch (itemType) {
case ITEM_IDX_CONVERSATION:
case ITEM_IDX_REPLY: {
case ITEM_IDX_CONVERSATION: {
if (mData == null) return null;
return mData.get(position - getIndexStart(ITEM_IDX_CONVERSATION));
}
case ITEM_IDX_REPLY: {
if (mData == null || mReplyStart < 0) return null;
return mData.get(position - getIndexStart(ITEM_IDX_CONVERSATION)
- mItemCounts[ITEM_IDX_CONVERSATION] - mItemCounts[ITEM_IDX_STATUS]
+ mReplyStart);
}
case ITEM_IDX_STATUS: {
return mStatus;
}
Expand Down Expand Up @@ -1551,24 +1557,25 @@ public void setData(List<ParcelableStatus> data) {
if (data == null || data.isEmpty()) {
setCount(ITEM_IDX_CONVERSATION, 0);
setCount(ITEM_IDX_REPLY, 0);
mReplyStart = -1;
} else {
int conversationCount = 0, replyCount = 0;
boolean containsStatus = false;
int replyStart = -1;
final long statusId = status.is_retweet ? status.retweet_id : status.id;
for (ParcelableStatus item : data) {
for (int i = 0, j = data.size(); i < j; i++) {
ParcelableStatus item = data.get(i);
if (item.id < statusId) {
conversationCount++;
} else if (item.id > statusId) {
if (replyStart < 0) {
replyStart = i;
}
replyCount++;
} else {
containsStatus = true;
}
}
if (!containsStatus) {
throw new IllegalArgumentException("Conversation data must contains original status");
}
setCount(ITEM_IDX_CONVERSATION, conversationCount);
setCount(ITEM_IDX_REPLY, replyCount);
mReplyStart = replyStart;
}
notifyDataSetChanged();
updateItemDecoration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.mariotaku.twidere.fragment.support.card;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.webkit.WebSettings;
import android.webkit.WebView;

Expand All @@ -37,7 +38,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
settings.setBuiltInZoomControls(false);
}

public static CardBrowserFragment show(String uri) {
public static CardBrowserFragment show(@NonNull String uri) {
final Bundle args = new Bundle();
args.putString(EXTRA_URI, uri);
final CardBrowserFragment fragment = new CardBrowserFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.mariotaku.twidere.util;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import org.mariotaku.twidere.fragment.support.card.CardBrowserFragment;
Expand All @@ -41,7 +42,9 @@ public static TwitterCardFragmentFactory getInstance() {
return new TwitterCardFragmentFactoryImpl();
}

public static Fragment createGenericPlayerFragment(ParcelableCardEntity card) {
@Nullable
public static Fragment createGenericPlayerFragment(@Nullable ParcelableCardEntity card) {
if (card == null) return null;
final String playerUrl = card.getString("player_url");
if (playerUrl == null) return null;
return CardBrowserFragment.show(playerUrl);
Expand Down

0 comments on commit 94ad1a6

Please sign in to comment.