feat issues refs #7636
This commit is contained in:
parent
dfd676613f
commit
67cd2b1fd2
|
@ -1,8 +1,10 @@
|
|||
package es.verdnatura
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.graphics.Color
|
||||
import android.media.MediaPlayer
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import es.verdnatura.dataStore.DataStoreLocal
|
||||
|
@ -16,6 +18,7 @@ import es.verdnatura.presentation.common.LoginListener
|
|||
import es.verdnatura.presentation.common.MainActivityListener
|
||||
import es.verdnatura.presentation.common.SignListener
|
||||
import es.verdnatura.presentation.view.component.CustomDialogMainActivity
|
||||
import es.verdnatura.presentation.view.feature.login.activity.LoginActivity
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.core.context.loadKoinModules
|
||||
|
@ -78,7 +81,7 @@ class MobileApplication : Application(), InteceptorListener {
|
|||
val restClient = RestClient(this, this)
|
||||
salix = restClient.salixClient
|
||||
|
||||
/* registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
||||
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||
}
|
||||
|
||||
|
@ -104,7 +107,7 @@ class MobileApplication : Application(), InteceptorListener {
|
|||
override fun onActivityDestroyed(activity: Activity) {
|
||||
isActivityLoginRunning = false
|
||||
}
|
||||
})*/
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
@ -127,6 +130,9 @@ class MobileApplication : Application(), InteceptorListener {
|
|||
)
|
||||
}
|
||||
|
||||
fun isLoginRunning(): Boolean {
|
||||
return isActivityLoginRunning
|
||||
}
|
||||
override fun onInterceptionResult(visibility: Int) {
|
||||
if (mainActivityListener != null) {
|
||||
handler.post {
|
||||
|
@ -149,6 +155,7 @@ class MobileApplication : Application(), InteceptorListener {
|
|||
val settings = this.resources.configuration
|
||||
return settings.locales.get(0).language
|
||||
}
|
||||
|
||||
fun clearApplicationData() {
|
||||
try {
|
||||
val cacheDir = this.cacheDir
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package es.verdnatura.domain
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.google.gson.Gson
|
||||
|
@ -26,7 +25,7 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
|
|||
var message = JSONObject(response.message()).getString("Message")
|
||||
onError(Error(message))
|
||||
} else if (response.code() == 401) {
|
||||
if (!isActivityRunning(context, LoginActivity::class.java)) {
|
||||
if (!(context as MobileApplication).isLoginRunning()){
|
||||
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)
|
||||
|
@ -72,7 +71,7 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
|
|||
throw t
|
||||
}
|
||||
|
||||
fun isActivityRunning(context: Context, activityClass: Class<*>): Boolean {
|
||||
/* 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)
|
||||
|
@ -84,7 +83,7 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
|
|||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}*/
|
||||
|
||||
private fun errorSalixMessage(response: Response<T>): String {
|
||||
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
package es.verdnatura.domain
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import es.verdnatura.presentation.base.nameofFunction
|
||||
import es.verdnatura.presentation.view.feature.login.activity.LoginActivity
|
||||
import org.json.JSONObject
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
//Se crea interceptor para así generalizar las respuestas y llamadas,
|
||||
//si hay respuesta de fallo 555 se llama onError que lanza un error para que se haga el catch() directamente,
|
||||
//si no queremos que haga el catch tenemos que reescribir la llamada onError en la clase donde se llama o incluso
|
||||
// lanzar un throw error de nuevo para que vuelva al catch y lo ejecute.
|
||||
//-> sería válido en el caso que el catch fuera lo general para todos ( por ejemplo un Toast y después realizáramos
|
||||
//otras acciones. Se reescribiria el método onError en LoginViewModel como:
|
||||
// do_actions-> Haz acciones del fallo
|
||||
// throw e -> De esta manera se consigue llegar al catch. El error se propaga a la llamada superior.
|
||||
|
||||
//Falta pasarle al Callback el tipo que queramos y poder lanzar el toast
|
||||
|
||||
|
||||
abstract class SilexCallback<T>(val context: Context) : Callback<T> {
|
||||
|
||||
override fun onResponse(call: Call<T>, response: Response<T>) {
|
||||
if (response.isSuccessful) {
|
||||
onSuccess(response)
|
||||
} else {
|
||||
try {
|
||||
if (response.code() == 555) {
|
||||
var message = JSONObject(response.message()).getString("Message")
|
||||
onError(Error(message))
|
||||
} else if (response.code() == 401) {
|
||||
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(errorSalixMessage(response)))
|
||||
// onError(Error(response.message().toString()))
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
defaultErrorHandler(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<T>, t: Throwable) {
|
||||
try {
|
||||
onError(t)
|
||||
} catch (t: Throwable) {
|
||||
defaultErrorHandler(t)
|
||||
}
|
||||
}
|
||||
|
||||
private fun defaultErrorHandler(t: Throwable) {
|
||||
(nameofFunction((this)) + t.message).toast(context)
|
||||
//(context as MobileApplication).playSoundIsOK(false)
|
||||
}
|
||||
|
||||
open fun onSuccess(response: Response<T>) {
|
||||
// (nameofFunction((this)) + context.getString(R.string.operationSuccessful)).toast(context)
|
||||
//(context as MobileApplication).playSoundIsOK(true)
|
||||
}
|
||||
|
||||
open fun onError(t: Throwable) {
|
||||
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
|
||||
}
|
||||
|
||||
private fun errorSalixMessage(response: Response<T>): String {
|
||||
|
||||
val messageResponse = response.errorBody()!!.string()
|
||||
return try {
|
||||
|
||||
val jsonObject = Gson().fromJson(messageResponse, JsonObject::class.java)
|
||||
jsonObject?.getAsJsonObject("error")?.get("message")?.asString.toString()
|
||||
|
||||
} catch (ex: Exception) {
|
||||
response.message()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package es.verdnatura.presentation.base
|
|||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.LocationRequest
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
|
@ -17,6 +16,7 @@ import androidx.databinding.ViewDataBinding
|
|||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationCallback
|
||||
import com.google.android.gms.location.LocationResult
|
||||
import com.google.android.gms.location.Priority
|
||||
import es.verdnatura.MobileApplication
|
||||
|
||||
interface LocationUpdateCallback {
|
||||
|
@ -35,16 +35,14 @@ abstract class BaseActivity<T : ViewDataBinding> : AppCompatActivity() {
|
|||
var locationUpdateCallback: LocationUpdateCallback? = null
|
||||
|
||||
protected lateinit var binding: T
|
||||
private lateinit var fusedLocationClient: com.google.android.gms.location.FusedLocationProviderClient
|
||||
private val locationRequest: com.google.android.gms.location.LocationRequest =
|
||||
com.google.android.gms.location.LocationRequest.create().apply {
|
||||
interval =
|
||||
10000
|
||||
fastestInterval =
|
||||
5000
|
||||
priority =
|
||||
LocationRequest.QUALITY_LOW_POWER
|
||||
}
|
||||
private lateinit var fusedLocationClient:FusedLocationProviderClient
|
||||
private val locationRequest =
|
||||
com.google.android.gms.location.LocationRequest.Builder(
|
||||
Priority.PRIORITY_LOW_POWER,
|
||||
10000L
|
||||
).apply {
|
||||
setMinUpdateIntervalMillis(5000L)
|
||||
}.build()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
|
@ -213,7 +213,7 @@ fun PackageManager.getPackageInfoCompat(packageName: String, flags: Int = 0): Pa
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
|
||||
} else {
|
||||
@Suppress("DEPRECATION") getPackageInfo(packageName, flags)
|
||||
getPackageInfo(packageName, flags)
|
||||
}
|
||||
|
||||
fun convertToDateString(date: String?): String? {
|
||||
|
@ -221,8 +221,8 @@ fun convertToDateString(date: String?): String? {
|
|||
if (date.isNullOrEmpty()) {
|
||||
return date
|
||||
}
|
||||
val formatoEntrada = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") // Formato de entrada
|
||||
val formatoSalida = SimpleDateFormat("yyyy-MM-dd") // Formato de salida
|
||||
val formatoEntrada = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()) // Formato de entrada
|
||||
val formatoSalida = SimpleDateFormat("yyyy-MM-dd",Locale.getDefault()) // Formato de salida
|
||||
val fechaDate = formatoEntrada.parse(date) // Convertir fecha de String a objeto Date
|
||||
return formatoSalida.format(fechaDate) // Convertir fecha a String con formato deseado
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class ImageViewActivity : BaseActivity<ActivityImageviewBinding>(){
|
|||
binding.imgView.loadUrl(intent.getStringExtra(getString(R.string.url))!!)
|
||||
|
||||
binding.mainToolbar.backButton.setOnClickListener {
|
||||
onBackPressed()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package es.verdnatura.presentation.view.feature.main.activity
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.MediaPlayer
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.Menu
|
||||
|
@ -265,7 +264,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
|
|||
startRepeatingTask(
|
||||
mobileApplication.dataStoreApp.readDataStoreKey(RENEWINTERVAL)
|
||||
)
|
||||
if (uriImage != null && uriImage is Uri) {
|
||||
if (uriImage != null) {
|
||||
onPasillerosItemClickListener(
|
||||
PasillerosItemVO(
|
||||
30,
|
||||
|
@ -820,14 +819,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
|
|||
}
|
||||
|
||||
getString(R.string.titleUnLoadTruck) -> {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
addFragmentOnTop(
|
||||
LoadUnloadFragment.newInstance(
|
||||
item.title, "DELIVERED", entryPoint, if (param != null) {
|
||||
param as ArrayList<ClientTicketSalix>
|
||||
} else {
|
||||
null
|
||||
}
|
||||
item.title, "DELIVERED", entryPoint,
|
||||
param as? ArrayList<ClientTicketSalix>
|
||||
), getString(R.string.titleUnLoadTruck), delete = true
|
||||
)
|
||||
|
||||
|
|
|
@ -17,19 +17,28 @@ import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
|
|||
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
|
||||
|
||||
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
|
||||
class ShowTicketFragment(var menuOrigin: String) :
|
||||
class ShowTicketFragment() :
|
||||
BaseFragment<FragmentShowTicketBinding, ShowTicketViewModel>(
|
||||
ShowTicketViewModel::class
|
||||
) {
|
||||
|
||||
private var menuOrigin: String? = null
|
||||
private var goBack: Boolean = false
|
||||
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
|
||||
override fun getLayoutId(): Int = R.layout.fragment_show_ticket
|
||||
private var type = ""
|
||||
private var adapter: TicketLastStateAdapter? = null
|
||||
|
||||
constructor(menuOrigin: String) : this() {
|
||||
this.menuOrigin = menuOrigin
|
||||
}
|
||||
companion object {
|
||||
fun newInstance(menuOrigin: String) = ShowTicketFragment(menuOrigin = menuOrigin)
|
||||
private const val ARG_MENU_ORIGIN = "menu_origin"
|
||||
|
||||
fun newInstance(menuOrigin: String) = ShowTicketFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_MENU_ORIGIN, menuOrigin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
|
@ -56,8 +65,10 @@ class ShowTicketFragment(var menuOrigin: String) :
|
|||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
type = ConstAndValues.VERTICKET
|
||||
arguments?.let {
|
||||
menuOrigin = it.getString(ARG_MENU_ORIGIN)
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue