Parcourir la source

通过检查粘贴板来弹出游戏框

zengjiebin il y a 7 ans
Parent
commit
63281fccfe

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -812,7 +812,7 @@ public interface ApiService {
      * 获取app_id
      */
     @GET("app/find/get/app_id")
-    Observable<BaseMessage> getAppId(@Query("game_id") int game_id);
+    Observable<BaseMessage> getAppId(@Query("game_id") String game_id);
 
     /**
      * 应用 各评分人数

+ 43 - 12
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -2602,17 +2602,20 @@ public class CommonUtil {
             String textString = text.toString();
             View.OnClickListener closeListener = view -> DataUtil.putAsString(Config.KEY_USED_COPY_TEXT, textString);
             DialogConfig dialogConfig = new DialogConfig().setTitle("小绵羊提示").setBtnCloseOnClickListener(closeListener);
-            Matcher matcher = Patterns.WEB_URL.matcher(text);
-            if (matcher.find()) {//如果是链接,直接跳转外部浏览器
-                shoGoWebDialog(dialogConfig, closeListener, textString, matcher.group());
-            } else if (textString.contains("://")) {
-                dialogConfig.setMsg("已经复制如下内容:\n" + textString + "\n,是否尝试跳转?")
-                        .setBtnLeftText("确定").setBtnLeftOnClickListener(view -> Jump2View.getInstance().tryGotoDeepLink(textString))
-                        .setBtnRightText("仅一次").setBtnRightOnClickListener(view -> {
-                    closeListener.onClick(view);
-                    Jump2View.getInstance().tryGotoDeepLink(textString);
-                });
-                ViewUtil.showMsgDialog(SheepApp.getInstance().getCurrentActivity(), dialogConfig);
+            String url;
+            if ((url = StringUtils.findUrl(text)) != null) {//如果是链接,直接跳转外部浏览器
+                LogUtil.println("checkCopyText", url);
+                if(StringUtils.isHttpUrl(url)) {
+                    showGoWebDialog(dialogConfig, closeListener, textString, url);
+                } else{
+                    dialogConfig.setMsg("已经复制如下内容:\n" + textString + "\n,是否尝试跳转?")
+                            .setBtnLeftText("确定").setBtnLeftOnClickListener(view -> Jump2View.getInstance().tryGotoDeepLink(textString))
+                            .setBtnRightText("仅一次").setBtnRightOnClickListener(view -> {
+                        closeListener.onClick(view);
+                        Jump2View.getInstance().tryGotoDeepLink(textString);
+                    });
+                    ViewUtil.showMsgDialog(SheepApp.getInstance().getCurrentActivity(), dialogConfig);
+                }
             } else if (TestUtil.isDev()) {
                 TestUtil.testFunction(SheepApp.getInstance().getCurrentActivity(), textString);
 //            } else {
@@ -2628,7 +2631,10 @@ public class CommonUtil {
         }
     }
 
-    private void shoGoWebDialog(DialogConfig dialogConfig, View.OnClickListener closeListener, String textString, String url) {
+    private void showGoWebDialog(DialogConfig dialogConfig, View.OnClickListener closeListener, String textString, String url) {
+        if(checkShouYouShare(closeListener, url)){
+            return;
+        }
         dialogConfig.setMsg("已经复制如下内容:\n" + textString + "\n,是否访问该链接?")
                 .setBtnLeftText("确定").setBtnLeftOnClickListener(view -> Jump2View.getInstance().goWeb(SheepApp.getInstance().getCurrentActivity(), url))
                 .setBtnRightText("仅一次").setBtnRightOnClickListener(view -> {
@@ -2637,4 +2643,29 @@ public class CommonUtil {
         });
         ViewUtil.showMsgDialog(SheepApp.getInstance().getCurrentActivity(), dialogConfig);
     }
+
+    private boolean checkShouYouShare(View.OnClickListener closeListener, String url) {
+        if(url.contains("/shou_you_share/index.html")) {
+            String gameId = StringUtils.getQueryParameter(url, "game_id");
+            if(!TextUtils.isEmpty(gameId)){
+                SheepApp.getInstance().getNetComponent().getApiService().getAppId(gameId)//http://10.8.220.229:8800/shou_you_share/index.html?invitation_code=12799442&game_id=1553
+                                .subscribeOn(Schedulers.io())
+                                .observeOn(AndroidSchedulers.mainThread())
+                                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                                    @Override
+                                    public void onNext(BaseMessage baseMessage) {
+                                        Applications applications = baseMessage.getData(Applications.class);
+                                        ViewUtil.showGameDialog(applications, closeListener);
+                                    }
+
+                                    @Override
+                                    public void onError(BaseMessage baseMessage) {
+                                        G.showToast(baseMessage);
+                                    }
+                                });
+                return true;
+            }
+        }
+        return false;
+    }
 }

+ 4 - 0
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -1853,6 +1853,10 @@ public class Jump2View {
      * @param item
      */
     public void goEntity(Applications item) {
+        if(item == null){
+            G.showToast(R.string.please_contact_customer_service);
+            return;
+        }
         goPlayGameDetail(item.getId());
     }
 

+ 19 - 0
app/src/main/java/com/sheep/gamegroup/util/StringUtils.java

@@ -5,6 +5,7 @@ import android.content.ClipboardManager;
 import android.content.Context;
 import android.net.Uri;
 import android.text.TextUtils;
+import android.util.Patterns;
 
 import com.lqr.emoji.EmotionLayout;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -427,4 +428,22 @@ public class StringUtils {
         //把非数字的字符替换为""
         return m.replaceAll("").trim();
     }
+
+    public static String findUrl(CharSequence text) {
+        Matcher matcher = Patterns.WEB_URL.matcher(text);
+        while (matcher.find()) {
+            String item = matcher.group();
+            if(item.contains("://")){
+                return item;
+            }
+        }
+        return null;
+    }
+
+    public static boolean isHttpUrl(String url) {
+        if (!url.startsWith("http") && !url.contains("://")) {
+            return false;
+        }
+        return true;
+    }
 }

+ 51 - 10
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -72,6 +72,7 @@ import com.sheep.gamegroup.absBase.ITag;
 import com.sheep.gamegroup.dateview.DatePickerDialog;
 import com.sheep.gamegroup.dateview.DateUtil;
 import com.sheep.gamegroup.model.entity.Advertising;
+import com.sheep.gamegroup.model.entity.Applications;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.Container;
 import com.sheep.gamegroup.model.entity.DialogConfig;
@@ -311,19 +312,20 @@ public class ViewUtil {
 
     public static void dismiss(final AlertDialog dialog, int delay) {
         if (dialog != null) {
-            if (delay > 0) {
-                delay(new AbsObserver<Integer>() {
-                    @Override
-                    public void onNext(Integer integer) {
-                        try {
-                            dialog.dismiss();
-                        } catch (Exception ignore) {
+            AbsObserver<Integer> absObserver =new AbsObserver<Integer>() {
+                @Override
+                public void onNext(Integer integer) {
+                    try {
+                        dialog.dismiss();
+                    } catch (Exception ignore) {
 
-                        }
                     }
-                }, delay);
+                }
+            };
+            if (delay > 0) {
+                delay(absObserver, delay);
             } else {
-                dialog.dismiss();
+                absObserver.onNext(0);
             }
         }
     }
@@ -1424,6 +1426,45 @@ public class ViewUtil {
         }
     }
 
+
+    public static void showGameDialog(Applications applications, View.OnClickListener onClickListener) {
+        Context mContext = SheepApp.getInstance();
+        View dialog_parent = View.inflate(SheepApp.getInstance(), R.layout.dialog_parent, null);
+        final AlertDialog dialog = new AlertDialog.Builder(mContext,R.style.AppTheme_Dialog_Alert).setView(dialog_parent).create();
+        LinearLayout dialog_center_ll = dialog_parent.findViewById(R.id.dialog_center_ll);
+        TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
+        View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
+
+        LayoutParamsUtil.resetLayoutParams(dialog_center_ll, new Lp().setWidth(G.WIDTH / 2));
+        dialog_center_ll.setPadding(0, 0, 0, 0);
+        ViewUtil.setVisibility(dialog_title, false);
+        dialog_close.setOnClickListener(view -> {
+            onClickListener.onClick(view);
+            dismiss(dialog, 0);
+        });
+
+        final View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_item_game_center_4_3, dialog_center_ll, true);
+        ImageView dialog_icon_iv = view.findViewById(R.id.dialog_icon_iv);
+        TextView dialog_name_tv = view.findViewById(R.id.dialog_name_tv);
+        TextView dialog_btn_tv = view.findViewById(R.id.dialog_btn_tv);
+
+        setGameImage(dialog_icon_iv, applications.getIcon());
+        setText(dialog_name_tv, applications.getName());
+        dialog_btn_tv.setOnClickListener(view1 -> {
+            Jump2View.getInstance().goEntity(applications);
+            dismiss(dialog, 0);
+        });
+
+        if (dialog.getWindow() != null) {
+            dialog.getWindow().setType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_TOAST);
+        }
+        try {
+            dialog.show();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
     /**
      * 通过map来设置字体颜色
      *

+ 36 - 0
app/src/main/res/layout/dialog_item_game_center_4_3.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_gravity="center"
+    android:orientation="vertical"
+    android:paddingTop="16dp">
+
+    <ImageView
+        android:id="@+id/dialog_icon_iv"
+        android:layout_width="62dp"
+        android:layout_height="62dp"
+        android:layout_marginStart="8dp"
+        android:layout_marginEnd="8dp"
+        android:layout_gravity="center"
+        android:src="@drawable/icon_lj" />
+
+    <TextView
+        android:id="@+id/dialog_name_tv"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="8dp"
+        android:paddingStart="4dp"
+        android:paddingEnd="4dp"
+        android:ellipsize="end"
+        android:gravity="center"
+        android:singleLine="true"
+        android:textColor="#333333"
+        android:textSize="13sp" />
+
+    <TextView
+        android:id="@+id/dialog_btn_tv"
+        style="@style/style_button"
+        android:layout_width="match_parent"
+        android:text="查看详情" />
+</LinearLayout>

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

@@ -13,6 +13,7 @@
             android:id="@+id/dialog_center_ll"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:layout_centerHorizontal="true"
             android:background="@drawable/shape_white_solid_rectangle"
             android:gravity="center"
             android:orientation="vertical"