Skip to content

Commit

Permalink
Fix issues #1 and #2
Browse files Browse the repository at this point in the history
Fix for #1: show/hide toolbar behaviour
Fix for #2: auto select camera image behaviour after taking new images
  • Loading branch information
roycornelissen committed Apr 20, 2016
1 parent d3843d4 commit 708d035
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
5 changes: 4 additions & 1 deletion src/GMImagePicker.Xamarin.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8.1">
<id>GMImagePicker.Xamarin</id>
<version>0.0.7</version>
<version>0.0.8</version>
<title>GMImagePicker for Xamarin.iOS</title>
<authors>Roy Cornelissen</authors>
<owners>Roy Cornelissen</owners>
Expand All @@ -18,6 +18,9 @@
<dependencies>
</dependencies>
<releaseNotes>
[0.0.8]
-Fixed issue [#1]: Toolbar gets hidden due to wrong evaluation of selection
-Fixed issue [#2]: Auto selection behaviour after creating a new picture with the camera was incorrect
[0.0.7]
-User is taken directly to Settings app to enable camera / photos access.
[0.0.6]
Expand Down
26 changes: 21 additions & 5 deletions src/GMImagePicker/GMAlbumsViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,28 @@ public void PhotoLibraryDidChange (PHChange changeInstance)
if (updatedCollectionsFetchResults != null) {
_collectionsFetchResults = updatedCollectionsFetchResults;
}
}
// Search for new photos and select them if camera is turned on
if (_picker.AutoSelectCameraImages && _picker.ShowCameraButton) {
foreach (var collection in _collectionsFetchResultsAssets) {
foreach (var fetchResult in collection) {
var changeDetails = changeInstance.GetFetchResultChangeDetails (fetchResult);
// However, we want to update if photos are added, so the counts of items & thumbnails are updated too.
// Maybe some checks could be done here , but for now is OKey.
UpdateFetchResults();
TableView.ReloadData();
if (changeDetails != null && changeDetails.InsertedObjects != null) {
foreach (var asset in changeDetails.InsertedObjects.OfType<PHAsset>()) {
_picker.SelectAsset (asset);
}
}
}
}
}
// However, we want to update if photos are added, so the counts of items & thumbnails are updated too.
// Maybe some checks could be done here , but for now is OKey.
UpdateFetchResults();
TableView.ReloadData();
});
}

Expand Down Expand Up @@ -181,7 +197,7 @@ public override UIStatusBarStyle PreferredStatusBarStyle ()
public void SelectAllAlbumsCell()
{
var path = NSIndexPath.Create(0, 0);
TableView.SelectRow (path, true, UITableViewScrollPosition.None);
TableView.Source.RowSelected (TableView, path);
}

private void UpdateFetchResults()
Expand Down
1 change: 0 additions & 1 deletion src/GMImagePicker/GMGridViewCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public GMGridViewCell (IntPtr handle): base (handle)
[Export("initWithFrame:frame")]
public GMGridViewCell (CGRect frame) : base(frame)
{
Console.WriteLine ("initWithFrame:frame");
Initialize ();
}

Expand Down
14 changes: 13 additions & 1 deletion src/GMImagePicker/GMGridViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,19 @@ public void PhotoLibraryDidChange (PHChange changeInstance)
if (changedIndexes != null && changedIndexes.Count > 0) {
collectionView.ReloadItems(GetIndexesWithSection(changedIndexes, 0));
}
}, null);
}, (x) => {
if (_picker.GridSortOrder == SortOrder.Ascending)
{
var item = collectionView.NumberOfItemsInSection(0) - 1;
var path = NSIndexPath.FromItemSection(item, 0);
collectionView.ScrollToItem(path, UICollectionViewScrollPosition.Bottom, true);
}
else
{
var path = NSIndexPath.FromItemSection(0, 0);
collectionView.ScrollToItem(path, UICollectionViewScrollPosition.Top, true);
}
});
}
ResetCachedAssets();
}
Expand Down
38 changes: 20 additions & 18 deletions src/GMImagePicker/GMImagePickerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GMImagePickerController: UIViewController
//However, the iPad is 1024x768 so it can allow popups up to 768!
public static readonly CGSize PopoverContentSize = new CGSize(480, 720);

private UINavigationController _navigationController;
internal UINavigationController _navigationController;
private GMAlbumsViewController _albumsViewController;

/// <summary>
Expand Down Expand Up @@ -291,26 +291,28 @@ public IList<PHAsset> SelectedAssets
/// </summary>
public void SelectAsset (PHAsset asset)
{
_selectedAssets.Add (asset);
UpdateDoneButton ();
if (!_selectedAssets.Exists(a => a.LocalIdentifier == asset.LocalIdentifier)) {
_selectedAssets.Add (asset);
UpdateDoneButton ();

if (!AllowsMultipleSelection) {
if (ConfirmSingleSelection) {
var message = ConfirmSingleSelectionPrompt ?? "picker.confirm.message".Translate (defaultValue: "Do you want to select the image you tapped on?");
if (!AllowsMultipleSelection) {
if (ConfirmSingleSelection) {
var message = ConfirmSingleSelectionPrompt ?? "picker.confirm.message".Translate (defaultValue: "Do you want to select the image you tapped on?");

var alert = UIAlertController.Create ("picker.confirm.title".Translate (defaultValue: "Are you sure?"), message, UIAlertControllerStyle.Alert);
alert.AddAction (UIAlertAction.Create ("picker.action.no".Translate (defaultValue: "No"), UIAlertActionStyle.Cancel, null));
alert.AddAction (UIAlertAction.Create ("picker.action.yes".Translate (defaultValue: "Yes"), UIAlertActionStyle.Default, action => {
FinishPickingAssets (this, EventArgs.Empty);
}));
var alert = UIAlertController.Create ("picker.confirm.title".Translate (defaultValue: "Are you sure?"), message, UIAlertControllerStyle.Alert);
alert.AddAction (UIAlertAction.Create ("picker.action.no".Translate (defaultValue: "No"), UIAlertActionStyle.Cancel, null));
alert.AddAction (UIAlertAction.Create ("picker.action.yes".Translate (defaultValue: "Yes"), UIAlertActionStyle.Default, action => {
FinishPickingAssets (this, EventArgs.Empty);
}));

PresentViewController (alert, true, null);
} else {
FinishPickingAssets (this, EventArgs.Empty);
PresentViewController (alert, true, null);
} else {
FinishPickingAssets (this, EventArgs.Empty);
}
}
else if (DisplaySelectionInfoToolbar || ShowCameraButton) {
UpdateToolbar ();
}
}
else if (DisplaySelectionInfoToolbar || ShowCameraButton) {
UpdateToolbar ();
}
}

Expand Down Expand Up @@ -384,7 +386,7 @@ private void UpdateToolbar()
vc.ToolbarItems [index].SetTitleTextAttributes (ToolbarTitleTextAttributes, UIControlState.Disabled);
vc.ToolbarItems [index].Title = ToolbarTitle;
}
var toolbarHidden = _selectedAssets.Any () && !ShowCameraButton;
var toolbarHidden = !ShowCameraButton && !_selectedAssets.Any ();
vc.NavigationController.SetToolbarHidden (toolbarHidden, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/GMImagePicker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("0.0.7")]
[assembly: AssemblyVersion("0.0.8")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down

0 comments on commit 708d035

Please sign in to comment.