|
|
@@ -0,0 +1,432 @@
|
|
|
+package com.sheep.gamegroup.view.activity;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
+import android.graphics.Canvas;
|
|
|
+import android.graphics.Matrix;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Environment;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.support.annotation.Nullable;
|
|
|
+import android.support.v7.app.AppCompatActivity;
|
|
|
+import android.support.v7.widget.GridLayoutManager;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.OrientationHelper;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.kfzs.duanduan.cardview.CardScaleHelper;
|
|
|
+import com.sheep.gamegroup.helper.ScalableCardHelper;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
+import com.sheep.gamegroup.model.entity.FriendAndAwardEntity;
|
|
|
+import com.sheep.gamegroup.model.entity.PictureInvitationEntity;
|
|
|
+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.FastJsonUtils;
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.StringUtils;
|
|
|
+import com.sheep.gamegroup.util.ViewHolder;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
+import com.sheep.gamegroup.view.adapter.MyAdapter;
|
|
|
+import com.sheep.gamegroup.view.dialog.DialogShare;
|
|
|
+import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.umeng.socialize.ShareAction;
|
|
|
+import com.umeng.socialize.bean.SHARE_MEDIA;
|
|
|
+import com.umeng.socialize.media.UMImage;
|
|
|
+import com.umeng.socialize.media.UMWeb;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.functions.Action1;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
+
|
|
|
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.LINK_SHARE;
|
|
|
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.QR_COPY;
|
|
|
+import static com.sheep.gamegroup.util.ViewUtil.getNetImgByName;
|
|
|
+
|
|
|
+/**
|
|
|
+ * created on:2018/9/4 on 15:09
|
|
|
+ * created by: YSL
|
|
|
+ * 描述:
|
|
|
+ */
|
|
|
+public class InvitationActivity extends AppCompatActivity implements ScalableCardHelper.OnPageChangeListener {
|
|
|
+ @BindView(R.id.ask_share_list)
|
|
|
+ RecyclerView ask_share_list;
|
|
|
+ @BindView(R.id.recyclerView)
|
|
|
+ RecyclerView mRecyclerView;
|
|
|
+ @BindView(R.id.blurView)
|
|
|
+ ImageView mBlurView;
|
|
|
+ private List<Integer> mList = new ArrayList<>();
|
|
|
+ private CardScaleHelper mCardScaleHelper = null;
|
|
|
+ private Runnable mBlurRunnable;
|
|
|
+ private int mLastPos = -1;//滑动当前的位置
|
|
|
+ private List<String> localPathList = new ArrayList<>();
|
|
|
+ private List<String> RxPathList = new ArrayList<>();
|
|
|
+ private String localPicturePath = Environment.getDataDirectory().getAbsolutePath() + "/pic/+pic";
|
|
|
+ private String localRxPath = Environment.getDataDirectory().getAbsolutePath() + "/rx/+rx";
|
|
|
+
|
|
|
+ GridLayoutManager gridLayoutManager;
|
|
|
+ UserEntity userEntity = DataUtil.getInstance().getUserEntity();
|
|
|
+ private FriendAndAwardEntity mEntity;
|
|
|
+ private String url;
|
|
|
+ private String description;
|
|
|
+ private Bitmap mBitmap;
|
|
|
+ private List<PictureInvitationEntity> mPictureList = new ArrayList<>();
|
|
|
+ private List<File> mPictureFileList = new ArrayList<>();
|
|
|
+ private List<File> mRxFileList = new ArrayList<>();
|
|
|
+ String localPath = "";
|
|
|
+ String localRx = "";
|
|
|
+ private int position = 0;
|
|
|
+ private List<Bitmap> listBitmap = new ArrayList<>();
|
|
|
+ private List<Bitmap> listBitmap1 = new ArrayList<>();
|
|
|
+ private List<Bitmap> listBitmap2 = new ArrayList<>();
|
|
|
+ private MyAdapter adapter;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_invitation);
|
|
|
+ ButterKnife.bind(this);
|
|
|
+ initData();
|
|
|
+ // initPicture();
|
|
|
+ cerateAdapter(listBitmap,this);
|
|
|
+ getPicetureList();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initPicture() {
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
+ mList.add(R.drawable.kaipin);
|
|
|
+ mList.add(R.drawable.kaipin);
|
|
|
+ mList.add(R.drawable.kaipin);
|
|
|
+ }
|
|
|
+
|
|
|
+ // final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
|
|
|
+ // mRecyclerView.setLayoutManager(linearLayoutManager);
|
|
|
+ //mRecyclerView.setAdapter(new CardAdapter(mList));
|
|
|
+ // mRecyclerView绑定scale效果
|
|
|
+ // mCardScaleHelper = new CardScaleHelper();
|
|
|
+ // mCardScaleHelper.setCurrentItemPos(1);
|
|
|
+ // mCardScaleHelper.attachToRecyclerView(mRecyclerView);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param list Bitmap集合
|
|
|
+ * @param context
|
|
|
+ */
|
|
|
+ private void cerateAdapter( List<Bitmap> list, Context context) {
|
|
|
+ adapter = new MyAdapter(context, list);
|
|
|
+ LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
|
|
+ layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
|
|
|
+ mRecyclerView.setLayoutManager(layoutManager);
|
|
|
+ // recyclerView.addItemDecoration(new InvitationPictureAdapter.SpacesItemDecoration(15));
|
|
|
+ mRecyclerView.setAdapter(adapter);
|
|
|
+ ScalableCardHelper cardHelper = new ScalableCardHelper(this);
|
|
|
+ cardHelper.attachToRecyclerView(mRecyclerView);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void init(final String url, final String description) {
|
|
|
+ gridLayoutManager = new GridLayoutManager(this, 5);
|
|
|
+ ask_share_list.setLayoutManager(gridLayoutManager);
|
|
|
+ final List<String> list = ListUtil.emptyList();
|
|
|
+ list.add(DialogShare.FACE_TO_FACE);
|
|
|
+ list.add(DialogShare.WX);
|
|
|
+ list.add(DialogShare.QQ);
|
|
|
+ list.add(DialogShare.WEIXIN_CIRCLE);
|
|
|
+ list.add(DialogShare.COPY_SHARE_LINK);
|
|
|
+ final List<String> imgList = ListUtil.emptyList();
|
|
|
+ imgList.add("share_face_to_face");
|
|
|
+ imgList.add("share_wx");
|
|
|
+ imgList.add("share_qq");
|
|
|
+ imgList.add("share_weixin_circle");
|
|
|
+ imgList.add("share_copy_share_link");
|
|
|
+ final List<String> nameList = ListUtil.emptyList();
|
|
|
+ nameList.add("面对面");
|
|
|
+ nameList.add("微信");
|
|
|
+ nameList.add("QQ好友");
|
|
|
+ nameList.add("朋友圈");
|
|
|
+ nameList.add("复制链接");
|
|
|
+ AdbCommonRecycler<String> adapter = new AdbCommonRecycler<String>(this, list) {
|
|
|
+ @Override
|
|
|
+ public int getViewIdByType(int type) {
|
|
|
+ return R.layout.ask_to_share_item;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void convert(ViewHolder holder, final String item) {
|
|
|
+ View itemView = holder.itemView;
|
|
|
+ if (item == null)
|
|
|
+ return;
|
|
|
+ ImageView ask_to_share_item_img = itemView.findViewById(R.id.ask_to_share_item_img);
|
|
|
+ TextView ask_to_share_item_name = itemView.findViewById(R.id.ask_to_share_item_name);
|
|
|
+ final int position = holder.getAdapterPosition();
|
|
|
+ GlideImageLoader.setImage(ask_to_share_item_img, getNetImgByName(imgList.get(position)));
|
|
|
+ ask_to_share_item_name.setText(nameList.get(position));
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ if (position == 1 || position == 2) {
|
|
|
+ mBitmap = getBitmap();
|
|
|
+ mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.kaipin);
|
|
|
+ popShare(InvitationActivity.this, url, item, description, mBitmap);
|
|
|
+ } else {
|
|
|
+ popShare(InvitationActivity.this, url, item, description, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ ask_share_list.setAdapter(adapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Bitmap getBitmap() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分享 url type 拼接
|
|
|
+ */
|
|
|
+ public String jointString(String url, @DialogShare.SHARE_TYPE String type) {
|
|
|
+ if (url.contains("&type="))
|
|
|
+ return url;
|
|
|
+ switch (type) {
|
|
|
+ case "qq":
|
|
|
+ return url + "&type=2";
|
|
|
+ case "wx":
|
|
|
+ return url + "&type=1";
|
|
|
+ default:
|
|
|
+ return url + "&type=4";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分享
|
|
|
+ *
|
|
|
+ * @param activity
|
|
|
+ * @param url
|
|
|
+ * @param type qq wx all
|
|
|
+ * @param description
|
|
|
+ */
|
|
|
+ public void popShare(Activity activity, final String url, @DialogShare.SHARE_TYPE String type, String description, Bitmap bitmap) {
|
|
|
+ if (activity == null || TextUtils.isEmpty(type) || TextUtils.isEmpty(url)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final String realUrl = jointString(url, type);
|
|
|
+ SHARE_MEDIA share_media;
|
|
|
+ switch (type) {
|
|
|
+ case DialogShare.ALL:
|
|
|
+ ViewUtil.newInstance().showShare(activity, realUrl, description);
|
|
|
+ return;
|
|
|
+ case DialogShare.FACE_TO_FACE:
|
|
|
+ ViewUtil.showQR(activity, realUrl);
|
|
|
+ return;
|
|
|
+ case DialogShare.COPY_SHARE_LINK:
|
|
|
+ LINK_SHARE.onEvent();
|
|
|
+ ViewUtil.showMsgDialog(activity, new DialogConfig().setTitle("分享链接").setMsg(realUrl)
|
|
|
+ .setMsgMore("他人通过该链接加入小绵羊即可成为你的好友").setMsgMoreColor(R.color.txt_black_9e9c9c)
|
|
|
+ .setBtnLeftText("复制链接").setBtnLeftOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ QR_COPY.onEvent();
|
|
|
+ StringUtils.CopyText(realUrl);
|
|
|
+ G.showToast("复制链接成功");
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ return;
|
|
|
+ case DialogShare.QQ:
|
|
|
+ share_media = SHARE_MEDIA.QQ;
|
|
|
+ break;
|
|
|
+ case DialogShare.WX:
|
|
|
+ share_media = SHARE_MEDIA.WEIXIN;
|
|
|
+ break;
|
|
|
+ case DialogShare.WEIXIN_CIRCLE:
|
|
|
+ default:
|
|
|
+ share_media = SHARE_MEDIA.WEIXIN_CIRCLE;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ UMImage umImage = null;
|
|
|
+
|
|
|
+ if (type == DialogShare.QQ || type == DialogShare.WX) {
|
|
|
+ umImage = new UMImage(activity, bitmap);
|
|
|
+ } else {
|
|
|
+ umImage = new UMImage(activity, R.mipmap.icon);
|
|
|
+ }
|
|
|
+ UMWeb umWeb = new UMWeb(realUrl);
|
|
|
+ umWeb.setTitle(activity.getResources().getString(R.string.app_name));
|
|
|
+ umWeb.setThumb(umImage);
|
|
|
+ umWeb.setDescription(TextUtils.isEmpty(description) ? activity.getResources().getString(R.string.app_name) : description);
|
|
|
+ if (type == DialogShare.QQ || type == DialogShare.WX) {
|
|
|
+ new ShareAction(activity)
|
|
|
+ .setPlatform(share_media)
|
|
|
+ .withMedia(umImage)
|
|
|
+ .setCallback(new CommonUtil.UMShareListener())
|
|
|
+ .share();
|
|
|
+ } else {
|
|
|
+ new ShareAction(activity)
|
|
|
+ .setPlatform(share_media)
|
|
|
+ .withMedia(umWeb)
|
|
|
+ .setCallback(new CommonUtil.UMShareListener())
|
|
|
+ .share();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initData() {
|
|
|
+ ViewUtil.newInstance().showProgress(this);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().FriendCountAndAward()
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ ViewUtil.newInstance().hideProgress(InvitationActivity.this);
|
|
|
+ if (BuildConfig.DEBUG)
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ if (baseMessage != null) {
|
|
|
+ mEntity = FastJsonUtils.toBean(JSONObject.toJSONString(baseMessage.getData()), FriendAndAwardEntity.class);
|
|
|
+ description = mEntity.getShare_desc();
|
|
|
+ ViewUtil.newInstance().hideProgress(InvitationActivity.this);
|
|
|
+ getmEntity();
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ /* tvSize.setText(mEntity.getFriend_count() + "");
|
|
|
+ tvMoney.setText(mEntity.getAward());*/
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ /* ViewUtil.newInstance().hideProgress(activity);*/
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getmEntity() {
|
|
|
+ CommonUtil.getInstance().updateUserInfo(new Action1<UserEntity>() {
|
|
|
+ @Override
|
|
|
+ public void call(UserEntity result) {
|
|
|
+ if (result != null) {
|
|
|
+ userEntity = result;
|
|
|
+ String audit_total_audit = String.format(getResources().getString(R.string.my_invitation_str), userEntity.getInvitation_code());
|
|
|
+ /* my_invitation_tv.setText(audit_total_audit);*/
|
|
|
+ url = userEntity.getShareLink();
|
|
|
+ init(url, description);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageSelected(int position) {
|
|
|
+ Log.i("aaaa", "当前位置" + position);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 来获取邀请图片,
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private void getPicetureList() {
|
|
|
+ ArrayList<PictureInvitationEntity> list = new ArrayList<>();
|
|
|
+ SheepApp
|
|
|
+ .getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getSharePicture()
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ mPictureList.addAll(baseMessage.getDataList(PictureInvitationEntity.class));
|
|
|
+ downloadPictures();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void downloadPictures() {
|
|
|
+ for (int i = 0; i < mPictureList.size(); i++) {
|
|
|
+ position = i;
|
|
|
+ GlideImageLoader.downLoadImage("pic" + i, mPictureList.get(i).getPicture(), new Action1<File>() {
|
|
|
+ @Override
|
|
|
+ public void call(File file) {
|
|
|
+ if (file == null) {
|
|
|
+ listBitmap1.add(BitmapFactory.decodeFile(ClassFileHelper.DIR + "pic" + position + ".png"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ GlideImageLoader.downLoadImage("rx" + i, mPictureList.get(i).getLink(), new Action1<File>() {
|
|
|
+ @Override
|
|
|
+ public void call(File file) {
|
|
|
+ if (file == null) {
|
|
|
+ listBitmap2.add(BitmapFactory.decodeFile(ClassFileHelper.DIR + "rx" + position + ".png"));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ handler.sendEmptyMessage(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("HandlerLeak")
|
|
|
+ private Handler handler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ super.handleMessage(msg);
|
|
|
+ if (msg.what == 1) {
|
|
|
+ for (int i = 0; i < mPictureFileList.size(); i++) {
|
|
|
+ if (!listBitmap1.isEmpty() && !listBitmap2.isEmpty()) {
|
|
|
+ listBitmap.add(mergeBitmap(listBitmap1.get(i), listBitmap2.get(i)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private Bitmap mergeBitmap(Bitmap firstBitmap, Bitmap secondBitmap) {
|
|
|
+ Bitmap bitmap = Bitmap.createBitmap(firstBitmap.getWidth(), firstBitmap.getHeight(), firstBitmap.getConfig());
|
|
|
+ Canvas canvas = new Canvas(bitmap);
|
|
|
+ canvas.drawBitmap(firstBitmap, new Matrix(), null);
|
|
|
+ canvas.drawBitmap(secondBitmap, 30, 30, null);
|
|
|
+ return bitmap;
|
|
|
+ }
|
|
|
+}
|