Skip to content

Commit

Permalink
Resolve warnings and also app crash if user not allow permission to c…
Browse files Browse the repository at this point in the history
…ameara.
  • Loading branch information
iTerminate committed Sep 24, 2020
1 parent 2eb2be7 commit f554148
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Component.DB/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
using System;
using System.Windows.Input;

using Xamarin.Essentials;
using Xamarin.Forms;

namespace Component.DB.ViewModels
Expand All @@ -15,8 +15,8 @@ public AboutViewModel()
{
Title = "About";

OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://xamarin.com/platform")));
OpenLicenseCommand = new Command(() => Device.OpenUri(new Uri("https://raw.githubusercontent.com/AdvancedPhotonSource/ComponentDB-Mobile/master/LICENSE")));
OpenWebCommand = new Command(() => Launcher.OpenAsync(new Uri("https://xamarin.com/platform")));
OpenLicenseCommand = new Command(() => Launcher.OpenAsync(new Uri("https://raw.githubusercontent.com/AdvancedPhotonSource/ComponentDB-Mobile/master/LICENSE")));
}

public ICommand OpenWebCommand { get; }
Expand Down
19 changes: 8 additions & 11 deletions Component.DB/ViewModels/ItemDetailEditViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
* See LICENSE file.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading.Tasks;
using Component.DB.Utilities;
using Gov.ANL.APS.CDB.Model;
using Stormlion.PhotoBrowser;

namespace Component.DB.ViewModels
{
Expand Down Expand Up @@ -38,23 +34,23 @@ public async Task<Item> UpdateItem()
}
}

public async Task<ItemLocationInformation> UpdateItemLocationAsync()
public ItemLocationInformation UpdateItemLocation()
{
if (this.ItemLocationInformation == null)
{
throw new Exception("The location was never loaded so it cannot be modified");
}
throw new Exception("The location was never loaded so it cannot be modified");
}

var dbLocationInformation = itemApi.GetItemLocation(Item.Id);

if (ItemLocationInformation.LocationDetails == null)
if (ItemLocationInformation.LocationDetails == null)
ItemLocationInformation.LocationDetails = "";
if (dbLocationInformation.LocationDetails == null)
if (dbLocationInformation.LocationDetails == null)
dbLocationInformation.LocationDetails = "";

// -1 means null
int curLocationd = -1;
int origLocationId = -1;
int origLocationId = -1;
if (ItemLocationInformation.LocationItem != null)
{
curLocationd = (int)ItemLocationInformation.LocationItem.Id;
Expand Down Expand Up @@ -87,7 +83,7 @@ public async Task<ItemLocationInformation> UpdateItemLocationAsync()
var locationDetails = ItemLocationInformation.LocationDetails;
var args = new SimpleLocationInformation(Item.Id, locationId, locationDetails);

itemApi.UpdateItemLocation(args);
itemApi.UpdateItemLocation(args);
}

return this.ItemLocationInformation;
Expand Down Expand Up @@ -139,6 +135,7 @@ public string QrIdEntry
Item.QrId = result;
} catch (Exception ex)
{
Debug.WriteLine(ex);
Item.QrId = null;
}

Expand Down
4 changes: 2 additions & 2 deletions Component.DB/ViewModels/ItemDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Input;
using Component.DB.Services;
using Component.DB.Utilities;
using Gov.ANL.APS.CDB.Model;
using Stormlion.PhotoBrowser;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace Component.DB.ViewModels
Expand Down Expand Up @@ -40,7 +40,7 @@ public void OpenViewInPortalCommand()

var portalUrl = address + Constants.ItemViewPath + Item.Id;

Device.OpenUri(new Uri(portalUrl));
Launcher.OpenAsync(new Uri(portalUrl));
}

public void loadFromQrId(int qrId)
Expand Down
10 changes: 9 additions & 1 deletion Component.DB/Views/ItemDetailPages/ItemDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,15 @@ async void HandleUploadImageClicked(object sender, System.EventArgs e)
DefaultCamera = CameraDevice.Rear
};

var photo = await CrossMedia.Current.TakePhotoAsync(config);
MediaFile photo = null;
try
{
photo = await CrossMedia.Current.TakePhotoAsync(config);
} catch(Exception ex)
{
HandleException(ex);
}


if (photo != null)
{
Expand Down
4 changes: 2 additions & 2 deletions Component.DB/Views/QrScannerPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public QrScannerPage()
itemApi = CdbApiFactory.Instance.itemApi;
}

public async void Handle_OnScanResult(Result result)
public void Handle_OnScanResult(Result result)
{
var v = CrossVibrate.Current;
v.Vibration(TimeSpan.FromSeconds(0.5));
Expand All @@ -33,7 +33,7 @@ public async void Handle_OnScanResult(Result result)
var topic = QrMessage.MESSAGE_SCANNED_TOPIC;
QrMessage message = new QrMessage(result.BarcodeFormat.ToString(), result.Text);

MessagingCenter.Send<QrMessage>(message, topic);
MessagingCenter.Send<QrMessage>(message, topic);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async void HandleSaveClicked(object sender, System.EventArgs e)

try
{
await viewModel.UpdateItemLocationAsync();
viewModel.UpdateItemLocation();
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async void HandleRelocateItemsClicked(object sender, System.EventArgs e)

locInfo.LocationItem = locationItem;
locInfo.LocationDetails = viewModel.LocationDetails;
await item.UpdateItemLocationAsync();
item.UpdateItemLocation();
}
catch (Exception ex)
{
Expand Down

0 comments on commit f554148

Please sign in to comment.