Selaa lähdekoodia

游戏详情可取消关注;
添加游戏详情分享功能;
添加发表成功的提示对话框

zengjiebin 7 vuotta sitten
vanhempi
commit
89124e126f

+ 7 - 0
app/src/main/java/com/sheep/gamegroup/util/ApiUtil.java

@@ -49,4 +49,11 @@ public class ApiUtil {
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(sheepSubscriber);
     }
+    //游戏 关注
+    public static void postGameUserFocusGame(int focus_game_id, SheepSubscriber<BaseMessage> sheepSubscriber) {
+        SheepApp.getInstance().getNetComponent().getApiService().postGameUserFocusGame(focus_game_id)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(sheepSubscriber);
+    }
 }

+ 10 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/ActCommentGameApp.java

@@ -1,5 +1,6 @@
 package com.sheep.gamegroup.view.activity;
 
+import android.content.DialogInterface;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.EditText;
@@ -11,6 +12,7 @@ import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.ApiJSONUtil;
 import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.view.dialog.DialogSuccessUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -18,6 +20,7 @@ import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
 import butterknife.BindView;
 import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
 import rx.schedulers.Schedulers;
 
 /**
@@ -61,9 +64,13 @@ public class ActCommentGameApp extends BaseActivity {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
                         act_comment_game_app_input_comment.setText("");
-                        G.showToast(baseMessage);
-                        setResult(RESULT_OK);
-                        finish();
+                        DialogSuccessUtil.showSuccess("发表成功", new DialogInterface.OnDismissListener() {
+                            @Override
+                            public void onDismiss(DialogInterface dialogInterface) {
+                                setResult(RESULT_OK);
+                                finish();
+                            }
+                        });
                     }
 
                     @Override

+ 29 - 26
app/src/main/java/com/sheep/gamegroup/view/activity/ActGcGameAppDetail.java

@@ -26,6 +26,7 @@ import com.sheep.gamegroup.helper.DownloadHelper;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.GameEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.util.ApiUtil;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
@@ -149,12 +150,16 @@ public class ActGcGameAppDetail extends BaseActivity {
 
     private GameEntity gameEntity;
 
+    //更新关注状态
+    private void updateFocusTv() {
+        if(gc_game_app_detail_bt1 != null && gameEntity != null)
+            gc_game_app_detail_bt1.setText(gameEntity.isIs_focus_game() ? R.string.has_focus : R.string.focus);
+    }
     //加载游戏数据
     private void loadData(GameEntity gameEntity) {
         this.gameEntity = gameEntity;
         //更新关注状态
-        gc_game_app_detail_bt1.setText(gameEntity.isIs_focus_game() ? "已关注" : "关注");
-        gc_game_app_detail_bt1.setEnabled(!gameEntity.isIs_focus_game());
+        updateFocusTv();
         tryInitWelfare();
         //更新评价数量
         if(gameEntity.getApp().getComment_num() > 0) {
@@ -265,8 +270,11 @@ public class ActGcGameAppDetail extends BaseActivity {
 
     //点击分享
     public void onClickShareImg(View view) {
-        //TODO 点击分享游戏
-        G.showToast(R.string.coming_soon);
+        if(gameEntity == null || gameEntity.getApp() == null || TextUtils.isEmpty(gameEntity.getApp().getName())){
+            CommonUtil.getInstance().tryShowShareDialog(this);
+            return;
+        }
+        CommonUtil.getInstance().tryShowShareDialog(this, String.format(Locale.CHINA, "小朋友,快来玩【%s】", gameEntity.getApp().getName()));
     }
 
     //点击加,发表评论
@@ -275,32 +283,27 @@ public class ActGcGameAppDetail extends BaseActivity {
     }
 
     //点击关注
-    public void onClickFollowTv(View view) {
+    public void onClickFollowTv(final View view) {
         if(gameEntity == null){
             G.showToast(R.string.loading_data);
             return;
         }
-        if(gameEntity.isIs_focus_game()){
-            G.showToast("已经关注");
-            return;
-        }
-        //点击关注游戏
-        SheepApp.getInstance().getNetComponent().getApiService().postGameUserFocusGame(id)
-                        .subscribeOn(Schedulers.io())
-                        .observeOn(AndroidSchedulers.mainThread())
-                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                            @Override
-                            public void onNext(BaseMessage baseMessage) {
-                                G.showToast("关注游戏成功");
-                                gc_game_app_detail_bt1.setText("已关注");
-                                gc_game_app_detail_bt1.setEnabled(false);
-                            }
-
-                            @Override
-                            public void onError(BaseMessage baseMessage) {
-                                G.showToast(baseMessage);
-                            }
-                        });
+        view.setEnabled(false);
+        ApiUtil.postGameUserFocusGame(id, new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+            @Override
+            public void onNext(BaseMessage baseMessage) {
+                G.showToast(gameEntity.isIs_focus_game() ? R.string.cancel_focus_success : R.string.focus_success);
+                gameEntity.setIs_focus_game(!gameEntity.isIs_focus_game());
+                updateFocusTv();
+                view.setEnabled(true);
+            }
+
+            @Override
+            public void onError(BaseMessage baseMessage) {
+                G.showToast(gameEntity.isIs_focus_game() ? R.string.cancel_focus_fail : R.string.focus_fail);
+                view.setEnabled(true);
+            }
+        });
     }
 
     private AbsGetDownloadListener absGetDownloadListener = new AbsGetDownloadListener(true) {

+ 41 - 0
app/src/main/java/com/sheep/gamegroup/view/dialog/DialogSuccessUtil.java

@@ -0,0 +1,41 @@
+package com.sheep.gamegroup.view.dialog;
+
+import android.content.DialogInterface;
+import android.support.v7.app.AlertDialog;
+import android.view.View;
+import android.widget.TextView;
+
+import com.sheep.gamegroup.util.ActivityManager;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+/**
+ * Created by realicing on 2018/11/7.
+ * realicing@sina.com
+ */
+public class DialogSuccessUtil {
+    public static void showSuccess(String msg, DialogInterface.OnDismissListener onDismissListener) {
+        View dialog_parent = View.inflate(SheepApp.getInstance(), R.layout.dialog_success, null);
+        final AlertDialog dialog = new AlertDialog.Builder(ActivityManager.getInstance().currentActivity(), R.style.AppTheme_Dialog_Alert)
+                .setView(dialog_parent)
+                .create();
+        TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
+        dialog_parent.findViewById(R.id.dialog_close).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                try {
+                    dialog.dismiss();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+        dialog_title.setText(msg);
+        dialog.setOnDismissListener(onDismissListener);
+        try {
+            dialog.show();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 8 - 2
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtArticleComment.java

@@ -1,5 +1,6 @@
 package com.sheep.gamegroup.view.fragment;
 
+import android.content.DialogInterface;
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -18,6 +19,7 @@ import com.sheep.gamegroup.util.ApiJSONUtil;
 import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.view.adapter.AdpArticleComment;
+import com.sheep.gamegroup.view.dialog.DialogSuccessUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -93,8 +95,12 @@ public class FgtArticleComment extends BaseListFragment3<UserComment> {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
                         input_comment_input.setText("");
-                        refreshData();
-                        G.showToast(baseMessage);
+                        DialogSuccessUtil.showSuccess("发表成功", new DialogInterface.OnDismissListener() {
+                            @Override
+                            public void onDismiss(DialogInterface dialogInterface) {
+                                refreshData();
+                            }
+                        });
                     }
 
                     @Override

+ 8 - 2
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtUserCommentDetail.java

@@ -1,5 +1,6 @@
 package com.sheep.gamegroup.view.fragment;
 
+import android.content.DialogInterface;
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -25,6 +26,7 @@ import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.util.viewHelper.UserCommentHelper;
 import com.sheep.gamegroup.view.adapter.AdpUserCommentReply;
+import com.sheep.gamegroup.view.dialog.DialogSuccessUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -107,8 +109,12 @@ public class FgtUserCommentDetail extends BaseListFragment3<UserCommentReply> {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
                         input_comment_input.setText("");
-                        refreshData();
-                        G.showToast(baseMessage);
+                        DialogSuccessUtil.showSuccess("发表成功", new DialogInterface.OnDismissListener() {
+                            @Override
+                            public void onDismiss(DialogInterface dialogInterface) {
+                                refreshData();
+                            }
+                        });
                     }
 
                     @Override

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

@@ -102,7 +102,6 @@
                         android:background="@drawable/selector_button_stroke_main"
                         android:gravity="center"
                         android:onClick="onClickFollowTv"
-                        android:enabled="false"
                         android:text="@string/loading"
                         android:textColor="@color/selector_color_stoke_main_btn"
                         android:textSize="13sp"

+ 46 - 0
app/src/main/res/layout/dialog_success.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_margin="@dimen/dp_10">
+
+        <LinearLayout
+            android:id="@+id/dialog_center_ll"
+            android:layout_width="294dp"
+            android:layout_height="253dp"
+            android:layout_centerHorizontal="true"
+            android:background="@drawable/shape_white_solid_rectangle"
+            android:gravity="center"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="74dp"
+                android:layout_height="74dp"
+                android:src="@drawable/ic_publish_done"/>
+
+            <TextView
+                android:id="@+id/dialog_title"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="27dp"
+                android:gravity="center"
+                android:text="提示"
+                android:textColor="#333333"
+                android:textSize="16sp" />
+        </LinearLayout>
+
+        <ImageView
+            android:id="@+id/dialog_close"
+            android:layout_width="40dp"
+            android:layout_height="40dp"
+            android:layout_below="@id/dialog_center_ll"
+            android:layout_centerHorizontal="true"
+            android:layout_marginTop="@dimen/content_padding_30"
+            android:src="@mipmap/close" />
+    </RelativeLayout>
+</FrameLayout>