Skip to content

Commit

Permalink
Merge pull request #341 from rockfordlhotka/302-friends
Browse files Browse the repository at this point in the history
Implement Friends, closes #12, closes #302
  • Loading branch information
rockfordlhotka authored Jul 29, 2019
2 parents 60dbb3a + eca25b9 commit b946d79
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 112 deletions.
15 changes: 1 addition & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,4 @@ src/MCM.KidsIdApp/www/lib/ionic-datepicker
src/MCM.KidsIdApp.MobileApi/Web.Debug.config

# Mac OS Hidden directories
.DS_Store
src/.mfractor/MobileKidsId.PdfGenerationAppService.8309b5a6-93db-4c37-9fa6-a63a6206ae50.db

src/.mfractor/MobileKidsIdApp.Android.29ca5279-e40b-4987-bd02-f690670825c8.db

src/.mfractor/MobileKidsIdApp.c16814ae-85b2-4df5-89ab-957d6d68d946.db

src/.mfractor/MobileKidsIdApp.DataAccess.90a002bb-4cd4-42ba-bab6-56c8a2217e7e.db

src/.mfractor/MobileKidsIdApp.Models.a6d14000-2f57-46fa-9378-6a2f1a6713e9.db

src/.mfractor/MobileKidsIdApp.Models.Test.d4bf6e89-1418-43bd-be8b-f04f44dffeca.db

src/.mfractor/MobileKidsIdApp.UWP.10997245-a694-4ab3-9766-299f2ccd8f1c.db
.DS_Store
20 changes: 20 additions & 0 deletions src/MobileKidsIdApp.Models.Test/FriendsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,27 @@ public async Task FriendsPersistence()
child = family[0];
friend = child.Friends[0];
Assert.AreEqual("id", friend.ContactId, "ContactId");
}

[TestMethod]
public async Task RemoveFriend()
{
var family = await Csla.DataPortal.FetchAsync<Models.Family>();

var child = family.AddNew();
var friends = child.Friends;
var friend = friends.AddNew();

friend.ContactId = "id";

await family.SaveAndMergeAsync();

child = family[0];
friend = child.Friends[0];
child.Friends.Remove(friend);

await family.SaveAndMergeAsync();
Assert.AreEqual(0, child.Friends.Count, "Zero friends");
}
}
}
5 changes: 5 additions & 0 deletions src/MobileKidsIdApp.Models/CareProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,10 @@ private void Child_Update(List<DataAccess.DataModels.CareProvider> list)
}
list.Add(provider);
}

private void Child_DeleteSelf()
{
// do nothing - if we don't re-add this item it won't exist
}
}
}
2 changes: 1 addition & 1 deletion src/MobileKidsIdApp.Models/Child.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void Child_Update(List<DataAccess.DataModels.Child> list)
}
private void Child_DeleteSelf()
{

// do nothing - if we don't re-add this item it won't exist
}
}
}
5 changes: 5 additions & 0 deletions src/MobileKidsIdApp.Models/ChildDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,10 @@ private void Child_Update(DataAccess.DataModels.ChildDetails details)
details.ContactId = ContactId;
}
}

private void Child_DeleteSelf()
{
// do nothing - if we don't re-add this item it won't exist
}
}
}
5 changes: 5 additions & 0 deletions src/MobileKidsIdApp.Models/DistinguishingFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,10 @@ private void Child_Update(List<DataAccess.DataModels.DistinguishingFeature> list
list.Add(feature);
}
}

private void Child_DeleteSelf()
{
// do nothing - if we don't re-add this item it won't exist
}
}
}
5 changes: 5 additions & 0 deletions src/MobileKidsIdApp.Models/FamilyMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,10 @@ private void Child_Update(List<DataAccess.DataModels.FamilyMember> list)
list.Add(member);
}
}

private void Child_DeleteSelf()
{
// do nothing - if we don't re-add this item it won't exist
}
}
}
13 changes: 10 additions & 3 deletions src/MobileKidsIdApp.Models/Friend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ private void Child_Update(List<DataAccess.DataModels.Person> list)
{
using (BypassPropertyChecks)
{
var person = new DataAccess.DataModels.Person();
person.Id = Id;
person.ContactId = ContactId;
var person = new DataAccess.DataModels.Person
{
Id = Id,
ContactId = ContactId
};
list.Add(person);
}
}

private void Child_DeleteSelf()
{
// do nothing - if we don't re-add this item it won't exist
}
}
}
5 changes: 5 additions & 0 deletions src/MobileKidsIdApp.Models/PreparationChecklist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@ private void Child_Update(DataAccess.DataModels.PreparationChecklist list)
list.OtherParentsAndFamily = OtherParentsAndFamily;
}
}

private void Child_DeleteSelf()
{
// do nothing - if we don't re-add this item it won't exist
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.HumanitarianToolbox.KidsIdKit" android:installLocation="auto">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:label="Kids Id Kit" android:icon="@mipmap/icon"></application>
<application android:label="Kids Id Kit"></application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Android;

[assembly: Xamarin.Forms.Dependency(typeof(MobileKidsIdApp.Droid.Services.ContactPicker))]
namespace MobileKidsIdApp.Droid.Services
Expand All @@ -17,7 +18,7 @@ public Task<ContactInfo> GetSelectedContactInfo()
{
var tcs = new TaskCompletionSource<ContactInfo>();

Intent pickContactIntent =
var pickContactIntent =
new Intent(Intent.ActionPick, Android.Net.Uri.Parse("content://contacts"));
pickContactIntent.SetType(Android.Provider.ContactsContract.CommonDataKinds.Phone.ContentType); // Show user only contacts w/ phone numbers

Expand All @@ -34,11 +35,11 @@ public Task<ContactInfo> GetSelectedContactInfo()
}
return tcs.Task;
}

static int PICK_CONTACT_REQUEST = 42; // The request code

protected void OnActivityResult(TaskCompletionSource<ContactInfo> tcs, ActivityResultEventArgs e)
{
{
// Check which request it is that we're responding to
if (e.requestCode == PICK_CONTACT_REQUEST)
{
Expand All @@ -62,7 +63,7 @@ protected void OnActivityResult(TaskCompletionSource<ContactInfo> tcs, ActivityR
}

tcs.SetResult(null);
}
}

private ContactInfo GetContactInfoFromCursor(Android.Database.ICursor cursor)
{
Expand All @@ -87,24 +88,42 @@ private ContactInfo GetContactInfoFromCursor(Android.Database.ICursor cursor)

public Task<ContactInfo> GetContactInfoForId(string id)
{
var uri = Android.Net.Uri.WithAppendedPath(ContactsContract.Contacts.ContentLookupUri, id);

ContactInfo contact = null;
var cursor = Application.Context
.ContentResolver.Query(uri, projection, null, null, null);
if ((cursor != null) && (cursor.Count > 0))
if (UserHasContactPermission())
{
cursor.MoveToFirst();
while ((cursor != null) && (cursor.IsAfterLast == false))
var uri = Android.Net.Uri.WithAppendedPath(ContactsContract.Contacts.ContentLookupUri, id);

ContactInfo contact = null;
var cursor = Application.Context
.ContentResolver.Query(uri, projection, null, null, null);
if ((cursor != null) && (cursor.Count > 0))
{
contact = GetContactInfoFromCursor(cursor);
cursor.MoveToNext();
cursor.MoveToFirst();
while ((cursor != null) && (cursor.IsAfterLast == false))
{
contact = GetContactInfoFromCursor(cursor);
cursor.MoveToNext();
}
}
if (cursor != null)
cursor.Close();

return Task.FromResult(contact);
}
else
{
return Task.FromResult(default(ContactInfo));
}
if (cursor != null)
cursor.Close();

return Task.FromResult(contact);
}

private bool UserHasContactPermission()
{
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadContacts) != (int)Android.Content.PM.Permission.Granted)
Android.Support.V4.App.ActivityCompat.RequestPermissions(MainActivity.Instance, new string[] { Manifest.Permission.ReadContacts }, PICK_CONTACT_REQUEST);

if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadContacts) == (int)Android.Content.PM.Permission.Granted)
return true;
else
return false;
}
}
}
30 changes: 20 additions & 10 deletions src/MobileKidsIdApp/MobileKidsIdApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
See MCM Brand Inspriation Board for usage guidelines on color pallette.
https://github.com/HTBox/MobileKidsIdApp/blob/master/resources/inspiration-board-square-green.jpg
-->
<Color x:Key="MCM-White-1">#FFFFFF</Color>

<Color x:Key="MCM-DarkTeal-1">#084150</Color>
<Color x:Key="MCM-DarkTeal-2">#245e6b</Color>
<Color x:Key="MCM-DarkTeal-3">#437985</Color>
Expand Down Expand Up @@ -46,7 +48,7 @@
<!-- Navigation -->
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{StaticResource MCM-DarkTeal-2}"/>
<Setter Property="BarTextColor" Value="White"/>
<Setter Property="BarTextColor" Value="{StaticResource MCM-White-1}"/>
</Style>

<!-- Label -->
Expand Down Expand Up @@ -97,35 +99,43 @@
</Style>

<!-- Button -->
<Style TargetType="Button">
<Setter Property="TextColor" Value="White" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="BackgroundColor" Value="{StaticResource MCM-Orange-1}" />
</Style>
<Style x:Key="LoginButton" TargetType="Button">
<Setter Property="TextColor" Value="White" />
<Setter Property="TextColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="BackgroundColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="Margin" Value="25,5" />
</Style>
<Style x:Key="GridButton" TargetType="Button">
<Setter Property="TextColor" Value="White" />
<Setter Property="TextColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="BackgroundColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="Margin" Value="5" />
</Style>
<Style x:Key="InstructionButton" TargetType="Button">
<Setter Property="TextColor" Value="White" />
<Setter Property="TextColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="BackgroundColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="Margin" Value="25,5" />
</Style>
<Style x:Key="ChildProfileEditButton" TargetType="Button">
<Setter Property="TextColor" Value="White" />
<Setter Property="TextColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="BackgroundColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="Margin" Value="25,5" />
</Style>
<Style x:Key="ItemButton" TargetType="Button">
<Setter Property="BackgroundColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="TextColor" Value="{StaticResource MCM-Orange-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="FontSize" Value="Micro"/>
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
</Style>
<Style TargetType="Button">
<Setter Property="TextColor" Value="{StaticResource MCM-White-1}" />
<Setter Property="FontFamily" Value="{StaticResource BodyCustomFont}" />
<Setter Property="BackgroundColor" Value="{StaticResource MCM-Orange-1}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public class ContactInfo
public string FamilyName { get; set; }
public string AdditionalName { get; set; }
public string GivenName { get; set; }

}
}
27 changes: 27 additions & 0 deletions src/MobileKidsIdApp/MobileKidsIdApp/ViewModels/FriendInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;

namespace MobileKidsIdApp.ViewModels
{
public class FriendInfo
{
public FriendInfo(ContactInfo contact)
{
ContactId = contact.Id;
FamilyName = contact.FamilyName;
GivenName = contact.GivenName;
AdditionalName = contact.AdditionalName;

Display = $"{GivenName} {FamilyName}";
}

public string ContactId { get; }
public string FamilyName { get; }
public string GivenName { get; }
public string AdditionalName { get; }
public string Display { get; set; }
}
}
Loading

0 comments on commit b946d79

Please sign in to comment.