mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
improved user color
This commit is contained in:
parent
c4161ae01f
commit
f01f52fc6c
@ -43,7 +43,7 @@ import org.mariotaku.commons.logansquare.JsonStringConverter;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.model.account.AccountExtras;
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials;
|
||||
import org.mariotaku.twidere.model.util.RGBHexColorConverter;
|
||||
import org.mariotaku.twidere.model.util.ContentObjectColorConverter;
|
||||
import org.mariotaku.twidere.model.util.UserKeyConverter;
|
||||
import org.mariotaku.twidere.util.model.AccountDetailsUtils;
|
||||
|
||||
@ -75,7 +75,7 @@ public class AccountDetails implements Parcelable, Comparable<AccountDetails> {
|
||||
public ParcelableUser user;
|
||||
|
||||
@ColorInt
|
||||
@JsonField(name = "color", typeConverter = RGBHexColorConverter.class)
|
||||
@JsonField(name = "color", typeConverter = ContentObjectColorConverter.class)
|
||||
public int color;
|
||||
|
||||
@JsonField(name = "position")
|
||||
|
@ -526,10 +526,10 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
|
||||
@ParcelableThisPlease
|
||||
@Nullable
|
||||
public String conversation_id;
|
||||
@JsonField(name = "spoiler_text")
|
||||
@JsonField(name = "summary_text")
|
||||
@ParcelableThisPlease
|
||||
@Nullable
|
||||
public String spoiler_text;
|
||||
public String summary_text;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
|
@ -36,7 +36,7 @@ import org.mariotaku.commons.objectcursor.LoganSquareCursorFieldConverter;
|
||||
import org.mariotaku.library.objectcursor.annotation.AfterCursorObjectCreated;
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorField;
|
||||
import org.mariotaku.library.objectcursor.annotation.CursorObject;
|
||||
import org.mariotaku.twidere.model.util.RGBHexColorConverter;
|
||||
import org.mariotaku.twidere.model.util.ContentObjectColorConverter;
|
||||
import org.mariotaku.twidere.model.util.UserKeyConverter;
|
||||
import org.mariotaku.twidere.model.util.UserKeyCursorFieldConverter;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
@ -161,15 +161,15 @@ public class ParcelableUser implements Parcelable, Comparable<ParcelableUser> {
|
||||
public long media_count = -1;
|
||||
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "background_color", typeConverter = RGBHexColorConverter.class)
|
||||
@JsonField(name = "background_color", typeConverter = ContentObjectColorConverter.class)
|
||||
@CursorField(CachedUsers.BACKGROUND_COLOR)
|
||||
public int background_color;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "link_color", typeConverter = RGBHexColorConverter.class)
|
||||
@JsonField(name = "link_color", typeConverter = ContentObjectColorConverter.class)
|
||||
@CursorField(CachedUsers.LINK_COLOR)
|
||||
public int link_color;
|
||||
@ParcelableThisPlease
|
||||
@JsonField(name = "text_color", typeConverter = RGBHexColorConverter.class)
|
||||
@JsonField(name = "text_color", typeConverter = ContentObjectColorConverter.class)
|
||||
@CursorField(CachedUsers.TEXT_COLOR)
|
||||
public int text_color;
|
||||
|
||||
|
@ -28,10 +28,11 @@ import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/3/11.
|
||||
* This converter converts color to #RRGGBB format, to null if color is fully transparent
|
||||
* <p>
|
||||
* Created by mariotaku on 2017/4/20.
|
||||
*/
|
||||
|
||||
public class RGBHexColorConverter extends StringBasedTypeConverter<Integer> {
|
||||
public class ContentObjectColorConverter extends StringBasedTypeConverter<Integer> {
|
||||
@Override
|
||||
public Integer getFromString(final String string) {
|
||||
if (string == null) return 0;
|
||||
@ -43,7 +44,7 @@ public class RGBHexColorConverter extends StringBasedTypeConverter<Integer> {
|
||||
|
||||
@Override
|
||||
public String convertToString(final Integer object) {
|
||||
if (object == null) return null;
|
||||
if (object == null || object == 0) return null;
|
||||
return String.format(Locale.US, "#%06X", 0xFFFFFF & object);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package org.mariotaku.ktextension
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
|
||||
val TextView.empty: Boolean
|
||||
@ -13,4 +14,12 @@ fun TextView.applyFontFamily(lightFont: Boolean) {
|
||||
if (lightFont) {
|
||||
typeface = Typeface.create("sans-serif-light", typeface?.style ?: Typeface.NORMAL)
|
||||
}
|
||||
}
|
||||
|
||||
fun TextView.hideIfEmpty() {
|
||||
visibility = if (empty) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
}
|
@ -23,8 +23,13 @@ import org.mariotaku.microblog.library.mastodon.model.Attachment
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
|
||||
/**
|
||||
* Extension functions for `Attachment` class
|
||||
* Created by mariotaku on 2017/4/19.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return [ParcelableMedia] converted media for Twidere
|
||||
*/
|
||||
fun Attachment.toParcelable(): ParcelableMedia {
|
||||
val result = ParcelableMedia()
|
||||
result.type = when (type) {
|
||||
|
@ -22,7 +22,9 @@ package org.mariotaku.twidere.extension.model.api.mastodon
|
||||
import org.mariotaku.ktextension.mapToArray
|
||||
import org.mariotaku.microblog.library.mastodon.model.Status
|
||||
import org.mariotaku.twidere.extension.model.api.spanItems
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.SpanItem
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils.addFilterFlag
|
||||
import org.mariotaku.twidere.util.HtmlSpanBuilder
|
||||
@ -38,7 +40,7 @@ fun Status.toParcelable(accountKey: UserKey): ParcelableStatus {
|
||||
result.id = id
|
||||
result.timestamp = createdAt?.time ?: 0
|
||||
|
||||
extras.spoiler_text = spoilerText
|
||||
extras.summary_text = spoilerText
|
||||
extras.external_url = url
|
||||
|
||||
val retweetedStatus = reblog
|
||||
@ -67,7 +69,6 @@ fun Status.toParcelable(accountKey: UserKey): ParcelableStatus {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result.reply_count = -1
|
||||
result.retweet_count = status.reblogsCount
|
||||
result.favorite_count = status.favouritesCount
|
||||
@ -87,14 +88,20 @@ fun Status.toParcelable(accountKey: UserKey): ParcelableStatus {
|
||||
result.text_unescaped = html.toString()
|
||||
result.text_plain = result.text_unescaped
|
||||
result.spans = html.spanItems
|
||||
|
||||
result.media = mediaAttachments?.mapToArray { it.toParcelable() }
|
||||
result.source = status.application?.sourceHtml
|
||||
result.is_favorite = status.isFavourited
|
||||
result.is_possibly_sensitive = status.isSensitive
|
||||
result.mentions = mentions?.mapToArray { it.toParcelable(accountKey) }
|
||||
|
||||
extras.display_text_range = calculateDisplayTextRange(result.spans, result.media)
|
||||
|
||||
result.extras = extras
|
||||
return result
|
||||
}
|
||||
|
||||
private fun calculateDisplayTextRange(spans: Array<SpanItem>?, media: Array<ParcelableMedia>?): IntArray? {
|
||||
if (spans == null || media == null) return null
|
||||
val lastMatch = spans.lastOrNull { span -> media.any { span.link == it.page_url } } ?: return null
|
||||
return intArrayOf(0, lastMatch.start)
|
||||
}
|
@ -1373,12 +1373,12 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
}
|
||||
|
||||
private fun setUiColor(color: Int) {
|
||||
uiColor = color
|
||||
val theme = Chameleon.getOverrideTheme(activity, activity)
|
||||
uiColor = if (color != 0) color else theme.colorPrimary
|
||||
previousActionBarItemIsDark = 0
|
||||
previousTabItemIsDark = 0
|
||||
setupBaseActionBar()
|
||||
val activity = activity as BaseActivity
|
||||
val theme = Chameleon.getOverrideTheme(activity, activity)
|
||||
if (theme.isToolbarColored) {
|
||||
primaryColor = color
|
||||
} else {
|
||||
|
@ -16,6 +16,7 @@ import android.widget.TextView
|
||||
import com.bumptech.glide.RequestManager
|
||||
import kotlinx.android.synthetic.main.list_item_status.view.*
|
||||
import org.mariotaku.ktextension.applyFontFamily
|
||||
import org.mariotaku.ktextension.hideIfEmpty
|
||||
import org.mariotaku.ktextension.isNotNullOrEmpty
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.R
|
||||
@ -53,6 +54,7 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
||||
private val itemContent by lazy { itemView.itemContent }
|
||||
private val mediaPreview by lazy { itemView.mediaPreview }
|
||||
private val statusContentUpperSpace by lazy { itemView.statusContentUpperSpace }
|
||||
private val summaryView by lazy { itemView.summary }
|
||||
private val textView by lazy { itemView.text }
|
||||
private val nameView by lazy { itemView.name }
|
||||
private val itemMenu by lazy { itemView.itemMenu }
|
||||
@ -351,6 +353,9 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
||||
|
||||
val displayEnd = status.extras?.display_text_range?.getOrNull(1) ?: -1
|
||||
|
||||
summaryView.text = status.extras?.summary_text
|
||||
summaryView.hideIfEmpty()
|
||||
|
||||
val text: CharSequence
|
||||
if (adapter.linkHighlightingStyle != VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
|
||||
text = SpannableStringBuilder.valueOf(status.text_unescaped).apply {
|
||||
@ -368,12 +373,7 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
||||
} else {
|
||||
textView.text = text
|
||||
}
|
||||
if (textView.length() == 0) {
|
||||
// No text
|
||||
textView.visibility = View.GONE
|
||||
} else {
|
||||
textView.visibility = View.VISIBLE
|
||||
}
|
||||
textView.hideIfEmpty()
|
||||
|
||||
if (replyCount > 0) {
|
||||
replyCountView.text = UnitConvertUtils.calculateProperCount(replyCount)
|
||||
@ -490,6 +490,7 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
||||
override fun setTextSize(textSize: Float) {
|
||||
nameView.setPrimaryTextSize(textSize)
|
||||
quotedNameView.setPrimaryTextSize(textSize)
|
||||
summaryView.textSize = textSize
|
||||
textView.textSize = textSize
|
||||
quotedTextView.textSize = textSize
|
||||
nameView.setSecondaryTextSize(textSize * 0.85f)
|
||||
@ -542,6 +543,7 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
||||
|
||||
nameView.applyFontFamily(adapter.lightFont)
|
||||
timeView.applyFontFamily(adapter.lightFont)
|
||||
summaryView.applyFontFamily(adapter.lightFont)
|
||||
textView.applyFontFamily(adapter.lightFont)
|
||||
mediaLabel.applyFontFamily(adapter.lightFont)
|
||||
|
||||
|
@ -141,7 +141,7 @@
|
||||
tools:textSize="@dimen/text_size_extra_small"/>
|
||||
|
||||
<org.mariotaku.twidere.view.TimelineContentTextView
|
||||
android:id="@+id/text"
|
||||
android:id="@+id/summary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/name"
|
||||
@ -151,6 +151,20 @@
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:visibility="visible"
|
||||
tools:text="@string/sample_summary_text"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<org.mariotaku.twidere.view.TimelineContentTextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/name"
|
||||
android:layout_alignStart="@+id/name"
|
||||
android:layout_below="@+id/summary"
|
||||
android:paddingTop="@dimen/element_spacing_small"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:visibility="visible"
|
||||
tools:text="@string/sample_status_text"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
<string name="font_family_light" translatable="false">Light</string>
|
||||
<string name="font_family_thin" translatable="false">Thin</string>
|
||||
<string name="easter_egg_triggered_message" translatable="false">不二对你的膝盖发动了会心一击!</string>
|
||||
<string name="sample_summary_text">Lorem ipsum dolor sit amet.</string>
|
||||
<string name="sample_status_text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam faucibus quis purus ac malesuada. Duis id vulputate magna, a eleifend amet.</string>
|
||||
<string name="unsupported_activity_action_title"><xliff:g id="action">%s</xliff:g> action</string>
|
||||
<string name="fanfou_repost_format"><xliff:g id="text">%1$s</xliff:g> 转 \@<xliff:g id="screen_name">%2$s</xliff:g> <xliff:g id="orig_text">%3$s</xliff:g></string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user