Bläddra i källkod

图片分享修改

zengjiebin 7 år sedan
förälder
incheckning
b94ed46d89

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/util/UMConfigUtils.java

@@ -168,6 +168,7 @@ public class UMConfigUtils {
         GIFT_BAG_LOOK_TIP("礼包中心 -> 点击提示图标 参数 gift_bag_id"),
         GIFT_BAG_DIALOG_COPY_CODE("礼包中心 -> 领取礼包 -> 对话框内复制礼包码 参数 gift_bag_id gift_bag_code"),
         GIFT_BAG_DIALOG_START_APP("礼包中心 -> 领取礼包 -> 对话框内启动游戏 参数 gift_bag_id package_name"),
+        SHARE_TO_WEIXIN_CIRCLE("分享到微信朋友圈"),
         ;
         private String tag;
 

+ 23 - 33
app/src/main/java/com/sheep/gamegroup/view/activity/InvitationActivity.java

@@ -49,6 +49,7 @@ import com.umeng.socialize.media.UMWeb;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 import butterknife.BindView;
 import butterknife.ButterKnife;
@@ -58,6 +59,9 @@ 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.UMConfigUtils.Event.SHARE_TO_QQ;
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.SHARE_TO_WEIXIN_CIRCLE;
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.SHARE_TO_WX;
 import static com.sheep.gamegroup.util.ViewUtil.getNetImgByName;
 
 /**
@@ -76,9 +80,6 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
     GridLayoutManager gridLayoutManager;
     UserEntity userEntity = DataUtil.getInstance().getUserEntity();
     private FriendAndAwardEntity mEntity;
-    private String url;
-    private String description;
-    private File file;
     private List<PictureInvitationEntity> mPictureList = new ArrayList<>();
 
     @Override
@@ -163,11 +164,18 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
                 itemView.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
-                        if (position == 1 || position == 2) {
-                            popShare(InvitationActivity.this, url, item, description, file);
-                        } else {
-                            popShare(InvitationActivity.this, url, item, description, null);
+                        File file = null;
+                        switch (position){
+                            case 1://qq
+                            case 2://wx
+                                String fileName = String.format(Locale.CHINA, "share%d.jpg", position);
+                                file = new File(ClassFileHelper.DIR, fileName);
+                                if(!file.exists())
+                                    file = ViewUtil.saveImage(mRecyclerView.getChildAt(curPosition).findViewById(R.id.layout_view), ClassFileHelper.DIR, fileName);
+                                break;
+
                         }
+                        popShare(InvitationActivity.this, url, item, description, file);
                     }
                 });
             }
@@ -200,7 +208,7 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
      * @param type        qq wx all
      * @param description
      */
-    public void popShare(Activity activity, final String url, @DialogShare.SHARE_TYPE String type, String description, File bitmap) {
+    public void popShare(Activity activity, final String url, @DialogShare.SHARE_TYPE String type, String description, File file) {
         if (activity == null || TextUtils.isEmpty(type) || TextUtils.isEmpty(url)) {
             return;
         }
@@ -227,13 +235,16 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
                         }));
                 return;
             case DialogShare.QQ:
+                SHARE_TO_QQ.onEvent();
                 share_media = SHARE_MEDIA.QQ;
                 break;
             case DialogShare.WX:
+                SHARE_TO_WX.onEvent();
                 share_media = SHARE_MEDIA.WEIXIN;
                 break;
             case DialogShare.WEIXIN_CIRCLE:
             default:
+                SHARE_TO_WEIXIN_CIRCLE.onEvent();
                 share_media = SHARE_MEDIA.WEIXIN_CIRCLE;
                 break;
         }
@@ -241,7 +252,7 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
         switch (type){
             case DialogShare.QQ:
             case DialogShare.WX:
-                umImage = new UMImage(activity, bitmap);
+                umImage = new UMImage(activity, file);
                 break;
             default:
                 umImage = new UMImage(activity, R.mipmap.icon);
@@ -287,7 +298,6 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
                     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();
                         }
@@ -304,22 +314,16 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
             public void call(UserEntity result) {
                 if (result != null) {
                     userEntity = result;
-                    url = userEntity.getShareLink();
-                    init(url, description);
+                    init(userEntity.getShareLink(), mEntity.getShare_desc());
                 }
             }
         });
     }
 
-
+    private int curPosition = 0;
     @Override
     public void onPageSelected(int position) {
-        try {
-            file=getViewFile(mRecyclerView.getChildAt(position).findViewById(R.id.layout_view));
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        Log.i("aaaa", "当前位置" + position);
+        curPosition = position;
     }
 
     /**
@@ -345,20 +349,6 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
                     }
                 });
     }
-//    private void createBitmapList(int y) {
-//        for (int i = 0; i < mPictureList.size(); i++) {
-//            listBitmap1.add(BitmapFactory.decodeFile(getSavePath(mPictureList.get(i).getPicture())));
-//            Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.sheep_logo);
-//            Bitmap bitmap = ZXingHelper.createQRCodeWithLogo(mPictureList.get(y).getLink(), logo);
-//        }
-//    }
 
 
-    private File getViewFile(View addViewContent) {
-        if (addViewContent==null){
-            return null;
-        }
-        return ViewUtil.saveImage(addViewContent, ClassFileHelper.DIR, System.currentTimeMillis() + ".jpg");
-    }
-
 }

+ 1 - 0
app/src/main/res/layout/item_image2.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/layout_view"
     android:layout_width="match_parent"
     android:layout_height="match_parent">