From 9c0cdd8c81b0dcf7738ef41d4f812f7c3ff6d9df Mon Sep 17 00:00:00 2001 From: Moritz Date: Sun, 11 Dec 2016 16:57:54 +0100 Subject: [PATCH] Bug fix #5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix resolves #5. “Android App does not show profile images” --- .../Frontend/Shared/HttpConferenceService.cs | 4 +-- .../Conference.Forms.Droid.csproj | 34 +++++++++++-------- .../DroidHttpService.cs | 31 +++++++++++++++++ .../EnvironmentVariables.txt | 1 + .../Properties/AndroidManifest.xml | 3 +- .../Conference.Forms/FormsHttpService.cs | 4 +-- .../Conference.Forms/MainPage.xaml.cs | 3 +- 7 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/DroidHttpService.cs create mode 100644 04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/EnvironmentVariables.txt diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Shared/HttpConferenceService.cs b/04 Speaker App with Xamarin.Forms/Code/Frontend/Shared/HttpConferenceService.cs index dd9a0e6..2d0bdeb 100644 --- a/04 Speaker App with Xamarin.Forms/Code/Frontend/Shared/HttpConferenceService.cs +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Shared/HttpConferenceService.cs @@ -19,14 +19,14 @@ public HttpConferenceService(IHttpService httpServiceImpl) public async Task> GetSessionsAsync() { - var json = await httpService.GetStringAsync("https://raw.githubusercontent.com/robinmanuelthiel/xamarinworkshop/master/06%20Speaker%20App%20with%20Xamarin.Forms/Mock/mocksessions.json"); + var json = await httpService.GetStringAsync("https://raw.githubusercontent.com/robinmanuelthiel/xamarinworkshop/master/04%20Speaker%20App%20with%20Xamarin.Forms/Mock/mocksessions.json"); var sessions = JsonConvert.DeserializeObject>(json); return sessions; } public async Task> GetSpeakersAsync() { - var json = await httpService.GetStringAsync("https://raw.githubusercontent.com/robinmanuelthiel/xamarinworkshop/master/06%20Speaker%20App%20with%20Xamarin.Forms/Mock/mockspeakers.json"); + var json = await httpService.GetStringAsync("https://raw.githubusercontent.com/robinmanuelthiel/xamarinworkshop/master/04%20Speaker%20App%20with%20Xamarin.Forms/Mock/mockspeakers.json"); var speakers = JsonConvert.DeserializeObject>(json); return speakers; } diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Conference.Forms.Droid.csproj b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Conference.Forms.Droid.csproj index 43752b8..0739c48 100644 --- a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Conference.Forms.Droid.csproj +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Conference.Forms.Droid.csproj @@ -48,10 +48,6 @@ SdkOnly - - ..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\FormsViewGroup.dll - True - @@ -95,27 +91,28 @@ ..\..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Vector.Drawable.dll True - - ..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Core.dll - True + + + ..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\FormsViewGroup.dll - - ..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Platform.dll - True + + ..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Core.dll - ..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll - True + ..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll + + + ..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Platform.dll - ..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll - True + ..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll + @@ -142,10 +139,17 @@ {f90fec10-353c-4800-b07a-796cef1fc60e} Conference.Forms + + {1CF6FBE3-1F39-43B1-8C91-A203CD44A934} + Conference.Frontend + + + + - + \ No newline at end of file diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/DroidHttpService.cs b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/DroidHttpService.cs new file mode 100644 index 0000000..aec9348 --- /dev/null +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/DroidHttpService.cs @@ -0,0 +1,31 @@ +using Conference.Frontend; +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Android.OS; + +[assembly: Xamarin.Forms.Dependency(typeof(Conference.Forms.Droid.DroidHttpService))] +namespace Conference.Forms.Droid +{ + public class DroidHttpService : IHttpService + { + private HttpClient httpClient; + + public DroidHttpService() + { + // HTTPS Fix + // see https://developer.xamarin.com/guides/cross-platform/transport-layer-security/ + httpClient = new HttpClient(new Xamarin.Android.Net.AndroidClientHandler()); + } + + public async Task GetStringAsync(string url) + { + // TEMP fix for NetWorkOnMainThread + // see http://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception + // and http://www.androiddesignpatterns.com/2012/06/app-force-close-honeycomb-ics.html + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build(); + StrictMode.SetThreadPolicy(policy); + return await httpClient.GetStringAsync(url); + } + } +} diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/EnvironmentVariables.txt b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/EnvironmentVariables.txt new file mode 100644 index 0000000..5c68b87 --- /dev/null +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/EnvironmentVariables.txt @@ -0,0 +1 @@ +XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler \ No newline at end of file diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Properties/AndroidManifest.xml b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Properties/AndroidManifest.xml index 1e51a07..b5d8904 100644 --- a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Properties/AndroidManifest.xml +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms.Droid/Properties/AndroidManifest.xml @@ -1,5 +1,6 @@  + - + \ No newline at end of file diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/FormsHttpService.cs b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/FormsHttpService.cs index fbc4683..e665543 100644 --- a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/FormsHttpService.cs +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/FormsHttpService.cs @@ -14,8 +14,8 @@ public FormsHttpService() httpClient = new HttpClient(new NativeMessageHandler()); } public async Task GetStringAsync(string url) - { - return await httpClient.GetStringAsync(url); + { + return await httpClient.GetStringAsync(url); } } } diff --git a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/MainPage.xaml.cs b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/MainPage.xaml.cs index 30eba54..9ab2651 100644 --- a/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/MainPage.xaml.cs +++ b/04 Speaker App with Xamarin.Forms/Code/Frontend/Xamarin.Forms/Conference.Forms/MainPage.xaml.cs @@ -18,7 +18,8 @@ public MainPage() { InitializeComponent(); - var httpService = new FormsHttpService(); + // var httpService = new FormsHttpService(); + var httpService = DependencyService.Get(); var conferenceService = new HttpConferenceService(httpService); viewModel = new MainViewModel(conferenceService);