improved list profile image style

This commit is contained in:
Mariotaku Lee 2017-03-07 19:14:11 +08:00
parent daf8937a76
commit 185e57f20b
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 56 additions and 64 deletions

View File

@ -25,7 +25,7 @@ import android.view.ViewGroup
import com.bumptech.glide.RequestManager
import org.mariotaku.twidere.R
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
import org.mariotaku.twidere.extension.view.holder.display
import org.mariotaku.twidere.adapter.iface.IUserListsAdapter
import org.mariotaku.twidere.model.ItemCounts
import org.mariotaku.twidere.model.ParcelableUserList
import org.mariotaku.twidere.view.holder.SimpleUserListViewHolder
@ -34,14 +34,17 @@ class SimpleParcelableUserListsAdapter(
context: Context,
requestManager: RequestManager
) : BaseArrayAdapter<ParcelableUserList>(context, R.layout.list_item_simple_user_list,
requestManager = requestManager) {
requestManager = requestManager), IUserListsAdapter<List<ParcelableUserList>> {
override val itemCounts: ItemCounts = ItemCounts(2)
override val userListsCount: Int = itemCounts[0]
override val showAccountsColor: Boolean = false
override val userListClickListener: IUserListsAdapter.UserListClickListener? = null
override fun getItemId(position: Int): Long {
when (itemCounts.getItemCountIndex(position)) {
0 -> {
return getItem(position - itemCounts.getItemStartPosition(0)).hashCode().toLong()
return getUserList(position)!!.hashCode().toLong()
}
1 -> {
return Integer.MAX_VALUE + 1L
@ -55,12 +58,12 @@ class SimpleParcelableUserListsAdapter(
0 -> {
val view = super.getView(position, convertView, parent)
val holder = view.tag as? SimpleUserListViewHolder ?: run {
val h = SimpleUserListViewHolder(view)
val h = SimpleUserListViewHolder(this, view)
view.tag = h
return@run h
}
val userList = getItem(position)
holder.display(userList, requestManager, userColorNameManager, profileImageEnabled)
holder.display(userList)
return view
}
1 -> {
@ -71,6 +74,14 @@ class SimpleParcelableUserListsAdapter(
throw UnsupportedOperationException()
}
override fun getUserList(position: Int): ParcelableUserList? {
return getItem(position - itemCounts.getItemStartPosition(0))
}
override fun getUserListId(position: Int): String? {
return getUserList(position)?.id
}
override fun getItemViewType(position: Int): Int {
return itemCounts.getItemCountIndex(position)
}
@ -85,15 +96,14 @@ class SimpleParcelableUserListsAdapter(
return itemCounts.itemCount
}
fun setData(data: List<ParcelableUserList>?) {
override fun setData(data: List<ParcelableUserList>?): Boolean {
clear()
if (data == null) return
for (user in data) {
if (data == null) return false
data.filter {
//TODO improve compare
if (findItemPosition(user.hashCode().toLong()) < 0) {
add(user)
}
}
findItemPosition(it.hashCode().toLong()) < 0
}.forEach { add(it) }
return true
}
}

View File

@ -82,7 +82,7 @@ fun RequestManager.loadProfileImage(context: Context, user: ParcelableUser,
}
fun RequestManager.loadProfileImage(context: Context, userList: ParcelableUserList,
@ImageShapeStyle shapeStyle: Int = ImageShapeStyle.SHAPE_CIRCLE,
@ImageShapeStyle shapeStyle: Int,
cornerRadius: Float = 0f, cornerRadiusRatio: Float = 0f): DrawableRequestBuilder<String?> {
return configureLoadProfileImage(context, shapeStyle, cornerRadius, cornerRadiusRatio) {
load(userList.user_profile_image_url)
@ -90,7 +90,7 @@ fun RequestManager.loadProfileImage(context: Context, userList: ParcelableUserLi
}
fun RequestManager.loadProfileImage(context: Context, group: ParcelableGroup,
@ImageShapeStyle shapeStyle: Int = ImageShapeStyle.SHAPE_CIRCLE,
@ImageShapeStyle shapeStyle: Int,
cornerRadius: Float = 0f, cornerRadiusRatio: Float = 0f): DrawableRequestBuilder<String?> {
return configureLoadProfileImage(context, shapeStyle, cornerRadius, cornerRadiusRatio) {
load(group.homepage_logo)

View File

@ -1,42 +0,0 @@
/*
* 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.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.model.ParcelableUserList
import org.mariotaku.twidere.util.UserColorNameManager
import org.mariotaku.twidere.view.holder.SimpleUserListViewHolder
fun SimpleUserListViewHolder.display(userList: ParcelableUserList, requestManager: RequestManager,
userColorNameManager: UserColorNameManager, displayProfileImage: Boolean) {
nameView.text = userList.name
createdByView.text = createdByView.context.getString(R.string.created_by,
userColorNameManager.getDisplayName(userList, false))
if (displayProfileImage) {
profileImageView.visibility = View.VISIBLE
val context = itemView.context
requestManager.loadProfileImage(context, userList).into(profileImageView)
} else {
profileImageView.visibility = View.GONE
}
}

View File

@ -11,8 +11,8 @@ import kotlinx.android.synthetic.main.layout_extra_config_user_list.view.*
import kotlinx.android.synthetic.main.list_item_simple_user_list.view.*
import org.mariotaku.twidere.R
import org.mariotaku.twidere.activity.UserListSelectorActivity
import org.mariotaku.twidere.adapter.DummyItemAdapter
import org.mariotaku.twidere.constant.IntentConstants.*
import org.mariotaku.twidere.extension.view.holder.display
import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment
import org.mariotaku.twidere.model.ParcelableUserList
import org.mariotaku.twidere.model.tab.TabConfiguration
@ -51,7 +51,8 @@ class UserListExtraConfiguration(key: String) : TabConfiguration.ExtraConfigurat
fragment.startExtraConfigurationActivityForResult(this@UserListExtraConfiguration, intent, 1)
}
hintView = view.selectUserListHint
viewHolder = SimpleUserListViewHolder(view.listItem)
val adapter = DummyItemAdapter(context, requestManager = Glide.with(context))
viewHolder = SimpleUserListViewHolder(adapter, view.listItem)
viewHolder.itemView.visibility = View.GONE
hintView.visibility = View.VISIBLE
@ -62,8 +63,7 @@ class UserListExtraConfiguration(key: String) : TabConfiguration.ExtraConfigurat
1 -> {
if (resultCode == Activity.RESULT_OK) {
val userList: ParcelableUserList = data!!.getParcelableExtra(EXTRA_USER_LIST)
viewHolder.display(userList, Glide.with(context),
dependencyHolder.userColorNameManager, true)
viewHolder.display(userList)
viewHolder.itemView.visibility = View.VISIBLE
hintView.visibility = View.GONE

View File

@ -2,18 +2,42 @@ package org.mariotaku.twidere.view.holder
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import kotlinx.android.synthetic.main.list_item_simple_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.view.ProfileImageView
/**
* Created by mariotaku on 2016/12/1.
*/
class SimpleUserListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class SimpleUserListViewHolder(
val adapter: IUserListsAdapter<*>,
itemView: View
) : RecyclerView.ViewHolder(itemView) {
val createdByView: TextView = itemView.createdBy
val nameView: TextView = itemView.name
val profileImageView: ImageView = itemView.profileImage
val profileImageView: ProfileImageView = itemView.profileImage
init {
profileImageView.style = adapter.profileImageStyle
}
fun display(userList: ParcelableUserList) {
nameView.text = userList.name
createdByView.text = createdByView.context.getString(R.string.created_by,
adapter.userColorNameManager.getDisplayName(userList, false))
if (adapter.profileImageEnabled) {
profileImageView.visibility = View.VISIBLE
val context = itemView.context
adapter.requestManager.loadProfileImage(context, userList, adapter.profileImageStyle,
profileImageView.cornerRadius, profileImageView.cornerRadiusRatio).into(profileImageView)
} else {
profileImageView.visibility = View.GONE
}
}
}