mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
parent
a82aa84456
commit
62e8a60c10
@ -56,6 +56,9 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
|
||||
@JsonField(name = "text")
|
||||
String text;
|
||||
|
||||
@JsonField(name = "statusnet_html")
|
||||
String statusnetHtml;
|
||||
|
||||
@JsonField(name = "source")
|
||||
String source;
|
||||
|
||||
@ -143,6 +146,12 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
|
||||
@JsonField(name = "external_url")
|
||||
String externalUrl;
|
||||
|
||||
/**
|
||||
* For GNU social
|
||||
*/
|
||||
@JsonField(name = "statusnet_conversation_id")
|
||||
String statusnetConversationId;
|
||||
|
||||
|
||||
/**
|
||||
* For GNU social
|
||||
@ -191,10 +200,17 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
|
||||
|
||||
|
||||
public String getText() {
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getHtmlText() {
|
||||
if (statusnetHtml != null) return statusnetHtml;
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getStatusnetHtml() {
|
||||
return statusnetHtml;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
@ -349,6 +365,10 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
|
||||
return externalUrl;
|
||||
}
|
||||
|
||||
public String getStatusnetConversationId() {
|
||||
return statusnetConversationId;
|
||||
}
|
||||
|
||||
public Attention[] getAttentions() {
|
||||
return attentions;
|
||||
}
|
||||
|
@ -499,6 +499,9 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
|
||||
@JsonField(name = "external_url")
|
||||
@ParcelableThisPlease
|
||||
public String external_url;
|
||||
@JsonField(name = "statusnet_conversation_id")
|
||||
@ParcelableThisPlease
|
||||
public String statusnet_conversation_id;
|
||||
@JsonField(name = "support_entities")
|
||||
@ParcelableThisPlease
|
||||
public boolean support_entities;
|
||||
|
@ -82,7 +82,11 @@ public class ConversationLoader extends TwitterAPIStatusesLoader {
|
||||
}
|
||||
case ParcelableAccount.Type.STATUSNET: {
|
||||
mCanLoadAllReplies = true;
|
||||
return twitter.getStatusNetConversation(status.id, paging);
|
||||
if (status.extras != null && status.extras.statusnet_conversation_id != null) {
|
||||
return twitter.getStatusNetConversation(status.extras.statusnet_conversation_id,
|
||||
paging);
|
||||
}
|
||||
return twitter.showConversation(status.id, paging);
|
||||
}
|
||||
case ParcelableAccount.Type.FANFOU: {
|
||||
mCanLoadAllReplies = true;
|
||||
|
@ -3,12 +3,12 @@ package org.mariotaku.twidere.model.util;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.URLSpan;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.api.statusnet.model.Attention;
|
||||
import org.mariotaku.twidere.api.twitter.model.GeoLocation;
|
||||
import org.mariotaku.twidere.api.twitter.model.Place;
|
||||
@ -20,7 +20,6 @@ import org.mariotaku.twidere.model.ParcelableLocation;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.SpanItem;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.util.HtmlEscapeHelper;
|
||||
import org.mariotaku.twidere.util.HtmlSpanBuilder;
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
@ -32,7 +31,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by mariotaku on 16/1/3.
|
||||
*/
|
||||
public class ParcelableStatusUtils {
|
||||
public class ParcelableStatusUtils implements Constants {
|
||||
|
||||
public static void makeOriginalStatus(@NonNull ParcelableStatus status) {
|
||||
if (!status.is_retweet) return;
|
||||
@ -47,6 +46,7 @@ public class ParcelableStatusUtils {
|
||||
|
||||
public static ParcelableStatus fromStatus(final Status orig, final UserKey accountKey,
|
||||
final boolean isGap) {
|
||||
|
||||
final ParcelableStatus result = new ParcelableStatus();
|
||||
result.is_gap = isGap;
|
||||
result.account_key = accountKey;
|
||||
@ -57,6 +57,7 @@ public class ParcelableStatusUtils {
|
||||
result.extras = new ParcelableStatus.Extras();
|
||||
result.extras.external_url = orig.getExternalUrl();
|
||||
result.extras.support_entities = orig.getEntities() != null;
|
||||
result.extras.statusnet_conversation_id = orig.getStatusnetConversationId();
|
||||
|
||||
final Status retweetedStatus = orig.getRetweetedStatus();
|
||||
result.is_retweet = orig.isRetweet();
|
||||
@ -77,12 +78,14 @@ public class ParcelableStatusUtils {
|
||||
final User quotedUser = quoted.getUser();
|
||||
result.quoted_id = quoted.getId();
|
||||
|
||||
String quotedText = quoted.getText();
|
||||
final String quotedText = quoted.getHtmlText();
|
||||
// Twitter will escape <> to <>, so if a status contains those symbols unescaped
|
||||
// We should treat this as an html
|
||||
if (quotedText.contains("<") && quotedText.contains(">")) {
|
||||
result.quoted_text_unescaped = HtmlEscapeHelper.toPlainText(quotedText);
|
||||
if (isHtml(quotedText)) {
|
||||
final CharSequence html = HtmlSpanBuilder.fromHtml(quotedText, quoted.getText());
|
||||
result.quoted_text_unescaped = html.toString();
|
||||
result.quoted_text_plain = result.quoted_text_unescaped;
|
||||
result.quoted_spans = getSpanItems(html);
|
||||
} else {
|
||||
final Pair<String, List<SpanItem>> textWithIndices = InternalTwitterContentUtils.formatStatusTextWithIndices(quoted);
|
||||
result.quoted_text_plain = InternalTwitterContentUtils.unescapeTwitterStatusText(quotedText);
|
||||
@ -140,18 +143,14 @@ public class ParcelableStatusUtils {
|
||||
if (result.extras.user_profile_image_url_profile_size == null) {
|
||||
result.extras.user_profile_image_url_profile_size = user.getProfileImageUrlLarge();
|
||||
}
|
||||
String text = status.getText();
|
||||
final String text = status.getHtmlText();
|
||||
// Twitter will escape <> to <>, so if a status contains those symbols unescaped
|
||||
// We should treat this as an html
|
||||
if (text.contains("<") && text.contains(">")) {
|
||||
final Spannable html = HtmlSpanBuilder.fromHtml(text);
|
||||
if (isHtml(text)) {
|
||||
final CharSequence html = HtmlSpanBuilder.fromHtml(text, status.getText());
|
||||
result.text_unescaped = html.toString();
|
||||
result.text_plain = result.text_unescaped;
|
||||
URLSpan[] spans = html.getSpans(0, html.length(), URLSpan.class);
|
||||
result.spans = new SpanItem[spans.length];
|
||||
for (int i = 0, j = spans.length; i < j; i++) {
|
||||
result.spans[i] = SpanItem.from(html, spans[i]);
|
||||
}
|
||||
result.spans = getSpanItems(html);
|
||||
} else {
|
||||
final Pair<String, List<SpanItem>> textWithIndices = InternalTwitterContentUtils.formatStatusTextWithIndices(status);
|
||||
result.text_plain = InternalTwitterContentUtils.unescapeTwitterStatusText(text);
|
||||
@ -177,6 +176,25 @@ public class ParcelableStatusUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static SpanItem[] getSpanItems(CharSequence html) {
|
||||
if (!(html instanceof Spanned)) return null;
|
||||
Spanned spanned = (Spanned) html;
|
||||
URLSpan[] spans = spanned.getSpans(0, html.length(), URLSpan.class);
|
||||
SpanItem[] items = new SpanItem[spans.length];
|
||||
for (int i = 0, j = spans.length; i < j; i++) {
|
||||
items[i] = SpanItem.from(spanned, spans[i]);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private static boolean isHtml(String text) {
|
||||
return text.contains("<") && text.contains(">");
|
||||
}
|
||||
|
||||
private static boolean isFanfouStatus(UserKey accountKey) {
|
||||
return USER_TYPE_FANFOU_COM.equals(accountKey.getHost());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static UserKey getInReplyToUserId(Status status, UserKey accountKey) {
|
||||
final String inReplyToUserId = status.getInReplyToUserId();
|
||||
|
@ -36,7 +36,7 @@ public class UnitConvertUtils {
|
||||
}
|
||||
value = value / 1000.0;
|
||||
}
|
||||
if (value < 10) {
|
||||
if (value < 10 && (value % 1.0) >= 0.049 && (value % 1.0) < 0.5) {
|
||||
return String.format(Locale.getDefault(), "%.1f %s", value, countUnits[index]);
|
||||
} else {
|
||||
return String.format(Locale.getDefault(), "%.0f %s", value, countUnits[index]);
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
|
||||
<!-- Normally you don't need to translate app name -->
|
||||
<string name="app_name">Twidere</string>
|
||||
<string name="app_description">Your own Twitter app</string>
|
||||
<string name="compose">Compose</string>
|
||||
<string name="add_account">Add account</string>
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
|
||||
<string name="app_name" translatable="false">Twidere</string>
|
||||
<string name="theme_twidere">@string/app_name</string>
|
||||
<string name="nyan_sakamoto" translatable="false">Nyan Sakamoto!</string>
|
||||
<string name="kuma_union" translatable="false">熊孩子联盟</string>
|
||||
|
@ -0,0 +1,26 @@
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/26.
|
||||
*/
|
||||
public class UnitConvertUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testCalculateProperCount() throws Exception {
|
||||
assertEquals("201", UnitConvertUtils.calculateProperCount(201));
|
||||
assertEquals("2.2 K", UnitConvertUtils.calculateProperCount(2201));
|
||||
assertEquals("2.1 K", UnitConvertUtils.calculateProperCount(2100));
|
||||
assertEquals("2 K", UnitConvertUtils.calculateProperCount(2000));
|
||||
assertEquals("2 K", UnitConvertUtils.calculateProperCount(2049));
|
||||
assertEquals("2.1 K", UnitConvertUtils.calculateProperCount(2050));
|
||||
assertEquals("2.1 K", UnitConvertUtils.calculateProperCount(2099));
|
||||
assertEquals("2.4 K", UnitConvertUtils.calculateProperCount(2430));
|
||||
assertEquals("2.5 K", UnitConvertUtils.calculateProperCount(2499));
|
||||
assertEquals("2.4 K", UnitConvertUtils.calculateProperCount(2449));
|
||||
assertEquals("2.5 K", UnitConvertUtils.calculateProperCount(2450));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user