From 8ed3753b482c8a5882ecec396a6c372329313b04 Mon Sep 17 00:00:00 2001 From: Mauricio Sanchez Date: Thu, 17 Sep 2020 19:32:25 -0300 Subject: [PATCH] 17092020 1900 --- .../deboinventariov20/DB/DAO/ArticulosDAO.kt | 4 +- .../focasoftware/deboinventariov20/Model/Tablas.kt | 1 + .../deboinventariov20/UI/Utils/Utils.kt | 22 +++- .../actualizacionMaestros/ActuaMaestrosFragment.kt | 7 +- .../UI/configuracion/ConfiguracionFragment.kt | 103 +++++++++++++---- .../UI/inventario/ProductosListAdapter.kt | 5 +- .../UI/servidores/AdapterServidores.kt | 1 + .../UI/servidores/ItemsServidores.kt | 2 +- .../UI/servidores/ServidoresFragment.kt | 7 +- .../main/res/layout-land/fragment_servidores.xml | 99 ++++++++++------ app/src/main/res/layout/fragment_servidores.xml | 126 +++++++++++++-------- app/src/main/res/layout/item_servidores.xml | 38 +++++-- app/src/main/res/values/strings.xml | 4 +- 13 files changed, 295 insertions(+), 124 deletions(-) diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt b/app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt index 40d9d5b..10b7c39 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt @@ -110,6 +110,6 @@ interface ServeInvDao { @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=1 WHERE SER_NUM = :numero") suspend fun UpdateServerPre(numero: Int) - @Query("SELECT SER_DIR FROM $TABLA_SERV_INV WHERE SER_PRE= 1") - suspend fun fetchServerPreOne(): String + @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_PRE= 1") + suspend fun fetchServerPreOne(): ServeInv } \ No newline at end of file diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/Model/Tablas.kt b/app/src/main/java/com/focasoftware/deboinventariov20/Model/Tablas.kt index ab53801..71758ea 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/Model/Tablas.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/Model/Tablas.kt @@ -112,6 +112,7 @@ data class InvBody(@ColumnInfo(name = "INV_NUM") var invNum: Int, data class ServeInv( @ColumnInfo(name = "SER_DESC") var descripcion: String?, @ColumnInfo(name = "SER_DIR") var direccion: String?, + @ColumnInfo(name = "SER_PUERTO") var puerto: String?, @ColumnInfo(name = "SER_PRE") var predeterminado: Int?): Serializable { @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "SER_NUM") diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt index bdbe8a9..fe393bd 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt @@ -9,6 +9,8 @@ import com.focasoftware.deboinventariov20.DB.DataBase.AppDb import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async +import java.io.IOException +import java.net.UnknownHostException fun modificarCantidadEnCabecera(inventarioActual: Int, b: Boolean,context: Context) { GlobalScope.async(Dispatchers.IO) { @@ -77,4 +79,22 @@ public class NoEncontradoSimple : DialogFragment() { return builder.create() } ?: throw IllegalStateException("Activity cannot be null") } -} \ No newline at end of file +} +fun isConnectedToThisServer(host: String): Boolean { + + val runtime = Runtime.getRuntime() + try { + val ipProcess = runtime.exec("/system/bin/ping -c 1 $host") + val exitValue = ipProcess.waitFor() + ipProcess.destroy() + return exitValue == 0 + } catch (e: UnknownHostException) { + e.printStackTrace() + } catch (e: IOException) { + e.printStackTrace() + } catch (e: InterruptedException) { + e.printStackTrace() + } + + return false +} diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/actualizacionMaestros/ActuaMaestrosFragment.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/actualizacionMaestros/ActuaMaestrosFragment.kt index 176ac9a..d58c07a 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/actualizacionMaestros/ActuaMaestrosFragment.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/actualizacionMaestros/ActuaMaestrosFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment import com.focasoftware.deboinventariov20.DB.DataBase.AppDb import com.focasoftware.deboinventariov20.Model.Articles import com.focasoftware.deboinventariov20.Model.ProductosService +import com.focasoftware.deboinventariov20.Model.ServeInv import com.focasoftware.deboinventariov20.R import com.focasoftware.deboinventariov20.UI.Utils.noServerConf import kotlinx.android.synthetic.main.fragment_actua_maestros.* @@ -25,17 +26,17 @@ class ActuaMaestrosFragment : Fragment() { super.onCreate(savedInstanceState) GlobalScope.launch(Main) { val serverPre = fetchServerPreOne() - if (serverPre.isNullOrEmpty()) { + if (serverPre!!.direccion.isNullOrEmpty()) { val modalDialog = noServerConf() modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") } else { - BASE_URL = serverPre.toString() + BASE_URL = serverPre.direccion.toString()+":"+serverPre.puerto.toString()+"/" } } // mostrarArticulos() } - private suspend fun fetchServerPreOne(): String? { + private suspend fun fetchServerPreOne(): ServeInv? { return GlobalScope.async(IO) { return@async AppDb.getAppDb(requireActivity())!!.ServeInvDao()!!.fetchServerPreOne() }.await() diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/configuracion/ConfiguracionFragment.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/configuracion/ConfiguracionFragment.kt index f358068..c56c4fc 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/configuracion/ConfiguracionFragment.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/configuracion/ConfiguracionFragment.kt @@ -16,6 +16,7 @@ import androidx.navigation.fragment.findNavController import com.focasoftware.deboinventariov20.DB.DataBase.AppDb import com.focasoftware.deboinventariov20.Model.ServeInv import com.focasoftware.deboinventariov20.R +import com.focasoftware.deboinventariov20.UI.Utils.isConnectedToThisServer import kotlinx.android.synthetic.main.fragment_configuracion.* import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.Main @@ -40,15 +41,25 @@ class ConfiguracionFragment : Fragment() { for (server in getDescServers()) { listServer.add((if (server.servNum < 9) "0" + server.servNum.toString() else server.servNum.toString()) + " - " + server.descripcion.toString()) } - val adapterSpServer = ArrayAdapter(requireContext(), R.layout.support_simple_spinner_dropdown_item, listServer) + val adapterSpServer = ArrayAdapter( + requireContext(), + R.layout.support_simple_spinner_dropdown_item, + listServer + ) spServidor.adapter = adapterSpServer if (sharedPreferences.contains("ServerPredeterminado")) { - spServidor.setSelection(sharedPreferences.getString("ServerPredeterminado", "").toString().toInt()) + spServidor.setSelection( + sharedPreferences.getString("ServerPredeterminado", "").toString().toInt() + ) } else (spServidor.setSelection(0)) } } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { val v = inflater.inflate(R.layout.fragment_configuracion, container, false) val etRuta = v.findViewById(R.id.etRuta) @@ -170,18 +181,34 @@ class ConfiguracionFragment : Fragment() { btnGuardar.setOnClickListener { guardarPreferencias() - Toast.makeText(v.context, "Los Datos se guardaron correctamente", Toast.LENGTH_LONG).show() + Toast.makeText(v.context, "Los Datos se guardaron correctamente", Toast.LENGTH_LONG) + .show() navController.navigate(R.id.action_configuracionFragment_to_mainFragment2) } btnAgregarServidor.setOnClickListener { findNavController().navigate(R.id.servidoresFragment) } - btnValidarServidor.setOnClickListener { Toast.makeText(requireContext(), "Dirección correcta", Toast.LENGTH_LONG).show() } + btnValidarServidor.setOnClickListener { + GlobalScope.launch(Main) { + val serverPre = fetchServerPreOne() + if (isConnectedToThisServer(serverPre!!.direccion.toString().substring(7,serverPre.direccion.toString().length))) { + Toast.makeText(requireContext(), "¡Dirección Valida!", Toast.LENGTH_LONG).show() + } else { + Toast.makeText(requireContext(), "¡Verifique la Dirección!", Toast.LENGTH_LONG) + .show() + } + } + } spServidor.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onNothingSelected(parent: AdapterView<*>?) {} - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + override fun onItemSelected( + parent: AdapterView<*>?, + view: View?, + position: Int, + id: Long + ) { itemSelect = parent!!.getItemAtPosition(position).toString().substring(0, 2).toInt() - indexSelect=position + indexSelect = position } } return v @@ -199,18 +226,51 @@ class ConfiguracionFragment : Fragment() { if (etRuta.text.isNotEmpty()) editor?.putString("etRuta", etRuta.text.toString()) - if (rbProInclu.isChecked) editor?.putString("rbProInclu", "1") else editor?.putString("rbProInclu", "0") - if (rbProNoInclu.isChecked) editor?.putString("rbProNoInclu", "1") else editor?.putString("rbProNoInclu", "0") - - if (cbHabiLectura.isChecked) editor?.putString("cbHabiLectura", "1") else editor?.putString("cbHabiLectura", "0") - if (cbMostrarStock.isChecked) editor?.putString("cbMostrarStock", "1") else editor?.putString("cbMostrarStock", "0") - if (rbVentas.isChecked) editor?.putString("rbVentas", "1") else editor?.putString("rbVentas", "0") - if (rbDeposito.isChecked) editor?.putString("rbDeposito", "1") else editor?.putString("rbDeposito", "0") - if (rbCodigoDebo.isChecked) editor?.putString("rbCodigoDebo", "1") else editor?.putString("rbCodigoDebo", "0") - if (rbCodigoOrigen.isChecked) editor?.putString("rbCodigoOrigen", "1") else editor?.putString("rbCodigoOrigen", "0") - if (rbCodigoBarras.isChecked) editor?.putString("rbCodigoBarras", "1") else editor?.putString("rbCodigoBarras", "0") - if (cbMostrarExistencia.isChecked) editor?.putString("cbMostrarExistencia", "1") else editor?.putString("cbMostrarExistencia", "0") - if (cbMostrarPrecio.isChecked) editor?.putString("cbMostrarPrecio", "1") else editor?.putString("cbMostrarPrecio", "0") + if (rbProInclu.isChecked) editor?.putString( + "rbProInclu", + "1" + ) else editor?.putString("rbProInclu", "0") + if (rbProNoInclu.isChecked) editor?.putString( + "rbProNoInclu", + "1" + ) else editor?.putString("rbProNoInclu", "0") + + if (cbHabiLectura.isChecked) editor?.putString("cbHabiLectura", "1") else editor?.putString( + "cbHabiLectura", + "0" + ) + if (cbMostrarStock.isChecked) editor?.putString( + "cbMostrarStock", + "1" + ) else editor?.putString("cbMostrarStock", "0") + if (rbVentas.isChecked) editor?.putString( + "rbVentas", + "1" + ) else editor?.putString("rbVentas", "0") + if (rbDeposito.isChecked) editor?.putString( + "rbDeposito", + "1" + ) else editor?.putString("rbDeposito", "0") + if (rbCodigoDebo.isChecked) editor?.putString( + "rbCodigoDebo", + "1" + ) else editor?.putString("rbCodigoDebo", "0") + if (rbCodigoOrigen.isChecked) editor?.putString( + "rbCodigoOrigen", + "1" + ) else editor?.putString("rbCodigoOrigen", "0") + if (rbCodigoBarras.isChecked) editor?.putString( + "rbCodigoBarras", + "1" + ) else editor?.putString("rbCodigoBarras", "0") + if (cbMostrarExistencia.isChecked) editor?.putString( + "cbMostrarExistencia", + "1" + ) else editor?.putString("cbMostrarExistencia", "0") + if (cbMostrarPrecio.isChecked) editor?.putString( + "cbMostrarPrecio", + "1" + ) else editor?.putString("cbMostrarPrecio", "0") editor?.putString("ServerPredeterminado", indexSelect.toString()) updateServerPreInZero() updateServerPre(itemSelect) @@ -245,4 +305,9 @@ class ConfiguracionFragment : Fragment() { } } } + private suspend fun fetchServerPreOne(): ServeInv? { + return GlobalScope.async(Dispatchers.IO) { + return@async AppDb.getAppDb(requireActivity())!!.ServeInvDao()!!.fetchServerPreOne() + }.await() + } } \ No newline at end of file diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/ProductosListAdapter.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/ProductosListAdapter.kt index 99bf903..54933d1 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/ProductosListAdapter.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/ProductosListAdapter.kt @@ -8,6 +8,8 @@ import androidx.recyclerview.widget.RecyclerView import com.focasoftware.deboinventariov20.R import com.focasoftware.deboinventariov20.UI.Utils.BaseViewHolder import kotlinx.android.synthetic.main.item.view.* +import java.io.IOException +import java.net.UnknownHostException class ProductosListAdapter(private val context: Context,private val productos: ArrayList, private val itemImageClickListener: OnImageDotsClickListener) : @@ -54,6 +56,5 @@ class ProductosListAdapter(private val context: Context,private val productos: A productos.removeAt(viewHolder.adapterPosition) notifyItemRemoved(viewHolder.adapterPosition) } +} - -} \ No newline at end of file diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/AdapterServidores.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/AdapterServidores.kt index e02a7c6..fb47ee0 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/AdapterServidores.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/AdapterServidores.kt @@ -17,6 +17,7 @@ class AdapterServidores(private val servidor: ArrayList, privat fun bind(itemsServidores: ItemsServidores) { vista.tvDescServidor.text = itemsServidores.descripcion vista.tvDireccionServidor.text = itemsServidores.direccion + vista.tvPuertoServidor.text = itemsServidores.puerto } } diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ItemsServidores.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ItemsServidores.kt index d045e42..2429cca 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ItemsServidores.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ItemsServidores.kt @@ -1,3 +1,3 @@ package com.focasoftware.deboinventariov20.UI.servidores -data class ItemsServidores(val descripcion: String?, var direccion: String?, var predeterminado: String?) \ No newline at end of file +data class ItemsServidores(val descripcion: String?, var direccion: String?, var puerto: String?, var predeterminado: String?) \ No newline at end of file diff --git a/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ServidoresFragment.kt b/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ServidoresFragment.kt index dac3689..4db0af3 100644 --- a/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ServidoresFragment.kt +++ b/app/src/main/java/com/focasoftware/deboinventariov20/UI/servidores/ServidoresFragment.kt @@ -51,7 +51,8 @@ class ServidoresFragment : Fragment() { if (!etDireccionServidor.text.isNullOrBlank() || !etNombreServidor.text.isNullOrBlank()) { // GlobalScope.launch(Dispatchers.Main) { // ServerNew =AppDb.getAppDb(requireContext())?.ServeInvDao()?.findLastServer()?.plus(1) ?: 1 - val servidor = ServeInv(etNombreServidor.text.toString(), "http://${etDireccionServidor.text}/", 0) + val servidor = ServeInv(etNombreServidor.text.toString(), "http://${etDireccionServidor.text}", + etPuerto.text.toString(),0) ingresarDatos(servidor) cargarRecicler(servidor) Toast.makeText(requireContext(), "Servidor ${etNombreServidor.text} Guardado", Toast.LENGTH_LONG).show() @@ -86,7 +87,7 @@ class ServidoresFragment : Fragment() { GlobalScope.launch(Dispatchers.Main) { servidores = buscarEnBD() for ((i, item) in servidores.withIndex()) { - val ser = ServeInv(servidores[i].descripcion, servidores[i].direccion, servidores[i].predeterminado) + val ser = ServeInv(servidores[i].descripcion, servidores[i].direccion,servidores[i].puerto, servidores[i].predeterminado) cargarRecicler(ser) } } @@ -95,7 +96,7 @@ class ServidoresFragment : Fragment() { fun cargarRecicler(ser: ServeInv) { //TODO CARGO EN LE RV deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! - val item = ItemsServidores(ser.descripcion, ser.direccion, ser.predeterminado.toString()) + val item = ItemsServidores(ser.descripcion, ser.direccion, ser.puerto.toString(),ser.predeterminado.toString()) listServ.add(item) diff --git a/app/src/main/res/layout-land/fragment_servidores.xml b/app/src/main/res/layout-land/fragment_servidores.xml index 4e0b2ba..c84964a 100644 --- a/app/src/main/res/layout-land/fragment_servidores.xml +++ b/app/src/main/res/layout-land/fragment_servidores.xml @@ -1,6 +1,5 @@ - + + app:layout_constraintTop_toBottomOf="@+id/tvNomServer" /> + app:layout_constraintTop_toBottomOf="@+id/etNombreServidor" /> + android:textSize="15sp" + app:layout_constraintBaseline_toBaselineOf="@+id/tvDirServer" + app:layout_constraintStart_toEndOf="@+id/tvDirServer" /> + + + + @@ -109,14 +139,15 @@ android:id="@+id/btnGuardarServidores" android:layout_width="0dp" android:layout_height="wrap_content" - + android:layout_marginTop="10dp" + android:layout_marginEnd="10dp" + android:background="@drawable/boton_borde_redondeado" + android:padding="10dp" android:text="@string/btnGuardarServidores" android:textColor="@android:color/white" - android:padding="5dp" - android:background="@drawable/boton_borde_redondeado" - app:layout_constraintTop_toBottomOf="@+id/rvServidores" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintBottom_toBottomOf="parent"/> + app:layout_constraintTop_toBottomOf="@+id/rvServidores" /> diff --git a/app/src/main/res/layout/fragment_servidores.xml b/app/src/main/res/layout/fragment_servidores.xml index 8f211f9..fd38e7d 100644 --- a/app/src/main/res/layout/fragment_servidores.xml +++ b/app/src/main/res/layout/fragment_servidores.xml @@ -1,6 +1,5 @@ - + + app:layout_constraintTop_toBottomOf="@+id/tvNomServer" /> + app:layout_constraintTop_toBottomOf="@+id/etNombreServidor" /> - + - + + + + + -