|
|
@@ -0,0 +1,197 @@
|
|
|
+package com.sheep.gamegroup.module.home.fragment;
|
|
|
+
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
+import android.support.v4.app.FragmentTransaction;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.kfzs.duanduan.utils.NumberFormatUtils;
|
|
|
+import com.sheep.gamegroup.event.BigEvent;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.MessageUnReadEntity;
|
|
|
+import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.activity.ActMsg;
|
|
|
+import com.sheep.gamegroup.view.dialog.DialogNotificationOfArrival;
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtFind;
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtPersonalCenter;
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtSmallSheep;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
+
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
+
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.OnClick;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
+
|
|
|
+public class FgtMainHeader extends BaseFragment {
|
|
|
+
|
|
|
+ @BindView(R.id.iv_user_face)
|
|
|
+ ImageView iv_user_face;
|
|
|
+ @BindView(R.id.tv_nickname)
|
|
|
+ TextView tv_nickname;
|
|
|
+ @BindView(R.id.tv_user_asset)
|
|
|
+ TextView tv_user_asset;
|
|
|
+ @BindView(R.id.tv_msg_count)
|
|
|
+ TextView tv_msg_count;
|
|
|
+ @BindView(R.id.iv_flag_vip)
|
|
|
+ ImageView iv_flag_vip;
|
|
|
+ @BindView(R.id.v_red_dot)
|
|
|
+ View v_red_dot;
|
|
|
+ @BindView(R.id.show_hide_pwd_btn)
|
|
|
+ ImageView show_hide_pwd_btn;
|
|
|
+
|
|
|
+ private UserEntity user;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutId() {
|
|
|
+ return R.layout.fgt_main_header;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle bundle) {
|
|
|
+ super.onCreate(bundle);
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ show_hide_pwd_btn.setImageResource(R.mipmap.pwd_hide);
|
|
|
+ tv_user_asset.setText("****");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onViewCreated() {
|
|
|
+ getUnReadMessageCounts();
|
|
|
+ ViewUtil.setVisibility(v_red_dot, SpUtils.isVoucherFirst());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
+ super.onViewCreated(view, savedInstanceState);
|
|
|
+ user = DataUtil.getInstance().getUserEntity();
|
|
|
+ if (user != null) {
|
|
|
+ showUserProfile();
|
|
|
+ } else {
|
|
|
+ CommonUtil.getInstance().getUserInfo(false, (userEntity) -> {
|
|
|
+ user = userEntity;
|
|
|
+ showUserProfile();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showUserProfile() {
|
|
|
+ GlideImageLoader.setAvatar(iv_user_face, user.getAvatar(), Color.argb(128, 255, 255, 255));
|
|
|
+ ViewUtil.setVisibility(iv_flag_vip, user.isVIP());
|
|
|
+ ViewUtil.setText(tv_nickname, user.getNickname());
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.show_hide_pwd_btn)
|
|
|
+ public void showAsset(View v) {
|
|
|
+ ImageView btn = (ImageView) v;
|
|
|
+ btn.setSelected(!btn.isSelected());
|
|
|
+ if (btn.isSelected()) {
|
|
|
+ btn.setImageResource(R.mipmap.pwd_show);
|
|
|
+ tv_user_asset.setText(String.format(Locale.CHINA, "%s\u0020元", NumberFormatUtils.retainMost2W(user.getBalance())));
|
|
|
+ } else {
|
|
|
+ btn.setImageResource(R.mipmap.pwd_hide);
|
|
|
+ tv_user_asset.setText("****");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.iv_user_face)
|
|
|
+ public void onFaceClick() {
|
|
|
+ Jump2View.getInstance().goPersonnalCenterView(getActivity(), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.iv_msg)
|
|
|
+ public void onMsgClick() {
|
|
|
+ startActivity(new Intent(getActivity(), ActMsg.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.iv_download)
|
|
|
+ public void onDownloadClick() {
|
|
|
+ Jump2View.getInstance().goActDownloadManager(getActivity());
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.iv_search)
|
|
|
+ public void onSearchClick() {
|
|
|
+ Jump2View.getInstance().goActSearch(getActivity());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取是否有未读消息并更新图标
|
|
|
+ */
|
|
|
+ private void getUnReadMessageCounts() {
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getMessageUnReadNum(DataUtil.getInstance().getUserId())
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ MessageUnReadEntity entity = baseMessage.getData(MessageUnReadEntity.class);
|
|
|
+ if (entity != null && entity.getNum() > 0) {
|
|
|
+ ViewUtil.setVisibility(tv_msg_count, true);
|
|
|
+ ViewUtil.setText(tv_msg_count, entity.getNum());
|
|
|
+ DialogNotificationOfArrival.checkNotificationOfArrivalList(getActivity());
|
|
|
+ } else {
|
|
|
+ ViewUtil.setVisibility(tv_msg_count, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe
|
|
|
+ public void onEventMainThread(BigEvent event) {
|
|
|
+ switch (event.getEventTypes()) {
|
|
|
+ case FGT_SHEEP_HOME_MESSAGE_COUNT:
|
|
|
+ if (getActivity() != null) {
|
|
|
+ getActivity().runOnUiThread(() -> getUnReadMessageCounts());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static final String KEY_HAS_APPOINT_TASK = "hasAppointTask";
|
|
|
+
|
|
|
+ @Subscribe
|
|
|
+ public void whenPersonVoucherClick(FgtPersonalCenter.PersonVoucherClickEvent ev) {
|
|
|
+ ViewUtil.setVisibility(v_red_dot, DataUtil.getAsBoolean(KEY_HAS_APPOINT_TASK, false));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|