Commit 4073a6b4 by 段启岩

用户信息对接完成

parent 688455d7
......@@ -7,12 +7,20 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import javax.inject.Inject;
import cn.yunliyunwai.beyondclouds.R;
import cn.yunliyunwai.beyondclouds.base.BaseFragment;
import cn.yunliyunwai.beyondclouds.databinding.FragmentMyBinding;
import cn.yunliyunwai.beyondclouds.util.ContextUtils;
import cn.yunliyunwai.beyondclouds.util.GlideRoundTransform;
import cn.yunliyunwai.beyondclouds.util.ViewModelUtils;
import cn.yunliyunwai.beyondclouds.viewmodel.AuthenticationViewModel;
import cn.yunliyunwai.beyondclouds.viewmodel.MyFragmentViewModel;
......@@ -24,11 +32,6 @@ public class MyFragment extends BaseFragment<MyFragmentViewModel, FragmentMyBind
AuthenticationViewModel authenticationViewModel;
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
protected void initInject() {
ContextUtils.getAppComponent(requireActivity()).inject(this);
}
......@@ -49,4 +52,30 @@ public class MyFragment extends BaseFragment<MyFragmentViewModel, FragmentMyBind
binding.setAuthViewModel(authenticationViewModel);
binding.setLifecycleOwner(this);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bindEventListenersAndObservers();
}
private void bindEventListenersAndObservers() {
authenticationViewModel.getAuthenticationState().observe(this, new Observer<AuthenticationViewModel.AuthenticationState>() {
@Override
public void onChanged(AuthenticationViewModel.AuthenticationState authenticationState) {
String userAvatar = authenticationViewModel.getUserInfo().getUserAvatar();
if (authenticationState == AuthenticationViewModel.AuthenticationState.AUTHENTICATED) {
RequestOptions glideRequestOptions = new RequestOptions()
.centerCrop()
.placeholder(R.drawable.placeholder_rectangle)
.error(R.drawable.placeholder_rectangle)
.priority(Priority.HIGH)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.transform(new GlideRoundTransform(26));
Glide.with(getContext()).load(userAvatar).apply(glideRequestOptions).into(binding.imgUserAvatar);
}
}
});
}
}
......@@ -41,8 +41,9 @@
android:layout_marginTop="24dp"
android:layout_marginStart="11dp"
android:layout_marginLeft="11dp"
android:layout_width="51dp"
android:layout_height="51dp"
android:layout_width="52dp"
android:layout_height="52dp"
android:onClick="@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? null : NavHandlers::toLogin}"
android:src="@drawable/un_sign_in" />
<TextView
android:id="@+id/txt_user_nick"
......@@ -64,9 +65,10 @@
app:layout_constraintStart_toEndOf="@id/img_user_avatar"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:text="领取活跃积分"
android:text='@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? authViewModel.userInfo.signature : @string/signature_un_login}'
android:textColor="#999999"
android:textSize="12sp"
android:onClick="@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? null : NavHandlers::toLogin}"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
......@@ -78,6 +80,7 @@
android:layout_marginEnd="11dp"
android:layout_marginRight="11dp"
android:layout_width="40dp"
android:onClick="@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? null : NavHandlers::toLogin}"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="start|center_vertical"
......@@ -112,6 +115,7 @@
android:layout_marginLeft="54dp"
app:layout_constraintHorizontal_chainStyle="spread_inside"
android:layout_marginTop="28dp"
android:onClick="@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? null : NavHandlers::toLogin}"
android:layout_width="wrap_content"
android:layout_height="45dp">
<TextView
......@@ -123,7 +127,7 @@
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/txt_follow_num"
android:text="0"
android:text='@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? authViewModel.userInfo.statistics.followedNum : 0}'
android:textColor="#333333"
android:textSize="18sp"
android:layout_gravity="bottom|center_horizontal"
......@@ -138,6 +142,7 @@
app:layout_constraintStart_toEndOf="@id/btn_follow_num"
app:layout_constraintEnd_toStartOf="@id/btn_fans_num"
android:layout_marginTop="28dp"
android:onClick="@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? null : NavHandlers::toLogin}"
android:layout_width="wrap_content"
android:layout_height="45dp">
<TextView
......@@ -149,7 +154,7 @@
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/txt_visit_num"
android:text="0"
android:text='@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? authViewModel.userInfo.statistics.visitedNum : 0}'
android:textColor="#333333"
android:textSize="18sp"
android:layout_gravity="bottom|center_horizontal"
......@@ -166,6 +171,7 @@
android:layout_marginEnd="54dp"
android:layout_marginRight="54dp"
android:layout_marginTop="28dp"
android:onClick="@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? null : NavHandlers::toLogin}"
android:layout_width="wrap_content"
android:layout_height="45dp">
<TextView
......@@ -177,7 +183,7 @@
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/txt_fans_num"
android:text="0"
android:text='@{authViewModel.authenticationState == AuthenticationState.AUTHENTICATED ? authViewModel.userInfo.statistics.fansNum : 0}'
android:textColor="#333333"
android:textSize="18sp"
android:layout_gravity="bottom|center_horizontal"
......
<resources>
<string name="app_name">云里云外</string>
<!-- fragment_my.xml start -->
<!-- activity_login.xml start -->
<string name="click_to_login">点击登录</string>
<string name="title_login">登录</string>
<string name="login_way_password">密码登录</string>
......@@ -20,7 +20,9 @@
<string name="copyright">Copyright © 2019 云里云外开源社区 All Rights Reserved</string>
<string name="third_party_login">第三方登录</string>
<string name="to_register">去注册</string>
<!-- fragment_my.xml end -->
<!-- activity_login.xml end -->
<string name="signature_un_login">领取活跃积分</string>
<!-- icons start -->
<string name="icon_arrow_right">&#xe61a;</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment