migrating to Glide
This commit is contained in:
parent
097752d30b
commit
922040ce9a
|
@ -171,6 +171,7 @@ dependencies {
|
|||
compile "com.google.android.exoplayer:extension-okhttp:$exoplayer_version"
|
||||
compile 'com.github.bumptech.glide:glide:3.7.0'
|
||||
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
|
||||
compile 'jp.wasabeef:glide-transformations:2.0.1'
|
||||
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.20'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.20'
|
||||
|
|
|
@ -148,6 +148,14 @@
|
|||
android:name="override_tinted_status_bar_defaults"
|
||||
android:value="true"/>
|
||||
|
||||
<meta-data
|
||||
android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule"
|
||||
tools:node="remove"/>
|
||||
|
||||
<meta-data
|
||||
android:name="org.mariotaku.twidere.util.glide.OkHttpGlideModule"
|
||||
android:value="GlideModule"/>
|
||||
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
|
|
@ -60,7 +60,6 @@ import com.twitter.Extractor
|
|||
import com.twitter.Validator
|
||||
import kotlinx.android.synthetic.main.activity_compose.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.apache.commons.lang3.ObjectUtils
|
||||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
import org.mariotaku.kpreferences.get
|
||||
|
@ -74,6 +73,7 @@ import org.mariotaku.twidere.adapter.MediaPreviewAdapter
|
|||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SCREEN_NAME
|
||||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getAccountUser
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.extension.model.textLimit
|
||||
|
@ -463,7 +463,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
if (accounts.size == 1) {
|
||||
accountsCount.setText(null)
|
||||
val account = accounts[0]
|
||||
mediaLoader.displayProfileImage(accountProfileImage, account.user)
|
||||
Glide.with(this).loadProfileImage(this, account).into(accountProfileImage)
|
||||
accountProfileImage.setBorderColor(account.color)
|
||||
} else {
|
||||
accountsCount.setText(accounts.size.toString())
|
||||
|
@ -1425,7 +1425,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
(itemView as CheckableLinearLayout).isChecked = isSelected
|
||||
if (account != iconView.tag || iconView.drawable == null) {
|
||||
iconView.tag = account
|
||||
adapter.getRequestManager().load(account.user.getBestProfileImage(adapter.context)).into(iconView)
|
||||
val context = adapter.context
|
||||
adapter.getRequestManager().loadProfileImage(context, account.user.getBestProfileImage(context)).into(iconView)
|
||||
}
|
||||
iconView.setBorderColor(account.color)
|
||||
nameView.text = if (adapter.isNameFirst) account.user.name else "@" + account.user.screen_name
|
||||
|
|
|
@ -891,12 +891,15 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
}
|
||||
}
|
||||
|
||||
private class UpdateUnreadCountTask internal constructor(
|
||||
private class UpdateUnreadCountTask(
|
||||
private val context: Context,
|
||||
private val preferences: SharedPreferences,
|
||||
private val readStateManager: ReadStateManager,
|
||||
private val indicator: TabPagerIndicator,
|
||||
private val tabs: Array<SupportTabSpec>) : AsyncTask<Any, UpdateUnreadCountTask.TabBadge, SparseIntArray>() {
|
||||
private val tabs: Array<SupportTabSpec>
|
||||
) : AsyncTask<Any, UpdateUnreadCountTask.TabBadge, SparseIntArray>() {
|
||||
|
||||
private val activatedKeys = DataStoreUtils.getActivatedAccountKeys(context)
|
||||
|
||||
override fun doInBackground(vararg params: Any): SparseIntArray {
|
||||
val result = SparseIntArray()
|
||||
|
@ -907,8 +910,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
}
|
||||
when (spec.type) {
|
||||
CustomTabType.HOME_TIMELINE -> {
|
||||
val accountKeys = Utils.getAccountKeys(context, spec.args) ?:
|
||||
DataStoreUtils.getActivatedAccountKeys(context)
|
||||
val accountKeys = Utils.getAccountKeys(context, spec.args) ?: activatedKeys
|
||||
val position = accountKeys.map {
|
||||
val tag = Utils.getReadPositionTagWithAccount(ReadPositionTag.HOME_TIMELINE, it)
|
||||
readStateManager.getPosition(tag)
|
||||
|
@ -920,8 +922,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
publishProgress(TabBadge(i, count))
|
||||
}
|
||||
CustomTabType.NOTIFICATIONS_TIMELINE -> {
|
||||
val accountKeys = Utils.getAccountKeys(context, spec.args) ?:
|
||||
DataStoreUtils.getActivatedAccountKeys(context)
|
||||
val accountKeys = Utils.getAccountKeys(context, spec.args) ?: activatedKeys
|
||||
val position = accountKeys.map {
|
||||
val tag = Utils.getReadPositionTagWithAccount(ReadPositionTag.ACTIVITIES_ABOUT_ME, it)
|
||||
readStateManager.getPosition(tag)
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.view.ViewGroup
|
|||
import android.widget.CompoundButton
|
||||
import com.bumptech.glide.RequestManager
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
@ -62,7 +63,7 @@ class AccountDetailsAdapter(
|
|||
holder.screenName.text = String.format("@%s", details.user.screen_name)
|
||||
holder.setAccountColor(details.color)
|
||||
if (profileImageEnabled) {
|
||||
getRequestManager().load(details.user.getBestProfileImage(context)).into(holder.profileImage)
|
||||
getRequestManager().loadProfileImage(context, details.user.getBestProfileImage(context)).into(holder.profileImage)
|
||||
} else {
|
||||
// TODO: display stub image?
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.view.ViewGroup
|
|||
import com.bumptech.glide.RequestManager
|
||||
import kotlinx.android.synthetic.main.list_item_simple_user.view.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
@ -69,7 +70,7 @@ class AccountsSpinnerAdapter(
|
|||
if (profileImageEnabled) {
|
||||
icon.visibility = View.VISIBLE
|
||||
icon.style = profileImageStyle
|
||||
getRequestManager().load(item.user.getBestProfileImage(context)).into(icon)
|
||||
getRequestManager().loadProfileImage(context, item.user.getBestProfileImage(context)).into(icon)
|
||||
} else {
|
||||
icon.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.bumptech.glide.RequestManager
|
|||
import com.commonsware.cwac.layouts.AspectLockedFrameLayout
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
|
@ -92,7 +93,8 @@ class StaggeredGridParcelableStatusesAdapter(
|
|||
mediaImageContainer.requestLayout()
|
||||
|
||||
mediaImageView.setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(firstMedia.type))
|
||||
adapter.getRequestManager().load(status.getBestProfileImage(itemView.context)).into(profileImageView)
|
||||
val context = itemView.context
|
||||
adapter.getRequestManager().loadProfileImage(context, status.getBestProfileImage(context)).into(profileImageView)
|
||||
// TODO image loaded event and credentials
|
||||
adapter.getRequestManager().load(firstMedia.preview_url).into(mediaImageView)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 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.extension
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import com.bumptech.glide.DrawableRequestBuilder
|
||||
import com.bumptech.glide.RequestManager
|
||||
import jp.wasabeef.glide.transformations.CropCircleTransformation
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
|
||||
fun RequestManager.loadProfileImage(context: Context, url: String?): DrawableRequestBuilder<String?> {
|
||||
return load(url).bitmapTransform(CropCircleTransformation(context))
|
||||
}
|
||||
|
||||
fun RequestManager.loadProfileImage(context: Context, resourceId: Int): DrawableRequestBuilder<Int> {
|
||||
return load(resourceId).bitmapTransform(CropCircleTransformation(context))
|
||||
}
|
||||
|
||||
fun RequestManager.loadProfileImage(context: Context, account: AccountDetails): DrawableRequestBuilder<String?> {
|
||||
if (account.user.extras != null && !TextUtils.isEmpty(account.user.extras.profile_image_url_profile_size)) {
|
||||
return load(account.user.extras.profile_image_url_profile_size)
|
||||
} else {
|
||||
return load(account.user.profile_image_url)
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import org.mariotaku.twidere.util.ParseUtils
|
|||
import java.io.IOException
|
||||
import java.util.concurrent.FutureTask
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
|
||||
fun Account.getCredentials(am: AccountManager): Credentials {
|
||||
|
@ -169,7 +170,11 @@ internal object AccountDataQueue {
|
|||
} else handler.post {
|
||||
future.run()
|
||||
}
|
||||
return future.get(1, TimeUnit.SECONDS)
|
||||
try {
|
||||
return future.get(5, TimeUnit.SECONDS)
|
||||
} catch (e: TimeoutException) {
|
||||
return manager.getUserData(account, key)
|
||||
}
|
||||
}
|
||||
|
||||
fun peekAuthToken(manager: AccountManager, account: Account, authTokenType: String): String? {
|
||||
|
@ -179,7 +184,11 @@ internal object AccountDataQueue {
|
|||
} else handler.post {
|
||||
future.run()
|
||||
}
|
||||
return future.get(1, TimeUnit.SECONDS)
|
||||
try {
|
||||
return future.get(5, TimeUnit.SECONDS)
|
||||
} catch (e: TimeoutException) {
|
||||
return manager.peekAuthToken(account, authTokenType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,9 +196,9 @@ private object AccountExtensionFunctionsL {
|
|||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
internal fun renameAccount(am: AccountManager, account: Account,
|
||||
newName: String,
|
||||
callback: AccountManagerCallback<Account>?,
|
||||
handler: Handler?): AccountManagerFuture<Account> {
|
||||
newName: String,
|
||||
callback: AccountManagerCallback<Account>?,
|
||||
handler: Handler?): AccountManagerFuture<Account> {
|
||||
return am.renameAccount(account, newName, callback, handler)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.widget.ImageView
|
||||
import com.bumptech.glide.RequestManager
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.ParcelableMessage
|
||||
import org.mariotaku.twidere.model.ParcelableMessageConversation
|
||||
|
@ -113,16 +114,17 @@ fun ParcelableMessageConversation.getSummaryText(context: Context, manager: User
|
|||
}
|
||||
|
||||
fun ParcelableMessageConversation.displayAvatarTo(getRequestManager: () -> RequestManager, view: ImageView) {
|
||||
val context = view.context
|
||||
if (conversation_type == ConversationType.ONE_TO_ONE) {
|
||||
val user = this.user
|
||||
if (user != null) {
|
||||
getRequestManager().load(user.getBestProfileImage(view.context)).into(view)
|
||||
getRequestManager().loadProfileImage(context, user.getBestProfileImage(context)).into(view)
|
||||
} else {
|
||||
// TODO: show default conversation icon
|
||||
getRequestManager().load(R.drawable.ic_profile_image_default_group).into(view)
|
||||
getRequestManager().loadProfileImage(context, R.drawable.ic_profile_image_default_group).into(view)
|
||||
}
|
||||
} else {
|
||||
getRequestManager().load(conversation_avatar).placeholder(R.drawable.ic_profile_image_default_group).into(view)
|
||||
getRequestManager().loadProfileImage(context, conversation_avatar).placeholder(R.drawable.ic_profile_image_default_group).into(view)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.mariotaku.twidere.extension.view.holder
|
|||
import android.view.View
|
||||
import com.bumptech.glide.RequestManager
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.model.ParcelableUserList
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
|
@ -34,7 +35,8 @@ fun SimpleUserListViewHolder.display(userList: ParcelableUserList, getRequestMan
|
|||
userColorNameManager.getDisplayName(userList, false))
|
||||
if (displayProfileImage) {
|
||||
profileImageView.visibility = View.VISIBLE
|
||||
getRequestManager().load(userList.getBestProfileImage(itemView.context)).into(profileImageView)
|
||||
val context = itemView.context
|
||||
getRequestManager().loadProfileImage(context, userList.getBestProfileImage(context)).into(profileImageView)
|
||||
} else {
|
||||
profileImageView.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import android.view.View.OnClickListener
|
|||
import android.view.animation.DecelerateInterpolator
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.RequestManager
|
||||
import kotlinx.android.synthetic.main.header_drawer_account_selector.view.*
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.kpreferences.set
|
||||
|
@ -70,6 +71,7 @@ import org.mariotaku.twidere.annotation.Referral
|
|||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.*
|
||||
import org.mariotaku.twidere.constant.extraFeaturesNoticeVersionKey
|
||||
import org.mariotaku.twidere.constant.profileImageStyleKey
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.setActivated
|
||||
import org.mariotaku.twidere.fragment.AccountsDashboardFragment.AccountsInfo
|
||||
import org.mariotaku.twidere.graphic.BadgeDrawable
|
||||
|
@ -83,7 +85,6 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Drafts
|
|||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.InternalTwitterContentUtils.getBestBannerUrl
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback
|
||||
import org.mariotaku.twidere.view.ShapedImageView
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
|
||||
|
@ -171,7 +172,6 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
})
|
||||
|
||||
profileContainer.setOnClickListener(this)
|
||||
accountProfileImageView.style = preferences[profileImageStyleKey]
|
||||
accountProfileBanner.setInAnimation(context, android.R.anim.fade_in)
|
||||
accountProfileBanner.setOutAnimation(context, android.R.anim.fade_out)
|
||||
accountProfileBanner.setFactory {
|
||||
|
@ -443,11 +443,13 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
snapshotView.setImageBitmap(snapshotBitmap)
|
||||
val profileDrawable = profileImageView.drawable
|
||||
clickedDrawable = clickedImageView.drawable
|
||||
clickedColors = clickedImageView.borderColors
|
||||
//TODO complete border color
|
||||
//clickedColors = clickedImageView.borderColors
|
||||
val oldSelectedAccount = accountsAdapter.selectedAccount ?: return
|
||||
mediaLoader.displayDashboardProfileImage(clickedImageView,
|
||||
oldSelectedAccount, profileDrawable)
|
||||
clickedImageView.setBorderColors(*profileImageView.borderColors)
|
||||
Glide.with(this@AccountsDashboardFragment).loadProfileImage(context,
|
||||
oldSelectedAccount).into(clickedImageView).onLoadStarted(profileDrawable)
|
||||
//TODO complete border color
|
||||
//clickedImageView.setBorderColors(*profileImageView.borderColors)
|
||||
|
||||
displayAccountBanner(account)
|
||||
|
||||
|
@ -476,7 +478,8 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
snapshotView.visibility = View.INVISIBLE
|
||||
snapshotView.setImageDrawable(null)
|
||||
profileImageView.setImageDrawable(clickedDrawable)
|
||||
profileImageView.setBorderColors(*clickedColors!!)
|
||||
//TODO complete border color
|
||||
//profileImageView.setBorderColors(*clickedColors!!)
|
||||
profileImageView.alpha = 1f
|
||||
clickedImageView.scaleX = 1f
|
||||
clickedImageView.scaleY = 1f
|
||||
|
@ -494,22 +497,17 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
val defWidth = res.displayMetrics.widthPixels
|
||||
val width = if (bannerWidth > 0) bannerWidth else defWidth
|
||||
val bannerView = accountProfileBanner.nextView as ImageView
|
||||
if (bannerView.drawable == null || account != bannerView.tag) {
|
||||
val url = getBestBannerUrl(ParcelableUserUtils.getProfileBannerUrl(account.user), width)
|
||||
Glide.with(this).load(url).into(bannerView)
|
||||
bannerView.tag = account
|
||||
} else {
|
||||
// TODO cancel loading
|
||||
}
|
||||
val url = getBestBannerUrl(ParcelableUserUtils.getProfileBannerUrl(account.user), width)
|
||||
Glide.with(this).load(url).into(bannerView)
|
||||
}
|
||||
|
||||
private fun displayCurrentAccount(profileImageSnapshot: Drawable?) {
|
||||
val account = accountsAdapter.selectedAccount ?: return
|
||||
accountProfileNameView.text = account.user.name
|
||||
accountProfileScreenNameView.text = String.format("@%s", account.user.screen_name)
|
||||
mediaLoader.displayDashboardProfileImage(accountProfileImageView, account,
|
||||
profileImageSnapshot)
|
||||
accountProfileImageView.setBorderColors(account.color)
|
||||
accountProfileScreenNameView.text = "@${account.user.screen_name}"
|
||||
Glide.with(this).loadProfileImage(context, account).into(accountProfileImageView).onLoadStarted(profileImageSnapshot)
|
||||
//TODO complete border color
|
||||
//accountProfileImageView.setBorderColors(account.color)
|
||||
accountProfileBanner.showNext()
|
||||
}
|
||||
|
||||
|
@ -600,18 +598,22 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
itemView: View
|
||||
) : RecyclerPagerAdapter.ViewHolder(itemView), OnClickListener {
|
||||
|
||||
val iconView: ShapedImageView
|
||||
val iconView: ImageView
|
||||
|
||||
init {
|
||||
itemView.setOnClickListener(this)
|
||||
iconView = itemView.findViewById(android.R.id.icon) as ShapedImageView
|
||||
iconView.style = adapter.profileImageStyle
|
||||
iconView = itemView.findViewById(android.R.id.icon) as ImageView
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
adapter.dispatchItemSelected(this)
|
||||
}
|
||||
|
||||
fun display(account: AccountDetails) {
|
||||
// iconView.setBorderColor(account.color)
|
||||
adapter.getRequestManager().loadProfileImage(itemView.context, account).into(iconView)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class AccountSelectorAdapter(
|
||||
|
@ -619,6 +621,8 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
private val fragment: AccountsDashboardFragment
|
||||
) : RecyclerPagerAdapter() {
|
||||
|
||||
internal var getRequestManager: () -> RequestManager = { Glide.with(fragment) }
|
||||
|
||||
internal var profileImageStyle: Int = fragment.preferences[profileImageStyleKey]
|
||||
internal var mediaLoader: MediaLoaderWrapper = fragment.mediaLoader
|
||||
|
||||
|
@ -682,12 +686,7 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
|
|||
when (itemViewType) {
|
||||
ITEM_VIEW_TYPE_ICON -> {
|
||||
val account = getAdapterAccount(position)!!
|
||||
holder as AccountProfileImageViewHolder
|
||||
holder.iconView.setBorderColor(account.color)
|
||||
if (holder.iconView.tag != account && holder.iconView.drawable == null) {
|
||||
mediaLoader.displayDashboardProfileImage(holder.iconView, account, null)
|
||||
}
|
||||
holder.iconView.tag = account
|
||||
(holder as AccountProfileImageViewHolder).display(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ import org.mariotaku.twidere.annotation.Referral
|
|||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.*
|
||||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.applyTo
|
||||
import org.mariotaku.twidere.extension.model.getAccountType
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
|
@ -927,7 +928,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||
itemView.name.screenName = String.format("@%s", status.user_screen_name)
|
||||
itemView.name.updateText(formatter)
|
||||
|
||||
adapter.getRequestManager().load(status.getBestProfileImage(context)).into(itemView.profileImage)
|
||||
adapter.getRequestManager().loadProfileImage(context, status.getBestProfileImage(context)).into(itemView.profileImage)
|
||||
|
||||
val typeIconRes = Utils.getUserTypeIconRes(status.user_is_verified, status.user_is_protected)
|
||||
val typeDescriptionRes = Utils.getUserTypeDescriptionRes(status.user_is_verified, status.user_is_protected)
|
||||
|
@ -1373,7 +1374,8 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||
}
|
||||
|
||||
fun displayUser(item: ParcelableUser) {
|
||||
adapter.getRequestManager().load(item.getBestProfileImage(adapter.context)).into(profileImageView)
|
||||
val context = adapter.context
|
||||
adapter.getRequestManager().loadProfileImage(context, item.getBestProfileImage(context)).into(profileImageView)
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
|
|
|
@ -523,10 +523,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||
val defWidth = resources.displayMetrics.widthPixels
|
||||
val width = if (bannerWidth > 0) bannerWidth else defWidth
|
||||
val bannerUrl = getBestBannerUrl(ParcelableUserUtils.getProfileBannerUrl(user), width)
|
||||
if (ObjectUtils.notEqual(profileBanner.tag, bannerUrl) || profileBanner.drawable == null) {
|
||||
profileBanner.tag = bannerUrl
|
||||
Glide.with(this).load(bannerUrl).into(profileBanner)
|
||||
}
|
||||
Glide.with(this).load(bannerUrl).into(profileBanner)
|
||||
val relationship = relationship
|
||||
if (relationship == null) {
|
||||
getFriendship()
|
||||
|
|
|
@ -26,7 +26,10 @@ import android.widget.ImageView
|
|||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.constant.mediaPreloadKey
|
||||
import org.mariotaku.twidere.constant.mediaPreloadOnWifiOnlyKey
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.ParcelableActivity
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.util.getActivityStatus
|
||||
|
||||
class MediaLoaderWrapper() {
|
||||
|
@ -59,15 +62,6 @@ class MediaLoaderWrapper() {
|
|||
fun displayProfileImage(view: ImageView, url: String?) {
|
||||
}
|
||||
|
||||
fun displayDashboardProfileImage(view: ImageView, account: AccountDetails, drawableOnLoading: Drawable?) {
|
||||
if (account.user.extras != null && !TextUtils.isEmpty(account.user.extras.profile_image_url_profile_size)) {
|
||||
displayDashboardProfileImage(view, account.user.extras.profile_image_url_profile_size,
|
||||
drawableOnLoading)
|
||||
} else {
|
||||
displayDashboardProfileImage(view, account.user.profile_image_url, drawableOnLoading)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun preloadStatus(status: ParcelableStatus) {
|
||||
if (!shouldPreload) return
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 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.util.glide
|
||||
|
||||
import android.content.Context
|
||||
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.GlideBuilder
|
||||
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.bumptech.glide.module.GlideModule
|
||||
import okhttp3.OkHttpClient
|
||||
import org.mariotaku.twidere.util.HttpClientFactory
|
||||
import org.mariotaku.twidere.util.dagger.DependencyHolder
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
class OkHttpGlideModule : GlideModule {
|
||||
override fun applyOptions(context: Context, builder: GlideBuilder) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
override fun registerComponents(context: Context, glide: Glide) {
|
||||
val holder = DependencyHolder.get(context)
|
||||
val builder = OkHttpClient.Builder()
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
||||
HttpClientFactory.initOkHttpClient(conf, builder, holder.dns, holder.connectionPool, holder.cache)
|
||||
glide.register(GlideUrl::class.java, InputStream::class.java, OkHttpUrlLoader.Factory(builder.build()))
|
||||
}
|
||||
}
|
|
@ -105,18 +105,15 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
|
|||
if (video) return@run null
|
||||
item.media_url
|
||||
}
|
||||
if (url != imageView.tag || imageView.drawable == null) {
|
||||
if (withCredentials) {
|
||||
getRequestManager().load(url).into(imageView)
|
||||
// TODO handle load progress w/ authentication
|
||||
// loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler, video)
|
||||
} else {
|
||||
getRequestManager().load(url).into(imageView)
|
||||
// TODO handle load progress
|
||||
// loader.displayPreviewImage(imageView, url, loadingHandler, video)
|
||||
}
|
||||
if (withCredentials) {
|
||||
getRequestManager().load(url).into(imageView)
|
||||
// TODO handle load progress w/ authentication
|
||||
// loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler, video)
|
||||
} else {
|
||||
getRequestManager().load(url).into(imageView)
|
||||
// TODO handle load progress
|
||||
// loader.displayPreviewImage(imageView, url, loadingHandler, video)
|
||||
}
|
||||
imageView.tag = url
|
||||
if (imageView is MediaPreviewImageView) {
|
||||
imageView.setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(item.type))
|
||||
}
|
||||
|
@ -129,7 +126,6 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
|
|||
child.visibility = View.VISIBLE
|
||||
} else {
|
||||
// TODO cancel image load task
|
||||
imageView.tag = null
|
||||
child.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.mariotaku.ktextension.applyFontFamily
|
|||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.ParcelableActivitiesAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.IActivitiesAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.model.ActivityTitleSummaryMessage
|
||||
import org.mariotaku.twidere.model.ParcelableActivity
|
||||
|
@ -134,7 +135,8 @@ class ActivityTitleSummaryViewHolder(
|
|||
view.setImageDrawable(null)
|
||||
if (i < length) {
|
||||
view.visibility = View.VISIBLE
|
||||
adapter.getRequestManager().load(statuses[i].getBestProfileImage(adapter.context)).into(view)
|
||||
val context = adapter.context
|
||||
adapter.getRequestManager().loadProfileImage(context, statuses[i].getBestProfileImage(context)).into(view)
|
||||
} else {
|
||||
view.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.widget.TextView
|
|||
import kotlinx.android.synthetic.main.card_item_group_compact.view.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IGroupsAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.model.ParcelableGroup
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
@ -77,7 +78,7 @@ class GroupViewHolder(private val adapter: IGroupsAdapter<*>, itemView: View) :
|
|||
}
|
||||
if (adapter.profileImageEnabled) {
|
||||
profileImageView.visibility = View.VISIBLE
|
||||
adapter.getRequestManager().load(group.homepage_logo).into(profileImageView)
|
||||
adapter.getRequestManager().loadProfileImage(context, group.homepage_logo).into(profileImageView)
|
||||
} else {
|
||||
profileImageView.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.widget.TextView
|
|||
import kotlinx.android.synthetic.main.list_item_simple_user.view.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IContentAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.view.ProfileImageView
|
||||
|
@ -33,7 +34,8 @@ open class SimpleUserViewHolder<out A : IContentAdapter>(
|
|||
nameView.text = user.name
|
||||
secondaryNameView.text = "@${user.screen_name}"
|
||||
if (adapter.profileImageEnabled) {
|
||||
adapter.getRequestManager().load(user.getBestProfileImage(itemView.context)).into(profileImageView)
|
||||
val context = itemView.context
|
||||
adapter.getRequestManager().loadProfileImage(context, user.getBestProfileImage(context)).into(profileImageView)
|
||||
profileImageView.visibility = View.VISIBLE
|
||||
} else {
|
||||
profileImageView.visibility = View.GONE
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.mariotaku.twidere.R
|
|||
import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM
|
||||
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.applyTo
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable
|
||||
|
@ -35,7 +36,6 @@ import org.mariotaku.twidere.task.RetweetStatusTask
|
|||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText
|
||||
import org.mariotaku.twidere.util.Utils.getUserTypeIconRes
|
||||
import org.mariotaku.twidere.view.ProfileImageView
|
||||
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
|
@ -47,7 +47,7 @@ import java.lang.ref.WeakReference
|
|||
*/
|
||||
class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View) : ViewHolder(itemView), IStatusViewHolder {
|
||||
|
||||
override val profileImageView: ProfileImageView by lazy { itemView.profileImage }
|
||||
override val profileImageView: ImageView by lazy { itemView.profileImage }
|
||||
override val profileTypeView: ImageView by lazy { itemView.profileType }
|
||||
|
||||
private val itemContent by lazy { itemView.itemContent }
|
||||
|
@ -299,7 +299,7 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
|||
|
||||
if (adapter.profileImageEnabled) {
|
||||
profileImageView.visibility = View.VISIBLE
|
||||
getRequestManager().load(status.getBestProfileImage(context)).into(profileImageView)
|
||||
getRequestManager().loadProfileImage(context, status.getBestProfileImage(context)).into(profileImageView)
|
||||
|
||||
profileTypeView.setImageResource(getUserTypeIconRes(status.user_is_verified, status.user_is_protected))
|
||||
profileTypeView.visibility = View.VISIBLE
|
||||
|
@ -502,7 +502,6 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
|
|||
|
||||
fun setupViewOptions() {
|
||||
setTextSize(adapter.textSize)
|
||||
profileImageView.style = adapter.profileImageStyle
|
||||
|
||||
mediaPreview.style = adapter.mediaPreviewStyle
|
||||
quotedMediaPreview.style = adapter.mediaPreviewStyle
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.widget.TextView
|
|||
import kotlinx.android.synthetic.main.list_item_user_list.view.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IUserListsAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.model.ParcelableUserList
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import org.mariotaku.twidere.view.ColorLabelRelativeLayout
|
||||
|
@ -72,7 +73,7 @@ class UserListViewHolder(
|
|||
|
||||
if (adapter.profileImageEnabled) {
|
||||
profileImageView.visibility = View.VISIBLE
|
||||
adapter.getRequestManager().load(userList.user_profile_image_url).into(profileImageView)
|
||||
adapter.getRequestManager().loadProfileImage(context, userList.user_profile_image_url).into(profileImageView)
|
||||
} else {
|
||||
profileImageView.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import kotlinx.android.synthetic.main.list_item_user.view.*
|
|||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.iface.IUsersAdapter
|
||||
import org.mariotaku.twidere.adapter.iface.IUsersAdapter.*
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
|
@ -135,7 +136,7 @@ class UserViewHolder(
|
|||
|
||||
if (adapter.profileImageEnabled) {
|
||||
profileImageView.visibility = View.VISIBLE
|
||||
adapter.getRequestManager().load(user.getBestProfileImage(context)).into(profileImageView)
|
||||
adapter.getRequestManager().loadProfileImage(context, user.getBestProfileImage(context)).into(profileImageView)
|
||||
} else {
|
||||
profileImageView.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.view.View
|
|||
import android.widget.ImageView
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.MediaPreviewAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableMediaUpdate
|
||||
|
||||
|
@ -43,7 +44,7 @@ class MediaPreviewViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
|
|||
}
|
||||
|
||||
fun displayMedia(adapter: MediaPreviewAdapter, media: ParcelableMediaUpdate) {
|
||||
adapter.getRequestManager().load(media.uri).into(imageView)
|
||||
adapter.getRequestManager().loadProfileImage(imageView.context, media.uri).into(imageView)
|
||||
videoIndicatorView.visibility = if (media.type == ParcelableMedia.Type.VIDEO) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
|
|
|
@ -30,6 +30,7 @@ import android.widget.RelativeLayout
|
|||
import android.widget.TextView
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.adapter.MessagesConversationAdapter
|
||||
import org.mariotaku.twidere.extension.loadProfileImage
|
||||
import org.mariotaku.twidere.extension.model.getBestProfileImage
|
||||
import org.mariotaku.twidere.extension.model.timestamp
|
||||
import org.mariotaku.twidere.model.ParcelableMessage
|
||||
|
@ -83,7 +84,7 @@ abstract class AbsMessageViewHolder(itemView: View, val adapter: MessagesConvers
|
|||
if (adapter.displaySenderProfile && adapter.profileImageEnabled && sender != null
|
||||
&& !message.is_outgoing) {
|
||||
this.visibility = View.VISIBLE
|
||||
adapter.getRequestManager().load(sender.getBestProfileImage(context)).into(this)
|
||||
adapter.getRequestManager().loadProfileImage(context, sender.getBestProfileImage(context)).into(this)
|
||||
} else {
|
||||
this.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
|
@ -27,14 +28,11 @@
|
|||
android:padding="@dimen/element_spacing_small"
|
||||
tools:layout_height="48dp">
|
||||
|
||||
<org.mariotaku.twidere.view.ProfileImageView
|
||||
<org.mariotaku.twidere.view.ForegroundImageView
|
||||
android:id="@android:id/icon"
|
||||
style="?profileImageStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
app:sivBorder="true"
|
||||
app:sivBorderWidth="1.5dp"
|
||||
tools:src="@drawable/ic_profile_image_twidere"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -54,18 +54,17 @@
|
|||
android:paddingBottom="@dimen/element_spacing_normal"
|
||||
android:paddingTop="@dimen/element_spacing_normal">
|
||||
|
||||
<org.mariotaku.twidere.view.ProfileImageView
|
||||
<org.mariotaku.twidere.view.ForegroundImageView
|
||||
android:id="@+id/profileImage"
|
||||
style="?profileImageStyle"
|
||||
android:layout_width="@dimen/icon_size_profile_image_dashboard_current"
|
||||
android:layout_height="@dimen/icon_size_profile_image_dashboard_current"
|
||||
android:layout_marginBottom="@dimen/element_spacing_mlarge"
|
||||
android:layout_marginLeft="@dimen/element_spacing_large"
|
||||
android:layout_marginStart="@dimen/element_spacing_large"
|
||||
android:layout_marginTop="@dimen/element_spacing_mlarge"
|
||||
android:contentDescription="@string/profile_image"
|
||||
android:focusable="false"
|
||||
app:sivBorder="true"
|
||||
app:sivBorderWidth="2dp"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/ic_profile_image_twidere"/>
|
||||
|
||||
<org.mariotaku.twidere.view.ExtendedViewPager
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
tools:textSize="@dimen/text_size_extra_small"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<org.mariotaku.twidere.view.ProfileImageView
|
||||
<ImageView
|
||||
android:id="@+id/profileImage"
|
||||
style="?profileImageStyle"
|
||||
android:layout_width="@dimen/icon_size_status_profile_image"
|
||||
|
|
Loading…
Reference in New Issue