From d8181279931b74c035d100158be9fc7f2b0ec7a2 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 6 Mar 2017 17:32:58 +0800 Subject: [PATCH] improved profile image density --- .../mariotaku/twidere/view/ShapedImageView.java | 9 ++++++++- .../message/MessageConversationInfoFragment.kt | 7 ++++--- .../twidere/loader/MicroBlogAPIUsersLoader.kt | 6 +++++- .../task/twitter/message/GetMessagesTask.kt | 17 +++++++++++------ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java index 6f888410f..51117e3c3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/ShapedImageView.java @@ -33,6 +33,7 @@ import android.graphics.PorterDuffXfermode; import android.graphics.RectF; import android.graphics.SweepGradient; import android.os.Build; +import android.support.annotation.FloatRange; import android.support.annotation.NonNull; import android.support.v4.view.ViewCompat; import android.support.v7.widget.AppCompatImageView; @@ -122,6 +123,7 @@ public class ShapedImageView extends AppCompatImageView { setBackgroundColor(color); } else { mBackgroundPaint.setColor(color); + invalidate(); } } @@ -179,7 +181,6 @@ public class ShapedImageView extends AppCompatImageView { @Override protected void onDraw(@NonNull Canvas canvas) { - mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom()); @@ -234,6 +235,12 @@ public class ShapedImageView extends AppCompatImageView { 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) { if (mBorderColors == null) return; final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt index 614ace5fd..9487fe689 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessageConversationInfoFragment.kt @@ -69,6 +69,7 @@ import org.mariotaku.twidere.activity.UserSelectorActivity import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter import org.mariotaku.twidere.adapter.iface.IItemCountsAdapter 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.nameFirstKey @@ -160,11 +161,11 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment, conversationAvatar.style = profileImageStyle val avatarBackground = ChameleonUtils.getColorDependent(theme.colorToolbar) - appBarIcon.setBackgroundColor(avatarBackground) + appBarIcon.setShapeBackground(avatarBackground) appBarTitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) appBarSubtitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) - conversationAvatar.setBackgroundColor(avatarBackground) + conversationAvatar.setShapeBackground(avatarBackground) conversationTitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) conversationSubtitle.setTextColor(ChameleonUtils.getColorDependent(theme.colorToolbar)) @@ -249,7 +250,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment, val requestManager = Glide.with(this) 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 conversationTitle.text = name if (summary != null) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIUsersLoader.kt index 64ea743ff..fe0a8c19b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIUsersLoader.kt @@ -25,6 +25,7 @@ import android.util.Log import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails @@ -42,6 +43,8 @@ abstract class MicroBlogAPIUsersLoader( fromUser: Boolean ) : ParcelableUsersLoader(context, data, fromUser) { + private val profileImageSize = context.getString(R.string.profile_image_size) + override fun loadInBackground(): List { if (accountKey == null) { return ListResponse.getListInstance(MicroBlogException("No Account")) @@ -64,7 +67,8 @@ abstract class MicroBlogAPIUsersLoader( if (hasId(user.id)) { continue } - val item = ParcelableUserUtils.fromUser(user, accountKey, pos.toLong()) + val item = ParcelableUserUtils.fromUser(user, accountKey, pos.toLong(), + profileImageSize = profileImageSize) processUser(item) data.add(item) pos++ diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt index 79ce48e37..8fc204477 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt @@ -164,10 +164,12 @@ class GetMessagesTask( conversations.addLocalConversations(context, accountKey, conversationIds) 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 -> - addConversationMessage(insertMessages, conversations, details, dm, i, sent.size, true) + addConversationMessage(insertMessages, conversations, details, dm, i, sent.size, + true, profileImageSize) } return DatabaseUpdateData(conversations.values, insertMessages) } @@ -385,7 +387,7 @@ class GetMessagesTask( val recentMessage = messagesMap[k]?.maxBy(ParcelableMessage::message_timestamp) val participants = respUsers.filterKeys { 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)) { DMResponse.Conversation.Type.ONE_TO_ONE -> ConversationType.ONE_TO_ONE DMResponse.Conversation.Type.GROUP_DM -> ConversationType.GROUP @@ -543,13 +545,16 @@ class GetMessagesTask( internal fun addConversationMessage(messages: MutableCollection, conversations: MutableMap, - 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 message = ParcelableMessageUtils.fromMessage(accountKey, dm, outgoing, 1.0 - (index.toDouble() / size)) messages.add(message) - val sender = ParcelableUserUtils.fromUser(dm.sender, accountKey) - val recipient = ParcelableUserUtils.fromUser(dm.recipient, accountKey) + val sender = ParcelableUserUtils.fromUser(dm.sender, accountKey, + profileImageSize = profileImageSize) + val recipient = ParcelableUserUtils.fromUser(dm.recipient, accountKey, + profileImageSize = profileImageSize) val conversation = conversations.addConversation(message.conversation_id, details, message, setOf(sender, recipient)) ?: return conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.DEFAULT