fix: 修复用户主页头像模糊
This commit is contained in:
parent
d917070d98
commit
af407efdb9
|
|
@ -22,7 +22,7 @@ import com.google.android.material.tabs.TabLayout
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
import com.huanchengfly.tieba.post.adapters.FragmentTabViewPagerAdapter
|
import com.huanchengfly.tieba.post.adapters.FragmentTabViewPagerAdapter
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.models.ProfileBean
|
import com.huanchengfly.tieba.post.api.models.protos.profile.ProfileResponseData
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||||
import com.huanchengfly.tieba.post.fragments.UserLikeForumFragment
|
import com.huanchengfly.tieba.post.fragments.UserLikeForumFragment
|
||||||
import com.huanchengfly.tieba.post.fragments.UserPostFragment
|
import com.huanchengfly.tieba.post.fragments.UserPostFragment
|
||||||
|
|
@ -35,14 +35,8 @@ import com.huanchengfly.tieba.post.ui.page.editprofile.view.EditProfileActivity
|
||||||
import com.huanchengfly.tieba.post.ui.widgets.theme.TintMaterialButton
|
import com.huanchengfly.tieba.post.ui.widgets.theme.TintMaterialButton
|
||||||
import com.huanchengfly.tieba.post.ui.widgets.theme.TintToolbar
|
import com.huanchengfly.tieba.post.ui.widgets.theme.TintToolbar
|
||||||
import com.huanchengfly.tieba.post.utils.*
|
import com.huanchengfly.tieba.post.utils.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.MainScope
|
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Callback
|
|
||||||
import retrofit2.Response
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -92,7 +86,7 @@ class UserActivity : BaseActivity() {
|
||||||
@BindView(R.id.user_info_chips)
|
@BindView(R.id.user_info_chips)
|
||||||
lateinit var infoChips: View
|
lateinit var infoChips: View
|
||||||
|
|
||||||
private var profileBean: ProfileBean? = null
|
private var profileBean: ProfileResponseData? = null
|
||||||
private var uid: String? = null
|
private var uid: String? = null
|
||||||
private var tab = 0
|
private var tab = 0
|
||||||
|
|
||||||
|
|
@ -113,7 +107,8 @@ class UserActivity : BaseActivity() {
|
||||||
uid = intent.getStringExtra(EXTRA_UID)
|
uid = intent.getStringExtra(EXTRA_UID)
|
||||||
tab = intent.getIntExtra(EXTRA_TAB, TAB_THREAD)
|
tab = intent.getIntExtra(EXTRA_TAB, TAB_THREAD)
|
||||||
val avatar = intent.getStringExtra(EXTRA_AVATAR)
|
val avatar = intent.getStringExtra(EXTRA_AVATAR)
|
||||||
if (uid == null) {
|
val uidLong = uid?.toLongOrNull()
|
||||||
|
if (uidLong == null) {
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -124,14 +119,17 @@ class UserActivity : BaseActivity() {
|
||||||
if (!TextUtils.isEmpty(avatar)) {
|
if (!TextUtils.isEmpty(avatar)) {
|
||||||
loadingView.visibility = View.GONE
|
loadingView.visibility = View.GONE
|
||||||
ImageUtil.load(avatarView, ImageUtil.LOAD_TYPE_AVATAR, StringUtil.getAvatarUrl(avatar))
|
ImageUtil.load(avatarView, ImageUtil.LOAD_TYPE_AVATAR, StringUtil.getAvatarUrl(avatar))
|
||||||
ImageUtil.initImageView(avatarView, PhotoViewBean(StringUtil.getAvatarUrl(avatar), null))
|
ImageUtil.initImageView(
|
||||||
|
avatarView,
|
||||||
|
PhotoViewBean(StringUtil.getAvatarUrl(avatar), null)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
appbar.addOnOffsetChangedListener { appBarLayout: AppBarLayout, verticalOffset: Int ->
|
appbar.addOnOffsetChangedListener { appBarLayout: AppBarLayout, verticalOffset: Int ->
|
||||||
val percent = abs(verticalOffset * 1.0f) / appBarLayout.totalScrollRange
|
val percent = abs(verticalOffset * 1.0f) / appBarLayout.totalScrollRange
|
||||||
headerView.alpha = 1f - percent
|
headerView.alpha = 1f - percent
|
||||||
headerMaskView.alpha = percent
|
headerMaskView.alpha = percent
|
||||||
if (profileBean != null && profileBean!!.user != null && abs(verticalOffset) >= appBarLayout.totalScrollRange) {
|
if (profileBean != null && abs(verticalOffset) >= appBarLayout.totalScrollRange) {
|
||||||
toolbar.title = profileBean!!.user!!.nameShow
|
toolbar.title = profileBean?.user?.nameShow
|
||||||
} else {
|
} else {
|
||||||
toolbar.title = null
|
toolbar.title = null
|
||||||
}
|
}
|
||||||
|
|
@ -142,36 +140,34 @@ class UserActivity : BaseActivity() {
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
val actionBar = supportActionBar
|
val actionBar = supportActionBar
|
||||||
actionBar?.setDisplayHomeAsUpEnabled(true)
|
actionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
TiebaApi.getInstance()
|
launch {
|
||||||
.profile(uid!!)
|
TiebaApi.getInstance()
|
||||||
.enqueue(object : Callback<ProfileBean?> {
|
.userProfileFlow(uidLong)
|
||||||
override fun onResponse(
|
.collect {
|
||||||
call: Call<ProfileBean?>,
|
|
||||||
response: Response<ProfileBean?>
|
|
||||||
) {
|
|
||||||
val data = response.body()
|
|
||||||
actionBtn.visibility = View.VISIBLE
|
actionBtn.visibility = View.VISIBLE
|
||||||
loadingView.visibility = View.GONE
|
loadingView.visibility = View.GONE
|
||||||
|
val data = it.data_
|
||||||
|
if (data?.user == null) {
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
profileBean = data
|
profileBean = data
|
||||||
refreshHeader()
|
refreshHeader()
|
||||||
adapter.clear()
|
adapter.clear()
|
||||||
adapter.addFragment(
|
adapter.addFragment(
|
||||||
UserPostFragment.newInstance(uid, true),
|
UserPostFragment.newInstance(uid, true),
|
||||||
"贴子 " + data!!.user!!.threadNum
|
"贴子 " + data.user.thread_num
|
||||||
)
|
)
|
||||||
adapter.addFragment(
|
adapter.addFragment(
|
||||||
UserPostFragment.newInstance(uid, false),
|
UserPostFragment.newInstance(uid, false),
|
||||||
"回复 " + data.user!!.repostNum
|
"回复 " + data.user.post_num
|
||||||
)
|
)
|
||||||
adapter.addFragment(
|
adapter.addFragment(
|
||||||
UserLikeForumFragment.newInstance(uid),
|
UserLikeForumFragment.newInstance(uid),
|
||||||
"关注吧 " + data.user.myLikeNum
|
"关注吧 " + data.user.my_like_num
|
||||||
)
|
)
|
||||||
viewPager.setCurrentItem(tab, false)
|
viewPager.setCurrentItem(tab, false)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
override fun onFailure(call: Call<ProfileBean?>, t: Throwable) {}
|
|
||||||
})
|
|
||||||
listOf(
|
listOf(
|
||||||
followStatTv,
|
followStatTv,
|
||||||
fansStatTv
|
fansStatTv
|
||||||
|
|
@ -180,39 +176,36 @@ class UserActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshHeader() {
|
private fun refreshHeader() {
|
||||||
profileBean?.let {
|
profileBean?.user?.let {
|
||||||
if (it.user == null) {
|
titleView.text = it.nameShow
|
||||||
return
|
sloganView.text = it.intro
|
||||||
}
|
followStatTv.text = "${it.concern_num}"
|
||||||
titleView.text = it.user.nameShow
|
fansStatTv.text = "${it.fans_num}"
|
||||||
sloganView.text = it.user.intro
|
|
||||||
followStatTv.text = "${it.user.concernNum}"
|
|
||||||
fansStatTv.text = "${it.user.fansNum}"
|
|
||||||
//getString(R.string.tip_stat, profileBean!!.user!!.concernNum, profileBean!!.user!!.fansNum)
|
//getString(R.string.tip_stat, profileBean!!.user!!.concernNum, profileBean!!.user!!.fansNum)
|
||||||
if (avatarView.tag == null) {
|
if (avatarView.tag == null) {
|
||||||
ImageUtil.load(
|
ImageUtil.load(
|
||||||
avatarView,
|
avatarView,
|
||||||
ImageUtil.LOAD_TYPE_AVATAR,
|
ImageUtil.LOAD_TYPE_AVATAR,
|
||||||
StringUtil.getAvatarUrl(it.user.portrait)
|
StringUtil.getAvatarUrl(it.portrait)
|
||||||
)
|
)
|
||||||
ImageUtil.initImageView(
|
ImageUtil.initImageView(
|
||||||
avatarView,
|
avatarView,
|
||||||
PhotoViewBean(StringUtil.getAvatarUrl(it.user.portrait), null)
|
PhotoViewBean(StringUtil.getBigAvatarUrl(it.portraith), null)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (TextUtils.equals(AccountUtil.getUid(), it.user.id)) {
|
if (TextUtils.equals(AccountUtil.getUid(), "${it.id}")) {
|
||||||
actionBtn.setText(R.string.menu_edit_info)
|
actionBtn.setText(R.string.menu_edit_info)
|
||||||
} else {
|
} else {
|
||||||
if ("1" == it.user.hasConcerned) {
|
if (1 == it.has_concerned) {
|
||||||
actionBtn.setText(R.string.button_unfollow)
|
actionBtn.setText(R.string.button_unfollow)
|
||||||
} else {
|
} else {
|
||||||
actionBtn.setText(R.string.button_follow)
|
actionBtn.setText(R.string.button_follow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sexTv.text =
|
sexTv.text =
|
||||||
if (it.user.sex == "1") "♂" else if (it.user.sex == "2") "♀" else "?"
|
if (it.sex == 1) "♂" else if (it.sex == 2) "♀" else "?"
|
||||||
tbAgeTv.text = getString(R.string.tb_age, it.user.tbAge)
|
tbAgeTv.text = getString(R.string.tb_age, it.tb_age)
|
||||||
infoChips.visibility = View.VISIBLE
|
infoChips.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -234,25 +227,25 @@ class UserActivity : BaseActivity() {
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_block_black, R.id.menu_block_white -> {
|
R.id.menu_block_black, R.id.menu_block_white -> {
|
||||||
if (profileBean == null || profileBean!!.user == null) {
|
profileBean?.user?.let {
|
||||||
return true
|
val category =
|
||||||
}
|
if (item.itemId == R.id.menu_block_black) Block.CATEGORY_BLACK_LIST else Block.CATEGORY_WHITE_LIST
|
||||||
val category =
|
Block(
|
||||||
if (item.itemId == R.id.menu_block_black) Block.CATEGORY_BLACK_LIST else Block.CATEGORY_WHITE_LIST
|
category = category,
|
||||||
Block(
|
type = Block.TYPE_USER,
|
||||||
category = category,
|
username = it.name,
|
||||||
type = Block.TYPE_USER,
|
uid = it.id.toString()
|
||||||
username = profileBean!!.user!!.name,
|
).saveAsync()
|
||||||
uid = profileBean!!.user!!.id
|
.listen { success: Boolean ->
|
||||||
).saveAsync()
|
if (success) {
|
||||||
.listen { success: Boolean ->
|
Toast.makeText(this, R.string.toast_add_success, Toast.LENGTH_SHORT)
|
||||||
if (success) {
|
.show()
|
||||||
Toast.makeText(this, R.string.toast_add_success, Toast.LENGTH_SHORT)
|
}
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.menu_edit_info -> {
|
R.id.menu_edit_info -> {
|
||||||
startActivity(WebViewActivity.newIntent(this, getString(R.string.url_edit_info)))
|
startActivity(WebViewActivity.newIntent(this, getString(R.string.url_edit_info)))
|
||||||
return true
|
return true
|
||||||
|
|
@ -272,45 +265,52 @@ class UserActivity : BaseActivity() {
|
||||||
|
|
||||||
@OnClick(R.id.user_center_action_btn)
|
@OnClick(R.id.user_center_action_btn)
|
||||||
fun onActionBtnClick(view: View?) {
|
fun onActionBtnClick(view: View?) {
|
||||||
if (TextUtils.equals(profileBean!!.user!!.id, AccountUtil.getUid())) {
|
profileBean?.user?.let { user ->
|
||||||
goToActivity<EditProfileActivity>()
|
if (TextUtils.equals(user.id.toString(), AccountUtil.getUid())) {
|
||||||
return
|
goToActivity<EditProfileActivity>()
|
||||||
}
|
return
|
||||||
if ("1" == profileBean!!.user!!.hasConcerned) {
|
|
||||||
MainScope().launch {
|
|
||||||
TiebaApi.getInstance()
|
|
||||||
.unfollowFlow(
|
|
||||||
profileBean!!.user!!.portrait!!,
|
|
||||||
AccountUtil.getLoginInfo()!!.tbs
|
|
||||||
)
|
|
||||||
.flowOn(Dispatchers.IO)
|
|
||||||
.catch { e ->
|
|
||||||
toastShort(e.getErrorMessage())
|
|
||||||
}
|
|
||||||
.collect {
|
|
||||||
//toastShort(R.string.toast_success)
|
|
||||||
profileBean!!.user!!.setHasConcerned("0")
|
|
||||||
refreshHeader()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if (1 == user.has_concerned) {
|
||||||
MainScope().launch {
|
launch {
|
||||||
TiebaApi.getInstance()
|
TiebaApi.getInstance()
|
||||||
.followFlow(
|
.unfollowFlow(
|
||||||
profileBean!!.user!!.portrait!!,
|
user.portrait,
|
||||||
AccountUtil.getLoginInfo()!!.tbs
|
AccountUtil.getLoginInfo()!!.tbs
|
||||||
)
|
)
|
||||||
.flowOn(Dispatchers.IO)
|
.catch { e ->
|
||||||
.catch { e ->
|
toastShort(e.getErrorMessage())
|
||||||
toastShort(e.getErrorMessage())
|
|
||||||
}
|
|
||||||
.collect {
|
|
||||||
if ("1" == it.info.isToast) {
|
|
||||||
toastShort(it.info.toastText)
|
|
||||||
}
|
}
|
||||||
profileBean!!.user!!.setHasConcerned("1")
|
.collect {
|
||||||
refreshHeader()
|
profileBean = profileBean!!.copy(
|
||||||
}
|
user = profileBean?.user!!.copy(
|
||||||
|
has_concerned = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
refreshHeader()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
launch {
|
||||||
|
TiebaApi.getInstance()
|
||||||
|
.followFlow(
|
||||||
|
user.portrait,
|
||||||
|
AccountUtil.getLoginInfo()!!.tbs
|
||||||
|
)
|
||||||
|
.catch { e ->
|
||||||
|
toastShort(e.getErrorMessage())
|
||||||
|
}
|
||||||
|
.collect {
|
||||||
|
if ("1" == it.info.isToast) {
|
||||||
|
toastShort(it.info.toastText)
|
||||||
|
}
|
||||||
|
profileBean = profileBean!!.copy(
|
||||||
|
user = profileBean?.user!!.copy(
|
||||||
|
has_concerned = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
refreshHeader()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ interface ITiebaApi {
|
||||||
*
|
*
|
||||||
* @param forumName 吧名
|
* @param forumName 吧名
|
||||||
* @param page 分页页码(从 1 开始)
|
* @param page 分页页码(从 1 开始)
|
||||||
* @param sortType 排序类型 [com.huanchengfly.tieba.api.ForumSortType]
|
* @param sortType 排序类型 [com.huanchengfly.tieba.post.api.ForumSortType]
|
||||||
* @param goodClassifyId 精品贴分类 ID
|
* @param goodClassifyId 精品贴分类 ID
|
||||||
*/
|
*/
|
||||||
fun forumPage(
|
fun forumPage(
|
||||||
|
|
@ -1222,7 +1222,7 @@ interface ITiebaApi {
|
||||||
*
|
*
|
||||||
* @param uid 用户 ID
|
* @param uid 用户 ID
|
||||||
*/
|
*/
|
||||||
fun profileFlow(
|
fun userProfileFlow(
|
||||||
uid: Long
|
uid: Long
|
||||||
): Flow<ProfileResponse>
|
): Flow<ProfileResponse>
|
||||||
}
|
}
|
||||||
|
|
@ -975,7 +975,7 @@ object MixedTiebaApiImpl : ITiebaApi {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun profileFlow(uid: Long): Flow<ProfileResponse> {
|
override fun userProfileFlow(uid: Long): Flow<ProfileResponse> {
|
||||||
val selfUid = AccountUtil.getUid()?.toLongOrNull()
|
val selfUid = AccountUtil.getUid()?.toLongOrNull()
|
||||||
val isSelf = selfUid == uid
|
val isSelf = selfUid == uid
|
||||||
return RetrofitTiebaApi.OFFICIAL_PROTOBUF_TIEBA_API.profileFlow(
|
return RetrofitTiebaApi.OFFICIAL_PROTOBUF_TIEBA_API.profileFlow(
|
||||||
|
|
@ -987,6 +987,7 @@ object MixedTiebaApiImpl : ITiebaApi {
|
||||||
friend_uid_portrait = "",
|
friend_uid_portrait = "",
|
||||||
has_plist = 1,
|
has_plist = 1,
|
||||||
is_from_usercenter = 1,
|
is_from_usercenter = 1,
|
||||||
|
is_guest = if (isSelf) 0 else 1,
|
||||||
need_post_count = 1,
|
need_post_count = 1,
|
||||||
page = 2,
|
page = 2,
|
||||||
pn = 1,
|
pn = 1,
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,16 @@ object StringUtil {
|
||||||
} else "http://tb.himg.baidu.com/sys/portrait/item/$portrait"
|
} else "http://tb.himg.baidu.com/sys/portrait/item/$portrait"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getBigAvatarUrl(portrait: String?): String {
|
||||||
|
if (portrait.isNullOrEmpty()) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return if (portrait.startsWith("http://") || portrait.startsWith("https://")) {
|
||||||
|
portrait
|
||||||
|
} else "http://tb.himg.baidu.com/sys/portraith/item/$portrait"
|
||||||
|
}
|
||||||
|
|
||||||
fun String.getShortNumString(): String {
|
fun String.getShortNumString(): String {
|
||||||
val long = toLongOrNull() ?: return ""
|
val long = toLongOrNull() ?: return ""
|
||||||
return long.getShortNumString()
|
return long.getShortNumString()
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ message ProfileRequestData {
|
||||||
optional string friend_uid_portrait = 16;
|
optional string friend_uid_portrait = 16;
|
||||||
uint32 has_plist = 8;
|
uint32 has_plist = 8;
|
||||||
int32 is_from_usercenter = 14;
|
int32 is_from_usercenter = 14;
|
||||||
|
uint32 is_guest = 4;
|
||||||
uint32 need_post_count = 2;
|
uint32 need_post_count = 2;
|
||||||
int32 page = 15;
|
int32 page = 15;
|
||||||
uint32 pn = 6;
|
uint32 pn = 6;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ message User {
|
||||||
int32 is_manager = 11;
|
int32 is_manager = 11;
|
||||||
int32 is_bawu = 25;
|
int32 is_bawu = 25;
|
||||||
string bawu_type = 26;
|
string bawu_type = 26;
|
||||||
|
string portraith = 27;
|
||||||
int32 fans_num = 30;
|
int32 fans_num = 30;
|
||||||
int32 concern_num = 31;
|
int32 concern_num = 31;
|
||||||
int32 sex = 32;
|
int32 sex = 32;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue