Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This fix resolves robinmanuelthiel#5. “Android App does not show profile images”
  • Loading branch information
Moritz authored and Moritz committed Dec 11, 2016
1 parent 8ae9486 commit 9c0cdd8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public HttpConferenceService(IHttpService httpServiceImpl)

public async Task<List<Session>> 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<List<Session>>(json);
return sessions;
}

public async Task<List<Speaker>> 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<List<Speaker>>(json);
return speakers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
</PropertyGroup>
<ItemGroup>
<Reference Include="FormsViewGroup">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down Expand Up @@ -95,27 +91,28 @@
<HintPath>..\..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Vector.Drawable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="System.Net.Http" />
<Reference Include="FormsViewGroup">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Platform.dll</HintPath>
<Private>True</Private>
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.Android">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Platform.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="DroidHttpService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand All @@ -142,10 +139,17 @@
<Project>{f90fec10-353c-4800-b07a-796cef1fc60e}</Project>
<Name>Conference.Forms</Name>
</ProjectReference>
<ProjectReference Include="..\..\Shared\Conference.Frontend.csproj">
<Project>{1CF6FBE3-1F39-43B1-8C91-A203CD44A934}</Project>
<Name>Conference.Frontend</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AndroidEnvironment Include="EnvironmentVariables.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
</Target>
<Import Project="..\..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets" Condition="Exists('..\..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" />
<Import Project="..\..\..\packages\Xamarin.Forms.2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\..\packages\Xamarin.Forms.2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
<Import Project="..\..\..\packages\Xamarin.Forms.2.3.3.175\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\..\packages\Xamarin.Forms.2.3.3.175\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -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<string> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XA_HTTP_CLIENT_HANDLER_TYPE=Xamarin.Android.Net.AndroidClientHandler
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="Conference.Forms.Droid"></application>
</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public FormsHttpService()
httpClient = new HttpClient(new NativeMessageHandler());
}
public async Task<string> GetStringAsync(string url)
{
return await httpClient.GetStringAsync(url);
{
return await httpClient.GetStringAsync(url);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public MainPage()
{
InitializeComponent();

var httpService = new FormsHttpService();
// var httpService = new FormsHttpService();
var httpService = DependencyService.Get<IHttpService>();
var conferenceService = new HttpConferenceService(httpService);
viewModel = new MainViewModel(conferenceService);

Expand Down

0 comments on commit 9c0cdd8

Please sign in to comment.