This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:CV="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions" | |
xmlns:FFImage="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" | |
xmlns:FFImageCache="clr-namespace:FFImageLoading.Cache;assembly=FFImageLoading" | |
mc:Ignorable="d" | |
x:Class="MultiImagePicker.ImageSelectionPage"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
All three projects: | |
- CarouselView.FormsPlguin | |
- Microsoft.Azure.Storage.Blob | |
- Xam.Plugin.Media | |
- Xamarin.FFImageLoading.Forms | |
MultiImagePicker Project: | |
- Plugin.Permissions | |
MultiImagePicker.Android Project: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async void SelectImagesButton_Clicked(object sender, EventArgs e) | |
{ | |
//Check users permissions. | |
var storagePermissions = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage); | |
var photoPermissions = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Photos); | |
if (storagePermissions == PermissionStatus.Granted && photoPermissions == PermissionStatus.Granted) | |
{ | |
//If we are on iOS, call GMMultiImagePicker. | |
if (Device.RuntimePlatform == Device.iOS) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Make sure Permissions are given to the users storage. | |
/// </summary> | |
/// <returns></returns> | |
private async Task<bool> AskForPermissions() | |
{ | |
try | |
{ | |
await CrossMedia.Current.Initialize(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ImageSelectionPage() | |
{ | |
InitializeComponent(); | |
//Ask for permissions. | |
Device.BeginInvokeOnMainThread(async () => await AskForPermissions() ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For iOS | |
MessagingCenter.Unsubscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectediOS"); | |
MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectediOS", (s, images) => | |
{ | |
//If we have selected images, put them into the carousel view. | |
if (images.Count > 0) | |
{ | |
ImgCarouselView.ItemsSource = images; | |
InfoText.IsVisible = true; //InfoText is optional | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Unsubsribe from the MessagingCenter on disappearing. | |
/// </summary> | |
protected override void OnDisappearing() | |
{ | |
base.OnDisappearing(); | |
MessagingCenter.Unsubscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectedAndroid"); | |
MessagingCenter.Unsubscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectediOS"); | |
GC.Collect(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Code implementation found in Android Project -> MediaService.cs | |
/// </summary> | |
public interface IMediaService | |
{ | |
void OpenGallery(); | |
void ClearFileDirectory(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async void UploadImagesButton_Clicked(object sender, EventArgs e) | |
{ | |
// Get the list of images we have selected. | |
List<string> imagePaths = ImgCarouselView.ItemsSource as List<string>; | |
// If user is using Android, compress the images. (Optional) | |
if (Device.RuntimePlatform == Device.Android) | |
{ | |
imagePaths = CompressAllImages(imagePaths); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Compress Android images before uploading them to Azure Blob Storage. | |
/// </summary> | |
/// <param name="totalImages"></param> | |
/// <returns></returns> | |
private List<string> CompressAllImages(List<string> totalImages) | |
{ | |
int displayCount = 1; | |
int totalCount = totalImages.Count; | |
List<string> compressedImages = new List<string>(); |
OlderNewer