Pārlūkot izejas kodu

fixed exit app then app reboot bug

hanjing 7 gadi atpakaļ
vecāks
revīzija
7e97d65d3c

+ 0 - 7
app/src/main/java/com/sheep/gamegroup/module/login/fragments/SignInFgt.java

@@ -83,11 +83,6 @@ public class SignInFgt extends AbsLoginFgt {
     CountDownButton countDownButton;
     @BindView(R.id.account_menu_btn)
     ImageView accountMenuBtn;
-
-    @BindView(R.id.test_change)
-    TextView testChange;
-    @BindView(R.id.test_change_user)
-    TextView testChangeUser;
     @BindView(R.id.show_hide_pwd_btn)
     ImageView showHidePwdBtn;
 
@@ -113,8 +108,6 @@ public class SignInFgt extends AbsLoginFgt {
 
     @Override
     public void onViewCreated() {
-        TestUtil.testChange(getActivity(), testChange);
-        TestUtil.testChangeUser(getActivity(), testChangeUser);
         if (loginType == LoginController.PLATFORM_PHONE) {
             forAccountPwdContainer.setVisibility(View.GONE);
             forPhoneContainer.setVisibility(View.VISIBLE);

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/module/login/fragments/WelcomeFgt.java

@@ -12,6 +12,7 @@ import android.widget.TextView;
 
 import com.sheep.gamegroup.module.login.controller.LoginController;
 import com.sheep.gamegroup.util.StringUtils;
+import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -29,6 +30,11 @@ public class WelcomeFgt extends AbsLoginFgt {
     @BindView(R.id.login_type_toggle_text)
     TextView loginToggleTextBtn;
 
+    @BindView(R.id.test_change)
+    TextView testChange;
+    @BindView(R.id.test_change_user)
+    TextView testChangeUser;
+
     public WelcomeFgt() {
         // Required empty public constructor
     }
@@ -46,6 +52,8 @@ public class WelcomeFgt extends AbsLoginFgt {
 
     @Override
     public void onViewCreated() {
+        TestUtil.testChange(getActivity(), testChange);
+        TestUtil.testChangeUser(getActivity(), testChangeUser);
         loginToggleIconBtn.setImageResource(R.mipmap.login_phone);
         loginToggleTextBtn.setText("一键登录");
     }

+ 0 - 105
app/src/main/java/com/sheep/gamegroup/presenter/LoginPresenter.java

@@ -1,105 +0,0 @@
-package com.sheep.gamegroup.presenter;
-
-import android.text.TextUtils;
-
-import com.alibaba.fastjson.JSONObject;
-import com.sheep.gamegroup.model.api.ApiService;
-import com.sheep.gamegroup.model.entity.BaseMessage;
-import com.sheep.gamegroup.model.entity.LoginEntity;
-import com.sheep.gamegroup.model.util.EntityUtils;
-import com.sheep.gamegroup.model.util.SheepSubscriber;
-import com.sheep.gamegroup.util.ChannelContent;
-import com.sheep.gamegroup.util.DataUtil;
-import com.sheep.gamegroup.util.FastJsonUtils;
-import com.sheep.gamegroup.util.Jump2View;
-import com.sheep.gamegroup.util.LogUtil;
-import com.sheep.gamegroup.util.PreferenceUtils;
-import com.sheep.gamegroup.util.TestUtil;
-import com.sheep.gamegroup.util.UMConfigUtils;
-import com.sheep.jiuyan.samllsheep.SheepApp;
-import com.sheep.jiuyan.samllsheep.utils.SpUtils;
-
-import javax.inject.Inject;
-
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.schedulers.Schedulers;
-
-/**
- * Created by Administrator on 2018/3/10.
- */
-
-public class LoginPresenter implements LoginContract.Presenter {
-    private LoginContract.View view;
-    private ApiService apiService;
-
-    @Inject
-    public LoginPresenter(LoginContract.View view, ApiService apiService) {
-        this.view = view;
-        this.apiService = apiService;
-    }
-
-
-    @Override
-    public void logByAuther(int type, String access_token, String openid) {
-        JSONObject j = new JSONObject();
-        j.put("code",access_token);
-        j.put("username",openid);
-        j.put("scope",ChannelContent.getInstance().getChannel_name() );
-        if(type==1){
-            PreferenceUtils.setPrefString(SheepApp.getInstance(), UMConfigUtils.LOGIN_TYPE,UMConfigUtils.Source.WECHAT);
-            apiService.LoginByWX(j).subscribeOn(Schedulers.io())
-                    .observeOn(AndroidSchedulers.mainThread())
-                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                        @Override
-                        public void onError(BaseMessage baseMessage) {
-                            view.NetError(-1, "微信登录失败  请检查网络是否正常");
-                        }
-
-                        @Override
-                        public void onNext(BaseMessage baseMessage) {
-                            loginSuccess(view, baseMessage);
-                        }
-                    });
-
-        }else{
-            PreferenceUtils.setPrefString(SheepApp.getInstance(), UMConfigUtils.LOGIN_TYPE,UMConfigUtils.Source.QQ);
-            apiService.LoginByQQ(j).subscribeOn(Schedulers.io())
-                    .observeOn(AndroidSchedulers.mainThread())
-                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-
-                        @Override
-                        public void onError(BaseMessage baseMessage) {
-                            view.NetError(-1, "QQ登录失败  请检查网络是否正常");
-                        }
-
-                        @Override
-                        public void onNext(BaseMessage baseMessage) {
-                            loginSuccess(view, baseMessage);
-
-                        }
-                    });
-
-        }
-
-
-    }
-    private void loginSuccess(LoginContract.View view, BaseMessage baseMessage){
-        LoginEntity loginEty = null;
-        if(baseMessage!=null){
-            loginEty =FastJsonUtils.toBean( JSONObject.toJSONString(baseMessage.getData()),LoginEntity.class);
-            if(loginEty.getCode() != null){
-                switch (loginEty.getCode()){
-                    case "bind_mobile":
-                        view.NetError(1, "请先绑定手机号");
-                        Jump2View.getInstance().goBindPhoneRegister(SheepApp.getInstance(), loginEty);
-                        return;
-                }
-            }
-            SpUtils.saveToken(SheepApp.getInstance(), loginEty.getToken());
-            DataUtil.getInstance().initUserEntity(loginEty.getUser());
-//            LogUtil.logI("token--------"+loginEty.getToken());
-        }
-        view.NetSuccess(1,"登录成功", EntityUtils.getUserCode(loginEty));
-        TestUtil.saveUser(loginEty);
-    }
-}

+ 31 - 28
app/src/main/java/com/sheep/gamegroup/util/CertificationUtil.java

@@ -30,8 +30,8 @@ public class CertificationUtil {
 
     private static CertificationUtil certificationUtil;
 
-    public static CertificationUtil newInstance(){
-        if(certificationUtil == null)
+    public static CertificationUtil newInstance() {
+        if (certificationUtil == null)
             certificationUtil = new CertificationUtil();
         return certificationUtil;
     }
@@ -39,71 +39,74 @@ public class CertificationUtil {
 
     /**
      * 退出app
+     *
      * @param errorMsg
      */
-    public void showCertificationErrorAndExitApp(final String errorMsg, long skip_time) {
+    public void showCertificationErrorAndExitApp(Activity activity, final String errorMsg, long skip_time) {
         new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
             @Override
             public void run() {
                 SheepApp.getInstance().setGamePackgeName("");
                 SheepApp.getInstance().setGameCode("");
                 SheepApp.getInstance().setGameFlag(false);
-                SheepApp.getInstance().quit();
+                activity.finish();
             }
         }, skip_time);
     }
+
     /**
      * 跳转回,游戏
      */
-    public void doCertification(final Context context, String token, String packageName, String ext){
+    public void doCertification(final Activity activity, String token, String packageName, String ext) {
         try {
-            Log.e("game_-packgename---"+packageName,"");
+            Log.e("game_-packgename---" + packageName, "");
             Intent intent = new Intent();
             intent.setClassName(packageName, "com.kfzs.duanduan.data.observer.helper.WhistleActivity");
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_certification_key), SheepApp.getInstance().getGameCode());
+            intent.putExtra(activity.getString(R.string.kfzs_duanduan_datashare_certification_key), SheepApp.getInstance().getGameCode());
 
             if (TextUtils.isEmpty(ext)) {
-                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_package_extras), "");
-                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_certification_token), token);
-            } else if("delete".equals(ext)){
-                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_certification_cancel), "delete");
-            }else  {
-                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_package_extras), ext);
-                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_certification_token), token);
+                intent.putExtra(activity.getString(R.string.kfzs_duanduan_datashare_package_extras), "");
+                intent.putExtra(activity.getString(R.string.kfzs_duanduan_datashare_certification_token), token);
+            } else if ("delete".equals(ext)) {
+                intent.putExtra(activity.getString(R.string.kfzs_duanduan_datashare_certification_cancel), "delete");
+            } else {
+                intent.putExtra(activity.getString(R.string.kfzs_duanduan_datashare_package_extras), ext);
+                intent.putExtra(activity.getString(R.string.kfzs_duanduan_datashare_certification_token), token);
             }
-            context.startActivity(intent);
-            showCertificationErrorAndExitApp("", 100);
+            activity.startActivity(intent);
+            showCertificationErrorAndExitApp(activity, "", 100);
         } catch (Exception e) {
             e.printStackTrace();
-            showCertificationErrorAndExitApp("认证失败", 100);
+            showCertificationErrorAndExitApp(activity, "认证失败", 100);
         }
     }
+
     /**
      * 验证获取数据
      */
-    public void authCertificationCode(final Context context, final String token){
-        ViewUtil.newInstance().showProgress((Activity) context);
+    public void authCertificationCode(final Activity activity, final String token) {
+        ViewUtil.newInstance().showProgress((Activity) activity);
         SheepApp.getInstance().getNetComponent().getApiService().verificationAuth(token, SheepApp.getInstance().getGameCode())
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
-                        ViewUtil.newInstance().hideProgress((Activity) context);
-                        if(baseMessage != null && baseMessage.getData() != null){
-                            Log.e("data-------","");
-                            doCertification(context, token,  SheepApp.getInstance().getGamePackgeName(), baseMessage.getData()+"");
-                        }else {
-                            CertificationUtil.newInstance().showCertificationErrorAndExitApp("请求授权错误 " + (baseMessage == null ? "无数据" : baseMessage.getMsg()),1000);
+                        ViewUtil.newInstance().hideProgress((Activity) activity);
+                        if (baseMessage != null && baseMessage.getData() != null) {
+                            Log.e("data-------", "");
+                            doCertification(activity, token, SheepApp.getInstance().getGamePackgeName(), baseMessage.getData() + "");
+                        } else {
+                            showCertificationErrorAndExitApp(activity, "请求授权错误 " + (baseMessage == null ? "无数据" : baseMessage.getMsg()), 1000);
                         }
 
                     }
 
                     @Override
                     public void onError(BaseMessage baseMessage) {
-                        ViewUtil.newInstance().hideProgress((Activity) context);
-                        CertificationUtil.newInstance().showCertificationErrorAndExitApp("请求授权错误 " + baseMessage.getMsg(),1000);
+                        ViewUtil.newInstance().hideProgress((Activity) activity);
+                        showCertificationErrorAndExitApp(activity, "请求授权错误 " + baseMessage.getMsg(), 1000);
                     }
                 });
     }
@@ -113,7 +116,7 @@ public class CertificationUtil {
         CommonUtil.getInstance().callActionWithUserInfo(new Action1<UserEntity>() {
             @Override
             public void call(UserEntity userEntity) {
-                if(userEntity != null){
+                if (userEntity != null) {
                     SdkLoginUser newSdkLoginUser = new SdkLoginUser();
                     newSdkLoginUser.setAvatar(userEntity.getAvatar());
                     newSdkLoginUser.setToken(SpUtils.getToken(SheepApp.getInstance()));

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -247,6 +247,7 @@ public class ActMain extends BaseActYmPermissionCheck {
     private void doBackPress() {
         if (System.currentTimeMillis() - mLastBackTime < 1000) {
             SheepApp.getInstance().quit();
+            finish();
         } else {
             try {
                 G.showToast(R.string.toast_double_click_exit_app);

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/GameCertificationActivity.java

@@ -139,12 +139,12 @@ public class GameCertificationActivity extends BaseActivity {
             packageName = extras.getString(getString(R.string.kfzs_duanduan_datashare_package_name), "");
             SheepApp.getInstance().setGamePackgeName(packageName);
             if (TextUtils.isEmpty(SheepApp.getInstance().getGameCode()) || TextUtils.isEmpty(packageName)) {
-                CertificationUtil.newInstance().showCertificationErrorAndExitApp("", 2000);
+                CertificationUtil.newInstance().showCertificationErrorAndExitApp(this, "", 2000);
                 return;
             }
             hasToken();
         } else {
-            CertificationUtil.newInstance().showCertificationErrorAndExitApp("", 2000);
+            CertificationUtil.newInstance().showCertificationErrorAndExitApp(this, "", 2000);
         }
         //获取登录过的用户列表
         userList.addAll(DDProviderHelper.getInstance().getSdkLoginUserList(SheepApp.getInstance().getConnectAddress().name()));

+ 3 - 2
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -145,6 +145,9 @@ public class SheepApp extends MultiDexApplication {
     public void setConnectAddress(ConnectAddress connectAddress) {
         if (this.connectAddress != connectAddress) {
             DataUtil.putAsString("flavor", connectAddress.name());
+            if (activityRef != null && activityRef.get() != null) {
+                activityRef.get().finish();
+            }
             quit();
         } else {
             G.showToast("已经是该服务器");
@@ -504,8 +507,6 @@ public class SheepApp extends MultiDexApplication {
         }
         try {
             OkDownload.with().downloadDispatcher().cancelAll();
-            android.os.Process.killProcess(android.os.Process.myPid());
-            System.exit(0);
         } catch (Exception ignore) {
         }
     }

+ 26 - 0
app/src/main/res/layout/fragment_login_welcome.xml

@@ -31,4 +31,30 @@
         android:text="登录" />
 
     <include layout="@layout/footer_thirdpart_login" />
+
+    <TextView
+        android:id="@+id/test_change"
+        style="@style/style_button_small_yellow"
+        android:layout_width="wrap_content"
+        android:layout_height="30dp"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentTop="true"
+        android:layout_margin="@dimen/dp_10"
+        android:paddingEnd="@dimen/dp_10"
+        android:paddingStart="@dimen/dp_10"
+        android:text="切换服务器"
+        android:visibility="gone" />
+
+    <TextView
+        android:id="@+id/test_change_user"
+        style="@style/style_button_small_yellow"
+        android:layout_width="wrap_content"
+        android:layout_height="30dp"
+        android:layout_alignParentEnd="true"
+        android:layout_below="@+id/test_change"
+        android:layout_margin="@dimen/dp_10"
+        android:paddingEnd="@dimen/dp_10"
+        android:paddingStart="@dimen/dp_10"
+        android:text="切换账号"
+        android:visibility="gone" />
 </RelativeLayout>

+ 0 - 24
app/src/main/res/layout/fragment_sign_in.xml

@@ -143,30 +143,6 @@
 
     <include layout="@layout/footer_thirdpart_login" />
 
-    <TextView
-        android:id="@+id/test_change"
-        style="@style/style_button_small_yellow"
-        android:layout_width="wrap_content"
-        android:layout_height="30dp"
-        android:layout_alignParentEnd="true"
-        android:layout_alignParentTop="true"
-        android:layout_margin="@dimen/dp_10"
-        android:paddingEnd="@dimen/dp_10"
-        android:paddingStart="@dimen/dp_10"
-        android:text="切换服务器"
-        android:visibility="gone" />
 
-    <TextView
-        android:id="@+id/test_change_user"
-        style="@style/style_button_small_yellow"
-        android:layout_width="wrap_content"
-        android:layout_height="30dp"
-        android:layout_alignParentEnd="true"
-        android:layout_below="@+id/test_change"
-        android:layout_margin="@dimen/dp_10"
-        android:paddingEnd="@dimen/dp_10"
-        android:paddingStart="@dimen/dp_10"
-        android:text="切换账号"
-        android:visibility="gone" />
 
 </RelativeLayout>