feat issues refs #7636
This commit is contained in:
parent
dfd676613f
commit
67cd2b1fd2
|
@ -1,8 +1,10 @@
|
||||||
package es.verdnatura
|
package es.verdnatura
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import es.verdnatura.dataStore.DataStoreLocal
|
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.MainActivityListener
|
||||||
import es.verdnatura.presentation.common.SignListener
|
import es.verdnatura.presentation.common.SignListener
|
||||||
import es.verdnatura.presentation.view.component.CustomDialogMainActivity
|
import es.verdnatura.presentation.view.component.CustomDialogMainActivity
|
||||||
|
import es.verdnatura.presentation.view.feature.login.activity.LoginActivity
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.core.context.loadKoinModules
|
import org.koin.core.context.loadKoinModules
|
||||||
|
@ -78,7 +81,7 @@ class MobileApplication : Application(), InteceptorListener {
|
||||||
val restClient = RestClient(this, this)
|
val restClient = RestClient(this, this)
|
||||||
salix = restClient.salixClient
|
salix = restClient.salixClient
|
||||||
|
|
||||||
/* registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
|
||||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +107,7 @@ class MobileApplication : Application(), InteceptorListener {
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
override fun onActivityDestroyed(activity: Activity) {
|
||||||
isActivityLoginRunning = false
|
isActivityLoginRunning = false
|
||||||
}
|
}
|
||||||
})*/
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +130,9 @@ class MobileApplication : Application(), InteceptorListener {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isLoginRunning(): Boolean {
|
||||||
|
return isActivityLoginRunning
|
||||||
|
}
|
||||||
override fun onInterceptionResult(visibility: Int) {
|
override fun onInterceptionResult(visibility: Int) {
|
||||||
if (mainActivityListener != null) {
|
if (mainActivityListener != null) {
|
||||||
handler.post {
|
handler.post {
|
||||||
|
@ -149,6 +155,7 @@ class MobileApplication : Application(), InteceptorListener {
|
||||||
val settings = this.resources.configuration
|
val settings = this.resources.configuration
|
||||||
return settings.locales.get(0).language
|
return settings.locales.get(0).language
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearApplicationData() {
|
fun clearApplicationData() {
|
||||||
try {
|
try {
|
||||||
val cacheDir = this.cacheDir
|
val cacheDir = this.cacheDir
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package es.verdnatura.domain
|
package es.verdnatura.domain
|
||||||
|
|
||||||
import android.app.ActivityManager
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.google.gson.Gson
|
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")
|
var message = JSONObject(response.message()).getString("Message")
|
||||||
onError(Error(message))
|
onError(Error(message))
|
||||||
} else if (response.code() == 401) {
|
} else if (response.code() == 401) {
|
||||||
if (!isActivityRunning(context, LoginActivity::class.java)) {
|
if (!(context as MobileApplication).isLoginRunning()){
|
||||||
val intent = Intent(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)
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
|
@ -72,7 +71,7 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isActivityRunning(context: Context, activityClass: Class<*>): Boolean {
|
/* fun isActivityRunning(context: Context, activityClass: Class<*>): Boolean {
|
||||||
val packageName = context.packageName
|
val packageName = context.packageName
|
||||||
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||||
val runningActivities = activityManager.getRunningTasks(Int.MAX_VALUE)
|
val runningActivities = activityManager.getRunningTasks(Int.MAX_VALUE)
|
||||||
|
@ -84,7 +83,7 @@ abstract class SalixCallback<T>(val context: Context) : Callback<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private fun errorSalixMessage(response: Response<T>): String {
|
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.Manifest
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.location.LocationRequest
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.View
|
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.FusedLocationProviderClient
|
||||||
import com.google.android.gms.location.LocationCallback
|
import com.google.android.gms.location.LocationCallback
|
||||||
import com.google.android.gms.location.LocationResult
|
import com.google.android.gms.location.LocationResult
|
||||||
|
import com.google.android.gms.location.Priority
|
||||||
import es.verdnatura.MobileApplication
|
import es.verdnatura.MobileApplication
|
||||||
|
|
||||||
interface LocationUpdateCallback {
|
interface LocationUpdateCallback {
|
||||||
|
@ -35,16 +35,14 @@ abstract class BaseActivity<T : ViewDataBinding> : AppCompatActivity() {
|
||||||
var locationUpdateCallback: LocationUpdateCallback? = null
|
var locationUpdateCallback: LocationUpdateCallback? = null
|
||||||
|
|
||||||
protected lateinit var binding: T
|
protected lateinit var binding: T
|
||||||
private lateinit var fusedLocationClient: com.google.android.gms.location.FusedLocationProviderClient
|
private lateinit var fusedLocationClient:FusedLocationProviderClient
|
||||||
private val locationRequest: com.google.android.gms.location.LocationRequest =
|
private val locationRequest =
|
||||||
com.google.android.gms.location.LocationRequest.create().apply {
|
com.google.android.gms.location.LocationRequest.Builder(
|
||||||
interval =
|
Priority.PRIORITY_LOW_POWER,
|
||||||
10000
|
10000L
|
||||||
fastestInterval =
|
).apply {
|
||||||
5000
|
setMinUpdateIntervalMillis(5000L)
|
||||||
priority =
|
}.build()
|
||||||
LocationRequest.QUALITY_LOW_POWER
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
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) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
|
getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION") getPackageInfo(packageName, flags)
|
getPackageInfo(packageName, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertToDateString(date: String?): String? {
|
fun convertToDateString(date: String?): String? {
|
||||||
|
@ -221,8 +221,8 @@ fun convertToDateString(date: String?): String? {
|
||||||
if (date.isNullOrEmpty()) {
|
if (date.isNullOrEmpty()) {
|
||||||
return date
|
return date
|
||||||
}
|
}
|
||||||
val formatoEntrada = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") // Formato de entrada
|
val formatoEntrada = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault()) // Formato de entrada
|
||||||
val formatoSalida = SimpleDateFormat("yyyy-MM-dd") // Formato de salida
|
val formatoSalida = SimpleDateFormat("yyyy-MM-dd",Locale.getDefault()) // Formato de salida
|
||||||
val fechaDate = formatoEntrada.parse(date) // Convertir fecha de String a objeto Date
|
val fechaDate = formatoEntrada.parse(date) // Convertir fecha de String a objeto Date
|
||||||
return formatoSalida.format(fechaDate) // Convertir fecha a String con formato deseado
|
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.imgView.loadUrl(intent.getStringExtra(getString(R.string.url))!!)
|
||||||
|
|
||||||
binding.mainToolbar.backButton.setOnClickListener {
|
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.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
@ -265,7 +264,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
|
||||||
startRepeatingTask(
|
startRepeatingTask(
|
||||||
mobileApplication.dataStoreApp.readDataStoreKey(RENEWINTERVAL)
|
mobileApplication.dataStoreApp.readDataStoreKey(RENEWINTERVAL)
|
||||||
)
|
)
|
||||||
if (uriImage != null && uriImage is Uri) {
|
if (uriImage != null) {
|
||||||
onPasillerosItemClickListener(
|
onPasillerosItemClickListener(
|
||||||
PasillerosItemVO(
|
PasillerosItemVO(
|
||||||
30,
|
30,
|
||||||
|
@ -820,14 +819,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
|
||||||
}
|
}
|
||||||
|
|
||||||
getString(R.string.titleUnLoadTruck) -> {
|
getString(R.string.titleUnLoadTruck) -> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
addFragmentOnTop(
|
addFragmentOnTop(
|
||||||
LoadUnloadFragment.newInstance(
|
LoadUnloadFragment.newInstance(
|
||||||
item.title, "DELIVERED", entryPoint, if (param != null) {
|
item.title, "DELIVERED", entryPoint,
|
||||||
param as ArrayList<ClientTicketSalix>
|
param as? ArrayList<ClientTicketSalix>
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
), getString(R.string.titleUnLoadTruck), delete = true
|
), 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
|
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
|
||||||
|
|
||||||
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
|
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
|
||||||
class ShowTicketFragment(var menuOrigin: String) :
|
class ShowTicketFragment() :
|
||||||
BaseFragment<FragmentShowTicketBinding, ShowTicketViewModel>(
|
BaseFragment<FragmentShowTicketBinding, ShowTicketViewModel>(
|
||||||
ShowTicketViewModel::class
|
ShowTicketViewModel::class
|
||||||
) {
|
) {
|
||||||
|
private var menuOrigin: String? = null
|
||||||
private var goBack: Boolean = false
|
private var goBack: Boolean = false
|
||||||
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
|
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
|
||||||
override fun getLayoutId(): Int = R.layout.fragment_show_ticket
|
override fun getLayoutId(): Int = R.layout.fragment_show_ticket
|
||||||
private var type = ""
|
private var type = ""
|
||||||
private var adapter: TicketLastStateAdapter? = null
|
private var adapter: TicketLastStateAdapter? = null
|
||||||
|
|
||||||
|
constructor(menuOrigin: String) : this() {
|
||||||
|
this.menuOrigin = menuOrigin
|
||||||
|
}
|
||||||
companion object {
|
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) {
|
override fun onAttach(context: Context) {
|
||||||
|
@ -56,8 +65,10 @@ class ShowTicketFragment(var menuOrigin: String) :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
type = ConstAndValues.VERTICKET
|
type = ConstAndValues.VERTICKET
|
||||||
|
arguments?.let {
|
||||||
|
menuOrigin = it.getString(ARG_MENU_ORIGIN)
|
||||||
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue