Ver código fonte

confirm switch account

billyyoyo 6 anos atrás
pai
commit
f1a74c23b2

+ 6 - 0
app/src/main/AndroidManifest.xml

@@ -330,6 +330,12 @@
             android:screenOrientation="behind"
             android:theme="@style/AppThemeTransparent" />
         <activity
+            android:name="com.sheep.gamegroup.module.login.AccountConsistenceAct"
+            android:exported="true"
+            android:launchMode="singleTask"
+            android:screenOrientation="behind"
+            android:theme="@style/AppThemeTransparent" />
+        <activity
             android:name="com.sheep.gamegroup.view.activity.ActBindMobileRegister"
             android:launchMode="singleTask"
             android:screenOrientation="portrait"

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/event/EventTypes.java

@@ -10,6 +10,8 @@ package com.sheep.gamegroup.event;
 
 public enum EventTypes {
 
+    APP_EXIT,
+
     TIPS_DOWN_ICON,//下载图标的小红点
     TIPS_USER_ICON,//用户图标的小红点
     TIPS_BOOK_ICON,//用户预约的小红点

+ 143 - 0
app/src/main/java/com/sheep/gamegroup/module/login/AccountConsistenceAct.java

@@ -0,0 +1,143 @@
+package com.sheep.gamegroup.module.login;
+
+import android.content.Intent;
+import android.support.v7.app.AlertDialog;
+import android.text.TextUtils;
+import android.view.TextureView;
+import android.view.View;
+import android.widget.TextView;
+
+import com.sheep.gamegroup.absBase.BaseActivity;
+import com.sheep.gamegroup.event.BigEvent;
+import com.sheep.gamegroup.event.EventTypes;
+import com.sheep.gamegroup.greendao.DDProviderHelper;
+import com.sheep.gamegroup.greendao.download.SdkLoginUser;
+import com.sheep.gamegroup.model.entity.UserEntity;
+import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
+
+import org.greenrobot.eventbus.EventBus;
+
+import butterknife.BindView;
+import butterknife.OnClick;
+
+public class AccountConsistenceAct extends BaseActivity {
+
+    @BindView(R.id.spin_view)
+    public View spin_view;
+    @BindView(R.id.close_btn)
+    public View close_btn;
+    @BindView(R.id.dialog_container)
+    public View dialog_container;
+    @BindView(R.id.game_code_view)
+    public TextView game_code_view;
+    @BindView(R.id.sheep_code_view)
+    public TextView sheep_code_view;
+
+    private int sdkAction;
+
+    private String gameCode, sheepCode, resultToken;
+    private UserEntity user;
+
+    @Override
+    protected int getLayoutId() {
+        return R.layout.act_account_consistence;
+    }
+
+    @Override
+    public void initView() {
+        spin_view.setVisibility(View.VISIBLE);
+        dialog_container.setVisibility(View.GONE);
+        sdkAction = getIntent().getIntExtra("sdk_action", 0);
+        TitleBarUtils.getInstance().setShowOrHide(this, false);
+        String game_token = getIntent().getStringExtra("game_token");
+        if (TextUtils.isEmpty(game_token)) {
+            finishWithResult(-1, null);
+            return;
+        }
+        String sheep_token = SpUtils.getToken(this);
+        sheepCode = DataUtil.getInstance().getInvitationCode();
+        if (TextUtils.isEmpty(sheep_token)) {
+            checkSdkUser(game_token, false);
+        } else {
+            String game_user_id = game_token.substring(0, game_token.indexOf("@"));
+            if (sheep_token.startsWith(game_user_id)) {
+                finishWithResult(0, game_token);
+            } else {
+                checkSdkUser(game_token, true);
+            }
+        }
+    }
+
+    private void checkSdkUser(String gameToken, boolean needAsk) {
+        SdkLoginUser user = DDProviderHelper.getInstance().getSdkLoginUser(gameToken);
+        gameCode = user.getInvitation_code();
+        if (user != null) {
+            getUserInfo(user.getToken(), needAsk);
+        } else {
+            getUserInfo(gameToken, needAsk);
+        }
+    }
+
+    private void getUserInfo(String token, boolean needAsk) {
+        CommonUtil.getInstance().getUserInfo(token, (user) -> {
+            if (user != null) {
+                this.user = user;
+                this.resultToken = token;
+                if (needAsk && !TextUtils.isEmpty(gameCode) && !TextUtils.isEmpty(sheepCode)) {
+                    spin_view.setVisibility(View.GONE);
+                    dialog_container.setVisibility(View.VISIBLE);
+                    close_btn.setVisibility(View.VISIBLE);
+                    game_code_view.setText(gameCode);
+                    sheep_code_view.setText(sheepCode);
+                } else {
+                    switchAccount(token, user);
+                }
+            } else {
+                finishWithResult(-2, null);
+            }
+        });
+    }
+
+    private void switchAccount(String token, UserEntity user) {
+        SpUtils.saveToken(this, token);
+        DataUtil.getInstance().initUserEntity(user);
+        finishWithResult(0, token);
+        EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.APP_EXIT));
+    }
+
+    @Override
+    public void onBackPressed() {
+        finishWithResult(-1, null);
+    }
+
+    @OnClick(R.id.close_btn)
+    public void onClose() {
+        finishWithResult(-1, null);
+    }
+
+    @OnClick(R.id.cancel_btn)
+    public void onCancel() {
+        finishWithResult(-1, null);
+    }
+
+    @OnClick(R.id.confirm_btn)
+    public void onConfirm() {
+        switchAccount(resultToken, user);
+    }
+
+    private void finishWithResult(int resultCode, String token) {
+        Intent intent = new Intent();
+        intent.putExtra("code", resultCode);
+        intent.putExtra("action", sdkAction);
+        if (TextUtils.isEmpty(token)) {
+            intent.putExtra("token", token);
+        }
+        setResult(RESULT_OK, intent);
+        finish();
+    }
+
+}

+ 16 - 7
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -331,13 +331,7 @@ public class ActMain extends BaseActYmPermissionCheck {
 //                }
 //            }
 //            transaction.commitAllowingStateLoss();
-            releaseInputMethodRefView();
-            Intent intent = new Intent();
-            intent.setAction(Intent.ACTION_MAIN);// "android.intent.action.MAIN"
-            intent.addCategory(Intent.CATEGORY_HOME); //"android.intent.category.HOME"
-            startActivity(intent);
-            SheepApp.getInstance().quit();
-            finish();
+            exit(true);
         } else {
             try {
                 G.showToast(R.string.toast_double_click_exit_app);
@@ -348,6 +342,18 @@ public class ActMain extends BaseActYmPermissionCheck {
         mLastBackTime = System.currentTimeMillis();
     }
 
+    private void exit(boolean backToHome){
+        releaseInputMethodRefView();
+        if(backToHome) {
+            Intent intent = new Intent();
+            intent.setAction(Intent.ACTION_MAIN);// "android.intent.action.MAIN"
+            intent.addCategory(Intent.CATEGORY_HOME); //"android.intent.category.HOME"
+            startActivity(intent);
+        }
+        SheepApp.getInstance().quit();
+        finish();
+    }
+
     private long lastBackTime = 0;
     private int pressCount = 0;
     private static final int PERIOD = 400;
@@ -458,6 +464,9 @@ public class ActMain extends BaseActYmPermissionCheck {
             case STORAGE_LOW:
                 DialogStorageLow.showDialog(null);
                 break;
+            case APP_EXIT:
+                exit(false);
+                return;
         }
         if (progressView != null && event.getData() instanceof DownLoadInfo) {
             DownLoadInfo task = (DownLoadInfo) event.getData();

+ 6 - 0
app/src/main/res/drawable/shape_blue_4ac155_18.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="#4ac155" />
+    <corners android:radius="18dp"  />
+</shape>

+ 6 - 0
app/src/main/res/drawable/shape_green_36a5ed_18.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="#36a5ed" />
+    <corners android:radius="18dp"  />
+</shape>

+ 7 - 0
app/src/main/res/drawable/shape_grey_stroke_2a3342_10.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="#ff2a3342" />
+    <stroke android:width="1dp" android:color="#59868d9e" />
+    <corners android:radius="10dp" />
+</shape>

+ 9 - 0
app/src/main/res/drawable/shape_oval_blue_gradient.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval">
+    <solid android:color="#ff4ac155" />
+    <gradient
+        android:angle="315"
+        android:endColor="#ff3293d2"
+        android:startColor="#ff084564" />
+</shape>

+ 9 - 0
app/src/main/res/drawable/shape_oval_green_gradient.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval">
+    <solid android:color="#ff4ac155" />
+    <gradient
+        android:angle="315"
+        android:endColor="#ff5d61bc"
+        android:startColor="#ff10416e" />
+</shape>

+ 6 - 0
app/src/main/res/drawable/shape_oval_grey_stroke_3c495e.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval">
+    <solid android:color="#ff3c495e" />
+    <stroke android:width="1dp" android:color="#597f8595" />
+</shape>

+ 161 - 0
app/src/main/res/layout/act_account_consistence.xml

@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="#50000000">
+
+    <com.github.ybq.android.spinkit.SpinKitView
+        android:id="@+id/spin_view"
+        style="@style/SpinKitView.Large.ThreeBounce"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_above="@+id/change_account_tv"
+        android:layout_centerHorizontal="true"
+        android:visibility="invisible"
+        app:SpinKit_Color="@color/colorAccent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <android.support.constraint.ConstraintLayout
+        android:id="@+id/dialog_container"
+        android:visibility="gone"
+        android:layout_width="320dp"
+        android:layout_height="200dp"
+        android:background="@drawable/shape_grey_stroke_2a3342_10"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
+
+        <TextView
+            android:layout_marginTop="12dp"
+            app:layout_constraintTop_toTopOf="parent"
+            android:gravity="center"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="温馨提示"
+            android:textColor="#ffc6f0ff"
+            android:textSize="14sp" />
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="center"
+            app:layout_constraintTop_toTopOf="parent"
+            android:text="检测的到你小绵羊APP登录的账号与游戏登录账号不一致,是否将小绵羊APP账号切换为游戏账号。"
+            android:textColor="#ffa1b3c7"
+            android:textSize="12sp"
+            android:layout_marginLeft="20dp"
+            android:layout_marginRight="20dp"
+            android:layout_marginTop="46dp"/>
+
+        <Button
+            android:id="@+id/cancel_btn"
+            android:text="取消"
+            android:textSize="14sp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintLeft_toLeftOf="parent"
+            android:layout_marginBottom="16dp"
+            android:layout_marginLeft="50dp"
+            android:background="@drawable/shape_green_36a5ed_18"
+            android:textColor="@color/white"
+            android:layout_width="90dp"
+            android:layout_height="30dp" />
+
+        <LinearLayout
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintRight_toLeftOf="@+id/arrow_view"
+            android:layout_marginTop="96dp"
+            android:gravity="center"
+            android:orientation="horizontal"
+            android:layout_width="wrap_content"
+            android:layout_height="40dp">
+            <TextView
+                android:background="@drawable/shape_oval_blue_gradient"
+                android:text="游戏"
+                android:textSize="12sp"
+                android:textColor="@color/white"
+                android:gravity="center"
+                android:layout_width="40dp"
+                android:layout_height="40dp" />
+            <TextView
+                android:id="@+id/game_code_view"
+                android:layout_marginLeft="8dp"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="1546546"
+                android:textColor="#ffffffff"
+                android:textSize="13sp"/>
+        </LinearLayout>
+        
+        <ImageView
+            android:id="@+id/arrow_view"
+            android:src="@mipmap/arrow_right_img"
+            app:layout_constraintLeft_toLeftOf="parent"
+            android:padding="5dp"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            android:layout_marginTop="106dp"
+            android:tint="#36A5ED"
+            android:layout_width="34dp"
+            android:layout_height="20dp" />
+
+        <LinearLayout
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintLeft_toRightOf="@+id/arrow_view"
+            android:layout_marginTop="96dp"
+            android:gravity="center"
+            android:orientation="horizontal"
+            android:layout_width="wrap_content"
+            android:layout_height="40dp">
+            <TextView
+                android:background="@drawable/shape_oval_green_gradient"
+                android:text="APP"
+                android:textSize="12sp"
+                android:textColor="@color/white"
+                android:gravity="center"
+                android:layout_width="40dp"
+                android:layout_height="40dp" />
+            <TextView
+                android:id="@+id/sheep_code_view"
+                android:layout_marginLeft="8dp"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="1546546"
+                android:textColor="#ffffffff"
+                android:textSize="13sp"/>
+        </LinearLayout>
+
+        <Button
+            android:id="@+id/confirm_btn"
+            android:text="切换"
+            android:textSize="14sp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            android:layout_marginBottom="16dp"
+            android:layout_marginRight="50dp"
+            android:background="@drawable/shape_blue_4ac155_18"
+            android:textColor="@color/white"
+            android:layout_width="90dp"
+            android:layout_height="30dp" />
+
+    </android.support.constraint.ConstraintLayout>
+    
+    <ImageView
+        android:id="@+id/close_btn"
+        android:src="@mipmap/x"
+        android:tint="#9BB1D5"
+        android:padding="12dp"
+        android:visibility="gone"
+        android:background="@drawable/shape_oval_grey_stroke_3c495e"
+        app:layout_constraintLeft_toLeftOf="@+id/dialog_container"
+        app:layout_constraintBottom_toBottomOf="@+id/dialog_container"
+        android:layout_marginBottom="180dp"
+        android:layout_marginLeft="295dp"
+        android:layout_width="36dp"
+        android:layout_height="36dp" />
+
+</android.support.constraint.ConstraintLayout>