|
|
@@ -7,10 +7,12 @@ import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Looper;
|
|
|
import android.os.Message;
|
|
|
+import android.support.annotation.RequiresApi;
|
|
|
import android.support.design.widget.TabLayout;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
import android.support.v4.widget.NestedScrollView;
|
|
|
@@ -24,7 +26,11 @@ import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.view.animation.Animation;
|
|
|
+import android.view.animation.OvershootInterpolator;
|
|
|
+import android.view.animation.TranslateAnimation;
|
|
|
import android.widget.AdapterView;
|
|
|
+import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.PopupWindow;
|
|
|
@@ -258,10 +264,173 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
|
|
|
|
|
|
}
|
|
|
};
|
|
|
+ /**
|
|
|
+ * @return 是否显示兑换邀请码红包
|
|
|
+ */
|
|
|
+ private void isShowRedPackageWithCode() {
|
|
|
+ // DataUtil.getInstance().是官方包吗();
|
|
|
+ if (userEntity == null) {
|
|
|
+ userEntity = DataUtil.getInstance().getUserEntity();
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ 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对象
|
|
|
+ *
|
|
|
+ * @param obj ,Context对象
|
|
|
*/
|
|
|
public void isShowRedPackages(Context obj) {
|
|
|
if (userEntity == null) {
|
|
|
@@ -280,13 +449,12 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
|
|
|
if (userEntity == null) {
|
|
|
userEntity = DataUtil.getInstance().getUserEntity();
|
|
|
}
|
|
|
- if(userEntity == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- if (SpUtils.getFirst("first"+userEntity.getId())) {
|
|
|
+
|
|
|
+ if (SpUtils.getFirst("first" + userEntity.getId())) {//不是第一次进入APP
|
|
|
+ isShowRedPackageWithCode();//虽然不是第一次,但是邀请码的那个红包还是让它显示
|
|
|
return;
|
|
|
}
|
|
|
- SpUtils.saveFirst("first"+userEntity.getId(), true);
|
|
|
+ SpUtils.saveFirst("first" + userEntity.getId(), true);//第一次登录成功后保存起来,下次进来就不再弹新人红包
|
|
|
if (((userEntity.getNewbie_task_status() & 16) == 0) && userEntity.getIs_new() == 1) {
|
|
|
showRedPackage(getContext());
|
|
|
}
|
|
|
@@ -356,10 +524,23 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
|
|
|
}
|
|
|
});
|
|
|
CommonUtil.getInstance().reflex(tabLayout, activity);
|
|
|
+ setAnimation(ivDuty);
|
|
|
}
|
|
|
|
|
|
private int curPosition = 0;
|
|
|
|
|
|
+ /**
|
|
|
+ * 给请红包浮标设置动画,达到左右晃动
|
|
|
+ * @param imageView 设置动画的imageview
|
|
|
+ */
|
|
|
+ private void setAnimation(ImageView imageView) {
|
|
|
+ TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0);
|
|
|
+ animation.setInterpolator(new OvershootInterpolator());
|
|
|
+ animation.setDuration(150);
|
|
|
+ animation.setRepeatCount(Integer.MAX_VALUE);//根据产品要求,要一直晃动
|
|
|
+ animation.setRepeatMode(Animation.REVERSE);
|
|
|
+ imageView.startAnimation(animation);
|
|
|
+ }
|
|
|
|
|
|
private void loadUserInfo() {
|
|
|
|
|
|
@@ -907,6 +1088,7 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
|
|
|
if(onResumeCount > 0)
|
|
|
refreshTaskList();
|
|
|
onResumeCount++;
|
|
|
+ setAnimation(ivDuty);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1254,6 +1436,7 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
popupWindow.dismiss();
|
|
|
+ isShowRedPackageWithCode();//关闭新人注册红包后,弹出邀请红包
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -1279,11 +1462,13 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
if (popupWindow.isShowing()){
|
|
|
popupWindow.dismiss();
|
|
|
+ isShowRedPackageWithCode();//兑换成功后弹出邀请红包
|
|
|
}
|
|
|
CommonUtil.getInstance().updateUserInfo(null);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 新手任务
|
|
|
*/
|