Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Created January 28, 2014 10:54
Show Gist options
  • Save wayne-o/8665602 to your computer and use it in GitHub Desktop.
Save wayne-o/8665602 to your computer and use it in GitHub Desktop.
DebugDialogController
public class DebugDialogController : DialogViewController
{
DebugFloatElement elem;
DebugViewModel vm;
public DebugDialogController(): base(null)
{
vm = new DebugViewModel();
ConfigureNavigationBar();
Root = new RootElement ("Settings") {
new Section ("Search User"){
CreateSearchUserSection()
},
new Section (){
CreateSearchTypeSection (),
},
new Section ("Results Type") {
CreateResultsTypeSection()
},
new Section ("Request Delay") {
CreateRequestDelaySection()
},
new Section ("Required Characters") {
new DebugEntryElement(string.Empty, string.Empty, vm.RequiredCharacters.ToString(), (s,e)=>{
vm.RequiredCharacters = Convert.ToInt32(((UITextField)s).Text);
}){
KeyboardType = UIKeyboardType.NumberPad,
}
},
new Section ("Max age of cache in seconds") {
new DebugEntryElement(string.Empty, string.Empty, vm.MaxCacheAge.ToString(),(s,e)=>{
vm.MaxCacheAge = Convert.ToInt32(((UITextField)s).Text);
}){
KeyboardType = UIKeyboardType.NumberPad,
}
},
new Section ("Add to sticky cache after this many hits") {
new DebugEntryElement(string.Empty, string.Empty, vm.StickyCache.ToString(),(s,e)=>{
vm.StickyCache = Convert.ToInt32(((UITextField)s).Text);
}){
KeyboardType = UIKeyboardType.NumberPad,
}
},
new Section ("RNumber of categories to display") {
new DebugEntryElement(string.Empty, string.Empty, vm.DisplayCategories.ToString(),(s,e)=>{
vm.DisplayCategories = Convert.ToInt32(((UITextField)s).Text);
}){
KeyboardType = UIKeyboardType.NumberPad,
}
},
new Section ("Search pagination page size") {
new DebugEntryElement(string.Empty, string.Empty, vm.PageSize.ToString(),(s,e)=>{
vm.PageSize = Convert.ToInt32(((UITextField)s).Text);
}){
KeyboardType = UIKeyboardType.NumberPad,
}
},
new Section ("Search cache database size") {
new StringElement(string.Empty, vm.DebugDbSize)
},
};
}
void ConfigureNavigationBar()
{
this.NavigationItem
.SetRightBarButtonItem (
new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender,args) => {
InvokeOnMainThread(()=> NavigationController.PopViewControllerAnimated(true));
}), true);
}
RootElement CreateSearchTypeSection ()
{
return new RootElement ("Search Type", new RadioGroup (vm.SearchPresentationType - 1)){
new Section (){
new DebugRadioElement("Categories & Products", (r, e) =>{vm.SearchPresentationType = 1;}),
new DebugRadioElement("Products Only", (r, e) =>{vm.SearchPresentationType = 2;})
}
};
}
RootElement CreateResultsTypeSection ()
{
return new RootElement ("Results Type", new RadioGroup (vm.SearchResultsType - 1)){
new Section (){
new DebugRadioElement("Text Only", (r, e) =>{vm.SearchResultsType = 1;}),
new DebugRadioElement("Images & Text", (r, e) =>{vm.SearchResultsType = 2;}),
new DebugRadioElement("Full Featured", (r, e) =>{vm.SearchResultsType = 3;}),
}
};
}
DebugFloatElement CreateRequestDelaySection()
{
return elem = new DebugFloatElement(50, lockable: false, valueChanged: (val) => SetRequestDelayValue(val) )
{
ShowCaption = true,
UseCaptionForValueDisplay = true,
ReserveCaptionPlaceholderString = "XXX",
};
}
RootElement CreateSearchUserSection()
{
return new RootElement("Search User")
{
new Section("Log in as")
{
new EntryElement("username", "username", null),
new EntryElement("password", "password", null),
new StyledStringElement("Save")
}
};
}
public void SetRequestDelayValue(int value){
elem.SetValue(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment