improved profile image density

This commit is contained in:
Mariotaku Lee 2017-03-06 17:32:58 +08:00
parent a4a6237aeb
commit d818127993
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 28 additions and 11 deletions

View File

@ -33,6 +33,7 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.SweepGradient; import android.graphics.SweepGradient;
import android.os.Build; import android.os.Build;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.support.v7.widget.AppCompatImageView; import android.support.v7.widget.AppCompatImageView;
@ -122,6 +123,7 @@ public class ShapedImageView extends AppCompatImageView {
setBackgroundColor(color); setBackgroundColor(color);
} else { } else {
mBackgroundPaint.setColor(color); mBackgroundPaint.setColor(color);
invalidate();
} }
} }
@ -179,7 +181,6 @@ public class ShapedImageView extends AppCompatImageView {
@Override @Override
protected void onDraw(@NonNull Canvas canvas) { protected void onDraw(@NonNull Canvas canvas) {
mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
getHeight() - getPaddingBottom()); getHeight() - getPaddingBottom());
@ -234,6 +235,12 @@ public class ShapedImageView extends AppCompatImageView {
updateBounds(); updateBounds();
} }
@Override
public void setAlpha(@FloatRange(from = 0.0, to = 1.0) final float alpha) {
super.setAlpha(alpha);
mBackgroundPaint.setAlpha(Math.round(alpha * 255));
}
private void drawBorder(@NonNull final Canvas canvas, @NonNull final RectF dest) { private void drawBorder(@NonNull final Canvas canvas, @NonNull final RectF dest) {
if (mBorderColors == null) return; if (mBorderColors == null) return;
final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination;

View File

@ -69,6 +69,7 @@ import org.mariotaku.twidere.activity.UserSelectorActivity
import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter
import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter
import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.annotation.ProfileImageSize
import org.mariotaku.twidere.constant.IntentConstants import org.mariotaku.twidere.constant.IntentConstants
import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.IntentConstants.*
import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.constant.nameFirstKey
@ -160,11 +161,11 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
conversationAvatar.style = profileImageStyle conversationAvatar.style = profileImageStyle
val avatarBackground = ChameleonUtils.getColorDependent(theme.colorToolbar) val avatarBackground = ChameleonUtils.getColorDependent(theme.colorToolbar)
appBarIcon.setBackgroundColor(avatarBackground) appBarIcon.setShapeBackground(avatarBackground)
appBarTitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) appBarTitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar))
appBarSubtitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) appBarSubtitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar))
conversationAvatar.setBackgroundColor(avatarBackground) conversationAvatar.setShapeBackground(avatarBackground)
conversationTitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) conversationTitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar))
conversationSubtitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) conversationSubtitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar))
@ -249,7 +250,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
val requestManager = Glide.with(this) val requestManager = Glide.with(this)
requestManager.loadProfileImage(context, data).into(conversationAvatar) requestManager.loadProfileImage(context, data).into(conversationAvatar)
requestManager.loadProfileImage(context, data).into(appBarIcon) requestManager.loadProfileImage(context, data, size = ProfileImageSize.REASONABLY_SMALL).into(appBarIcon)
appBarTitle.text = name appBarTitle.text = name
conversationTitle.text = name conversationTitle.text = name
if (summary != null) { if (summary != null) {

View File

@ -25,6 +25,7 @@ import android.util.Log
import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.microblog.library.twitter.model.User
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants import org.mariotaku.twidere.TwidereConstants
import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.newMicroBlogInstance
import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.AccountDetails
@ -42,6 +43,8 @@ abstract class MicroBlogAPIUsersLoader(
fromUser: Boolean fromUser: Boolean
) : ParcelableUsersLoader(context, data, fromUser) { ) : ParcelableUsersLoader(context, data, fromUser) {
private val profileImageSize = context.getString(R.string.profile_image_size)
override fun loadInBackground(): List<ParcelableUser> { override fun loadInBackground(): List<ParcelableUser> {
if (accountKey == null) { if (accountKey == null) {
return ListResponse.getListInstance(MicroBlogException("No Account")) return ListResponse.getListInstance(MicroBlogException("No Account"))
@ -64,7 +67,8 @@ abstract class MicroBlogAPIUsersLoader(
if (hasId(user.id)) { if (hasId(user.id)) {
continue continue
} }
val item = ParcelableUserUtils.fromUser(user, accountKey, pos.toLong()) val item = ParcelableUserUtils.fromUser(user, accountKey, pos.toLong(),
profileImageSize = profileImageSize)
processUser(item) processUser(item)
data.add(item) data.add(item)
pos++ pos++

View File

@ -164,10 +164,12 @@ class GetMessagesTask(
conversations.addLocalConversations(context, accountKey, conversationIds) conversations.addLocalConversations(context, accountKey, conversationIds)
received.forEachIndexed { i, dm -> received.forEachIndexed { i, dm ->
addConversationMessage(insertMessages, conversations, details, dm, i, received.size, false) addConversationMessage(insertMessages, conversations, details, dm, i, received.size,
false, profileImageSize)
} }
sent.forEachIndexed { i, dm -> sent.forEachIndexed { i, dm ->
addConversationMessage(insertMessages, conversations, details, dm, i, sent.size, true) addConversationMessage(insertMessages, conversations, details, dm, i, sent.size,
true, profileImageSize)
} }
return DatabaseUpdateData(conversations.values, insertMessages) return DatabaseUpdateData(conversations.values, insertMessages)
} }
@ -385,7 +387,7 @@ class GetMessagesTask(
val recentMessage = messagesMap[k]?.maxBy(ParcelableMessage::message_timestamp) val recentMessage = messagesMap[k]?.maxBy(ParcelableMessage::message_timestamp)
val participants = respUsers.filterKeys { userId -> val participants = respUsers.filterKeys { userId ->
v.participants.any { it.userId == userId } v.participants.any { it.userId == userId }
}.values.map { ParcelableUserUtils.fromUser(it, accountKey) } }.values.map { ParcelableUserUtils.fromUser(it, accountKey, profileImageSize = profileImageSize) }
val conversationType = when (v.type?.toUpperCase(Locale.US)) { val conversationType = when (v.type?.toUpperCase(Locale.US)) {
DMResponse.Conversation.Type.ONE_TO_ONE -> ConversationType.ONE_TO_ONE DMResponse.Conversation.Type.ONE_TO_ONE -> ConversationType.ONE_TO_ONE
DMResponse.Conversation.Type.GROUP_DM -> ConversationType.GROUP DMResponse.Conversation.Type.GROUP_DM -> ConversationType.GROUP
@ -543,13 +545,16 @@ class GetMessagesTask(
internal fun addConversationMessage(messages: MutableCollection<ParcelableMessage>, internal fun addConversationMessage(messages: MutableCollection<ParcelableMessage>,
conversations: MutableMap<String, ParcelableMessageConversation>, conversations: MutableMap<String, ParcelableMessageConversation>,
details: AccountDetails, dm: DirectMessage, index: Int, size: Int, outgoing: Boolean) { details: AccountDetails, dm: DirectMessage, index: Int, size: Int,
outgoing: Boolean, profileImageSize: String = "normal") {
val accountKey = details.key val accountKey = details.key
val message = ParcelableMessageUtils.fromMessage(accountKey, dm, outgoing, val message = ParcelableMessageUtils.fromMessage(accountKey, dm, outgoing,
1.0 - (index.toDouble() / size)) 1.0 - (index.toDouble() / size))
messages.add(message) messages.add(message)
val sender = ParcelableUserUtils.fromUser(dm.sender, accountKey) val sender = ParcelableUserUtils.fromUser(dm.sender, accountKey,
val recipient = ParcelableUserUtils.fromUser(dm.recipient, accountKey) profileImageSize = profileImageSize)
val recipient = ParcelableUserUtils.fromUser(dm.recipient, accountKey,
profileImageSize = profileImageSize)
val conversation = conversations.addConversation(message.conversation_id, details, val conversation = conversations.addConversation(message.conversation_id, details,
message, setOf(sender, recipient)) ?: return message, setOf(sender, recipient)) ?: return
conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.DEFAULT conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.DEFAULT