This commit is contained in:
Mariotaku Lee 2016-01-04 11:32:48 +08:00
parent e998e8426c
commit 483a8707a2
9 changed files with 113 additions and 114 deletions

View File

@ -37,14 +37,14 @@ android {
dependencies {
apt 'com.bluelinelabs:logansquare-compiler:1.3.4'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.1'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2'
apt 'com.github.mariotaku.ObjectCursor:processor:0.9.3'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.bluelinelabs:logansquare:1.3.4'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.github.mariotaku.RestFu:library:0.9.8'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.1'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.github.mariotaku.SQLiteQB:library:0.9.3'
compile 'com.github.mariotaku.ObjectCursor:core:0.9.3'
compile fileTree(dir: 'libs', include: ['*.jar'])

View File

@ -1,102 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.util.ArrayMap;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
import org.mariotaku.twidere.api.twitter.model.CardEntity;
import java.util.Map;
/**
* Created by mariotaku on 15/12/31.
*/
@ParcelablePlease
@JsonObject
public final class ParcelableBindingValue implements Parcelable {
public static final Creator<ParcelableBindingValue> CREATOR = new Creator<ParcelableBindingValue>() {
public ParcelableBindingValue createFromParcel(Parcel source) {
ParcelableBindingValue target = new ParcelableBindingValue();
ParcelableBindingValueParcelablePlease.readFromParcel(target, source);
return target;
}
public ParcelableBindingValue[] newArray(int size) {
return new ParcelableBindingValue[size];
}
};
@ParcelableThisPlease
@JsonField(name = "type")
public String type;
@ParcelableThisPlease
@JsonField(name = "value")
public String value;
public ParcelableBindingValue() {
}
public ParcelableBindingValue(CardEntity.BindingValue value) {
if (value instanceof CardEntity.ImageValue) {
this.type = CardEntity.BindingValue.TYPE_IMAGE;
this.value = ((CardEntity.ImageValue) value).getUrl();
} else if (value instanceof CardEntity.StringValue) {
this.type = CardEntity.BindingValue.TYPE_STRING;
this.value = ((CardEntity.StringValue) value).getValue();
} else if (value instanceof CardEntity.BooleanValue) {
this.type = CardEntity.BindingValue.TYPE_BOOLEAN;
this.value = String.valueOf(((CardEntity.BooleanValue) value).getValue());
} else if (value instanceof CardEntity.UserValue) {
this.type = CardEntity.BindingValue.TYPE_USER;
this.value = String.valueOf(((CardEntity.UserValue) value).getUserId());
}
}
public static Map<String, ParcelableBindingValue> from(Map<String, CardEntity.BindingValue> bindingValues) {
if (bindingValues == null) return null;
final ArrayMap<String, ParcelableBindingValue> map = new ArrayMap<>();
for (Map.Entry<String, CardEntity.BindingValue> entry : bindingValues.entrySet()) {
map.put(entry.getKey(), new ParcelableBindingValue(entry.getValue()));
}
return map;
}
@Override
public String toString() {
return value + " (" + type + ")";
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
ParcelableBindingValueParcelablePlease.writeToParcel(this, dest, flags);
}
}

View File

@ -192,4 +192,72 @@ public final class ParcelableCardEntity implements Parcelable {
}
/**
* Created by mariotaku on 15/12/31.
*/
@ParcelablePlease
@JsonObject
public static final class ParcelableBindingValue implements Parcelable {
public static final Creator<ParcelableBindingValue> CREATOR = new Creator<ParcelableBindingValue>() {
public ParcelableBindingValue createFromParcel(Parcel source) {
ParcelableBindingValue target = new ParcelableBindingValue();
ParcelableCardEntity$ParcelableBindingValueParcelablePlease.readFromParcel(target, source);
return target;
}
public ParcelableBindingValue[] newArray(int size) {
return new ParcelableBindingValue[size];
}
};
@ParcelableThisPlease
@JsonField(name = "type")
public String type;
@ParcelableThisPlease
@JsonField(name = "value")
public String value;
public ParcelableBindingValue() {
}
public ParcelableBindingValue(CardEntity.BindingValue value) {
if (value instanceof CardEntity.ImageValue) {
this.type = CardEntity.BindingValue.TYPE_IMAGE;
this.value = ((CardEntity.ImageValue) value).getUrl();
} else if (value instanceof CardEntity.StringValue) {
this.type = CardEntity.BindingValue.TYPE_STRING;
this.value = ((CardEntity.StringValue) value).getValue();
} else if (value instanceof CardEntity.BooleanValue) {
this.type = CardEntity.BindingValue.TYPE_BOOLEAN;
this.value = String.valueOf(((CardEntity.BooleanValue) value).getValue());
} else if (value instanceof CardEntity.UserValue) {
this.type = CardEntity.BindingValue.TYPE_USER;
this.value = String.valueOf(((CardEntity.UserValue) value).getUserId());
}
}
public static Map<String, ParcelableBindingValue> from(Map<String, CardEntity.BindingValue> bindingValues) {
if (bindingValues == null) return null;
final ArrayMap<String, ParcelableBindingValue> map = new ArrayMap<>();
for (Map.Entry<String, CardEntity.BindingValue> entry : bindingValues.entrySet()) {
map.put(entry.getKey(), new ParcelableBindingValue(entry.getValue()));
}
return map;
}
@Override
public String toString() {
return value + " (" + type + ")";
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
ParcelableCardEntity$ParcelableBindingValueParcelablePlease.writeToParcel(this, dest, flags);
}
}
}

View File

@ -74,7 +74,7 @@ repositories {
dependencies {
// wearApp project(':twidere.wear')
apt 'com.bluelinelabs:logansquare-compiler:1.3.4'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.1'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
apt "com.github.mariotaku.ObjectCursor:processor:0.9.3"
compile 'com.android.support:multidex:1.0.1'
@ -108,7 +108,7 @@ dependencies {
compile 'com.github.mariotaku:jackson-jr-trees:7fe682ee09'
compile 'com.makeramen:roundedimageview:2.1.1'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.1'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.github.mariotaku:PickNCrop:0.9.2'
compile 'com.github.mariotaku.RestFu:library:0.9.8'
compile 'com.github.mariotaku.RestFu:okhttp:0.9.8'

View File

@ -70,6 +70,7 @@ public abstract class BaseRecyclerViewAdapter<VH extends RecyclerView.ViewHolder
return mPreferences;
}
@NonNull
public final UserColorNameManager getUserColorNameManager() {
return mUserColorNameManager;
}
@ -78,6 +79,7 @@ public abstract class BaseRecyclerViewAdapter<VH extends RecyclerView.ViewHolder
return mMultiSelectManager;
}
@NonNull
public final MediaLoaderWrapper getMediaLoader() {
return mMediaLoader;
}
@ -86,10 +88,12 @@ public abstract class BaseRecyclerViewAdapter<VH extends RecyclerView.ViewHolder
return mReadStateManager;
}
@NonNull
public final AsyncTwitterWrapper getTwitterWrapper() {
return mTwitterWrapper;
}
@NonNull
public final BidiFormatter getBidiFormatter() {
return mBidiFormatter;
}

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.adapter.iface;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.text.BidiFormatter;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
@ -52,4 +53,7 @@ public interface IContentCardAdapter extends ILoadMoreSupportAdapter {
@NonNull
MediaLoaderWrapper getMediaLoader();
@NonNull
BidiFormatter getBidiFormatter();
}

View File

@ -849,8 +849,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
if (!hasName) {
final Matcher m = PATTERN_SCREEN_NAME.matcher(query);
if (m.matches()) {
final String screenName = m.group(1);
screenNameCursor.addRow(new Object[]{0, Suggestions.Search.TYPE_SCREEN_NAME,
query, null, null, 0, null, query});
screenName, null, null, 0, null, screenName});
}
}
cursors = new Cursor[3];

View File

@ -22,6 +22,8 @@ package org.mariotaku.twidere.view;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.support.v4.text.BidiFormatter;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@ -89,13 +91,21 @@ public class NameView extends ThemedTextView {
}
public void updateText() {
updateText(null);
}
public void updateText(@Nullable BidiFormatter formatter) {
if (isInEditMode()) return;
final SpannableStringBuilder sb = new SpannableStringBuilder();
final String primaryText = mNameFirst ? mName : mScreenName;
final String secondaryText = mNameFirst ? mScreenName : mName;
if (primaryText != null) {
int start = sb.length();
sb.append(primaryText);
if (formatter != null) {
sb.append(formatter.unicodeWrap(primaryText));
} else {
sb.append(primaryText);
}
int end = sb.length();
sb.setSpan(mPrimaryTextColor, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sb.setSpan(mPrimaryTextStyle, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
@ -104,7 +114,11 @@ public class NameView extends ThemedTextView {
sb.append(" ");
if (secondaryText != null) {
int start = sb.length();
sb.append(secondaryText);
if (formatter != null) {
sb.append(formatter.unicodeWrap(secondaryText));
} else {
sb.append(secondaryText);
}
int end = sb.length();
sb.setSpan(mSecondaryTextColor, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sb.setSpan(mSecondaryTextStyle, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.text.BidiFormatter;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.Spanned;
@ -115,7 +116,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
profileImageView.setImageResource(R.mipmap.ic_launcher);
nameView.setName(TWIDERE_PREVIEW_NAME);
nameView.setScreenName("@" + TWIDERE_PREVIEW_SCREEN_NAME);
nameView.updateText();
nameView.updateText(adapter.getBidiFormatter());
if (adapter.getLinkHighlightingStyle() == VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
final TwidereLinkify linkify = adapter.getTwidereLinkify();
final Spanned text = HtmlSpanBuilder.fromHtml(TWIDERE_PREVIEW_TEXT_HTML);
@ -141,6 +142,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper();
final TwidereLinkify linkify = adapter.getTwidereLinkify();
final UserColorNameManager manager = adapter.getUserColorNameManager();
final BidiFormatter formatter = adapter.getBidiFormatter();
final Context context = adapter.getContext();
final boolean nameFirst = adapter.isNameFirst();
@ -156,14 +158,14 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
} else if (status.retweet_id > 0) {
final String retweetedBy = manager.getDisplayName(status.retweeted_by_user_id,
status.retweeted_by_user_name, status.retweeted_by_user_screen_name, nameFirst, false);
statusInfoLabel.setText(context.getString(R.string.name_retweeted, retweetedBy));
statusInfoLabel.setText(context.getString(R.string.name_retweeted, formatter.unicodeWrap(retweetedBy)));
statusInfoIcon.setImageResource(R.drawable.ic_activity_action_retweet);
statusInfoLabel.setVisibility(View.VISIBLE);
statusInfoIcon.setVisibility(View.VISIBLE);
} else if (status.in_reply_to_status_id > 0 && status.in_reply_to_user_id > 0 && displayInReplyTo) {
final String inReplyTo = manager.getDisplayName(status.in_reply_to_user_id,
status.in_reply_to_name, status.in_reply_to_screen_name, nameFirst, false);
statusInfoLabel.setText(context.getString(R.string.in_reply_to_name, inReplyTo));
statusInfoLabel.setText(context.getString(R.string.in_reply_to_name, formatter.unicodeWrap(inReplyTo)));
statusInfoIcon.setImageResource(R.drawable.ic_activity_action_reply);
statusInfoLabel.setVisibility(View.VISIBLE);
statusInfoIcon.setVisibility(View.VISIBLE);
@ -306,8 +308,8 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
extraTypeView.setVisibility(View.GONE);
}
nameView.updateText();
quotedNameView.updateText();
nameView.updateText(formatter);
quotedNameView.updateText(formatter);
}
@Override
@ -462,6 +464,8 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
AsyncTwitterWrapper twitter;
@Inject
UserColorNameManager manager;
@Inject
BidiFormatter formatter;
private int profileImageStyle;
private int mediaPreviewStyle;
@ -498,6 +502,12 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
return loader;
}
@NonNull
@Override
public BidiFormatter getBidiFormatter() {
return formatter;
}
@NonNull
@Override
public Context getContext() {