refs #5322 Nature
This commit is contained in:
parent
65d1b4a7fd
commit
6db09cd73a
|
@ -21,6 +21,7 @@ import es.verdnatura.presentation.view.feature.packingHolland.fragment.PackingHo
|
|||
import es.verdnatura.presentation.view.feature.paletizador.fragment.*
|
||||
import es.verdnatura.presentation.view.feature.parking.fragment.ParkingViewModel
|
||||
import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel
|
||||
import es.verdnatura.presentation.view.feature.photos.fragment.PhotosViewModel
|
||||
import es.verdnatura.presentation.view.feature.precontrol.ShowTicketViewModel
|
||||
import es.verdnatura.presentation.view.feature.presacador.fragment.PreSacadorViewModel
|
||||
import es.verdnatura.presentation.view.feature.qr.QrFragmentViewModel
|
||||
|
@ -189,4 +190,7 @@ val viewModelModule = module {
|
|||
viewModel {
|
||||
PackingHollandViewModel(androidContext())
|
||||
}
|
||||
viewModel {
|
||||
PhotosViewModel(androidContext())
|
||||
}
|
||||
}
|
|
@ -9,12 +9,12 @@ import es.verdnatura.presentation.view.feature.collection.listSaleSalix
|
|||
import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.ShelvingLogSalix
|
||||
import es.verdnatura.presentation.view.feature.login.model.LoginSalixVO
|
||||
import es.verdnatura.presentation.view.feature.login.model.SalixGrupo
|
||||
import es.verdnatura.presentation.view.feature.login.model.SalixMessageVO
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.EntrySalix
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ItemSupplier
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
|
||||
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
|
||||
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake
|
||||
import okhttp3.MultipartBody
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.*
|
||||
|
||||
|
@ -26,17 +26,17 @@ interface SalixService {
|
|||
):
|
||||
Call<LoginSalixVO>
|
||||
|
||||
/* @POST("chats/sendCheckingPresence")
|
||||
fun sendChekingPresence(
|
||||
@Body params: SalixMessageVO
|
||||
):
|
||||
Call<Boolean>
|
||||
/* @POST("chats/sendCheckingPresence")
|
||||
fun sendChekingPresence(
|
||||
@Body params: SalixMessageVO
|
||||
):
|
||||
Call<Boolean>
|
||||
|
||||
@POST("chats/send")
|
||||
fun sendGroup(
|
||||
@Body params: SalixGrupo
|
||||
):
|
||||
Call<Boolean>*/
|
||||
@POST("chats/send")
|
||||
fun sendGroup(
|
||||
@Body params: SalixGrupo
|
||||
):
|
||||
Call<Boolean>*/
|
||||
|
||||
@GET("collections/getSectors")
|
||||
fun getSectorsSalix(
|
||||
|
@ -153,6 +153,16 @@ interface SalixService {
|
|||
):
|
||||
Call<EntrySalix>
|
||||
|
||||
@POST("Images/upload")
|
||||
@Multipart
|
||||
fun uploadImage(
|
||||
@Part ("collection") collection: String,
|
||||
@Query("filter") filter: String,
|
||||
@Query("id") id: Int,
|
||||
@Part filePart: MultipartBody.Part,
|
||||
):
|
||||
Call<Any>
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -512,7 +512,7 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) {
|
|||
)
|
||||
|
||||
//#tarea4021
|
||||
/* _pasillerositem.add(
|
||||
_pasillerositem.add(
|
||||
PasillerosItemVO(
|
||||
6,
|
||||
R.drawable.ic_packaging,
|
||||
|
@ -520,9 +520,18 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) {
|
|||
R.string.titlePackaging,
|
||||
contextApp.getString(R.string.titlePackagingDescrip)
|
||||
)
|
||||
)*/
|
||||
)
|
||||
_pasillerositem.add(
|
||||
PasillerosItemVO(
|
||||
6,
|
||||
R.drawable.photo_camera,
|
||||
contextApp.getString(R.string.titlePhotos),
|
||||
R.string.titlePhotos,
|
||||
contextApp.getString(R.string.titlePhotos)
|
||||
)
|
||||
)
|
||||
|
||||
val working_in_test=false
|
||||
val working_in_test=true
|
||||
if (working_in_test){
|
||||
_pasillerositem.add(
|
||||
PasillerosItemVO(
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.view.View
|
||||
import android.view.View.*
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import es.verdnatura.R
|
||||
import es.verdnatura.databinding.FragmentPhotosBinding
|
||||
import es.verdnatura.databinding.FragmentVehiclecontrolUserBinding
|
||||
import es.verdnatura.presentation.base.BaseFragment
|
||||
import es.verdnatura.presentation.common.OnOptionsSelectedListener
|
||||
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
||||
import es.verdnatura.presentation.common.loadUrl
|
||||
import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.ControlVehiculoUsuarioFragment
|
||||
import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.ControlVehiculoViewModel
|
||||
import es.verdnatura.presentation.view.feature.photos.fragment.PhotosViewModel
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
class PhotosFragment(
|
||||
var title: String
|
||||
) : BaseFragment<FragmentPhotosBinding, PhotosViewModel>(
|
||||
PhotosViewModel::class
|
||||
) {
|
||||
|
||||
override fun getLayoutId(): Int = R.layout.fragment_photos
|
||||
|
||||
|
||||
companion object {
|
||||
fun newInstance(title: String) = PhotosFragment(title)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun init() {
|
||||
binding.mainToolbar.toolbarTitle.text = title
|
||||
binding.splashProgress.visibility = GONE
|
||||
setEvents()
|
||||
setToolBar()
|
||||
loadImage()
|
||||
super.init()
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun setToolBar() {
|
||||
|
||||
binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE
|
||||
binding.mainToolbar.toolbarIcons.visibility = VISIBLE
|
||||
binding.mainToolbar.backButton.visibility = VISIBLE
|
||||
|
||||
val listIcons: ArrayList<ImageView> = ArrayList()
|
||||
val iconPhone = ImageView(context)
|
||||
iconPhone.setImageResource(R.drawable.phone_call)
|
||||
|
||||
iconPhone.tooltipText = getTooltip(R.drawable.phone_call)
|
||||
listIcons.add(iconPhone)
|
||||
binding.mainToolbar.toolbarIcons.adapter =
|
||||
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
|
||||
override fun onOptionsItemSelected(item: Drawable) {
|
||||
|
||||
when (item) {
|
||||
iconPhone.drawable -> upLoadPhoto()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
binding.mainToolbar.toolbarIcons.layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun loadImage() {
|
||||
|
||||
// binding.splashProgress.visibility = VISIBLE
|
||||
|
||||
binding.userImage.loadUrl(
|
||||
getData("base_urlSalix") + "/api/Images/user/160x160/19591/download?access_token=${
|
||||
getData(
|
||||
TOKEN
|
||||
)
|
||||
}"
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun setEvents() {
|
||||
binding.mainToolbar.backButton.setOnClickListener {
|
||||
requireActivity().onBackPressed()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun observeViewModel() {
|
||||
|
||||
with(viewModel) {
|
||||
binding.splashProgress.visibility = View.GONE
|
||||
|
||||
|
||||
|
||||
responseinsert.observe(viewLifecycleOwner, Observer {
|
||||
|
||||
binding.splashProgress.visibility = View.GONE
|
||||
|
||||
if (it.isError) {
|
||||
ma.messageWithSound(
|
||||
getString(R.string.noSIP) + it.errorMessage + getString(R.string.user) + title,
|
||||
isError = true,
|
||||
true
|
||||
)
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun upLoadPhoto() {
|
||||
val drawable = binding.userImage.drawable
|
||||
if (drawable is BitmapDrawable) {
|
||||
val bitmap = drawable.bitmap
|
||||
|
||||
viewModel.uploadPhoto(saveBitmapAsTempFile(requireContext(),bitmap))
|
||||
}
|
||||
}
|
||||
fun saveBitmapAsTempFile(context: Context, bitmap: Bitmap): String {
|
||||
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
|
||||
val fileName = "IMG_$timeStamp.jpg"
|
||||
|
||||
val storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
|
||||
val tempFile = File.createTempFile(fileName, null, storageDir)
|
||||
|
||||
return try {
|
||||
val fileOutputStream = FileOutputStream(tempFile)
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
|
||||
fileOutputStream.close()
|
||||
tempFile.absolutePath
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package es.verdnatura.presentation.view.feature.photos.fragment
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import es.verdnatura.domain.SilexCallback
|
||||
import es.verdnatura.presentation.base.BaseViewModel
|
||||
import es.verdnatura.presentation.base.getMessageFromAllResponse
|
||||
import es.verdnatura.presentation.base.nameofFunction
|
||||
import es.verdnatura.presentation.common.ResponseItemVO
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.QueryMap
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
class PhotosViewModel(val context: Context) : BaseViewModel(context) {
|
||||
|
||||
|
||||
private val _responseinsert by lazy { MutableLiveData<ResponseItemVO>() }
|
||||
val responseinsert: LiveData<ResponseItemVO>
|
||||
get() = _responseinsert
|
||||
|
||||
|
||||
fun uploadPhoto(
|
||||
// val img = dataURItoBlob(cropper.getCroppedCanvas().toDataURL("image/png"))
|
||||
urlImage:String,
|
||||
itemFK:Int = 10 ,
|
||||
itemId:String = "10" ,
|
||||
date: Date = Date(),
|
||||
timestamp: Long = date.time,
|
||||
fileName: String = "${itemFK}_$timestamp",
|
||||
file: File = File("$urlImage"),
|
||||
fileRequestBody: RequestBody = RequestBody.create(MediaType.parse("image/jpeg"), file),
|
||||
filePart: MultipartBody.Part = MultipartBody.Part.createFormData("file", file.name, fileRequestBody),
|
||||
fileNameRequestBody: RequestBody = RequestBody.create(MediaType.parse("text/plain"), fileName),
|
||||
|
||||
|
||||
|
||||
) {
|
||||
salix.uploadImage("catalog",fileName,itemFK,filePart)
|
||||
.enqueue(object : SilexCallback<Any>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_responseinsert.value = ResponseItemVO(
|
||||
isError = true,
|
||||
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<Any>) {
|
||||
|
||||
//sergio devuelve true o false
|
||||
|
||||
if (response.body().toString() == "false") {
|
||||
_responseinsert.value = ResponseItemVO(
|
||||
isError = true,
|
||||
errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this),
|
||||
response.message()
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
||||
_responseinsert.value =
|
||||
ResponseItemVO(isError = false, response = response.body()!!.toString())
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#F7931E">
|
||||
<path android:fillColor="#F7931E"
|
||||
android:pathData="M479.5,694q72.5,0 121.5,-49t49,-121.5q0,-72.5 -49,-121T479.5,354q-72.5,0 -121,48.5t-48.5,121q0,72.5 48.5,121.5t121,49ZM479.5,634q-47.5,0 -78.5,-31.5t-31,-79q0,-47.5 31,-78.5t78.5,-31q47.5,0 79,31t31.5,78.5q0,47.5 -31.5,79t-79,31.5ZM140,840q-24,0 -42,-18t-18,-42v-513q0,-23 18,-41.5t42,-18.5h147l73,-87h240l73,87h147q23,0 41.5,18.5T880,267v513q0,24 -18.5,42T820,840L140,840ZM820,780v-513L645,267l-73,-87L388,180l-73,87L140,267v513h680ZM480,524Z"/>
|
||||
</vector>
|
|
@ -0,0 +1,90 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/itemcard_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/toolbar_height"
|
||||
android:hint="Item"
|
||||
android:textColor="@color/verdnatura_white"
|
||||
android:textSize="@dimen/h5"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/user_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/itemcard_image_height"
|
||||
android:layout_margin="10dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/loadphoto" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginBottom="@dimen/layout_margin_min"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/layout_margin_min">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
android:id="@+id/main_toolbar"
|
||||
layout="@layout/toolbar_fragment"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/splash_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/verdnatura_black_8_alpha_6"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.airbnb.lottie.LottieAnimationView
|
||||
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/verdnatura_logo_large_height"
|
||||
app:lottie_autoPlay="true"
|
||||
app:lottie_loop="true"
|
||||
app:lottie_rawRes="@raw/orange_loading"
|
||||
app:lottie_speed="2" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
|
@ -0,0 +1,3 @@
|
|||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<cache-path name="cache" path="/" />
|
||||
</paths>
|
Loading…
Reference in New Issue