瀏覽代碼

short url & home page tune up

hanjing 6 年之前
父節點
當前提交
7fc27b5583

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

@@ -1893,4 +1893,7 @@ public interface ApiService {
     @GET("app/url/{name}")
     Observable<BaseMessage> getNameUrl(@Path("name") String name);
 
+    @GET("app/user/get_short_url")
+    Observable<BaseMessage> getShortUrl(@Query("oldurl") String oldUrl);
+
 }

+ 30 - 8
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -277,7 +277,7 @@ public class ViewUtil {
 
     //加载js
     public static void loadJs(com.tencent.smtt.sdk.WebView mWebView, String js, com.tencent.smtt.sdk.ValueCallback<String> stringValueCallback) {
-        if(mWebView == null){
+        if (mWebView == null) {
             return;
         }
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
@@ -351,6 +351,7 @@ public class ViewUtil {
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(observer);
     }
+
     public static void delay2(Observer<Integer> observer, long delay) {
         io.reactivex.Observable.just(1)
                 .delay(delay, TimeUnit.MILLISECONDS)
@@ -378,20 +379,21 @@ public class ViewUtil {
     }
 
     public static void setImageLevel(ImageView imageView, int level) {
-        if(imageView != null){
+        if (imageView != null) {
             imageView.setImageLevel(level);
         }
 
     }
 
     public static void showMiddleLine(TextView textView) {
-        if(textView != null){
-            textView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG );
+        if (textView != null) {
+            textView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
         }
     }
+
     public static void showUnderLine(TextView textView) {
-        if(textView != null){
-            textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG  | Paint.ANTI_ALIAS_FLAG );
+        if (textView != null) {
+            textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
         }
     }
 
@@ -780,6 +782,24 @@ public class ViewUtil {
     }
 
     public static void shareLink(final Activity activity, String viewTitle, final String link, final String title, final String content, final ShareCallback callback) {
+        SheepApp.getInstance().getNetComponent().getApiService().getShortUrl(link)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        toShare(activity, viewTitle, baseMessage.getData().toString(), title, content, callback);
+                    }
+
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                        G.shortToast("分享失败");
+                    }
+                });
+    }
+
+    private static void toShare(final Activity activity, String viewTitle, final String link, final String title, final String content, final ShareCallback callback) {
         View dialog_parent = View.inflate(activity, R.layout.dialog_parent, null);
         final AlertDialog dialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
                 .setView(dialog_parent)
@@ -1625,8 +1645,8 @@ public class ViewUtil {
                 if (TextUtils.isEmpty(advertising.getDesc())) {//没有标题时 去掉下面的边距 并给图片左下理右下添加图角
                     builder.apply(new RequestOptions().transform(new RoundedCornersTransformation(activity.getResources().getDimensionPixelSize(R.dimen.content_padding_36), 0, RoundedCornersTransformation.CornerType.BOTTOM)));
                     dialog_center_ll.setPadding(0, activity.getResources().getDimensionPixelSize(R.dimen.content_padding_54), 0, 0);
-                    ViewGroup parent = (ViewGroup)dialog_center_ll.getParent();
-                    ((FrameLayout.LayoutParams)parent.getLayoutParams()).setMargins(0, 0, 0, 0);
+                    ViewGroup parent = (ViewGroup) dialog_center_ll.getParent();
+                    ((FrameLayout.LayoutParams) parent.getLayoutParams()).setMargins(0, 0, 0, 0);
                     Window win = dialog.getWindow();
                     win.getDecorView().setPadding(0, 0, 0, 0);
                     WindowManager.LayoutParams lp = win.getAttributes();
@@ -2124,11 +2144,13 @@ public class ViewUtil {
             textView.setText(TextUtils.isEmpty(msg) ? "" : msg);
         }
     }
+
     public static void setTextId(TextView textView, int msg) {
         if (textView != null) {
             textView.setText(SheepApp.getInstance().getString(msg));
         }
     }
+
     public static void setOnClickListener(View view, View.OnClickListener onClickListener) {
         if (view != null && onClickListener != null) {
             view.setOnClickListener(onClickListener);

+ 30 - 3
app/src/main/java/com/sheep/gamegroup/util/share/ShareLinkConfig.java

@@ -12,9 +12,11 @@ import android.text.TextUtils;
 import android.view.View;
 
 import com.kfzs.duanduan.utils.ApkUtils;
+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.UserEntity;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.skin.util.SkinUtil;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
@@ -40,6 +42,8 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.Locale;
 
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
 import rx.functions.Action1;
 
 import static com.sheep.gamegroup.util.UMConfigUtils.Event.LINK_SHARE;
@@ -158,10 +162,33 @@ public class ShareLinkConfig {
     }
 
     public void toShare(Activity activity) {
-        if(activity instanceof UMShareListener){
-            toShare(activity, (UMShareListener) activity);
+        if (link != null && !link.startsWith("http://kfzs.com/") && !link.contains("?")) {
+            SheepApp.getInstance().getNetComponent().getApiService().getShortUrl(link)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            link = baseMessage.getData().toString();
+                            if (activity instanceof UMShareListener) {
+                                toShare(activity, (UMShareListener) activity);
+                            } else {
+                                toShare(activity, null);
+                            }
+                        }
+
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            G.shortToast("分享失败");
+                        }
+                    });
         } else {
-            toShare(activity, null);
+            if (activity instanceof UMShareListener) {
+                toShare(activity, (UMShareListener) activity);
+            } else {
+                toShare(activity, null);
+            }
         }
     }
 

+ 60 - 34
app/src/main/java/com/sheep/gamegroup/view/activity/ActInvitation.java

@@ -440,40 +440,7 @@ public class ActInvitation extends BaseUMActivity {
                             G.showToast("图片正在加载中,请稍等");
                             return;
                         }
-                        new ShareLinkConfig()
-                                .setLink(url)
-                                .setShareType(item)
-                                .setDes(description)
-                                .setIconFile(file)
-                                .setType(ShareLinkConfig.IMG)
-                                .toShare(ActInvitation.this, new UMShareListener() {
-
-                                    @Override
-                                    public void onStart(SHARE_MEDIA share_media) {
-
-                                    }
-
-                                    @Override
-                                    public void onResult(SHARE_MEDIA share_media) {
-                                        if (TextUtils.isEmpty(picParamUrl)) {
-                                            callMissionExecute(2);
-                                        } else {
-                                            if (forMission > 0) {
-                                                callMissionExecute(forMission);
-                                            }
-                                        }
-                                    }
-
-                                    @Override
-                                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
-
-                                    }
-
-                                    @Override
-                                    public void onCancel(SHARE_MEDIA share_media) {
-
-                                    }
-                                });
+                        getShortUrl(url, item, description, file);
                     }
                 });
             }
@@ -481,6 +448,65 @@ public class ActInvitation extends BaseUMActivity {
         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) {
+                            toShare(baseMessage.getData().toString(), item, description, file);
+                        }
+
+                        @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(ActInvitation.this, new UMShareListener() {
+
+                    @Override
+                    public void onStart(SHARE_MEDIA share_media) {
+
+                    }
+
+                    @Override
+                    public void onResult(SHARE_MEDIA share_media) {
+                        if (TextUtils.isEmpty(picParamUrl)) {
+                            callMissionExecute(2);
+                        } else {
+                            if (forMission > 0) {
+                                callMissionExecute(forMission);
+                            }
+                        }
+                    }
+
+                    @Override
+                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
+
+                    }
+
+                    @Override
+                    public void onCancel(SHARE_MEDIA share_media) {
+
+                    }
+                });
+    }
+
     private void callMissionExecute(int act) {
         JSONObject json = new JSONObject();
         json.put("act", act);

+ 1 - 1
app/src/main/res/layout/homepage_act_layout.xml

@@ -117,7 +117,6 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_below="@id/hp_refresh_welfare_box"
-                    android:layout_marginTop="@dimen/content_padding"
                     android:background="@android:color/white"
                     android:orientation="vertical">
 
@@ -195,6 +194,7 @@
 
     <include
         layout="@layout/view_float_title_card"
+        android:visibility="gone"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_below="@id/to_search_but_rl" />