From a8071581a09caaed0de552e7762618eb0325bc5a Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Thu, 20 Jul 2023 11:53:45 +0200 Subject: [PATCH] refs ##5613 login --- app/build.gradle | 4 +-- .../es/verdnatura/domain/SilexCallback.kt | 27 +++++++++++++++---- .../feature/login/fragment/LoginFragment.kt | 5 ++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 42453a4b..9cab2c50 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "es.verdnatura" minSdkVersion 24 //21 targetSdkVersion 33 - versionCode 214 - versionName = "23.28Beta" //Esta rama viene de esta version + versionCode 217 + versionName = "23.28" //Esta rama viene de esta version testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/es/verdnatura/domain/SilexCallback.kt b/app/src/main/java/es/verdnatura/domain/SilexCallback.kt index 234d7435..ecdf6ec7 100644 --- a/app/src/main/java/es/verdnatura/domain/SilexCallback.kt +++ b/app/src/main/java/es/verdnatura/domain/SilexCallback.kt @@ -1,6 +1,6 @@ package es.verdnatura.domain -import android.app.Activity +import android.app.ActivityManager import android.content.Context import android.content.Intent import es.verdnatura.presentation.base.nameofFunction @@ -35,10 +35,14 @@ abstract class SilexCallback(val context: Context) : Callback { var message = JSONObject(response.message()).getString("Message") onError(Error(message)) } else if (response.code() == 401) { - val intent = Intent(context, LoginActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(intent) - exitProcess(0) + if (!isActivityRunning(context, LoginActivity::class.java)) { + val intent = Intent(context, LoginActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(intent) + exitProcess(0) + } else { + onError(Error(response.message().toString())) + } } else { onError(Error(response.message().toString())) } @@ -70,5 +74,18 @@ abstract class SilexCallback(val context: Context) : Callback { throw t } + fun isActivityRunning(context: Context, activityClass: Class<*>): Boolean { + val packageName = context.packageName + val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + val runningActivities = activityManager.getRunningTasks(Int.MAX_VALUE) + + for (taskInfo in runningActivities) { + if (taskInfo.baseActivity?.className == activityClass.name && taskInfo.topActivity?.packageName == packageName) { + return true + } + } + + return false + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt index 3440ab4d..160e5901 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt @@ -95,6 +95,7 @@ class LoginFragment(var imageUri: Uri?) : //deleteWorkForm("all") listForms = getWorkForm().sortedBy { it.created } + binding.edittextServer.keyListener = null binding.edittextServer.setOnLongClickListener { showWorkingForms() @@ -526,8 +527,8 @@ class LoginFragment(var imageUri: Uri?) : } else { if (!it.list[0].isError) { - app.renewPeriod = it.list[0].renewPeriod!! - app.renewInterval = it.list[0].renewInterval!! + /* app.renewPeriod = it.list[0].renewPeriod!! + app.renewInterval = it.list[0].renewInterval!!*/ saveDataLong("renewPeriod", it.list[0].renewPeriod!!) saveDataLong("renewInterval", it.list[0].renewInterval) viewModel.operator_add()