|
|
@@ -0,0 +1,224 @@
|
|
|
+package com.sheep.gamegroup.view.activity;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.annotation.Nullable;
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
+import android.support.v4.app.FragmentTransaction;
|
|
|
+import android.support.v7.widget.GridLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.kfzs.duanduan.utils.StatusBarUtils;
|
|
|
+import com.sheep.gamegroup.absBase.BaseUMActivity;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.WebParams;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.module.webview.fragment.FgtWeb;
|
|
|
+import com.sheep.gamegroup.module.webview.fragment.FgtWebX5;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.ViewHolder;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.util.share.ShareLinkConfig;
|
|
|
+import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
+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.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+import com.snail.antifake.jni.EmulatorDetectUtil;
|
|
|
+import com.umeng.socialize.UMShareListener;
|
|
|
+import com.umeng.socialize.bean.SHARE_MEDIA;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
+import rx.functions.Action1;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by realicing on 2018/9/7.
|
|
|
+ * realicing@sina.com
|
|
|
+ * 邀请赚钱分享界面
|
|
|
+ */
|
|
|
+public class ActWebShareImage extends BaseUMActivity {
|
|
|
+ @BindView(R.id.ask_share_list)
|
|
|
+ RecyclerView ask_share_list;
|
|
|
+
|
|
|
+ GridLayoutManager gridLayoutManager;
|
|
|
+
|
|
|
+ @BindView(R.id.fragment_container)
|
|
|
+ View fragmentContainer;
|
|
|
+
|
|
|
+ String webUrl;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ StatusBarUtils.setTranslucent(this);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ if (getIntent().hasExtra("web_url")) {
|
|
|
+ webUrl = getIntent().getStringExtra("web_url");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.act_web_share_image;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean showWhiteStatusBar() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ TitleBarUtils.getInstance().setShowOrHide(this, true)
|
|
|
+ .setTitle(this, "分享")
|
|
|
+ .setTitleFinish(this);
|
|
|
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
|
|
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag("tag");
|
|
|
+ if (fragment == null) {
|
|
|
+ if (EmulatorDetectUtil.isEmulator()) {
|
|
|
+ fragment = FgtWeb.newInstance(new WebParams(webUrl, "分享"));
|
|
|
+ } else {
|
|
|
+ fragment = FgtWebX5.newInstance(new WebParams(webUrl, "分享"));
|
|
|
+ }
|
|
|
+ transaction.add(R.id.fragment_container, fragment, "tag");
|
|
|
+ transaction.commitAllowingStateLoss();
|
|
|
+ } else {
|
|
|
+ transaction.replace(R.id.fragment_container, fragment);
|
|
|
+ transaction.commitAllowingStateLoss();
|
|
|
+ }
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init() {
|
|
|
+ gridLayoutManager = new GridLayoutManager(this, 5);
|
|
|
+ ask_share_list.setLayoutManager(gridLayoutManager);
|
|
|
+ final List<String> list = ListUtil.emptyList();
|
|
|
+ final List<Integer> imgList = ListUtil.emptyList();
|
|
|
+ final List<String> nameList = ListUtil.emptyList();
|
|
|
+ list.add(ShareLinkConfig.WX);
|
|
|
+ list.add(ShareLinkConfig.QQ);
|
|
|
+ list.add(ShareLinkConfig.WEIXIN_CIRCLE);
|
|
|
+ imgList.add(R.mipmap.share_wx);
|
|
|
+ imgList.add(R.mipmap.share_qq);
|
|
|
+ imgList.add(R.mipmap.share_weixin_circle);
|
|
|
+ nameList.add("微信");
|
|
|
+ nameList.add("QQ好友");
|
|
|
+ nameList.add("朋友圈");
|
|
|
+ list.add(0, ShareLinkConfig.FACE_TO_FACE);
|
|
|
+ list.add(ShareLinkConfig.COPY_SHARE_LINK);
|
|
|
+ imgList.add(0, R.mipmap.share_face_to_face);
|
|
|
+ imgList.add(R.mipmap.share_copy_share_link);
|
|
|
+ nameList.add(0, "面对面");
|
|
|
+ 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();
|
|
|
+ ask_to_share_item_img.setImageResource(imgList.get(position));
|
|
|
+ ask_to_share_item_name.setText(nameList.get(position));
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ File file;
|
|
|
+ try {
|
|
|
+ String fileName = String.format(Locale.CHINA, "share%s.jpg", BuildConfig.FLAVOR);
|
|
|
+ file = new File(ClassFileHelper.DIR, fileName);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file = ViewUtil.saveImage(fragmentContainer, ClassFileHelper.DIR, fileName);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ G.showToast(e.getMessage());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ toShare("", item, "", file);
|
|
|
+// getShortUrl(url, item, description, file);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ ask_share_list.setAdapter(adapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getShortUrl(String url, String item, String description, File file) {
|
|
|
+ if (url != null) {
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getShortUrl(url)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.shortToast("分享失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ toShare(url, item, description, file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void toShare(String url, String item, String description, File file) {
|
|
|
+ new ShareLinkConfig()
|
|
|
+ .setLink(url)
|
|
|
+ .setShareType(item)
|
|
|
+ .setDes(description)
|
|
|
+ .setIconFile(file)
|
|
|
+ .setType(ShareLinkConfig.IMG)
|
|
|
+ .toShare(ActWebShareImage.this, new UMShareListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStart(SHARE_MEDIA share_media) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResult(SHARE_MEDIA share_media) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(SHARE_MEDIA share_media, Throwable throwable) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancel(SHARE_MEDIA share_media) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|