Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Last active Dec 14, 2020
Embed
What would you like to do?
ViewModels/AnalisisImagenViewModel.cs
using System.Windows.Input;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Xamarin.Forms;
using ICTalkMobileApp.Models;
using ICTalkMobileApp.Services;
namespace ICTalkMobileApp.ViewModels
{
public class AnalisisImagenViewModel : BaseViewModel
{
private ObservableCollection<Analisis> imagenesSimilares;
public ObservableCollection<Analisis> ImagenesSimilares
{
get => imagenesSimilares;
set { imagenesSimilares = value; OnPropertyChanged(); }
}
private Analisis imagenActual;
public Analisis ImagenActual
{
get => imagenActual;
set { imagenActual = value; OnPropertyChanged(); }
}
private string rutaImagen;
public string RutaImagen
{
get { return rutaImagen; }
set { rutaImagen = value; OnPropertyChanged(); }
}
public ICommand ComandoTomarFoto { get; private set; }
public ICommand ComandoSeleccionarFoto { get; private set; }
public ICommand ComandoSubirImagen { get; private set; }
public ICommand ComandoObtenerSimilares { get; private set; }
private ServicioStorage servicioStorage;
public AnalisisImagenViewModel()
{
servicioStorage = new ServicioStorage();
ComandoTomarFoto = new Command(async () => await TomarFoto());
ComandoSeleccionarFoto = new Command(async () => await SeleccionarFoto());
ComandoSubirImagen = new Command(async () => await SubirImagen());
ComandoObtenerSimilares = new Command(async () => await ObtenerSimilares());
}
private async Task TomarFoto()
{
RutaImagen = await ServicioImagen.TomarFoto();
}
private async Task SeleccionarFoto()
{
RutaImagen = await ServicioImagen.SeleccionarFoto();
}
private async Task SubirImagen()
{
await servicioStorage.SubirImagen(RutaImagen);
}
private async Task ObtenerSimilares()
{
var lista = await servicioStorage.ObtenerImagenesSimilares(RutaImagen);
ImagenesSimilares = new ObservableCollection<Analisis>(lista);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment