Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
HBHAndroid
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨秀秀
HBHAndroid
Commits
20094435
Commit
20094435
authored
Feb 27, 2024
by
小费同学阿
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
商户端
头像更新fixd
parent
f0b0ebaf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
19 deletions
+69
-19
MineFragment.java
...rc/main/java/com/xx/hbhconsumer/ui/mine/MineFragment.java
+40
-5
MineViewModel.java
...c/main/java/com/xx/hbhconsumer/ui/mine/MineViewModel.java
+22
-11
dialog_change_avatar.xml
consumer/src/main/res/layout/dialog_change_avatar.xml
+2
-1
fragment_mine.xml
consumer/src/main/res/layout/fragment_mine.xml
+5
-2
No files found.
consumer/src/main/java/com/xx/hbhconsumer/ui/mine/MineFragment.java
View file @
20094435
package
com
.
xx
.
hbhconsumer
.
ui
.
mine
;
package
com
.
xx
.
hbhconsumer
.
ui
.
mine
;
import
static
com
.
xx
.
hbhconsumer
.
utils
.
RetrofitClient
.
baseImgUrl
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.lifecycle.Observer
;
import
androidx.lifecycle.Observer
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.load.resource.bitmap.RoundedCorners
;
import
com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
;
import
com.bumptech.glide.request.RequestOptions
;
import
com.xx.hbhconsumer.BR
;
import
com.xx.hbhconsumer.BR
;
import
com.xx.hbhconsumer.R
;
import
com.xx.hbhconsumer.R
;
import
com.xx.hbhconsumer.data.http.requst.MineRequest
;
import
com.xx.hbhconsumer.data.http.requst.MineRequest
;
import
com.xx.hbhconsumer.data.local.LocalData
;
import
com.xx.hbhconsumer.databinding.FragmentMineBinding
;
import
com.xx.hbhconsumer.databinding.FragmentMineBinding
;
import
com.xx.hbhconsumer.utils.RetrofitClient
;
import
com.xx.hbhconsumer.utils.RetrofitClient
;
...
@@ -30,7 +37,12 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
...
@@ -30,7 +37,12 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
public
int
initContentView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
public
int
initContentView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
return
R
.
layout
.
fragment_mine
;
return
R
.
layout
.
fragment_mine
;
}
}
@Override
public
void
onResume
()
{
super
.
onResume
();
}
@Override
@Override
public
int
initVariableId
()
{
public
int
initVariableId
()
{
return
BR
.
mineViewModel
;
return
BR
.
mineViewModel
;
...
@@ -40,10 +52,33 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
...
@@ -40,10 +52,33 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
@Override
@Override
public
void
initData
()
{
public
void
initData
()
{
super
.
initData
();
super
.
initData
();
viewModel
.
integralTotal
.
observe
(
this
,
integralTotal
->
binding
.
tvPoint
.
setText
(
String
.
valueOf
(
integralTotal
)));
viewModel
.
integralTotal
.
observe
(
this
,
integralTotal
->
binding
.
tvPoint
.
setText
(
String
.
valueOf
(
integralTotal
)));
viewModel
.
memberCoupon
.
observe
(
this
,
memberCoupon
->
binding
.
tvCouponNum
.
setText
(
String
.
valueOf
(
memberCoupon
)));
viewModel
.
memberCoupon
.
observe
(
this
,
memberCoupon
->
binding
.
tvCouponNum
.
setText
(
String
.
valueOf
(
memberCoupon
)));
viewModel
.
memberName
.
observe
(
this
,
memberName
->
binding
.
tvMemberName
.
setText
(
memberName
));
viewModel
.
memberName
.
observe
(
this
,
memberName
->
binding
.
tvMemberName
.
setText
(
memberName
));
/*控制台拿到了图片路径了*/
/*如果图片有刷新就会进行更新*/
viewModel
.
avatarImageUrl
.
observe
(
this
,
new
Observer
<
String
>()
{
@Override
public
void
onChanged
(
String
imageUrl
)
{
if
(!
StringUtils
.
isEmpty
(
imageUrl
))
{
// 设置圆角半径
int
radius
=
120
;
// 创建圆角转换器
RoundedCorners
roundedCorners
=
new
RoundedCorners
(
radius
);
// 创建Glide请求选项
RequestOptions
requestOptions
=
RequestOptions
.
bitmapTransform
(
roundedCorners
);
// 使用Glide加载图片并应用圆角转换器
Glide
.
with
(
MineFragment
.
this
)
.
load
(
baseImgUrl
+
imageUrl
)
.
apply
(
requestOptions
)
.
transition
(
DrawableTransitionOptions
.
withCrossFade
())
.
into
(
binding
.
ivAvatar
);
}
else
{
}
}
});
viewModel
.
collectionBean
.
observe
(
this
,
collectionBean
->
{
viewModel
.
collectionBean
.
observe
(
this
,
collectionBean
->
{
if
(
collectionBean
!=
null
)
{
if
(
collectionBean
!=
null
)
{
ViewGroup
.
LayoutParams
layoutParams
=
binding
.
ivCollectionImg
.
getLayoutParams
();
ViewGroup
.
LayoutParams
layoutParams
=
binding
.
ivCollectionImg
.
getLayoutParams
();
...
@@ -53,7 +88,7 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
...
@@ -53,7 +88,7 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
binding
.
ivCollectionImg
.
setLayoutParams
(
layoutParams
);
binding
.
ivCollectionImg
.
setLayoutParams
(
layoutParams
);
Glide
.
with
(
this
)
Glide
.
with
(
this
)
.
load
(
RetrofitClient
.
baseImgUrl
+
collectionBean
.
getFilePath
())
.
load
(
baseImgUrl
+
collectionBean
.
getFilePath
())
.
into
(
binding
.
ivCollectionImg
);
.
into
(
binding
.
ivCollectionImg
);
}
}
});
});
...
@@ -62,11 +97,11 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
...
@@ -62,11 +97,11 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
if
(
userBean
!=
null
)
{
if
(
userBean
!=
null
)
{
binding
.
etNickname
.
setText
(
userBean
.
getNickName
());
binding
.
etNickname
.
setText
(
userBean
.
getNickName
());
if
(!
StringUtils
.
isEmpty
(
userBean
.
getAvatar
()))
{
/*
if (!StringUtils.isEmpty(userBean.getAvatar())) {
Glide.with(this)
Glide.with(this)
.
load
(
RetrofitClient
.
baseImgUrl
+
userBean
.
getAvatar
())
.load(baseImgUrl + userBean.getAvatar())
.into(binding.ivAvatar);
.into(binding.ivAvatar);
}
}
*/
}
}
...
...
consumer/src/main/java/com/xx/hbhconsumer/ui/mine/MineViewModel.java
View file @
20094435
...
@@ -7,6 +7,7 @@ import android.view.View;
...
@@ -7,6 +7,7 @@ import android.view.View;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.databinding.ObservableField
;
import
androidx.databinding.ObservableField
;
import
androidx.lifecycle.LiveData
;
import
androidx.lifecycle.MutableLiveData
;
import
androidx.lifecycle.MutableLiveData
;
import
com.huantansheng.easyphotos.callback.SelectCallback
;
import
com.huantansheng.easyphotos.callback.SelectCallback
;
...
@@ -42,10 +43,12 @@ import me.goldze.mvvmhabit.utils.RxUtils;
...
@@ -42,10 +43,12 @@ import me.goldze.mvvmhabit.utils.RxUtils;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
public
class
MineViewModel
extends
BaseViewModel
<
MineRequest
>
{
public
class
MineViewModel
extends
BaseViewModel
<
MineRequest
>
{
//头像的绑定
public
MutableLiveData
<
String
>
avatarImageUrl
=
new
MutableLiveData
<>();
public
MutableLiveData
<
CollectionBean
>
collectionBean
=
new
MutableLiveData
<>(
null
);
//昵称的绑定
//昵称的绑定
public
MutableLiveData
<
Boolean
>
nickNameEditFlag
=
new
MutableLiveData
<>(
false
);
public
MutableLiveData
<
Boolean
>
nickNameEditFlag
=
new
MutableLiveData
<>(
false
);
public
ObservableField
<
String
>
nickName
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
nickName
=
new
ObservableField
<>(
""
);
public
MutableLiveData
<
CollectionBean
>
collectionBean
=
new
MutableLiveData
<>(
null
);
public
MutableLiveData
<
Integer
>
integralTotal
=
new
MutableLiveData
<>(
0
);
public
MutableLiveData
<
Integer
>
integralTotal
=
new
MutableLiveData
<>(
0
);
public
MutableLiveData
<
String
>
memberCoupon
=
new
MutableLiveData
<>(
"0"
);
public
MutableLiveData
<
String
>
memberCoupon
=
new
MutableLiveData
<>(
"0"
);
public
MutableLiveData
<
String
>
memberName
=
new
MutableLiveData
<>(
"0"
);
public
MutableLiveData
<
String
>
memberName
=
new
MutableLiveData
<>(
"0"
);
...
@@ -58,6 +61,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -58,6 +61,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
public
MutableLiveData
<
Boolean
>
hasUnReadMessage
=
new
MutableLiveData
<>(
false
);
public
MutableLiveData
<
Boolean
>
hasUnReadMessage
=
new
MutableLiveData
<>(
false
);
ChangeAvatarDialog
changeAvatarDialog
;
ChangeAvatarDialog
changeAvatarDialog
;
/*获取会员头像路径*/
File
file
=
new
File
(
""
);
public
MineViewModel
(
@NonNull
Application
application
)
{
public
MineViewModel
(
@NonNull
Application
application
)
{
super
(
application
);
super
(
application
);
...
@@ -107,12 +112,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -107,12 +112,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
startPhotoPage
(
true
,
new
SelectCallback
()
{
startPhotoPage
(
true
,
new
SelectCallback
()
{
@Override
@Override
public
void
onResult
(
ArrayList
<
Photo
>
photos
,
boolean
isOriginal
)
{
public
void
onResult
(
ArrayList
<
Photo
>
photos
,
boolean
isOriginal
)
{
file
=
new
File
(
photos
.
get
(
0
).
path
);
/*Bitmap mBitmap = BitmapFactory.decodeFile(photos.get(0).path);*/
File
file
=
new
File
(
photos
.
get
(
0
).
path
);
model
.
upLoadFile
(
file
).
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
model
.
upLoadFile
(
file
).
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
@Override
@Override
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
showDialog
(
"请稍等"
);
showDialog
(
"请稍等"
);
...
@@ -122,7 +125,6 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -122,7 +125,6 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
public
void
onSuccess
(
List
<
Filebean
>
resultBean
)
{
public
void
onSuccess
(
List
<
Filebean
>
resultBean
)
{
changeAvatarDialog
.
dismiss
();
changeAvatarDialog
.
dismiss
();
dismissDialog
();
dismissDialog
();
uploadPicture
(
resultBean
.
get
(
0
).
getBusinessId
());
uploadPicture
(
resultBean
.
get
(
0
).
getBusinessId
());
}
}
...
@@ -145,7 +147,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -145,7 +147,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
private
void
uploadPicture
(
String
memberPicture
)
{
private
void
uploadPicture
(
String
memberPicture
)
{
model
.
uploadPicture
(
memberPicture
).
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
model
.
uploadPicture
(
memberPicture
).
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
@Override
@Override
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
}
}
...
@@ -154,6 +156,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -154,6 +156,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
public
void
onSuccess
(
Integer
resultBean
)
{
public
void
onSuccess
(
Integer
resultBean
)
{
dismissDialog
();
dismissDialog
();
ToastUtils
.
showShort
(
"修改成功"
);
ToastUtils
.
showShort
(
"修改成功"
);
/*最后执行这个*/
memberInfo
();
getUserInfo
();
getUserInfo
();
changeAvatarDialog
.
dismiss
();
changeAvatarDialog
.
dismiss
();
}
}
...
@@ -205,8 +209,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -205,8 +209,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}).
subscribe
(
new
ApiDisposableObserver
<
String
>()
{
}).
subscribe
(
new
ApiDisposableObserver
<
String
>()
{
@Override
@Override
public
void
onSuccess
(
String
resultBean
)
{
public
void
onSuccess
(
String
resultBean
)
{
ToastUtils
.
showShort
(
"修改成功"
);
ToastUtils
.
showShort
(
"修改成功"
);
getUserInfo
();
getUserInfo
();
}
}
@Override
@Override
...
@@ -227,7 +231,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -227,7 +231,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
File
file
=
new
File
(
photos
.
get
(
0
).
path
);
File
file
=
new
File
(
photos
.
get
(
0
).
path
);
model
.
upLoadFile
(
file
).
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
model
.
upLoadFile
(
file
).
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
@Override
@Override
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
showDialog
(
"请稍等"
);
showDialog
(
"请稍等"
);
...
@@ -235,6 +239,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -235,6 +239,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}).
subscribe
(
new
ApiDisposableObserver
<
List
<
Filebean
>>()
{
}).
subscribe
(
new
ApiDisposableObserver
<
List
<
Filebean
>>()
{
@Override
@Override
public
void
onSuccess
(
List
<
Filebean
>
resultBean
)
{
public
void
onSuccess
(
List
<
Filebean
>
resultBean
)
{
uploadPicture
(
resultBean
.
get
(
0
).
getBusinessId
());
ToastUtils
.
showShort
(
"修改成功"
);
ToastUtils
.
showShort
(
"修改成功"
);
changeAvatarDialog
.
dismiss
();
changeAvatarDialog
.
dismiss
();
dismissDialog
();
dismissDialog
();
...
@@ -257,7 +262,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -257,7 +262,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}
}
/**
/**
*
获取积分
* 获取积分
*/
*/
private
void
memberInfo
()
{
private
void
memberInfo
()
{
model
.
memberInfo
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
model
.
memberInfo
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
...
@@ -266,10 +271,14 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -266,10 +271,14 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}).
subscribe
(
new
ApiDisposableObserver
<
MemberInfoBean
>()
{
}).
subscribe
(
new
ApiDisposableObserver
<
MemberInfoBean
>()
{
@Override
@Override
public
void
onSuccess
(
MemberInfoBean
resultBean
)
{
public
void
onSuccess
(
MemberInfoBean
resultBean
)
{
Log
.
v
(
"头像头像"
,
resultBean
.
getMemberPicture
());
/*头像赋值*/
avatarImageUrl
.
setValue
(
resultBean
.
getMemberPicture
());
integralTotal
.
postValue
(
resultBean
.
getUsableIntegral
());
integralTotal
.
postValue
(
resultBean
.
getUsableIntegral
());
memberCoupon
.
postValue
(
resultBean
.
getMemberCoupon
());
memberCoupon
.
postValue
(
resultBean
.
getMemberCoupon
());
memberName
.
postValue
(
resultBean
.
getGradeName
());
memberName
.
postValue
(
resultBean
.
getGradeName
());
}
}
@Override
@Override
public
void
onError
(
String
Error
)
{
public
void
onError
(
String
Error
)
{
dismissDialog
();
dismissDialog
();
...
@@ -347,9 +356,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -347,9 +356,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
roleName
.
set
(
LocalData
.
getUser
().
getRoles
().
get
(
0
).
getRoleName
());
roleName
.
set
(
LocalData
.
getUser
().
getRoles
().
get
(
0
).
getRoleName
());
}
}
public
void
refreshNickName
()
{
public
void
refreshNickName
()
{
setValueToNickName
();
setValueToNickName
();
}
}
//跳转修改密码界面
//跳转修改密码界面
public
BindingCommand
goMyCoupon
=
new
BindingCommand
(
new
BindingAction
()
{
public
BindingCommand
goMyCoupon
=
new
BindingCommand
(
new
BindingAction
()
{
@Override
@Override
...
...
consumer/src/main/res/layout/dialog_change_avatar.xml
View file @
20094435
...
@@ -48,7 +48,8 @@
...
@@ -48,7 +48,8 @@
<TextView
<TextView
android:id=
"@+id/tv_photo"
android:id=
"@+id/tv_photo"
android:layout_width=
"wrap_content"
android:layout_width=
"match_parent"
android:gravity=
"center"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"20dp"
android:layout_marginTop=
"20dp"
...
...
consumer/src/main/res/layout/fragment_mine.xml
View file @
20094435
...
@@ -67,10 +67,13 @@
...
@@ -67,10 +67,13 @@
<ImageView
<ImageView
android:id=
"@+id/iv_avatar"
android:id=
"@+id/iv_avatar"
android:layout_width=
"80dp"
android:layout_width=
"88dp"
android:layout_height=
"80dp"
android:layout_height=
"88dp"
android:contentDescription=
"TODO"
android:scaleType=
"fitXY"
android:layout_centerVertical=
"true"
android:layout_centerVertical=
"true"
android:src=
"@mipmap/wode_img_morentouxiang"
android:src=
"@mipmap/wode_img_morentouxiang"
tools:ignore=
"ContentDescription,HardcodedText"
android:onClick=
"@{mineViewModel.changeAvatar}"
/>
android:onClick=
"@{mineViewModel.changeAvatar}"
/>
<RelativeLayout
<RelativeLayout
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment