Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/profile #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions GroctaXP.Android/Extensions/CustomUrlSchemeInterceptorActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using GroctaXP.Models;

namespace GroctaXP.Droid
{
[Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[] { "https", "com.googleusercontent.apps.948349008811-s2teuqt9nb11md9hdon362f28k91bgou" },
DataPath = "/oauth2redirect")]
public class CustomUrlSchemeInterceptorActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

// Convert Android.Net.Url to Uri
var uri = new Uri(Intent.Data.ToString());

// Load redirectUrl page
AuthenticationState.Authenticator.OnPageLoading(uri);
var intent = new Intent(this, typeof(MainActivity));
intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
StartActivity(intent);

this.Finish();

return;
}
}
}
5 changes: 5 additions & 0 deletions GroctaXP.Android/GroctaXP.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@
<PackageReference Include="Xamarin.Forms" Version="4.6.0.800" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\CustomUrlSchemeInterceptorActivity.cs" />
<Compile Include="Extensions\Renderers\GroctaTabbedPageRenderer.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\DeviceInfo.cs" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\Celias-Medium.ttf" />
Expand Down Expand Up @@ -192,5 +194,8 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable\logo_grocta.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\btn_google_dark_normal_hdpi.9.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion GroctaXP.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override void OnCreate(Bundle savedInstanceState)

Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, savedInstanceState);
CachedImageRenderer.Init(true);
CachedImageRenderer.InitImageViewHandler();

Expand Down
2 changes: 2 additions & 0 deletions GroctaXP.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="GroctaXP.Android" android:icon="@drawable/logo_grocta"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
317 changes: 244 additions & 73 deletions GroctaXP.Android/Resources/Resource.designer.cs

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions GroctaXP.Android/Services/DeviceInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Telephony;
using Android.Views;
using Android.Widget;
using GroctaXP.Services;
using Xamarin.Forms;

[assembly: Dependency(typeof(GroctaXP.Droid.Services.DeviceInfo))]
namespace GroctaXP.Droid.Services
{

public class DeviceInfo : IDeviceInfo
{
public string GetMyPhoneNumber()
{
try
{
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)Android.App.Application.Context.GetSystemService(Context.TelephonyService);

var Number = mTelephonyMgr.Line1Number;
return Number;
}
catch (Exception ex)
{
return null;
}
}
}
}
3 changes: 2 additions & 1 deletion GroctaXP/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public App()

DependencyService.Register<MockDataStore>();
//MainPage = new MainPage();
MainPage = new MainPageTabbed();
// MainPage = new MainPageTabbed();
MainPage = new LoginPage();
}

protected override void OnStart()
Expand Down
5 changes: 5 additions & 0 deletions GroctaXP/GroctaXP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@

<ItemGroup>
<PackageReference Include="NControl.Controls" Version="0.9.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Xamarin.Auth" Version="1.7.0" />
<PackageReference Include="Xamarin.FFImageLoading.Svg.Forms" Version="2.4.11.982" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.800" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Views\LoginPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\MainPageTabbed.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
12 changes: 12 additions & 0 deletions GroctaXP/Models/AuthenticationState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Auth;

namespace GroctaXP.Models
{
public class AuthenticationState
{
public static OAuth2Authenticator Authenticator;
}
}
28 changes: 28 additions & 0 deletions GroctaXP/Models/FacebookUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GroctaXP.Models
{
public class FacebookEmail
{
public string Id { get; set; }
public string Name { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string Email { get; set; }
public Picture Picture { get; set; }
}

public class Picture
{
public Data Data { get; set; }
}
public class Data
{
public string Height { get; set; }
public string Is_Silhouette { get; set; }
public string Url { get; set; }
public string Width { get; set; }
}
}
38 changes: 38 additions & 0 deletions GroctaXP/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace GroctaXP.Models
{
[JsonObject]
public class User
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("email")]
public string Email { get; set; }

[JsonProperty("verified_email")]
public bool VerifiedEmail { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("given_name")]
public string GivenName { get; set; }

[JsonProperty("family_name")]
public string FamilyName { get; set; }

[JsonProperty("link")]
public string Link { get; set; }

[JsonProperty("picture")]
public string Picture { get; set; }

[JsonProperty("gender")]
public string Gender { get; set; }
}
}
43 changes: 43 additions & 0 deletions GroctaXP/Resources/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GroctaXP.Resources
{
public static class Constants
{
public static string AppName = "XamarinFormsLogin";

// Google OAuth
// For Google login, configure at https://console.developers.google.com/
public static string GoogleiOSClientId = "<insert IOS client ID here>";
public static string GoogleAndroidClientId = "948349008811-s2teuqt9nb11md9hdon362f28k91bgou.apps.googleusercontent.com";

// These values do not need changing
public static string GoogleScope = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";
public static string GoogleAuthorizeUrl = "https://accounts.google.com/o/oauth2/auth";
public static string GoogleAccessTokenUrl = "https://www.googleapis.com/oauth2/v4/token";
public static string GoogleUserInfoUrl = "https://www.googleapis.com/oauth2/v2/userinfo";

// Set these to reversed iOS/Android client ids, with :/oauth2redirect appended
public static string GoogleiOSRedirectUrl = "<insert IOS redirect URL here>:/oauth2redirect";
public static string GoogleAndroidRedirectUrl = "com.googleusercontent.apps.948349008811-s2teuqt9nb11md9hdon362f28k91bgou:/oauth2redirect";

//-------------------------------------------------------------------------------------------------------

// Facebook OAuth
// For Facebook login, configure at https://developers.facebook.com
public static string FacebookiOSClientId = "<insert IOS client ID here>";
public static string FacebookAndroidClientId = "377296112967592";

// These values do not need changing
public static string FacebookScope = "email";
public static string FacebookAuthorizeUrl = "https://www.facebook.com/dialog/oauth/";
public static string FacebookAccessTokenUrl = "https://www.facebook.com/connect/login_success.html";
public static string FacebookUserInfoUrl = "https://graph.facebook.com/me?fields=email&access_token={accessToken}";

// Set these to reversed iOS/Android client ids, with :/oauth2redirect appended
public static string FacebookiOSRedirectUrl = "<insert IOS redirect URL here>:/oauth2redirect";
public static string FacebookAndroidRedirectUrl = "https://www.facebook.com/connect/login_success.html";
}
}
11 changes: 11 additions & 0 deletions GroctaXP/Services/IDeviceInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GroctaXP.Services
{
public interface IDeviceInfo
{
string GetMyPhoneNumber();
}
}
17 changes: 17 additions & 0 deletions GroctaXP/Views/LoginPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"

x:Class="GroctaXP.Views.LoginPage">
<ContentPage.Content Title="Login">
<StackLayout BackgroundColor="{StaticResource ColorPrimaryDark}">
<Button Text="Sign in with Google" ImageSource="btn_google_dark_normal_hdpi.9.png"
HorizontalOptions="Center" BorderColor="White"
VerticalOptions="CenterAndExpand"
Clicked="OnGoogleLoginClicked" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Loading