|
|
@@ -470,6 +470,191 @@ public class FgtSmallSheep extends BaseFragment implements SmallSheepContract.Vi
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * @return 是否显示兑换邀请码红包
|
|
|
+ */
|
|
|
+ private void isShowRedPackageWithCode() {
|
|
|
+ // DataUtil.getInstance().是官方包吗();
|
|
|
+ if (userEntity == null) {
|
|
|
+ userEntity = DataUtil.getInstance().getUserEntity();
|
|
|
+ }
|
|
|
+//userEntity.getParent_code()获取到的不会存在null,没有时,时"",所以不用判断为null的情况
|
|
|
+ if (!userEntity.getParent_code().equals("") || (userEntity.getCreate_time_line() < 2) || (userEntity.getPackage_cate() == 1)) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ changeRedPackage(getActivity(), LayoutInflater.from(getContext()).inflate(R.layout.activity_main, null), this);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 兑换红包弹窗
|
|
|
+ *
|
|
|
+ * @param mActivity 当前Activity的,
|
|
|
+ */
|
|
|
+ public static void changeRedPackage(final Activity mActivity, View viewAnchor, final FgtSmallSheep fgtSmallSheep) {
|
|
|
+ View view = LayoutInflater.from(mActivity).inflate(R.layout.pop_get_redpackage, null);
|
|
|
+ final EditText edInvitationCode = view.findViewById(R.id.ed_invitation_code);
|
|
|
+ TextView tvTitle = view.findViewById(R.id.tv_title);
|
|
|
+ final TextView tvGetRedPackage = view.findViewById(R.id.tv_get_redpackage);
|
|
|
+ ImageView ivClose = view.findViewById(R.id.iv_close);
|
|
|
+ final PopupWindow popupWindow = new PopupWindow(mActivity);
|
|
|
+ popupWindow.setContentView(view);
|
|
|
+ popupWindow.setWidth(ActionBar.LayoutParams.MATCH_PARENT);
|
|
|
+ popupWindow.setHeight(ActionBar.LayoutParams.MATCH_PARENT);
|
|
|
+ popupWindow.setTouchable(true);
|
|
|
+ popupWindow.setFocusable(true);
|
|
|
+ popupWindow.setOutsideTouchable(false);
|
|
|
+ popupWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ backgroundAlpha(0.7f, mActivity);
|
|
|
+ try {
|
|
|
+ popupWindow.showAtLocation(viewAnchor, Gravity.CENTER, 0, 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ popupWindow.setOnDismissListener(new ViewUtil.PopDismissListener(mActivity));
|
|
|
+ tvTitle.setText("邀请码领取,金额更大");
|
|
|
+ tvGetRedPackage.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (TextUtils.isEmpty(edInvitationCode.getText())) {
|
|
|
+ G.showToast("邀请码不能为空!");
|
|
|
+ } else {
|
|
|
+ fgtSmallSheep.getRedPackage(edInvitationCode.getText().toString(), popupWindow);
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ edInvitationCode.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onLongClick(View view) {
|
|
|
+ // 获取系统剪贴板
|
|
|
+ ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
+ // 获取剪贴板的剪贴数据集
|
|
|
+ ClipData clipData = clipboard.getPrimaryClip();
|
|
|
+
|
|
|
+ if (clipData != null && clipData.getItemCount() > 0) {
|
|
|
+ // 从数据集中获取(粘贴)第一条文本数据
|
|
|
+ CharSequence codetext = clipData.getItemAt(0).getText();
|
|
|
+ if (!TextUtils.isEmpty(codetext)){
|
|
|
+ edInvitationCode.setText(codetext);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ivClose.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 兑换红包
|
|
|
+ *
|
|
|
+ * @param code ,邀请码
|
|
|
+ */
|
|
|
+ public void getRedPackage(String code, final PopupWindow popupWindow) {
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().exchangeRedPackage(code)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ LogUtil.logI("0------" + new Gson().toJson(baseMessage));
|
|
|
+ G.showToast(baseMessage.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ showRedPackageAfterInvitation(activity, LayoutInflater.from(getContext()).inflate(R.layout.activity_main, null), baseMessage);
|
|
|
+ if (popupWindow.isShowing()) {
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 邀请成功后在个人资料显示领红包弹窗
|
|
|
+ *
|
|
|
+ * @param mActivity 当前Activity
|
|
|
+ */
|
|
|
+ public void showRedPackageAfterInvitation(final Activity mActivity, View viewAnchor, BaseMessage baseMessage) {
|
|
|
+ if (viewAnchor == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ View view = LayoutInflater.from(mActivity).inflate(R.layout.dialog_redpackage_after_invitation, null, false);
|
|
|
+ TextView tvGetRedPackage = view.findViewById(R.id.tv_get_redpackage);
|
|
|
+ TextView tvMoney = view.findViewById(R.id.tv_money);
|
|
|
+ ImageView ivClose = view.findViewById(R.id.iv_close);
|
|
|
+ final PopupWindow popupWindow = new PopupWindow(mActivity);
|
|
|
+ popupWindow.setContentView(view);
|
|
|
+ popupWindow.setAnimationStyle(R.style.Rising);
|
|
|
+ popupWindow.setWidth(ActionBar.LayoutParams.MATCH_PARENT);
|
|
|
+ popupWindow.setHeight(ActionBar.LayoutParams.MATCH_PARENT);
|
|
|
+ popupWindow.setTouchable(true);
|
|
|
+ popupWindow.setFocusable(true);
|
|
|
+ popupWindow.setOutsideTouchable(false);
|
|
|
+ popupWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ backgroundAlpha(0.7f, mActivity);
|
|
|
+ try {
|
|
|
+ popupWindow.showAtLocation(viewAnchor, Gravity.CENTER, 0, 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ popupWindow.setOnDismissListener(new ViewUtil.PopDismissListener(mActivity));
|
|
|
+ tvMoney.setText("1");
|
|
|
+ tvGetRedPackage.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ // CommonUtil.getInstance().updateUserInfo(null);
|
|
|
+ updateUserInfo(null);
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ivClose.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ popupWindow.dismiss();
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateUserInfo(final Action1<UserEntity> action1) {
|
|
|
+ SheepApp.get(SheepApp.getInstance())
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getInfo()
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(null);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ UserEntity userEntity = baseMessage.getData(UserEntity.class);
|
|
|
+ if (userEntity != null) {
|
|
|
+ DataUtil.getInstance().setUserEntity(userEntity);
|
|
|
+ }
|
|
|
+ if (action1 != null)
|
|
|
+ action1.call(userEntity);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 新手任务对话框中,注册账号并登录得红包,这里判断是否已经领取过了,如果领取过了就不显示,不然就显示
|
|
|
*
|
|
|
* @param obj ,Context对象
|