-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving spotlight into separate service
- Loading branch information
Mike James
committed
Jul 4, 2016
1 parent
b0e943c
commit f9a435a
Showing
12 changed files
with
242 additions
and
276 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
ClientSDKs/BeerDrinkin.Core.Abstractions/Services/IDeviceSearchProvider.cs
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
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); | ||
} | ||
} | ||
|
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
46 changes: 46 additions & 0 deletions
46
ClientSDKs/BeerDrinkin.Core/ViewModels/BeerDescriptionViewModel.cs
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
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"; | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
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
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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(); | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
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
Oops, something went wrong.