Skip to content

Commit

Permalink
Moving spotlight into separate service
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike James committed Jul 4, 2016
1 parent b0e943c commit f9a435a
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
<Compile Include="ViewModels\ICheckInViewModel.cs" />
<Compile Include="ViewModels\ITrendingBeersViewModel.cs" />
<Compile Include="ViewModels\IEnableUserLocationViewModel.cs" />
<Compile Include="Services\IDeviceSearchProvider.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="ViewModels\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BeerDrinkin.Services.Abstractions\BeerDrinkin.Services.Abstractions.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using BeerDrinkin.DataObjects;

namespace BeerDrinkin.Core.Abstractions.Services
{
public interface IDeviceSearchProvider
{
void AddBeerToIndex(Beer beer);
}
}

1 change: 1 addition & 0 deletions ClientSDKs/BeerDrinkin.Core/BeerDrinkin.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="ViewModels\Discover\UsersViewModel.cs" />
<Compile Include="ViewModels\CheckInViewModel.cs" />
<Compile Include="ViewModels\Welcome\EnableUserLocationViewModel.cs" />
<Compile Include="ViewModels\BeerDescriptionViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="BreweryDB">
Expand Down
46 changes: 46 additions & 0 deletions ClientSDKs/BeerDrinkin.Core/ViewModels/BeerDescriptionViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading.Tasks;
using BeerDrinkin.Core.Abstractions.Services;
using BeerDrinkin.DataObjects;
using BeerDrinkin.Utils;

namespace BeerDrinkin.Core.ViewModels
{
public class BeerDescriptionViewModel
{

public BeerDescriptionViewModel(Beer beer)
{
Beer = beer;
Name = beer.Name;
BreweryName = beer?.Brewery?.Name;
Description = beer.Description;
if (beer.HasImages == true)
ImageUrl = beer.Image.LargeUrl;


SearchProvider = ServiceLocator.Instance.Resolve<IDeviceSearchProvider>();
SearchProvider.AddBeerToIndex(beer);
}

public IDeviceSearchProvider SearchProvider { get; private set;}
public Beer Beer { get; set;}
public string Name { get; set;}
public double ABV { get; set;}
public string BreweryName { get; set;}
public int Average { get; set;}
public int ReviewCount { get; set;}
public string Description { get; set;}
public string ImageUrl { get; set;}

public string SharingMessage
{
get
{
return $"I've just read about {Beer.Name} with Beer Drinkin for iOS";
}
}

}
}

2 changes: 1 addition & 1 deletion ClientSDKs/BeerDrinkin.Core/ViewModels/CheckInViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task CheckInBeer(Beer beer, int score)
CheckIn = checkIn
};

checkIn.Rating = rating;
checkIn.RatingId = rating.Id;

await checkInStore.InsertAsync(checkIn);
await ratingStore.InsertAsync(rating);
Expand Down
5 changes: 0 additions & 5 deletions ClientSDKs/BeerDrinkin.DataObjects/CheckIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ public class CheckIn : BaseDataObject
public double Latitude { get; set; }
public bool IsBottled { get; set; }
public string RatingId { get; set; }


#if !BACKEND
public Rating Rating { get; set; }
#endif
}
}
3 changes: 3 additions & 0 deletions MobileApps/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using BeerDrinkin.Services.Abstractions;
using BeerDrinkin.iOS.Helpers;
using BeerDrinkin.AzureClient;
using BeerDrinkin.Core.Abstractions.Services;
using BeerDrinkin.iOS.Services;

namespace BeerDrinkin.iOS
{
Expand All @@ -27,6 +29,7 @@ public override bool FinishedLaunching (UIApplication application, NSDictionary
{
Core.ViewModels.ViewModelBase.Init();
ServiceLocator.Instance.Add<IAppInsights, AppInsights>();
ServiceLocator.Instance.Add<IDeviceSearchProvider, SpotlightService>();

#if DEBUG
Utils.Helpers.Settings.UserId = string.Empty;
Expand Down
2 changes: 2 additions & 0 deletions MobileApps/iOS/BeerDrinkin.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@
<Compile Include="View Controllers\CheckInViewController.designer.cs">
<DependentUpon>CheckInViewController.cs</DependentUpon>
</Compile>
<Compile Include="Services\SpotlightService.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<Import Project="..\packages\Xamarin.Insights.1.10.5\build\Xamarin.iOS10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.10.5\build\Xamarin.iOS10\Xamarin.Insights.targets')" />
Expand Down Expand Up @@ -820,5 +821,6 @@
<Folder Include="View Controllers\Misc\" />
<Folder Include="View Controllers\UserProfile\" />
<Folder Include="UITableViewCells\Discover\" />
<Folder Include="Services\" />
</ItemGroup>
</Project>
272 changes: 100 additions & 172 deletions MobileApps/iOS/Main.storyboard

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions MobileApps/iOS/Services/SpotlightService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using BeerDrinkin.Core.Abstractions.Services;
using BeerDrinkin.DataObjects;
using CoreSpotlight;
using Foundation;

namespace BeerDrinkin.iOS.Services
{
public class SpotlightService : IDeviceSearchProvider
{
public SpotlightService()
{
}

public void AddBeerToIndex(Beer beer)
{
var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails");

if (!string.IsNullOrEmpty(beer.Description))
{
var info = new NSMutableDictionary();
info.Add(new NSString("name"), new NSString(beer.Name));
info.Add(new NSString("description"), new NSString(beer.Description));

if (beer.Image.MediumUrl != null)
{
info.Add(new NSString("imageUrl"), new NSString(beer.Image.LargeUrl));
}

var attributes = new CSSearchableItemAttributeSet();
attributes.DisplayName = beer.Name;
attributes.ContentDescription = beer.Description;

var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") };
activity.Keywords = new NSSet<NSString>(keywords);
activity.ContentAttributeSet = attributes;

activity.Title = beer.Name;
activity.UserInfo = info;

activity.EligibleForSearch = true;
activity.EligibleForPublicIndexing = true;
activity.BecomeCurrent();
}

}
}
}

2 changes: 2 additions & 0 deletions MobileApps/iOS/UITableViewCells/BeerDescriptionCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public override void AwakeFromNib()
base.AwakeFromNib();

Helpers.Animator.GrowDivider(divider, this);

BackgroundColor = UIColor.Red;
}
}
}
Loading

0 comments on commit f9a435a

Please sign in to comment.