honghengqiang 11 месяцев назад
Родитель
Сommit
a5b865ca7c

+ 49 - 22
app/src/main/java/com/swago/app/SplashActivity.kt

@@ -1,10 +1,11 @@
 package com.swago.app
 
 import android.Manifest
-import androidx.appcompat.app.AppCompatActivity
+import android.os.Build
 import android.os.Bundle
 import android.widget.Toast
 import androidx.activity.viewModels
+import androidx.appcompat.app.AppCompatActivity
 import com.alibaba.android.arouter.launcher.ARouter
 import com.permissionx.guolindev.PermissionX
 import com.swago.baseswago.constant.ARouteConstant
@@ -17,29 +18,55 @@ class SplashActivity : AppCompatActivity() {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_splash)
 
-        PermissionX.init(this@SplashActivity)
-            .permissions(
-                Manifest.permission.READ_EXTERNAL_STORAGE,
-                Manifest.permission.WRITE_EXTERNAL_STORAGE
-            )
-            .request { allGranted, grantedList, deniedList ->
-                if (allGranted) {
-                    splashVm.getApiDomain()
-                    splashVm.jumpToLoginLiveData.observe(this){
-                        if (!it){
-                            ARouter.getInstance().build(ARouteConstant.Login.login).navigation()
-                            finish()
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
+            PermissionX.init(this@SplashActivity)
+                .permissions(
+                    Manifest.permission.READ_MEDIA_IMAGES,
+                )
+                .request { allGranted, grantedList, deniedList ->
+                    if (allGranted) {
+                        splashVm.getApiDomain()
+                        splashVm.jumpToLoginLiveData.observe(this){
+                            if (!it){
+                                ARouter.getInstance().build(ARouteConstant.Login.login).navigation()
+                                finish()
+                            }
+                        }
+                    } else {
+                        Toast.makeText(
+                            this@SplashActivity,
+                            "These permissions are denied: $deniedList",
+                            Toast.LENGTH_LONG
+                        ).show()
+                        ARouter.getInstance().build(ARouteConstant.Login.login).navigation()
+                        finish()
+                    }
+                }
+        }else {
+            PermissionX.init(this@SplashActivity)
+                .permissions(
+                    Manifest.permission.READ_EXTERNAL_STORAGE,
+                    Manifest.permission.WRITE_EXTERNAL_STORAGE
+                )
+                .request { allGranted, grantedList, deniedList ->
+                    if (allGranted) {
+                        splashVm.getApiDomain()
+                        splashVm.jumpToLoginLiveData.observe(this){
+                            if (!it){
+                                ARouter.getInstance().build(ARouteConstant.Login.login).navigation()
+                                finish()
+                            }
                         }
+                    } else {
+                        Toast.makeText(
+                            this@SplashActivity,
+                            "These permissions are denied: $deniedList",
+                            Toast.LENGTH_LONG
+                        ).show()
+                        ARouter.getInstance().build(ARouteConstant.Login.login).navigation()
+                        finish()
                     }
-                } else {
-                    Toast.makeText(
-                        this@SplashActivity,
-                        "These permissions are denied: $deniedList",
-                        Toast.LENGTH_LONG
-                    ).show()
-                    ARouter.getInstance().build(ARouteConstant.Login.login).navigation()
-                    finish()
                 }
-            }
+        }
     }
 }

+ 115 - 51
login/src/main/java/com/swago/login/LoginActivity.kt

@@ -3,6 +3,7 @@ package com.swago.login
 import android.Manifest
 import android.app.Activity
 import android.content.Intent
+import android.os.Build
 import android.view.View
 import android.widget.Toast
 import androidx.activity.viewModels
@@ -52,22 +53,41 @@ class LoginActivity : BaseXActivity<ActivityLoginBinding>() {
         binding.clFaceBook.setOnClickListener(object : NoDoubleClickListener() {
             override fun onClick() {
                 if (SwagoShareUtils.isInstall(this@LoginActivity,FACEBOOK)){
-                    PermissionX.init(this@LoginActivity)
-                        .permissions(
-                            Manifest.permission.READ_EXTERNAL_STORAGE
-                        )
-                        .request { allGranted, grantedList, deniedList ->
-                            if (allGranted) {
-                                FBLogin.login(this@LoginActivity)
-                            } else {
-                                FBLogin.login(this@LoginActivity)
-                                Toast.makeText(
-                                    this@LoginActivity,
-                                    "These permissions are denied: $deniedList",
-                                    Toast.LENGTH_LONG
-                                ).show()
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
+                        PermissionX.init(this@LoginActivity)
+                            .permissions(
+                                Manifest.permission.READ_MEDIA_IMAGES
+                            )
+                            .request { allGranted, grantedList, deniedList ->
+                                if (allGranted) {
+                                    FBLogin.login(this@LoginActivity)
+                                } else {
+                                    FBLogin.login(this@LoginActivity)
+                                    Toast.makeText(
+                                        this@LoginActivity,
+                                        "These permissions are denied: $deniedList",
+                                        Toast.LENGTH_LONG
+                                    ).show()
+                                }
                             }
-                        }
+                    }else{
+                        PermissionX.init(this@LoginActivity)
+                            .permissions(
+                                Manifest.permission.READ_EXTERNAL_STORAGE
+                            )
+                            .request { allGranted, grantedList, deniedList ->
+                                if (allGranted) {
+                                    FBLogin.login(this@LoginActivity)
+                                } else {
+                                    FBLogin.login(this@LoginActivity)
+                                    Toast.makeText(
+                                        this@LoginActivity,
+                                        "These permissions are denied: $deniedList",
+                                        Toast.LENGTH_LONG
+                                    ).show()
+                                }
+                            }
+                    }
                 }else{
                     Toast.makeText(AppContext.getContext(), AppContext.getContext().resources.getString(R.string.install_facebook), Toast.LENGTH_SHORT).show()
                 }
@@ -77,22 +97,41 @@ class LoginActivity : BaseXActivity<ActivityLoginBinding>() {
         binding.clGoogle.setOnClickListener(object : NoDoubleClickListener() {
             override fun onClick() {
                 if (SwagoShareUtils.isInstall(this@LoginActivity,GOOGLE)) {
-                    PermissionX.init(this@LoginActivity)
-                        .permissions(
-                            Manifest.permission.READ_EXTERNAL_STORAGE
-                        )
-                        .request { allGranted, grantedList, deniedList ->
-                            if (allGranted) {
-                                GoogleLogin.login(this@LoginActivity)
-                            } else {
-                                GoogleLogin.login(this@LoginActivity)
-                                Toast.makeText(
-                                    this@LoginActivity,
-                                    "These permissions are denied: $deniedList",
-                                    Toast.LENGTH_LONG
-                                ).show()
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
+                        PermissionX.init(this@LoginActivity)
+                            .permissions(
+                                Manifest.permission.READ_MEDIA_IMAGES
+                            )
+                            .request { allGranted, grantedList, deniedList ->
+                                if (allGranted) {
+                                    GoogleLogin.login(this@LoginActivity)
+                                } else {
+                                    GoogleLogin.login(this@LoginActivity)
+                                    Toast.makeText(
+                                        this@LoginActivity,
+                                        "These permissions are denied: $deniedList",
+                                        Toast.LENGTH_LONG
+                                    ).show()
+                                }
                             }
-                        }
+                    }else{
+                        PermissionX.init(this@LoginActivity)
+                            .permissions(
+                                Manifest.permission.READ_EXTERNAL_STORAGE
+                            )
+                            .request { allGranted, grantedList, deniedList ->
+                                if (allGranted) {
+                                    GoogleLogin.login(this@LoginActivity)
+                                } else {
+                                    GoogleLogin.login(this@LoginActivity)
+                                    Toast.makeText(
+                                        this@LoginActivity,
+                                        "These permissions are denied: $deniedList",
+                                        Toast.LENGTH_LONG
+                                    ).show()
+                                }
+                            }
+                    }
                 }else{
                     Toast.makeText(AppContext.getContext(), "", Toast.LENGTH_SHORT).show()
                 }
@@ -139,28 +178,53 @@ class LoginActivity : BaseXActivity<ActivityLoginBinding>() {
 
         binding.ivAccountLogin.setOnClickListener(object:NoDoubleClickListener(){
             override fun onClick() {
-                PermissionX.init(this@LoginActivity)
-                    .permissions(
-                        Manifest.permission.READ_EXTERNAL_STORAGE
-                    )
-                    .request { allGranted, grantedList, deniedList ->
-                        if (allGranted) {
-                            SwagoLoading.showLoadingDialog(this@LoginActivity)
-                            val account = binding.etAccount.text.toString()
-                            val secret = binding.etSecret.text.toString()
-                            loginVm.loginByAccount(account, secret)
-                        } else {
-                            SwagoLoading.showLoadingDialog(this@LoginActivity)
-                            val account = binding.etAccount.text.toString()
-                            val secret = binding.etSecret.text.toString()
-                            loginVm.loginByAccount(account, secret)
-                            Toast.makeText(
-                                this@LoginActivity,
-                                "These permissions are denied: $deniedList",
-                                Toast.LENGTH_LONG
-                            ).show()
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
+                    PermissionX.init(this@LoginActivity)
+                        .permissions(
+                            Manifest.permission.READ_MEDIA_IMAGES
+                        )
+                        .request { allGranted, grantedList, deniedList ->
+                            if (allGranted) {
+                                SwagoLoading.showLoadingDialog(this@LoginActivity)
+                                val account = binding.etAccount.text.toString()
+                                val secret = binding.etSecret.text.toString()
+                                loginVm.loginByAccount(account, secret)
+                            } else {
+                                SwagoLoading.showLoadingDialog(this@LoginActivity)
+                                val account = binding.etAccount.text.toString()
+                                val secret = binding.etSecret.text.toString()
+                                loginVm.loginByAccount(account, secret)
+                                Toast.makeText(
+                                    this@LoginActivity,
+                                    "These permissions are denied: $deniedList",
+                                    Toast.LENGTH_LONG
+                                ).show()
+                            }
                         }
-                    }
+                }else{
+                    PermissionX.init(this@LoginActivity)
+                        .permissions(
+                            Manifest.permission.READ_EXTERNAL_STORAGE
+                        )
+                        .request { allGranted, grantedList, deniedList ->
+                            if (allGranted) {
+                                SwagoLoading.showLoadingDialog(this@LoginActivity)
+                                val account = binding.etAccount.text.toString()
+                                val secret = binding.etSecret.text.toString()
+                                loginVm.loginByAccount(account, secret)
+                            } else {
+                                SwagoLoading.showLoadingDialog(this@LoginActivity)
+                                val account = binding.etAccount.text.toString()
+                                val secret = binding.etSecret.text.toString()
+                                loginVm.loginByAccount(account, secret)
+                                Toast.makeText(
+                                    this@LoginActivity,
+                                    "These permissions are denied: $deniedList",
+                                    Toast.LENGTH_LONG
+                                ).show()
+                            }
+                        }
+                }
             }
         })
     }