-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.cs
More file actions
45 lines (35 loc) · 1.23 KB
/
MainActivity.cs
File metadata and controls
45 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace Colors
{
using System.Threading.Tasks;
using Android.App;
using Android.OS;
using Android.Support.V7.Widget;
using Android.Widget;
[Activity(Label = "Colors", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
private string testUrl = "https://gist.githubusercontent.com/jjdelc/1868136/raw/c9160b1e60bd8c10c03dbd1a61b704a8e977c46b/crayola.json";
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
await InitViewsAsync();
}
async Task InitViewsAsync()
{
var progressView = FindViewById<TextView>(Resource.Id.progress);
ColorsContainer colors = new ColorsContainer();
await colors.LoadAsync(testUrl,
(string info) =>
{
// in case of ConfigureAwait(false)
RunOnUiThread(() => progressView.Text = info);
}
);
progressView.Visibility = Android.Views.ViewStates.Gone;
var colorList = FindViewById<RecyclerView>(Resource.Id.colorList);
colorList.SetAdapter(new ColorsAdapter(colors));
colorList.SetLayoutManager(new GridLayoutManager(this, Resources.Configuration.Orientation == Android.Content.Res.Orientation.Portrait ? 2 : 4));
}
}
}