Skip to content

Instantly share code, notes, and snippets.

@RosiersRobin
Created November 26, 2017 20:30
Show Gist options
  • Save RosiersRobin/3e3edf4e8513d84e1bf22f082c85fe81 to your computer and use it in GitHub Desktop.
Save RosiersRobin/3e3edf4e8513d84e1bf22f082c85fe81 to your computer and use it in GitHub Desktop.
private async Task GeneratePage()
{
List<Folder> folders = await ApiManager.GetFoldersAsync();
ObservedFoldersList = new ObservableCollection<Folder>(folders);
// TEMPLATE
// Make a template for the view
var template = new DataTemplate(typeof(TextCell));
// Create a text-field (same as <Label /> in xaml).
// title is here the property of the class Lists
template.SetBinding(TextCell.TextProperty, "title");
// Set a color to the label.
template.SetValue(TextCell.TextColorProperty, Color.FromHex("#212121"));
// Make the splashscreen
ActivityIndicator actInd = new ActivityIndicator
{
IsRunning = true,
IsEnabled = true,
VerticalOptions = LayoutOptions.Center
};
ContentPage loadingPage = new ContentPage
{
Content = new Grid
{
Children =
{
actInd
}
}
};
// Generate the page
this.Children.Add(loadingPage);
// Loop trough the folders with var f
foreach (var f in ObservedFoldersList)
{
// Make a new List object for the lists in a folder
List<Lists> lists = new List<Lists>();
ObservedListsList = new ObservableCollection<Lists>(lists);
// Loop trough the ID's of the lists
foreach (int id in f.list_ids)
{
// Add the lists to the lists object using an async link.
ObservedListsList.Add(await ApiManager.GetSpecificListAsync(id));
}
// listview for the ContentPage
ListView lvwLists = new ListView
{
ItemsSource = ObservedListsList,
SeparatorVisibility = SeparatorVisibility.None,
// Here, we specify the template to be used (it's defined above of this) under the 'TEMPLATE' tag.
ItemTemplate = template
};
Button btn_add_new_list = new Button
{
Text = "Add a new list",
BackgroundColor = Color.FromHex("#5b7a59"),
TextColor = Color.FromHex("#FAFAFA"),
BorderRadius = 0,
Margin = new Thickness(20),
CommandParameter = f
};
// Event listeners
lvwLists.ItemSelected += LvwLists_ItemSelected;
btn_add_new_list.Clicked += Btn_add_new_list_Clicked;
ContentPage page = new ContentPage
{
Title = f.title,
Content = new StackLayout
{
Children =
{
lvwLists,
btn_add_new_list
}
}
};
// Generate the page
this.Children.Add(page);
}
this.Children.Remove(loadingPage);
actInd.IsRunning = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment