|
@@ -1,17 +1,25 @@
|
|
|
package com.xuqinmin.android.app.ui
|
|
|
|
|
|
+import android.R.attr
|
|
|
import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.telephony.TelephonyManager
|
|
|
+import android.util.Log
|
|
|
import androidx.activity.viewModels
|
|
|
import com.bigkoo.alertview.AlertView
|
|
|
+import com.google.android.gms.auth.api.signin.GoogleSignIn
|
|
|
+import com.google.android.gms.auth.api.signin.GoogleSignInAccount
|
|
|
+import com.google.android.gms.auth.api.signin.GoogleSignInClient
|
|
|
+import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
|
|
+import com.google.android.gms.common.api.ApiException
|
|
|
+import com.google.android.gms.tasks.Task
|
|
|
import com.xuqinmin.android.app.MyApplication
|
|
|
import com.xuqinmin.android.app.R
|
|
|
import com.xuqinmin.android.app.common.DEVICE_ID
|
|
|
+import com.xuqinmin.android.app.common.GOOGLE_ID
|
|
|
import com.xuqinmin.android.app.common.MCC
|
|
|
import com.xuqinmin.android.app.databinding.ActivityWelcomeBinding
|
|
|
import com.xuqinmin.android.app.model.DataLogin
|
|
|
-import com.xuqinmin.android.app.model.ModelHideIn
|
|
|
import com.xuqinmin.android.app.viewmodel.WelcomeVM
|
|
|
import com.xuqm.base.common.AppManager
|
|
|
import com.xuqm.base.common.DeviceUuidFactory
|
|
@@ -19,17 +27,17 @@ import com.xuqm.base.common.GsonImplHelp
|
|
|
import com.xuqm.base.common.SHARE_LOGIN_OBJ
|
|
|
import com.xuqm.base.common.SHARE_UESR_ID
|
|
|
import com.xuqm.base.common.SHARE_UESR_TOKEN
|
|
|
+import com.xuqm.base.common.ToolsHelper
|
|
|
import com.xuqm.base.dialog.loading.LoadingDialog
|
|
|
import com.xuqm.base.extensions.Fonts
|
|
|
-import com.xuqm.base.extensions.getIntForPreferences
|
|
|
import com.xuqm.base.extensions.getStringForPreferences
|
|
|
+import com.xuqm.base.extensions.loge
|
|
|
import com.xuqm.base.extensions.putInt
|
|
|
import com.xuqm.base.extensions.putString
|
|
|
import com.xuqm.base.extensions.setFont
|
|
|
import com.xuqm.base.extensions.showMessage
|
|
|
import com.xuqm.base.ui.BaseActivity
|
|
|
import com.xuqm.base.web.XWebViewHelper
|
|
|
-import kotlin.random.Random
|
|
|
|
|
|
|
|
|
class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|
@@ -38,10 +46,18 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|
|
override fun fullscreen(): Boolean = true
|
|
|
|
|
|
private val vm: WelcomeVM by viewModels()
|
|
|
-
|
|
|
+ private lateinit var mGoogleSignInClient: GoogleSignInClient
|
|
|
override fun initView(savedInstanceState: Bundle?) {
|
|
|
super.initView(savedInstanceState)
|
|
|
AppManager.getInstance().logout()
|
|
|
+
|
|
|
+ val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
|
|
+ .requestEmail()
|
|
|
+ .build()
|
|
|
+ mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
|
|
|
+ val account = GoogleSignIn.getLastSignedInAccount(this)
|
|
|
+ account?.loge()
|
|
|
+
|
|
|
binding.world1.setFont(mContext, Fonts.Bold)
|
|
|
binding.world2.setFont(mContext, Fonts.Bold)
|
|
|
binding.loginGuest.setFont(mContext, Fonts.Bold)
|
|
@@ -71,6 +87,7 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|
|
}
|
|
|
binding.loginGuest.setOnClickListener {
|
|
|
LoadingDialog.showDialog("")
|
|
|
+ putString(GOOGLE_ID,"")
|
|
|
vm.thirdLogin(
|
|
|
DataLogin(
|
|
|
getStringForPreferences(DEVICE_ID),
|
|
@@ -80,9 +97,47 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|
|
)
|
|
|
}
|
|
|
binding.loginGoogle.setOnClickListener {
|
|
|
+ val signInIntent = mGoogleSignInClient.signInIntent
|
|
|
+ startActivityForResult(signInIntent, 10010)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data)
|
|
|
+ if (requestCode === 10010) {
|
|
|
+ // The Task returned from this call is always completed, no need to attach
|
|
|
+ // a listener.
|
|
|
+ val task: Task<GoogleSignInAccount> =
|
|
|
+ GoogleSignIn.getSignedInAccountFromIntent(data)
|
|
|
+ handleSignInResult(task)
|
|
|
}
|
|
|
}
|
|
|
+ private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
|
|
|
+ try {
|
|
|
+ val account = completedTask.getResult(ApiException::class.java)
|
|
|
+ account.loge()
|
|
|
+ account.id?.let {
|
|
|
+ putString(GOOGLE_ID,it)
|
|
|
+ LoadingDialog.showDialog("")
|
|
|
+ vm.thirdLogin(
|
|
|
+ DataLogin(
|
|
|
+ getStringForPreferences(DEVICE_ID),
|
|
|
+ it,
|
|
|
+ 2
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
+ // Signed in successfully, show authenticated UI.
|
|
|
+// updateUI(account)
|
|
|
+ } catch (e: ApiException) {
|
|
|
+ // The ApiException status code indicates the detailed failure reason.
|
|
|
+ // Please refer to the GoogleSignInStatusCodes class reference for more information.
|
|
|
+ Log.w(TAG, "signInResult:failed code=" + e.statusCode)
|
|
|
+// updateUI(null)
|
|
|
+ "Failed to obtain account information".showMessage()
|
|
|
+ }
|
|
|
+ }
|
|
|
override fun initData() {
|
|
|
super.initData()
|
|
|
val telManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
|
@@ -134,11 +189,12 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|
|
val stringForPreferences = getStringForPreferences(SHARE_LOGIN_OBJ)
|
|
|
if (stringForPreferences.isNotEmpty()) {
|
|
|
LoadingDialog.showDialog("")
|
|
|
+ val googleId = getStringForPreferences(GOOGLE_ID)
|
|
|
vm.thirdLogin(
|
|
|
DataLogin(
|
|
|
getStringForPreferences(DEVICE_ID),
|
|
|
- getStringForPreferences(DEVICE_ID),
|
|
|
- 0
|
|
|
+ if (ToolsHelper.isNull(googleId))getStringForPreferences(DEVICE_ID) else googleId,
|
|
|
+ if (ToolsHelper.isNull(googleId))0 else 2
|
|
|
)
|
|
|
)
|
|
|
}
|